Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix outdated systemd config parameter #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/facter/systemd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Fact: systemd_version
#
# Purpose:
# Determine the version of systemd installed
#
# Resolution:
# Check the output of systemctl --version

Facter.add(:systemd_version) do
confine :systemd => true
setcode do
Facter::Util::Resolution.exec("systemctl --version")[/[0-9]+(\.[0-9]+)*/].to_i
end
end
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
}
}
'systemd': {
$systemd_version = $::vault::params::systemd_version
file { '/etc/systemd/system/vault.service':
ensure => file,
owner => 'root',
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
$version = $::vault::params::version,
$os = $::vault::params::os,
$arch = $::vault::params::arch,
$systemd_version = $::vault::params::systemd_version,
$extra_config = {},
) inherits ::vault::params {

Expand Down
3 changes: 3 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@
case $::lsbdistcodename {
/(jessie|stretch|sid|xenial|yakketi|zesty)/: {
$service_provider = 'systemd'
$systemd_version = $facts['systemd_version']
}
/(trusty|vivid)/: {
$service_provider = 'upstart'
}
default: {
$service_provider = 'systemd'
$systemd_version = $facts['systemd_version']
warning("Module ${module_name} is not supported on '${::lsbdistcodename}'")
}
}
Expand All @@ -68,6 +70,7 @@
$service_provider = 'redhat'
} else {
$service_provider = 'systemd'
$systemd_version = $facts['systemd_version']
}
}
default: {
Expand Down
128 changes: 112 additions & 16 deletions spec/classes/vault_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@
:architecture => 'x86_64',
:kernel => 'Linux',
}}
context 'includes systemd init script' do
context 'includes systemd init script with systemd_version < 229' do
let(:facts) {{
:systemd_version => 228
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some funky indentation in all the :facts blocks you've added, can you de-dent to match.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

}}
it {
is_expected.to contain_file('/etc/systemd/system/vault.service')
.with_mode('0644')
Expand All @@ -409,6 +412,50 @@
.with_content(/NoNewPrivileges=yes/)
}
end
context 'includes systemd init script with systemd_version = 229' do
let(:facts) {{
:systemd_version => 229
}}
it {
is_expected.to contain_file('/etc/systemd/system/vault.service')
.with_mode('0644')
.with_ensure('file')
.with_owner('root')
.with_group('root')
.with_notify('Exec[systemd-reload]')
.with_content(/^# vault systemd unit file/)
.with_content(/^User=vault$/)
.with_content(/^Group=vault$/)
.with_content(/Environment=GOMAXPROCS=3/)
.with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $})
.with_content(/SecureBits=keep-caps/)
.with_content(/AmbientCapabilities=CAP_IPC_LOCK/)
.with_content(/CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK/)
.with_content(/NoNewPrivileges=yes/)
}
end
context 'includes systemd init script with systemd_version > 229' do
let(:facts) {{
:systemd_version => 230
}}
it {
is_expected.to contain_file('/etc/systemd/system/vault.service')
.with_mode('0644')
.with_ensure('file')
.with_owner('root')
.with_group('root')
.with_notify('Exec[systemd-reload]')
.with_content(/^# vault systemd unit file/)
.with_content(/^User=vault$/)
.with_content(/^Group=vault$/)
.with_content(/Environment=GOMAXPROCS=3/)
.with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $})
.with_content(/SecureBits=keep-caps/)
.with_content(/AmbientCapabilities=CAP_IPC_LOCK/)
.with_content(/CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK/)
.with_content(/NoNewPrivileges=yes/)
}
end
context 'service with non-default options' do
let(:params) {{
:bin_dir => '/opt/bin',
Expand Down Expand Up @@ -459,6 +506,7 @@
.with_content(/^Group=vault$/)
.with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $})
.without_content(/SecureBits=keep-caps/)
.without_content(/AmbientCapabilities=CAP_IPC_LOCK/)
.without_content(/Capabilities=CAP_IPC_LOCK\+ep/)
.with_content(/CapabilityBoundingSet=CAP_SYSLOG/)
.with_content(/NoNewPrivileges=yes/)
Expand Down Expand Up @@ -651,23 +699,70 @@
:architecture => 'x86_64',
:kernel => 'Linux',
}}
context 'includes systemd init script' do
context 'includes systemd init script with systemd_version < 229' do
let(:facts) {{
:systemd_version => 228
}}
it {
is_expected.to contain_file('/etc/systemd/system/vault.service')
.with_mode('0644')
.with_ensure('file')
.with_owner('root')
.with_group('root')
.with_notify('Exec[systemd-reload]')
.with_content(/^# vault systemd unit file/)
.with_content(/^User=vault$/)
.with_content(/^Group=vault$/)
.with_content(/Environment=GOMAXPROCS=3/)
.with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $})
.with_content(/SecureBits=keep-caps/)
.with_content(/Capabilities=CAP_IPC_LOCK\+ep/)
.with_content(/CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK/)
.with_content(/NoNewPrivileges=yes/)
.with_mode('0644')
.with_ensure('file')
.with_owner('root')
.with_group('root')
.with_notify('Exec[systemd-reload]')
.with_content(/^# vault systemd unit file/)
.with_content(/^User=vault$/)
.with_content(/^Group=vault$/)
.with_content(/Environment=GOMAXPROCS=3/)
.with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $})
.with_content(/SecureBits=keep-caps/)
.with_content(/Capabilities=CAP_IPC_LOCK\+ep/)
.with_content(/CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK/)
.with_content(/NoNewPrivileges=yes/)
}
end
context 'includes systemd init script with systemd_version = 229' do
let(:facts) {{
:systemd_version => 229
}}
it {
is_expected.to contain_file('/etc/systemd/system/vault.service')
.with_mode('0644')
.with_ensure('file')
.with_owner('root')
.with_group('root')
.with_notify('Exec[systemd-reload]')
.with_content(/^# vault systemd unit file/)
.with_content(/^User=vault$/)
.with_content(/^Group=vault$/)
.with_content(/Environment=GOMAXPROCS=3/)
.with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $})
.with_content(/SecureBits=keep-caps/)
.with_content(/AmbientCapabilities=CAP_IPC_LOCK/)
.with_content(/CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK/)
.with_content(/NoNewPrivileges=yes/)
}
end
context 'includes systemd init script with systemd_version > 229' do
let(:facts) {{
:systemd_version => 230
}}
it {
is_expected.to contain_file('/etc/systemd/system/vault.service')
.with_mode('0644')
.with_ensure('file')
.with_owner('root')
.with_group('root')
.with_notify('Exec[systemd-reload]')
.with_content(/^# vault systemd unit file/)
.with_content(/^User=vault$/)
.with_content(/^Group=vault$/)
.with_content(/Environment=GOMAXPROCS=3/)
.with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $})
.with_content(/SecureBits=keep-caps/)
.with_content(/AmbientCapabilities=CAP_IPC_LOCK/)
.with_content(/CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK/)
.with_content(/NoNewPrivileges=yes/)
}
end
context 'service with non-default options' do
Expand Down Expand Up @@ -721,6 +816,7 @@
.with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $})
.without_content(/SecureBits=keep-caps/)
.without_content(/Capabilities=CAP_IPC_LOCK\+ep/)
.without_content(/AmbientCapabilities=CAP_IPC_LOCK/)
.with_content(/CapabilityBoundingSet=CAP_SYSLOG/)
.with_content(/NoNewPrivileges=yes/)
}
Expand Down
4 changes: 4 additions & 0 deletions templates/vault.systemd.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ CapabilityBoundingSet=CAP_SYSLOG
NoNewPrivileges=yes
<% else -%>
SecureBits=keep-caps
<% if scope['vault::systemd_version'] > 229 -%>
AmbientCapabilities=CAP_IPC_LOCK
<% else -%>
Capabilities=CAP_IPC_LOCK+ep
<% end -%>
CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK
NoNewPrivileges=yes
<% end -%>
Expand Down