Skip to content

Commit

Permalink
Merge pull request #228 from josqu4red/feature/remove-sysctl-cookbook
Browse files Browse the repository at this point in the history
Remove sysctl cookbook dependency and use new native sysctl resource
  • Loading branch information
artem-sidorenko committed Mar 12, 2019
2 parents faf8ae7 + 5220c3b commit e993020
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ It will not:

## Requirements

* Chef >= 14
* Cookbooks:
* Sander van Zoest sysctl `https://github.com/svanzoest-cookbooks/sysctl`
* Chef >= 14.0

### Platform

Expand Down
2 changes: 0 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
supports 'suse'
supports 'opensuseleap', '>= 42.1'

depends 'sysctl', '~> 1.0'

recipe 'os-hardening::default', 'harden the operating system (all recipes)'
recipe 'os-hardening::limits', 'prevent core dumps'
recipe 'os-hardening::login_defs', 'harden /etc/login.defs'
Expand Down
2 changes: 1 addition & 1 deletion recipes/sysctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
if node.attribute?('sysctl') && node['sysctl'].attribute?('params')
coerce_attributes(node['sysctl']['params']).each do |x|
k, v = x.split('=')
sysctl_param k do
sysctl k do
value v
end
end
Expand Down
26 changes: 13 additions & 13 deletions spec/recipes/sysctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
let(:network_forwarding) { true }

it 'should enable IPv4 forwarding in sysctl attributes' do
expect(chef_run).to apply_sysctl_param('net.ipv4.ip_forward').with(
expect(chef_run).to apply_sysctl('net.ipv4.ip_forward').with(
value: '1'
)
end
Expand All @@ -168,7 +168,7 @@
let(:network_forwarding) { false }

it 'should disable IPv4 forwarding in sysctl attributes' do
expect(chef_run).to apply_sysctl_param('net.ipv4.ip_forward').with(
expect(chef_run).to apply_sysctl('net.ipv4.ip_forward').with(
value: '0'
)
end
Expand All @@ -178,7 +178,7 @@
describe 'IPv6 forwarding' do
RSpec.shared_examples 'IPv6 forwarding in sysctl attributes' do |state|
it "should #{state == 1 ? 'enable' : 'disable'} IPv6 forwarding in sysctl attributes" do # rubocop:disable Metrics/LineLength
expect(chef_run).to apply_sysctl_param('net.ipv6.conf.all.forwarding').with(
expect(chef_run).to apply_sysctl('net.ipv6.conf.all.forwarding').with(
value: state.to_s
)
end
Expand Down Expand Up @@ -221,7 +221,7 @@
let(:ipv6_enable) { true }

it 'should not disable IPv6' do
expect(chef_run).to apply_sysctl_param('net.ipv4.ip_forward').with(
expect(chef_run).to apply_sysctl('net.ipv4.ip_forward').with(
value: '0'
)
end
Expand All @@ -231,7 +231,7 @@
let(:ipv6_enable) { false }

it 'should not disable IPv6' do
expect(chef_run).to apply_sysctl_param('net.ipv6.conf.all.forwarding').with(
expect(chef_run).to apply_sysctl('net.ipv6.conf.all.forwarding').with(
value: '0'
)
end
Expand All @@ -242,15 +242,15 @@
RSpec.shared_examples 'ARP restrictions in sysctl attributes' do |arp_ignore, arp_announce| # rubocop:disable Metrics/LineLength
describe 'arp_ignore' do
it "should be set to #{arp_ignore}" do
expect(chef_run).to apply_sysctl_param('net.ipv4.conf.all.arp_ignore').with(
expect(chef_run).to apply_sysctl('net.ipv4.conf.all.arp_ignore').with(
value: arp_ignore.to_s
)
end
end

describe 'arp_announce' do
it "should be set to #{arp_announce}" do
expect(chef_run).to apply_sysctl_param('net.ipv4.conf.all.arp_announce').with(
expect(chef_run).to apply_sysctl('net.ipv4.conf.all.arp_announce').with(
value: arp_announce.to_s
)
end
Expand All @@ -275,7 +275,7 @@
let(:enable_module_loading) { true }

it 'should not set the sysctl flag' do
expect(chef_run).to_not apply_sysctl_param('kernel.modules_disabled')
expect(chef_run).to_not apply_sysctl('kernel.modules_disabled')
end

describe 'rebuild of initramfs' do
Expand All @@ -295,7 +295,7 @@
let(:enable_module_loading) { false }

it 'should disable module loading via sysctl flag' do
expect(chef_run).to apply_sysctl_param('kernel.modules_disabled').with(
expect(chef_run).to apply_sysctl('kernel.modules_disabled').with(
value: '1'
)
end
Expand All @@ -319,7 +319,7 @@
let(:enable_sysrq) { true }

it 'should enable sysrq with safe value' do
expect(chef_run).to apply_sysctl_param('kernel.sysrq').with(
expect(chef_run).to apply_sysctl('kernel.sysrq').with(
value: '244'
)
end
Expand All @@ -329,7 +329,7 @@
let(:enable_sysrq) { false }

it 'should disable sysrq' do
expect(chef_run).to apply_sysctl_param('kernel.sysrq').with(
expect(chef_run).to apply_sysctl('kernel.sysrq').with(
value: '0'
)
end
Expand All @@ -341,7 +341,7 @@
let(:enable_core_dump) { true }

it 'should set suid_dumpable to safe value' do
expect(chef_run).to apply_sysctl_param('fs.suid_dumpable').with(
expect(chef_run).to apply_sysctl('fs.suid_dumpable').with(
value: '2'
)
end
Expand All @@ -351,7 +351,7 @@
let(:enable_core_dump) { false }

it 'should set suid_dumpable to default value' do
expect(chef_run).to apply_sysctl_param('fs.suid_dumpable').with(
expect(chef_run).to apply_sysctl('fs.suid_dumpable').with(
value: '0'
)
end
Expand Down

0 comments on commit e993020

Please sign in to comment.