cloud-mu 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Berksfile +2 -1
  3. data/bin/mu-upload-chef-artifacts +3 -0
  4. data/cloud-mu.gemspec +2 -2
  5. data/cookbooks/firewall/CHANGELOG.md +295 -0
  6. data/cookbooks/firewall/CONTRIBUTING.md +2 -0
  7. data/cookbooks/firewall/MAINTAINERS.md +19 -0
  8. data/cookbooks/firewall/README.md +339 -0
  9. data/cookbooks/firewall/attributes/default.rb +5 -0
  10. data/cookbooks/firewall/attributes/firewalld.rb +1 -0
  11. data/cookbooks/firewall/attributes/iptables.rb +17 -0
  12. data/cookbooks/firewall/attributes/ufw.rb +12 -0
  13. data/cookbooks/firewall/attributes/windows.rb +8 -0
  14. data/cookbooks/firewall/libraries/helpers.rb +100 -0
  15. data/cookbooks/firewall/libraries/helpers_firewalld.rb +116 -0
  16. data/cookbooks/firewall/libraries/helpers_iptables.rb +112 -0
  17. data/cookbooks/firewall/libraries/helpers_ufw.rb +135 -0
  18. data/cookbooks/firewall/libraries/helpers_windows.rb +130 -0
  19. data/cookbooks/firewall/libraries/matchers.rb +30 -0
  20. data/cookbooks/firewall/libraries/provider_firewall_firewalld.rb +179 -0
  21. data/cookbooks/firewall/libraries/provider_firewall_iptables.rb +171 -0
  22. data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu.rb +196 -0
  23. data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu1404.rb +196 -0
  24. data/cookbooks/firewall/libraries/provider_firewall_rule.rb +34 -0
  25. data/cookbooks/firewall/libraries/provider_firewall_ufw.rb +138 -0
  26. data/cookbooks/firewall/libraries/provider_firewall_windows.rb +126 -0
  27. data/cookbooks/firewall/libraries/resource_firewall.rb +26 -0
  28. data/cookbooks/firewall/libraries/resource_firewall_rule.rb +52 -0
  29. data/cookbooks/firewall/metadata.json +1 -0
  30. data/cookbooks/firewall/recipes/default.rb +80 -0
  31. data/cookbooks/firewall/recipes/disable_firewall.rb +23 -0
  32. data/cookbooks/firewall/templates/default/ufw/default.erb +13 -0
  33. data/cookbooks/mu-firewall/metadata.rb +1 -1
  34. data/cookbooks/mu-master/recipes/default.rb +3 -1
  35. data/cookbooks/mu-master/recipes/init.rb +3 -1
  36. data/cookbooks/mu-master/templates/default/mu.rc.erb +3 -0
  37. data/cookbooks/mu-tools/recipes/apply_security.rb +2 -2
  38. data/cookbooks/mu-tools/recipes/aws_api.rb +1 -1
  39. data/cookbooks/mu-tools/recipes/base_repositories.rb +1 -1
  40. data/cookbooks/mu-tools/recipes/clamav.rb +1 -1
  41. data/cookbooks/mu-tools/recipes/cloudinit.rb +1 -1
  42. data/cookbooks/mu-tools/recipes/disable-requiretty.rb +2 -2
  43. data/cookbooks/mu-tools/recipes/eks.rb +1 -1
  44. data/cookbooks/mu-tools/recipes/gcloud.rb +1 -1
  45. data/cookbooks/mu-tools/recipes/nrpe.rb +1 -1
  46. data/cookbooks/mu-tools/recipes/rsyslog.rb +2 -2
  47. data/cookbooks/mu-tools/recipes/set_local_fw.rb +37 -28
  48. data/environments/dev.json +1 -1
  49. data/environments/prod.json +1 -1
  50. data/modules/mu/cleanup.rb +4 -0
  51. data/modules/mu/clouds/aws/container_cluster.rb +3 -0
  52. data/modules/mu/clouds/aws/role.rb +14 -2
  53. data/modules/mu/clouds/aws/userdata/linux.erb +2 -3
  54. data/modules/mu/clouds/aws.rb +30 -14
  55. data/modules/mu.rb +4 -0
  56. metadata +30 -2
