le1t0-deprec 2.1.6.057 → 2.1.6.058

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/lib/deprec/recipes/app/passenger.rb +70 -18
  2. data/lib/deprec/recipes/iptables.rb +8 -9
  3. data/lib/deprec/recipes/profiles.rb +84 -0
  4. data/lib/deprec/recipes/redis.rb +2 -7
  5. data/lib/deprec/recipes/ruby/rvm.rb +75 -0
  6. data/lib/deprec/recipes/sphinx/thinking_sphinx.rb +3 -3
  7. data/lib/deprec/recipes/sphinx/ultrasphinx.rb +3 -3
  8. data/lib/deprec/recipes/syslog/syslog_ng.rb +6 -6
  9. data/lib/deprec/recipes/ubuntu.rb +35 -0
  10. data/lib/deprec/recipes/xen.rb +97 -29
  11. data/lib/deprec/recipes/xentools.rb +97 -58
  12. data/lib/deprec/templates/iptables/firewall-init.erb +141 -175
  13. data/lib/deprec/templates/passenger/passenger.conf.erb +1 -1
  14. data/lib/deprec/templates/redis/redis-conf.erb +225 -45
  15. data/lib/deprec/templates/ubuntu/getlibs.erb +599 -0
  16. data/lib/deprec/templates/xentools/{98-custom → 01-mount-devpts.erb} +2 -5
  17. data/lib/deprec/templates/xentools/98-custom.erb +42 -0
  18. data/lib/deprec/templates/xentools/99-devpts-umount.erb +14 -0
  19. data/lib/deprec/templates/xentools/kernel-img.conf.example.erb +10 -0
  20. data/lib/deprec/templates/xentools/update-grub-xenu.example.erb +4 -0
  21. data/lib/deprec/templates/xentools/xm.tmpl.erb +20 -48
  22. data/lib/deprec.rb +15 -1
  23. metadata +18 -13
  24. data/lib/deprec/recipes/rvm.rb +0 -32
  25. data/lib/deprec/templates/iptables/firewall-default.erb +0 -13
  26. data/lib/deprec/templates/xentools/100-ubuntu-setup +0 -26
  27. data/lib/deprec/templates/xentools/15-disable-hwclock +0 -40
  28. data/lib/deprec/templates/xentools/30-disable-gettys +0 -57
  29. data/lib/deprec/templates/xentools/31-ubuntu-setup +0 -32
  30. data/lib/deprec/templates/xentools/40-setup-networking +0 -145
  31. data/lib/deprec/templates/xentools/xen-tools.conf.erb +0 -278
@@ -2,185 +2,151 @@
2
2
  # Copyright 2009-2010 by le1t0@github. All rights reserved.
3
3
 
4
4
  PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
5
- DRYRUN="NO" # Set to exactly YES to enable dry runs
6
- IPTABLES="/sbin/iptables"
7
- IPTABLES_SAVE="/sbin/iptables-save"
8
- ENABLED=1
5
+ IPTABLES="<%= iptables_binary || "/sbin/iptables" %>"
6
+ IPTABLES_SAVE="<%= iptables_save_binary || "/sbin/iptables-save" %>"
9
7
 
10
8
  test -x $IPTABLES || exit 0
11
9
 
12
- if [ -e /etc/default/firewall ]; then
13
- . /etc/default/firewall
14
- fi
10
+ ### SET /PROC VARIABLES
11
+ # Kernel monitoring support
12
+ # More information:
13
+ # /usr/src/linux-`uname -r`/Documentation/networking/ip-sysctl.txt
14
+ # http://www.linuxgazette.com/book/view/1645
15
+ # http://www.spirit.com/Network/net0300.html
16
+ # http://www.symantec.com/connect/articles/linux-firewall-related-proc-entries
17
+
18
+ # Drop ICMP echo-request messages sent to broadcast or multicast addresses (Prevent Smurf attack)
19
+ echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
20
+
21
+ # Drop source routed packets (Prevent abuse of trust relationships/TCP Wrapper acls)
22
+ echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
23
+
24
+ # Enable TCP SYN cookie protection from SYN floods
25
+ echo 1 > /proc/sys/net/ipv4/tcp_syncookies
26
+
27
+ # Ignore invalid ICMP answers
28
+ echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
29
+
30
+ # Don't accept ICMP redirect messages (Prevent Man-In-The-Middle attacks)
31
+ echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
15
32
 
