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

Fix cron environment leaking #126

Merged
merged 1 commit into from
Aug 16, 2018
Merged
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
15 changes: 7 additions & 8 deletions manifests/certonly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@
$command = "${command_start}${command_domains}${command_end}"
$live_path = inline_template("${config_dir}/live/<%= @domains.first %>/cert.pem")

$venv_path_var = "VENV_PATH=${letsencrypt::venv_path}"
$execution_environment = concat([ "VENV_PATH=${letsencrypt::venv_path}", ], $environment)
exec { "letsencrypt certonly ${title}":
command => $command,
path => $::path,
environment => concat([ $venv_path_var ], $environment),
environment => $execution_environment,
creates => $live_path,
require => Class['letsencrypt'],
}
Expand Down Expand Up @@ -100,14 +100,13 @@
mode => '0755',
owner => 'root',
group => $::letsencrypt::cron_owner_group,
content => "#!/bin/sh\n${cron_cmd}",
content => template('letsencrypt/renew-script.sh.erb'),
}
cron { "letsencrypt renew cron ${title}":
command => "${::letsencrypt::cron_scripts_path}/renew-${title}.sh",
environment => concat([ $venv_path_var ], $environment),
user => root,
hour => $cron_hour,
minute => $cron_minute,
command => "${::letsencrypt::cron_scripts_path}/renew-${title}.sh",
user => root,
hour => $cron_hour,
minute => $cron_minute,
}
}
}
10 changes: 5 additions & 5 deletions spec/defines/letsencrypt_certonly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
end

it { is_expected.to contain_cron('letsencrypt renew cron foo.example.com').with_command '/var/lib/puppet/letsencrypt/renew-foo.example.com.sh' }
it { is_expected.to contain_file('/var/lib/puppet/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\nletsencrypt --text --agree-tos --non-interactive certonly -a apache --keep-until-expiring -d foo.example.com" }
it { is_expected.to contain_file('/var/lib/puppet/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\nexport VENV_PATH=/opt/letsencrypt/.venv\nletsencrypt --text --agree-tos --non-interactive certonly -a apache --keep-until-expiring -d foo.example.com\n" }
end

context 'with custom puppet_vardir path and manage_cron' do
Expand All @@ -96,7 +96,7 @@
end

it { is_expected.to contain_cron('letsencrypt renew cron foo.example.com').with_command '/tmp/custom_vardir/letsencrypt/renew-foo.example.com.sh' }
it { is_expected.to contain_file('/tmp/custom_vardir/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\nletsencrypt --text --agree-tos --non-interactive certonly -a apache --keep-until-expiring -d foo.example.com" }
it { is_expected.to contain_file('/tmp/custom_vardir/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\nexport VENV_PATH=/opt/letsencrypt/.venv\nletsencrypt --text --agree-tos --non-interactive certonly -a apache --keep-until-expiring -d foo.example.com\n" }
end

context 'with custom plugin and manage cron and cron_success_command' do
Expand All @@ -111,7 +111,7 @@
end

it { is_expected.to contain_cron('letsencrypt renew cron foo.example.com').with_command '/var/lib/puppet/letsencrypt/renew-foo.example.com.sh' }
it { is_expected.to contain_file('/var/lib/puppet/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\n(echo before) && letsencrypt --text --agree-tos --non-interactive certonly -a apache --keep-until-expiring -d foo.example.com && (echo success)" }
it { is_expected.to contain_file('/var/lib/puppet/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\nexport VENV_PATH=/opt/letsencrypt/.venv\n(echo before) && letsencrypt --text --agree-tos --non-interactive certonly -a apache --keep-until-expiring -d foo.example.com && (echo success)\n" }
end

context 'without plugin' do
Expand Down Expand Up @@ -146,7 +146,7 @@
let(:title) { 'foo.example.com' }
let(:params) { { environment: ['FOO=bar', 'FIZZ=buzz'], manage_cron: true } }

it { is_expected.to contain_cron('letsencrypt renew cron foo.example.com').with_environment(['VENV_PATH=/opt/letsencrypt/.venv', 'FOO=bar', 'FIZZ=buzz']) }
it { is_expected.to contain_file('/var/lib/puppet/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\nexport VENV_PATH=/opt/letsencrypt/.venv\nexport FOO=bar\nexport FIZZ=buzz\nletsencrypt --text --agree-tos --non-interactive certonly -a standalone --keep-until-expiring -d foo.example.com\n" }
end

context 'with manage cron and suppress_cron_output' do
Expand All @@ -157,7 +157,7 @@
end

it { is_expected.to contain_cron('letsencrypt renew cron foo.example.com').with_command '/var/lib/puppet/letsencrypt/renew-foo.example.com.sh' }
it { is_expected.to contain_file('/var/lib/puppet/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\nletsencrypt --text --agree-tos --non-interactive certonly -a standalone --keep-until-expiring -d foo.example.com > /dev/null 2>&1" }
it { is_expected.to contain_file('/var/lib/puppet/letsencrypt/renew-foo.example.com.sh').with_content "#!/bin/sh\nexport VENV_PATH=/opt/letsencrypt/.venv\nletsencrypt --text --agree-tos --non-interactive certonly -a standalone --keep-until-expiring -d foo.example.com > /dev/null 2>&1\n" }
end

context 'with custom config_dir' do
Expand Down
5 changes: 5 additions & 0 deletions templates/renew-script.sh.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
<%- @execution_environment.each do |environment| -%>
export <%= environment %>
<%- end -%>
<%= @cron_cmd %>