@@ -0,0 +1,138 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Cookbook:: firewall
4
+ # Resource:: default
5
+ #
6
+ # Copyright:: 2011-2016, Chef Software, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ class Chef
21
+ class Provider::FirewallUfw < Chef::Provider::LWRPBase
22
+ include FirewallCookbook::Helpers::Ufw
23
+
24
+ provides :firewall, os: 'linux', platform_family: %w(debian) do |node|
25
+ !(node['firewall'] && node['firewall']['ubuntu_iptables'])
26
+ end
27
+
28
+ def whyrun_supported?
29
+ false
30
+ end
31
+
32
+ def action_install
33
+ return if disabled?(new_resource)
34
+
35
+ pkg_ufw = package 'ufw' do
36
+ action :nothing
37
+ end
38
+ pkg_ufw.run_action(:install)
39
+ new_resource.updated_by_last_action(true) if pkg_ufw.updated_by_last_action?
40
+
41
+ defaults_ufw = template '/etc/default/ufw' do
42
+ action :nothing
43
+ owner 'root'
44
+ group 'root'
45
+ mode '0644'
46
+ source 'ufw/default.erb'
47
+ cookbook 'firewall'
48
+ end
49
+ defaults_ufw.run_action(:create)
50
+ new_resource.updated_by_last_action(true) if defaults_ufw.updated_by_last_action?
51
+
52
+ return if ::File.exist?(ufw_rules_filename)
53
+
54
+ ufw_file = lookup_or_create_rulesfile
55
+ ufw_file.content '# created by chef to allow service to start'
56
+ ufw_file.run_action(:create)
57
+
58
+ new_resource.updated_by_last_action(true) if ufw_file.updated_by_last_action?
59
+ end
60
+
61
+ def action_restart
62
+ return if disabled?(new_resource)
63
+
64
+ # ensure it's initialized
65
+ new_resource.rules({}) unless new_resource.rules
66
+ new_resource.rules['ufw'] = {} unless new_resource.rules['ufw']
67
+
68
+ # this populates the hash of rules from firewall_rule resources
69
+ firewall_rules = Chef.run_context.resource_collection.select { |item| item.is_a?(Chef::Resource::FirewallRule) }
70
+ firewall_rules.each do |firewall_rule|
71
+ next unless firewall_rule.action.include?(:create) && !firewall_rule.should_skip?(:create)
72
+
73
+ # build rules to apply with weight
74
+ k = build_rule(firewall_rule)
75
+ v = firewall_rule.position
76
+
77
+ # unless we're adding them for the first time.... bail out.
78
+ unless new_resource.rules['ufw'].key?(k) && new_resource.rules['ufw'][k] == v
79
+ new_resource.rules['ufw'][k] = v
80
+ end
81
+ end
82
+
83
+ # ensure a file resource exists with the current ufw rules
84
+ ufw_file = lookup_or_create_rulesfile
85
+ ufw_file.content build_rule_file(new_resource.rules['ufw'])
86
+ ufw_file.run_action(:create)
87
+
88
+ # if the file was changed, restart iptables
89
+ return unless ufw_file.updated_by_last_action?
90
+ ufw_reset!
91
+ ufw_logging!(new_resource.log_level) if new_resource.log_level
92
+
93
+ new_resource.rules['ufw'].sort_by { |_k, v| v }.map { |k, _v| k }.each do |cmd|
94
+ ufw_rule!(cmd)
95
+ end
96
+
97
+ # ensure it's enabled _after_ rules are inputted, to catch malformed rules
98
+ ufw_enable! unless ufw_active?
99
+ new_resource.updated_by_last_action(true)
100
+ end
101
+
102
+ def action_disable
103
+ return if disabled?(new_resource)
104
+
105
+ ufw_file = lookup_or_create_rulesfile
106
+ ufw_file.content '# created by chef to allow service to start'
107
+ ufw_file.run_action(:create)
108
+ new_resource.updated_by_last_action(true) if ufw_file.updated_by_last_action?
109
+
110
+ return unless ufw_active?
111
+ ufw_disable!
112
+ new_resource.updated_by_last_action(true)
113
+ end
114
+
115
+ def action_flush
116
+ return if disabled?(new_resource)
117
+
118
+ ufw_reset!
119
+ new_resource.updated_by_last_action(true)
120
+
121
+ ufw_file = lookup_or_create_rulesfile
122
+ ufw_file.content '# created by chef to allow service to start'
123
+ ufw_file.run_action(:create)
124
+ new_resource.updated_by_last_action(true) if ufw_file.updated_by_last_action?
125
+ end
126
+
127
+ def lookup_or_create_rulesfile
128
+ begin
129
+ ufw_file = Chef.run_context.resource_collection.find(file: ufw_rules_filename)
130
+ rescue
131
+ ufw_file = file ufw_rules_filename do
132
+ action :nothing
133
+ end
134
+ end
135
+ ufw_file
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,126 @@
1
+ #
2
+ # Author:: Sander van Harmelen (<svanharmelen@schubergphilis.com>)
3
+ # Cookbook:: firewall
4
+ # Provider:: windows
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Chef
20
+ class Provider::FirewallWindows < Chef::Provider::LWRPBase
21
+ include FirewallCookbook::Helpers::Windows
22
+
23
+ provides :firewall, os: 'windows'
24
+
25
+ def whyrun_supported?
26
+ false
27
+ end
28
+
29
+ def action_install
30
+ return if disabled?(new_resource)
31
+
32
+ svc = service 'MpsSvc' do
33
+ action :nothing
34
+ end
35
+
36
+ [:enable, :start].each do |act|
37
+ svc.run_action(act)
38
+ new_resource.updated_by_last_action(true) if svc.updated_by_last_action?
39
+ end
40
+ end
41
+
42
+ def action_restart
43
+ return if disabled?(new_resource)
44
+
45
+ # ensure it's initialized
46
+ new_resource.rules({}) unless new_resource.rules
47
+ new_resource.rules['windows'] = {} unless new_resource.rules['windows']
48
+
49
+ firewall_rules = Chef.run_context.resource_collection.select { |item| item.is_a?(Chef::Resource::FirewallRule) }
50
+ firewall_rules.each do |firewall_rule|
51
+ next unless firewall_rule.action.include?(:create) && !firewall_rule.should_skip?(:create)
52
+
53
+ # build rules to apply with weight
54
+ k = build_rule(firewall_rule)
55
+ v = firewall_rule.position
56
+
57
+ # unless we're adding them for the first time.... bail out.
58
+ unless new_resource.rules['windows'].key?(k) && new_resource.rules['windows'][k] == v
59
+ new_resource.rules['windows'][k] = v
60
+ end
61
+ end
62
+
63
+ input_policy = node['firewall']['windows']['defaults']['policy']['input']
64
+ output_policy = node['firewall']['windows']['defaults']['policy']['output']
65
+ unless new_resource.rules['windows'].key?("set currentprofile firewallpolicy #{input_policy},#{output_policy}")
66
+ # Make this the possible last rule in the list
67
+ new_resource.rules['windows']["set currentprofile firewallpolicy #{input_policy},#{output_policy}"] = 99999
68
+ end
69
+
70
+ # ensure a file resource exists with the current rules
71
+ begin
72
+ windows_file = Chef.run_context.resource_collection.find(file: windows_rules_filename)
73
+ rescue
74
+ windows_file = file windows_rules_filename do
75
+ action :nothing
76
+ end
77
+ end
78
+ windows_file.content build_rule_file(new_resource.rules['windows'])
79
+ windows_file.run_action(:create)
80
+
81
+ # if the file was changed, restart iptables
82
+ return unless windows_file.updated_by_last_action?
83
+
84
+ disable! if active?
85
+ delete_all_rules! # clear entirely
86
+ reset! # populate default rules
87
+
88
+ new_resource.rules['windows'].sort_by { |_k, v| v }.map { |k, _v| k }.each do |cmd|
89
+ add_rule!(cmd)
90
+ end
91
+ # ensure it's enabled _after_ rules are inputted, to catch malformed rules
92
+ enable! unless active?
93
+
94
+ new_resource.updated_by_last_action(true)
95
+ end
96
+
97
+ def action_disable
98
+ return if disabled?(new_resource)
99
+
100
+ if active?
101
+ disable!
102
+ Chef::Log.info("#{new_resource} disabled.")
103
+ new_resource.updated_by_last_action(true)
104
+ else
105
+ Chef::Log.debug("#{new_resource} already disabled.")
106
+ end
107
+
108
+ svc = service 'MpsSvc' do
109
+ action :nothing
110
+ end
111
+
112
+ [:disable, :stop].each do |act|
113
+ svc.run_action(act)
114
+ new_resource.updated_by_last_action(true) if svc.updated_by_last_action?
115
+ end
116
+ end
117
+
118
+ def action_flush
119
+ return if disabled?(new_resource)
120
+
121
+ reset!
122
+ Chef::Log.info("#{new_resource} reset.")
123
+ new_resource.updated_by_last_action(true)
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,26 @@
1
+ class Chef
2
+ class Resource::Firewall < Chef::Resource::LWRPBase
3
+ resource_name(:firewall)
4
+ provides(:firewall)
5
+ actions(:install, :restart, :disable, :flush, :save)
6
+ default_action(:install)
7
+
8
+ # allow both kinds of logic -- eventually remove the :disabled one.
9
+ # the positive logic is much easier to follow.
10
+ attribute(:disabled, kind_of: [TrueClass, FalseClass], default: false)
11
+ attribute(:enabled, kind_of: [TrueClass, FalseClass], default: true)
12
+
13
+ attribute(:log_level, kind_of: Symbol, equal_to: [:low, :medium, :high, :full, :off], default: :low)
14
+ attribute(:rules, kind_of: Hash)
15
+
16
+ # for firewalld, specify the zone when firewall is disable and enabled
17
+ attribute(:disabled_zone, kind_of: Symbol, default: :public)
18
+ attribute(:enabled_zone, kind_of: Symbol, default: :drop)
19
+
20
+ # for firewall implementations where ipv6 can be skipped (currently iptables-specific)
21
+ attribute(:ipv6_enabled, kind_of: [TrueClass, FalseClass], default: true)
22
+
23
+ # allow override of package options for firewalld package
24
+ attribute(:package_options, kind_of: String, default: nil)
25
+ end
26
+ end
@@ -0,0 +1,52 @@
1
+ require 'ipaddr'
2
+
3
+ class Chef
4
+ class Resource::FirewallRule < Chef::Resource::LWRPBase
5
+ include FirewallCookbook::Helpers
6
+
7
+ resource_name(:firewall_rule)
8
+ provides(:firewall_rule)
9
+ actions(:create)
10
+ default_action(:create)
11
+
12
+ attribute(:firewall_name, kind_of: String, default: 'default')
13
+
14
+ attribute(:command, kind_of: Symbol, equal_to: [:reject, :allow, :deny, :masquerade, :redirect, :log], default: :allow)
15
+
16
+ attribute(:protocol, kind_of: [Integer, Symbol], default: :tcp,
17
+ callbacks: { 'must be either :tcp, :udp, :icmp, :\'ipv6-icmp\', :icmpv6, :none, or a valid IP protocol number' => lambda do |p|
18
+ !!(p.to_s =~ /(udp|tcp|icmp|icmpv6|ipv6-icmp|esp|ah|ipv6|none)/ || (p.to_s =~ /^\d+$/ && p.between?(0, 142)))
19
+ end })
20
+ attribute(:direction, kind_of: Symbol, equal_to: [:in, :out, :pre, :post], default: :in)
21
+ attribute(:logging, kind_of: Symbol, equal_to: [:connections, :packets])
22
+
23
+ attribute(:source, callbacks: { 'must be a valid ip address' => ->(ip) { !!IPAddr.new(ip) } })
24
+ attribute(:source_port, kind_of: [Integer, Array, Range]) # source port
25
+ attribute(:interface, kind_of: String)
26
+
27
+ attribute(:port, kind_of: [Integer, Array, Range]) # shorthand for dest_port
28
+ attribute(:destination, callbacks: { 'must be a valid ip address' => ->(ip) { !!IPAddr.new(ip) } })
29
+ attribute(:dest_port, kind_of: [Integer, Array, Range])
30
+ attribute(:dest_interface, kind_of: String)
31
+
32
+ attribute(:position, kind_of: Integer, default: 50)
33
+ attribute(:stateful, kind_of: [Symbol, Array])
34
+ attribute(:redirect_port, kind_of: Integer)
35
+ attribute(:description, kind_of: String, name_attribute: true)
36
+ attribute(:include_comment, kind_of: [TrueClass, FalseClass], default: true)
37
+
38
+ # only used for firewalld
39
+ attribute(:permanent, kind_of: [TrueClass, FalseClass], default: false)
40
+
41
+ # only used for Windows Firewalls
42
+ attribute(:program, kind_of: String)
43
+ attribute(:service, kind_of: String)
44
+
45
+ # for when you just want to pass a raw rule
46
+ attribute(:raw, kind_of: String)
47
+
48
+ # do you want this rule to notify the firewall to recalculate
49
+ # (and potentially reapply) the firewall_rule(s) it finds?
50
+ attribute(:notify_firewall, kind_of: [TrueClass, FalseClass], default: true)
51
+ end
52
+ end
@@ -0,0 +1 @@
1
+ {"name":"firewall","version":"2.7.1","description":"Provides a set of primitives for managing firewalls and associated rules.","long_description":"firewall Cookbook\n=================\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/firewall.svg?branch=master)](http://travis-ci.org/chef-cookbooks/firewall)\n[![Cookbook Version](https://img.shields.io/cookbook/v/firewall.svg)](https://supermarket.chef.io/cookbooks/firewall)\n\nProvides a set of primitives for managing firewalls and associated rules.\n\nPLEASE NOTE - The resource/providers in this cookbook are under heavy development. An attempt is being made to keep the resource simple/stupid by starting with less sophisticated firewall implementations first and refactor/vet the resource definition with each successive provider.\n\nRequirements\n------------\n**Chef 12.5.x+** is required. We are currently testing against Chef 13. If you need Chef 11 support, please try pinning back to a version less than 2.0, e.g.:\n```\ndepends 'firewall', '< 2.0'\n```\n\n### Supported firewalls and platforms\n* UFW - Ubuntu, Debian (except 9)\n* IPTables - Red Hat & CentOS, Ubuntu\n* FirewallD - Red Hat & CentOS >= 7.0 (IPv4 only support, [needs contributions/testing](https://github.com/chef-cookbooks/firewall/issues/86))\n* Windows Advanced Firewall - 2012 R2\n\nTested on:\n* Ubuntu 14.04, 16.04 with iptables, ufw\n* Debian 7, 8 with ufw\n* Debian 9 with iptables\n* CentOS 6 with iptables\n* CentOS 7.1 with firewalld\n* Windows Server 2012r2 with Windows Advanced Firewall\n\nBy default, Ubuntu chooses ufw. To switch to iptables, set this in an attribute file:\n```\ndefault['firewall']['ubuntu_iptables'] = true\n```\n\nBy default, Red Hat & CentOS >= 7.0 chooses firewalld. To switch to iptables, set this in an attribute file:\n```\ndefault['firewall']['redhat7_iptables'] = true\n```\n\n# Considerations that apply to all firewall providers and resources\n\nThis cookbook comes with two resources, firewall and firewall rule. The typical usage scenario is as follows:\n\n- run the `:install` action on the `firewall` resource named 'default', which installs appropriate packages and configures services to start on boot and starts them\n\n- run the `:create` action on every `firewall_rule` resource, which adds to the list of rules that should be configured on the firewall. `firewall_rule` then automatically sends a delayed notification to the `firewall['default']` resource to run the `:restart` action.\n\n- run the delayed notification with action `:restart` on the `firewall` resource. if any rules are different than the last run, the provider will update the current state of the firewall rules to match the expected rules.\n\nThere is a fundamental mismatch between the idea of a chef action and the action that should be taken on a firewall rule. For this reason, the chef action for a firewall_rule may be `:nothing` (the rule should not be present in the firewall) or `:create` (the rule should be present in the firewall), but the action taken on a packet in a firewall (`DROP`, `ACCEPT`, etc) is denoted as a `command` parameter on the `firewall_rule` resource.\n\n# iptables considerations\n\nIf you need to use a table other than `*filter`, the best way to do so is like so:\n```\nnode.default['firewall']['iptables']['defaults'][:ruleset] = {\n '*filter' => 1,\n ':INPUT DROP' => 2,\n ':FORWARD DROP' => 3,\n ':OUTPUT ACCEPT_FILTER' => 4,\n 'COMMIT_FILTER' => 100,\n '*nat' => 101,\n ':PREROUTING DROP' => 102,\n ':POSTROUTING DROP' => 103,\n ':OUTPUT ACCEPT_NAT' => 104,\n 'COMMIT_NAT' => 200\n}\n```\n\nNote -- in order to support multiple hash keys containing the same rule, anything found after the underscore will be stripped for: `:OUTPUT :INPUT :POSTROUTING :PREROUTING COMMIT`. This allows an example like the above to be reduced to just repeated lines of `COMMIT` and `:OUTPUT ACCEPT` while still avoiding duplication of other things.\n\nThen it's trivial to add additional rules to the `*nat` table using the raw parameter:\n```\nfirewall_rule \"postroute\" do\n raw \"-A POSTROUTING -o eth1 -p tcp -d 172.28.128.21 -j SNAT --to-source 172.28.128.6\"\n position 150\nend\n```\n\nNote that any line starting with `COMMIT` will become just `COMMIT`, as hash\nkeys must be unique but we need multiple commit lines.\n\n# Recipes\n\n### default\nThe default recipe creates a firewall resource with action install.\n\n### disable_firewall\nUsed to disable platform specific firewall. Many clouds have their own firewall configured outside of the OS instance such as AWS Security Groups.\n\n# Attributes\n\n* `default['firewall']['allow_ssh'] = false`, set true to open port 22 for SSH when the default recipe runs\n* `default['firewall']['allow_mosh'] = false`, set to true to open UDP ports 60000 - 61000 for [Mosh][0] when the default recipe runs\n* `default['firewall']['allow_winrm'] = false`, set true to open port 5989 for WinRM when the default recipe runs\n* `default['firewall']['allow_loopback'] = false`, set to true to allow all traffic on the loopback interface\n* `default['firewall']['allow_icmp'] = false`, set true to allow icmp protocol on supported OSes (note: ufw and windows implementations don't support this)\n\n* `default['firewall']['ubuntu_iptables'] = false`, set to true to use iptables on Ubuntu / Debian when using the default recipe\n* `default['firewall']['redhat7_iptables'] = false`, set to true to use iptables on Red Hat / CentOS 7 when using the default recipe\n\n* `default['firewall']['ufw']['defaults']` hash for template `/etc/default/ufw`\n* `default['firewall']['iptables']['defaults']` hash for default policies for 'filter' table's chains`\n\n* `default['firewall']['windows']['defaults']` hash to define inbound / outbound firewall policy on Windows platform\n\n* `default['firewall']['allow_established'] = true`, set to false if you don't want a related/established default rule on iptables\n* `default['firewall']['ipv6_enabled'] = true`, set to false if you don't want IPv6 related/established default rule on iptables (this enables ICMPv6, which is required for much of IPv6 communication)\n\n* `default['firewall']['firewalld']['permanent'] = false`, set to true if you want firewalld rules to be added with `--permanent` so they survive a reboot. This will be changed to `true` by default in a future major version release.\n\n# Resources\n\n### firewall\n\n***NB***: The name 'default' of this resource is important as it is used for firewall_rule providers to locate the firewall resource. If you change it, you must also supply the same value to any firewall_rule resources using the `firewall_name` parameter.\n\n#### Actions\n- `:install` (*default action*): Install and Enable the firewall. This will ensure the appropriate packages are installed and that any services have been started.\n- `:disable`: Disable the firewall. Drop any rules and put the node in an unprotected state. Flush all current rules. Also erase any internal state used to detect when rules should be applied.\n- `:flush`: Flush all current rules. Also erase any internal state used to detect when rules should be applied.\n- `:save`: Ensure all rules are added permanently under firewalld using `--permanent`. Not supported on ufw, iptables. You must notify this action at the end of the chef run if you want permanent firewalld rules (they are not persistent by default).\n\n#### Parameters\n\n- `disabled` (default to `false`): If set to true, all actions will no-op on this resource. This is a way to prevent included cookbooks from configuring a firewall.\n- `ipv6_enabled` (default to `true`): If set to false, firewall will not perform any ipv6 related work. Currently only supported in iptables.\n- `log_level`: UFW only. Level of verbosity the firewall should log at. valid values are: :low, :medium, :high, :full, :off. default is :low.\n- `rules`: This is used internally for firewall_rule resources to append their rules. You should NOT touch this value unless you plan to supply an entire firewall ruleset at once, and skip using firewall_rule resources.\n- `disabled_zone` (firewalld only): The zone to set on firewalld when the firewall should be disabled. Can be any string in symbol form, e.g. :public, :drop, etc. Defaults to `:public.`\n- `enabled_zone` (firewalld only): The zone to set on firewalld when the firewall should be enabled. Can be any string in symbol form, e.g. :public, :drop, etc. Defaults to `:drop.`\n- `package_options`: Used to pass options to the package install of firewall\n\n#### Examples\n\n```ruby\n# all defaults\nfirewall 'default'\n\n# enable platform default firewall\nfirewall 'default' do\n action :install\nend\n\n# increase logging past default of 'low'\nfirewall 'default' do\n log_level :high\n action :install\nend\n```\n\n### firewall_rule\n\n#### Actions\n- `:create` (_default action_): If a firewall_rule runs this action, the rule will be recorded in a chef resource's internal state, and applied when providers automatically notify the firewall resource with action `:reload`. The notification happens automatically.\n\n#### Parameters\n\n- `firewall_name`: the matching firewall resource that this rule applies to. Default value: `default`\n\n- `raw`: Used to pass an entire rule as a string, omitting all other parameters. This line will be directly loaded by `iptables-restore`, fed directly into `ufw` on the command line, or run using `firewall-cmd`.\n\n- `description` (_default: same as rule name_): Used to provide a comment that will be included when adding the firewall rule.\n\n- `include_comment` (_default: true_): Used to optionally exclude the comment in the rule.\n\n- `position` (_default: 50_): **relative** position to insert rule at. Position may be any integer between 0 < n < 100 (exclusive), and more than one rule may specify the same position.\n\n- `command`: What action to take on a particular packet\n\n - `:allow` (_default action_): the rule should allow matching packets\n - `:deny`: the rule should deny matching packets\n - `:reject`: the rule should reject matching packets\n - `:masqerade`: Masquerade the matching packets\n - `:redirect`: Redirect the matching packets\n - `:log`: Configure logging\n\n- `stateful`: a symbol or array of symbols, such as ``[:related, :established]` that will be passed to the state module in iptables or firewalld.\n\n- `protocol`: `:tcp` (_default_), `:udp`, `:icmp`, `:none` or protocol number. Using protocol numbers is not supported using the ufw provider (default for debian/ubuntu systems).\n\n- `direction`: For ufw, direction of the rule. valid values are: `:in` (_default_), `:out`, `:pre`, `:post`.\n\n- `source` (_Default is `0.0.0.0/0` or `Anywhere`_): source ip address or subnet to filter.\n\n- `source_port` (_Default is nil_): source port for filtering packets.\n\n- `destination`: ip address or subnet to filter on packet destination, must be a valid IP\n\n- `port` or `dest_port`: target port number (ie. 22 to allow inbound SSH), or an array of incoming port numbers (ie. [80,443] to allow inbound HTTP & HTTPS).\n\n NOTE: `protocol` attribute is required with multiple ports, or a range of incoming port numbers (ie. 60000..61000 to allow inbound mobile-shell. NOTE: `protocol`, or an attribute is required with a range of ports.\n\n- `interface`: (source) interface to apply rule (ie. `eth0`).\n\n- `dest_interface`: interface where packets may be destined to go\n\n- `redirect_port`: redirected port for rules with command `:redirect`\n\n- `logging`: may be added to enable logging for a particular rule. valid values are: `:connections`, `:packets`. In the ufw provider, `:connections` logs new connections while `:packets` logs all packets.\n\n#### Examples\n\n```ruby\n# open standard ssh port\nfirewall_rule 'ssh' do\n port 22\n command :allow\nend\n\n# open standard http port to tcp traffic only; insert as first rule\nfirewall_rule 'http' do\n port 80\n protocol :tcp\n position 1\n command :allow\nend\n\n# restrict port 13579 to 10.0.111.0/24 on eth0\nfirewall_rule 'myapplication' do\n port 13579\n source '10.0.111.0/24'\n direction :in\n interface 'eth0'\n command :allow\nend\n\n# specify a protocol number (supported on centos/redhat)\nfirewall_rule 'vrrp' do\n protocol 112\n command :allow\nend\n\n# use the iptables provider to specify protocol number on debian/ubuntu\nfirewall_rule 'vrrp' do\n provider Chef::Provider::FirewallRuleIptables\n protocol 112\n command :allow\nend\n\n# can use :raw command with UFW provider for VRRP\nfirewall_rule \"VRRP\" do\n command :allow\n raw \"allow to 224.0.0.18\"\nend\n\n# open UDP ports 60000..61000 for mobile shell (mosh.mit.edu), note\n# that the protocol attribute is required when using port_range\nfirewall_rule 'mosh' do\n protocol :udp\n port 60000..61000\n command :allow\nend\n\n# open multiple ports for http/https, note that the protocol\n# attribute is required when using ports\nfirewall_rule 'http/https' do\n protocol :tcp\n port [80, 443]\n command :allow\nend\n\nfirewall 'default' do\n enabled false\n action :nothing\nend\n```\n\n#### Providers\n\n- See `libraries/z_provider_mapping.rb` for a full list of providers for each platform and version.\n\nDifferent providers will determine the current state of the rules differently -- parsing the output of a command, maintaining the state in a file, or some other way. If the firewall is adjusted from outside of chef (non-idempotent), it's possible that chef may be caught unaware of the current state of the firewall. The best workaround is to add a `:flush` action to the firewall resource as early as possible in the chef run, if you plan to modify the firewall state outside of chef.\n\n# Troubleshooting\n\nTo figure out what the position values are for current rules, print the hash that contains the weights:\n```\nrequire pp\ndefault_firewall = resources(:firewall, 'default')\npp default_firewall.rules\n```\n\n# Development\nThis section details \"quick development\" steps. For a detailed explanation, see [[Contributing.md]].\n\n1. Clone this repository from GitHub:\n\n $ git clone git@github.com:chef-cookbooks/firewall.git\n\n2. Create a git branch\n\n $ git checkout -b my_bug_fix\n\n3. Install dependencies:\n\n $ bundle install\n\n4. Make your changes/patches/fixes, committing appropiately\n5. **Write tests**\n6. Run the tests:\n - `bundle exec foodcritic -f any .`\n - `bundle exec rspec`\n - `bundle exec rubocop`\n - `bundle exec kitchen test`\n\n In detail:\n - Foodcritic will catch any Chef-specific style errors\n - RSpec will run the unit tests\n - Rubocop will check for Ruby-specific style errors\n - Test Kitchen will run and converge the recipes\n\n\n# License & Authors\n<!-- $ find -type f -iname \"*.rb\" -exec grep -i author '{}' \\; | sort -k4 | uniq | sed 's/#/-/g' -->\n- Author:: Seth Chisamore (<schisamo@opscode.com>)\n- Author:: Ronald Doorn (<rdoorn@schubergphilis.com>)\n- Author:: Martin Smith (<martin@mbs3.org>)\n- Author:: Sander van Harmelen (<svanharmelen@schubergphilis.com>)\n\n```text\nCopyright:: 2011-2015, Chef Software, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n[0]: https://mosh.mit.edu/\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"centos":">= 0.0.0","debian":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0"},"dependencies":{"chef-sugar":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/firewall","issues_url":"https://github.com/chef-cookbooks/firewall/issues","chef_version":[[">= 12.5"]],"ohai_version":[]}
@@ -0,0 +1,80 @@
1
+ #
2
+ # Cookbook:: firewall
3
+ # Recipe:: default
4
+ #
5
+ # Copyright:: 2011-2016, Chef Software, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ chef_sugar_cookbook_version = Gem::Version.new(run_context.cookbook_collection['chef-sugar'].metadata.version)
21
+
22
+ include_recipe 'chef-sugar' if chef_sugar_cookbook_version < Gem::Version.new('4.0.0')
23
+
24
+ firewall 'default' do
25
+ ipv6_enabled node['firewall']['ipv6_enabled']
26
+ action :install
27
+ end
28
+
29
+ # create a variable to use as a condition on some rules that follow
30
+ iptables_firewall = rhel? || node['firewall']['ubuntu_iptables']
31
+
32
+ firewall_rule 'allow loopback' do
33
+ interface 'lo'
34
+ protocol :none
35
+ command :allow
36
+ only_if { linux? && node['firewall']['allow_loopback'] }
37
+ end
38
+
39
+ firewall_rule 'allow icmp' do
40
+ protocol :icmp
41
+ command :allow
42
+ # debian ufw doesn't allow 'icmp' protocol, but does open
43
+ # icmp by default, so we skip it in default recipe
44
+ only_if { (!debian?(node) || iptables_firewall) && node['firewall']['allow_icmp'] }
45
+ end
46
+
47
+ firewall_rule 'allow world to ssh' do
48
+ port 22
49
+ source '0.0.0.0/0'
50
+ only_if { linux? && node['firewall']['allow_ssh'] }
51
+ end
52
+
53
+ firewall_rule 'allow world to winrm' do
54
+ port 5989
55
+ source '0.0.0.0/0'
56
+ only_if { windows? && node['firewall']['allow_winrm'] }
57
+ end
58
+
59
+ firewall_rule 'allow world to mosh' do
60
+ protocol :udp
61
+ port 60000..61000
62
+ source '0.0.0.0/0'
63
+ only_if { linux? && node['firewall']['allow_mosh'] }
64
+ end
65
+
66
+ # allow established connections, ufw defaults to this but iptables does not
67
+ firewall_rule 'established' do
68
+ stateful [:related, :established]
69
+ protocol :none # explicitly don't specify protocol
70
+ command :allow
71
+ only_if { node['firewall']['allow_established'] && iptables_firewall }
72
+ end
73
+
74
+ # ipv6 needs ICMP to reliably work, so ensure it's enabled if ipv6
75
+ # allow established connections, ufw defaults to this but iptables does not
76
+ firewall_rule 'ipv6_icmp' do
77
+ protocol :'ipv6-icmp'
78
+ command :allow
79
+ only_if { node['firewall']['ipv6_enabled'] && node['firewall']['allow_established'] && iptables_firewall }
80
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Cookbook:: firewall
3
+ # Recipe:: disable_firewall
4
+ #
5
+ # Copyright:: 2011-2016, Chef Software, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ # Disable platform default firewall
21
+ firewall 'default' do
22
+ action :disable
23
+ end
@@ -0,0 +1,13 @@
1
+ # /etc/default/ufw
2
+ # This file is managed by Chef. Do not edit.
3
+
4
+ IPV6=<%= node['firewall']['ufw']['defaults']['ipv6'] %>
5
+ MANAGE_BUILTINS=<%= node['firewall']['ufw']['defaults']['manage_builtins'] %>
6
+
7
+ <% node['firewall']['ufw']['defaults']['policy'].each do |policy, value| -%>
8
+ <%= "DEFAULT_#{policy.upcase}_POLICY=\"#{value}\"" %>
9
+ <% end -%>
10
+
11
+ IPT_SYSCTL="<%= node['firewall']['ufw']['defaults']['ipt_sysctl'] %>"
12
+
13
+ IPT_MODULES="<%= node['firewall']['ufw']['defaults']['ipt_modules'] %>"
@@ -13,4 +13,4 @@ version '0.1.0'
13
13
  supports os
14
14
  end
15
15
 
16
- depends 'firewall', '~> 2.7.0'
16
+ depends 'firewall', '~> 2.7.1'
@@ -329,10 +329,12 @@ if !node['update_nagios_only']
329
329
  mode 0644
330
330
  owner "root"
331
331
  variables(
332
- :installdir => MU.installDir
332
+ :installdir => MU.installDir,
333
+ :repos => MU.muCfg['repos']
333
334
  )
334
335
  not_if { ::File.size?("#{MU.etcDir}/mu.rc") }
335
336
  end
337
+
336
338
  execute "source #{MU.etcDir}/mu.rc from root dotfiles" do
337
339
  command "echo 'source #{MU.etcDir}/mu.rc' >> #{Etc.getpwnam("root").dir}/.bashrc"
338
340
  not_if "test -f #{Etc.getpwnam("root").dir}/.bashrc && grep '^source #{MU.etcDir}/mu.rc$' #{Etc.getpwnam("root").dir}/.bashrc"
@@ -292,7 +292,7 @@ yum_package 'ruby23-2.3.1-1.el7.centos.x86_64' do
292
292
  end
293
293
 
294
294
  execute "Kill ruby-2.3.1" do
295
- command "yum erase ruby23-2.3.1-1.el7.centos.x86_64 -y"
295
+ command "yum erase ruby23-2.3.1-1.el7.centos.x86_64 -y; rpm -e ruby23"
296
296
  only_if { ::Dir.exist?("/opt/rubies/ruby-2.3.1") }
297
297
  end
298
298
 
@@ -547,6 +547,8 @@ export MU_DATADIR="#{MU_BASE}/var"
547
547
  export PATH="#{MU_BASE}/bin:/usr/local/ruby-current/bin:${PATH}:/opt/opscode/embedded/bin"
548
548
  }