16
- test "$ENABLED" != "0" || exit 0
33
+ # Don't send ICMP redirect messages
34
+ echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects<% if iptables_ipfrag_high_thresh || iptables_ipfrag_low_thresh || iptables_ipfrag_time %>
35
+
36
+ # Prevent attack of many fragmented packets<% if iptables_ipfrag_high_thresh %>
37
+ echo <%= iptables_ipfrag_high_thresh %> > /proc/sys/net/ipv4/ipfrag_high_thresh # memory usage in bytes<% end %><% if iptables_ipfrag_low_thresh %>
38
+ echo <%= iptables_ipfrag_low_thresh %> > /proc/sys/net/ipv4/ipfrag_low_thresh # memory usage in bytes<% end %><% if iptables_ipfrag_time %>
39
+ echo <%= iptables_ipfrag_time %> > /proc/sys/net/ipv4/ipfrag_time<% end %><% end %>
40
+
41
+ # Enable source address spoofing protection
42
+ echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
43
+
44
+ # Log packets with impossible source addresses
45
+ echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
46
+
47
+ ### FLUSH RULES
48
+ if [ -x $IPTABLES_SAVE ]; then
49
+ tmpfile="/tmp/.firewall.save.$(date +"%Y%m%d%H%M%S").tmp"
50
+ # save current firewall FORWARD rules with physdev-in, these are necessary for the functioning of xen
51
+ $IPTABLES_SAVE -t filter | perl -ne "m/^-A FORWARD/ && m/physdev-in/ && print \"${IPTABLES} \" . \$_" > $tmpfile
52
+ fi
53
+ # flush default chains
54
+ $IPTABLES -F -t nat
55
+ $IPTABLES -F
56
+ # delete all custom chains
57
+ $IPTABLES -X
58
+ # source, re-apply and remove saved rules of above
59
+ if [ -x $IPTABLES_SAVE ]; then
60
+ . $tmpfile
61
+ rm -f $tmpfile
62
+ fi
17
63
 
18
- if [ "$DRYRUN" = "YES" ] ; then
19
- IPTABLES="echo ${IPTABLES}"
64
+ ### SET DEFAULT POLICIES
65
+ if [ "$1" = "stop" ] ; then
66
+ $IPTABLES --policy INPUT ACCEPT
67
+ $IPTABLES --policy OUTPUT ACCEPT
68
+ $IPTABLES --policy FORWARD ACCEPT
69
+ exit 0
70
+ else
71
+ $IPTABLES --policy INPUT DROP
72
+ $IPTABLES --policy OUTPUT ACCEPT
73
+ $IPTABLES --policy FORWARD ACCEPT
20
74
  fi
21
75
 