549
549
  mode 0644
550
+ action :create_if_missing
551
+ not_if { ::File.size?("#{MU_BASE}/etc/mu.rc") }
550
552
  end
551
553
 
552
554
  # Community cookbooks keep touching gems, and none of them are smart about our
@@ -4,6 +4,9 @@
4
4
  export PATH="<%= @installdir %>/bin:/usr/local/ruby-current/bin:${PATH}:/opt/opscode/embedded/bin"
5
5
  export MU_INSTALLDIR="<%= @installdir %>"
6
6
  export MU_DATADIR="<%= @installdir %>/var"
7
+ <% if @repos %>
8
+ export ADDTL_CHEF_REPOS="<%= @repos.join(" ") %>"
9
+ <% end %>
7
10
 
8
11
  alias vi=vim
9
12
  export EDITOR=vim
@@ -18,8 +18,8 @@
18
18
  # Apply security patterns for hardening
19
19
 
20
20
  if !node['application_attributes']['skip_recipes'].include?('apply_security')
21
- case node['platform']
22
- when platform_family?('rhel')
21
+ case node['platform_family']
22
+ when "rhel", "amazon"
23
23
  include_recipe "mu-tools::aws_api"
24
24
  include_recipe "mu-tools::google_api"
25
25
 
@@ -18,6 +18,6 @@
18
18
 
19
19
  chef_gem "aws-sdk-core" do
20
20
  compile_time true
21
- version "2.6.50"
21
+ version "2.11.24"
22
22
  action :install
23
23
  end
@@ -19,7 +19,7 @@
19
19
 
20
20
  if !node['application_attributes']['skip_recipes'].include?('base_repositories')
21
21
  case node['platform_family']
22
- when "rhel", "redhat" # ~FC024
22
+ when "rhel", "redhat", "amazon" # ~FC024
23
23
  # Workaround for EOL CentOS 5 repos
24
24
  if node['platform'] != "amazon" and node['platform_version'].to_i == 5
25
25
  cookbook_file "/etc/yum.repos.d/CentOS-Base.repo" do
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
  if !node['application_attributes']['skip_recipes'].include?('clamav')
21
- if platform_family?("rhel")
21
+ if platform_family?("rhel") or platform_family?("amazon")
22
22
  include_recipe "yum-epel"
23
23
  if node['platform_version'].to_i >= 7
24
24
  package "clamav-update"
@@ -20,7 +20,7 @@
20
20
  # common Linux platforms.
21
21
 
22
22
  if !node['application_attributes']['skip_recipes'].include?('epel') and !node['application_attributes']['skip_recipes'].include?('base_repositories')
23
- if platform_family?("rhel")
23
+ if platform_family?("rhel") or platform_family?("amazon")
24
24
  include_recipe "yum-epel"