22
- [ -f /etc/default/rcS ] && . /etc/default/rcS
23
- . /lib/lsb/init-functions
24
-
25
- function flush_rules () {
26
- if [ -x $IPTABLES_SAVE ]; then
27
- tmpfile="/tmp/.firewall.save.$(date +"%Y%m%d%H%M%S").tmp"
28
- # save current firewall FORWARD rules with physdev-in, these are necessary for the functioning of xen
29
- $IPTABLES_SAVE -t filter | perl -ne "m/^-A FORWARD/ && m/physdev-in/ && print \"${IPTABLES} \" . \$_" > $tmpfile
30
- fi
31
- # flush default chains
32
- $IPTABLES -F -t nat
33
- $IPTABLES -F
34
- # delete all custom chains
35
- $IPTABLES -X
36
- # source, re-apply and remove saved rules of above
37
- if [ -x $IPTABLES_SAVE ]; then
38
- . $tmpfile
39
- rm -f $tmpfile
40
- fi
41
- }
42
-
43
- function define_forwards () {
44
- for forward in $forwards ; do {
45
- proto="$(echo $forward | cut -d ';' -f 2)"
46
- localip="$(echo $forward | cut -d '>' -f 1 | cut -d ':' -f 1)"
47
- srcport="$(echo $forward | cut -d '>' -f 1 | cut -d ':' -f 2)"
48
- destip="$(echo $forward | cut -d ';' -f 1 | cut -d '>' -f '2' | cut -d ':' -f 1)"
49
- destport="$(echo $forward | cut -d ';' -f 1 | cut -d '>' -f '2' | cut -d ':' -f 2)"
50
- # define forward in the nat chain, redirect to the destination IP and port
51
- $IPTABLES -t nat -A PREROUTING -p $proto -d $localip --dport $srcport -j DNAT --to $destip:$destport
52
- # allow access to the destination IP and port in the FORWARD chain
53
- $IPTABLES -A FORWARD -p $proto -d $destip --dport $destport -j ACCEPT
54
- } ; done
55
- }
56
-
57
- function set_default_policies () {
58
- $IPTABLES --policy INPUT $1
59
- $IPTABLES --policy OUTPUT $2
60
- $IPTABLES --policy FORWARD $3
61
- }
62
-
63
- function set_default_rules () {
64
- # Allow unlimited traffic on the loopback interface
65
- $IPTABLES -A INPUT -i lo -j ACCEPT
66
- $IPTABLES -A OUTPUT -o lo -j ACCEPT
67
-
68
- # Previously initiated and accepted exchanges bypass rule checking
69
- $IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
70
- # Allow unlimited outbound traffic
71
- $IPTABLES -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
72
- }
73
-
74
- # don't call parse_sources directly! It's called by set_allowed_rules
75
- function parse_sources () {
76
- # parse all sources
77
- for sourcedef in $1 ; do {
78
- # define targets for each source
79
- parse_targets "$2" "-s ${sourcedef}"
80
- } ; done
81
- }
82
-
83
- # don't call parse_targets directly! It's called by set_allowed_rules
84
- function parse_targets () {
85
- sourcedef="$2"
86
- # parse all targets
87
- for targetdef in $1 ; do {
88
- # targets should be define as:
89
- # protocol[,protocol[,...]][:port[,port[,...]]]
90
- protocols="$(echo $targetdef | awk -F ":" '{ print $1; }' | sed 's/,/ /g')"
91
- ports="$(echo $targetdef | awk -F ":" '{ print $2; }' | sed 's/,/ /g')"
92
- for protocol in ${protocols} ; do {
93
- # if no ports are defined, just allow access to the entire protocol (i.e. pptp, vrrp, etc)
94
- if [ -z "${ports}" ] ; then
95
- $IPTABLES -A INPUT -p ${protocol} ${sourcedef} -m state --state NEW -j ACCEPT ;
96
- else
97
- # for each defined port, allow access to the defined source or the world (if empty)
98
- for port in ${ports} ; do {
99
- OPT="--dport"
100
- [ "$protocol" = "icmp" ] && OPT="--icmp-type"
101
- $IPTABLES -A INPUT -p ${protocol} ${sourcedef} -m state --state NEW $OPT ${port} -j ACCEPT ;
102
- } ; done
103
- fi
104
- } ; done
105
- } ; done
106
- }
107
-
108
- function set_allowed_rules () {
109
- # all rules should be defined in one space separated variable called allowed
110
- for ruledef in ${allowed} ; do {
111
- # everything before the @ sign defines the target specification (i.e. IP + port or protocol to allow access to)
112
- # targets should be semi colon (;) separated (which are changed to spaces for easy parsing)
113
- target="$(echo $ruledef | awk -F "@" '{ print $1; }' | sed 's/;/ /g')"
114
- # everything after the @ sign defines the source specification (i.e. IP, etc from where the request is coming)
115
- # sources should be comma (,) separated (which are changed to spaces for easy parsing)
116
- source="$(echo $ruledef | awk -F "@" '{ print $2; }' | sed 's/,/ /g')"
117
- # if there is no source specification (allow entire world), then only define the target
118
- if [ -z "${source}" ] ; then
119
- parse_targets "$target"
120
- else # else define the source first
121
- parse_sources "$source" "$target"
122
- fi
123
- } ; done
124
- }
125
-
126
- function set_proc_variables () {
127
- # Kernel monitoring support
128
- # More information:
129
- # /usr/src/linux-`uname -r`/Documentation/networking/ip-sysctl.txt
130
- # http://www.linuxgazette.com/book/view/1645
131
- # http://www.spirit.com/Network/net0300.html
132
-
133
- # Drop ICMP echo-request messages sent to broadcast or multicast addresses
134
- echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
135
-
136
- # Drop source routed packets
137
- echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
138
-
139
- # Enable TCP SYN cookie protection from SYN floods
140
- echo 1 > /proc/sys/net/ipv4/tcp_syncookies
141
-
142
- # Don't accept ICMP redirect messages
143
- echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
144
-
145
- # Don't send ICMP redirect messages
146
- echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
147
-
148
- # Enable source address spoofing protection
149
- echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
150
-
151
- # Log packets with impossible source addresses
152
- echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
153
- }
154
-
155
- function firewall_start () {
156
- set_proc_variables
157
- flush_rules
158
- set_default_policies DROP ACCEPT ACCEPT
159
- define_forwards
160
- set_default_rules
161
- set_allowed_rules
162
- }
163
-
164
- function firewall_stop () {
165
- flush_rules
166
- set_default_policies ACCEPT ACCEPT ACCEPT
167
- }
168
-
169
- case "$1" in
170
- start)
171
- firewall_start
172
- ;;
173
- stop)
174
- firewall_stop
175
- ;;
176
- reload|force-reload)
177
- firewall_start
178
- ;;
179
- restart)
180
- firewall_start
181
- ;;
182
- *)
183
- echo "Usage: /etc/init.d/firewall {start|stop|reload|restart}"
184
- exit 3
185
- ;;
186
- esac
76
+ ### SET DEFAULT RULES
77
+ # Allow unlimited traffic on the loopback interface
78
+ $IPTABLES -A INPUT -i lo -j ACCEPT
79
+ $IPTABLES -A OUTPUT -o lo -j ACCEPT
80
+
81
+ # Previously initiated and accepted exchanges bypass rule checking
82
+ $IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
83
+ # Allow unlimited outbound traffic
84
+ $IPTABLES -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
85
+
86
+ # DROP/REJECT any traffic from known bad IPs
87
+ $IPTABLES -A INPUT -m recent --name droplist --update -j DROP
88
+ $IPTABLES -A INPUT -m recent --name rejectlist --update -j REJECT
89
+
90
+ ### SET RATE LIMITS
91
+ <% iptables_rate_limits.split(/ /).each do |rate_limit|
92
+ net, rate, action = rate_limit.split(/[@;]/).collect { |x| x.empty? ? nil : x }
93
+ action ||= "DROP"
94
+ dest, intfs = net.split(/[\#]/).collect { |x| x.empty? ? nil : x }
95
+ intfs_array = intfs ? intfs.split(/,/).map { |x| x.gsub(/^/, '-i ') } : [ "" ]
96
+ protos, ports, states = dest.split(/[:\[]/).collect { |x| x.empty? ? nil : x.gsub(/\]$/, '') }
97
+ states_opt = states ? "-m state --state #{states}" : ""
98
+ protos_array = protos.split(/,/)
99
+ ports_array = ports.split(/,/)
100
+ hitcount, seconds = rate.gsub(/^\</, '').split(/\//).collect { |x| x.empty? ? nil : x }
101
+ recent_action = rate =~ /^\</ ? "rcheck" : "update"
102
+ intfs_array.each do |intf| protos_array.each do |proto| ports_array.each do |port| list_name="#{proto}_#{port}#{intf.gsub(/^ -i/, '')}"
103
+ %>$IPTABLES -A INPUT <%= intf %> -p <%= proto %> --dport <%= port %> <%= states_opt %> -m recent --name <%= list_name %> --set
104
+ $IPTABLES -A INPUT <%= intf %> -p <%= proto %> --dport <%= port %> <%= states_opt %> -m recent --name <%= list_name %> --<%= recent_action %> --seconds <%= seconds %> --hitcount <%= hitcount %> -j <%= action %>
105
+ <% end ; end ; end ; end %>
106
+
107
+ ### DEFINE FORWARDS
108
+ <% iptables_forwards.split(/ /).each do |forward|
109
+ dest, fullsrc, protos = forward.split(/[\>;]/).collect { |x| x.empty? ? nil : x }
110
+ src, intf = fullsrc.split(/[\#]/).collect { |x| x.empty? ? nil : x }
111
+ opt_intf = intf ? "-i #{intf}" : ""
112
+ srcip, srcport = src.split(/:/).collect { |x| x.empty? ? nil : x }
113
+ opt_srcip = srcip ? "-d #{srcip}" : ""
114
+ opt_srcport = srcport ? "--dport #{srcport}" : ""
115
+ destip, destport = dest.split(/:/).collect { |x| x.empty? ? nil : x }
116
+ opt_destip = destip ? "-d #{destip}" : ""
117
+ opt_destport = destport ? "--dport #{destport}" : ""
118
+ protos_array = protos.split(/,/).collect { |x| x.empty? ? nil : x }
119
+ protos_array.each do |proto|
120
+ %>
121
+ # define forward in the nat chain, redirect to the destination IP and port
122
+ $IPTABLES -t nat -A PREROUTING -p <%= proto %> <%= opt_intf %> <%= opt_srcip %> <%= opt_srcport %> -j DNAT --to <%= destip %>:<%= destport %>
123
+ # allow access to the destination IP and port in the FORWARD chain
124
+ $IPTABLES -A FORWARD -p <%= proto %> <%= opt_intf %> <%= opt_destip %> <%= opt_destport %> -j ACCEPT
125
+ <% end ; end %>
126
+
127
+ ### SET_ALLOWED_RULES / SET_DROP_RULES / SET_REJECT_RULES
128
+ <% {
129
+ "-j ACCEPT" => iptables_allowed,
130
+ "-m recent --name droplist --set -j DROP" => iptables_drop,
131
+ "-m recent --name rejectlist --set -j REJECT" => iptables_reject
132
+ }.each do |action, rulesdef| rulesdef.each do |ruledef|
133
+ targetdef, sourcedef = ruledef.split(/@/).collect { |x| x.empty? ? nil : x }
134
+ sourcedefs = sourcedef ?
135
+ sourcedef.split(/,/).map do |x|
136
+ src, intf = x.split(/\#/).collect { |x| x.empty? ? nil : x }
137
+ opt_intf = intf ? "-i #{intf}" : nil
138
+ ["-s #{src}", opt_intf].compact.join(' ')
139
+ end : [ "" ]
140
+
141
+ targetdefs = targetdef ? targetdef.split(/;/).collect { |x| x.empty? ? nil : x }.compact : [ "" ]
142
+ sourcedefs.each do |src|
143
+ targetdefs.each do |target|
144
+ dest, intf = target.split(/[\#]/).collect { |x| x.empty? ? nil : x }
145
+ opt_intf = intf ? "-i #{intf}" : nil
146
+ protos = dest.split(/:/)[0].split(/,/)
147
+ ports = dest.split(/:/)[1]
148
+ ports_args = ports ? ports.split(/,/) : [ "" ]
149
+ protos.each do |proto| ports_opt = ports ? (proto == "icmp" ? "--icmp-type" : "--dport") : ""
150
+ ports.each do |port|
151
+ %>$IPTABLES -A INPUT -p <%= proto %> <%= opt_intf %> <%= src %> -m state --state NEW <%= ports_opt %> <%= port %> <%= action %>
152
+ <% end ; end ; end ; end ; end ; end %>
@@ -5,7 +5,7 @@
5
5
 
6
6
  PassengerRoot <%= passenger_install_dir %>
7
7
  PassengerLogLevel <%= passenger_log_level %>
8
- PassengerRuby /usr/local/bin/ruby
8
+ PassengerRuby <%= passenger_ruby %>
9
9
  PassengerUserSwitching <%= passenger_user_switching %>
10
10
  PassengerDefaultUser <%= passenger_default_user %>
11
11
  PassengerMaxPoolSize <%= passenger_max_pool_size %>