25
25
  package "cloud-init" do
26
26
  ignore_failure true
@@ -12,8 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- case node['platform']
16
- when platform_family?('rhel')
15
+ case node['platform_family']
16
+ when "rhel", "amazon"
17
17
  execute "sed -i 's/^Defaults.*requiretty$/Defaults !requiretty/' /etc/sudoers" do
18
18
  not_if "grep '!requiretty' /etc/sudoers"
19
19
  end
@@ -18,7 +18,7 @@
18
18
  # Client-side behavior for interfacing with Amazon Elastic File System
19
19
 
20
20
  if node['deployment'].has_key?('container_clusters')
21
- cluster_short_name = node['service_name'].sub(/-workers$/, "")
21
+ cluster_short_name = node['service_name'].sub(/-?workers$/, "")
22
22
  region = node['deployment']['container_clusters'][cluster_short_name]['region']
23
23
  cluster = node['deployment']['container_clusters'][cluster_short_name]['name']
24
24
  max_pods = node['deployment']['container_clusters'][cluster_short_name]['max_pods']
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
- if platform_family?("rhel")
19
+ if platform_family?("rhel") or platform_family?("amazon")
20
20
  if node['platform_version'].to_i >= 7
21
21
  yum_repository "google-cloud-sdk" do
22
22
  description 'Google Cloud SDK'
@@ -16,7 +16,7 @@
16
16
 
17
17
  if !node['application_attributes']['skip_recipes'].include?('nrpe')
18
18
  case node['platform_family']
19
- when "rhel"
19
+ when "rhel", "amazon"
20
20
  package ['nrpe', 'nagios-plugins-disk', 'nagios-plugins-nrpe', 'nagios-plugins-ssh']
21
21
  master_ips = get_mu_master_ips
22
22
  master_ips << "127.0.0.1"