Skip to content

Commit 1f79744

Browse files
committed
Add automation for certbot
1 parent bbdb83b commit 1f79744

File tree

9 files changed

+194
-7
lines changed

9 files changed

+194
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ kitchen.local.yml
1616
Berksfile.lock
1717
.zero-knife.rb
1818
Policyfile.lock.json
19+
Policyfile.*.lock.json
1920

2021
.DS_Store
2122

@@ -29,4 +30,4 @@ nodes/
2930

3031
*-clear/
3132

32-
bundle-metadata.json
33+
bundle-metadata.json

cookbooks/boxcutter_acme/kitchen.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ platforms:
4848
image: boxcutter/dokken-ubuntu-22.04
4949
pid_one_command: /bin/systemd
5050

51+
- name: ubuntu-24.04
52+
driver:
53+
image: boxcutter/dokken-ubuntu-24.04
54+
pid_one_command: /bin/systemd
55+
5156
- name: centos-stream-9
5257
driver:
5358
image: boxcutter/dokken-centos-stream-9
@@ -59,12 +64,17 @@ platforms:
5964
- RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
6065

6166
suites:
62-
- name: default
63-
# run_list set in Policyfile.rb, this does nothing
64-
# run_list:
65-
# - recipe[boxcutter_ohai]
66-
# - recipe[boxcutter_init]
67-
# - recipe[boxcutter_acme::default]
67+
- name: certbot
68+
provisioner:
69+
policyfile_path: policyfiles/Policyfile.certbot.rb
70+
verifier:
71+
inspec_tests:
72+
- test/integration/default
73+
attributes:
74+
75+
- name: lego
76+
provisioner:
77+
policyfile_path: policyfiles/Policyfile.lego.rb
6878
verifier:
6979
inspec_tests:
7080
- test/integration/default
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Policyfile.certbot.rb - Describe how you want Chef Infra Client to build your system.
2+
#
3+
# For more information on the Policyfile feature, visit
4+
# https://docs.chef.io/policyfile/
5+
6+
# A name that describes what the system you're building with Chef does.
7+
name 'boxcutter_acme'
8+
9+
# Where to find external cookbooks:
10+
default_source :chef_repo, '../../../../chef-cookbooks/cookbooks'
11+
default_source :chef_repo, '../../'
12+
13+
# run_list: chef-client will run these recipes in the order specified.
14+
run_list 'boxcutter_ohai', 'boxcutter_init', 'boxcutter_acme_test::certbot'
15+
16+
# Specify a custom source for a single cookbook:
17+
cookbook 'boxcutter_acme', path: '..'
18+
cookbook 'boxcutter_acme_test', path: '../test/cookbooks/boxcutter_acme_test'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Policyfile.lego.rb - Describe how you want Chef Infra Client to build your system.
2+
#
3+
# For more information on the Policyfile feature, visit
4+
# https://docs.chef.io/policyfile/
5+
6+
# A name that describes what the system you're building with Chef does.
7+
name 'boxcutter_acme'
8+
9+
# Where to find external cookbooks:
10+
default_source :chef_repo, '../../../../chef-cookbooks/cookbooks'
11+
default_source :chef_repo, '../../'
12+
13+
# run_list: chef-client will run these recipes in the order specified.
14+
run_list 'boxcutter_ohai', 'boxcutter_init', 'boxcutter_acme_test::lego'
15+
16+
# Specify a custom source for a single cookbook:
17+
cookbook 'boxcutter_acme', path: '..'
18+
cookbook 'boxcutter_acme_test', path: '../test/cookbooks/boxcutter_acme_test'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Cookbook:: boxcutter_acme
3+
# Recipe:: certbot
4+
#
5+
# Copyright:: 2024, Boxcutter
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+
package ['python3', 'python3-venv'] do
20+
action :upgrade
21+
end
22+
23+
directory '/opt/certbot' do
24+
owner node.root_user
25+
group node.root_group
26+
mode '0755'
27+
end
28+
29+
execute 'create certbot virtualenv' do
30+
command 'python3 -m venv /opt/certbot/venv'
31+
creates '/opt/certbot/venv/bin/python'
32+
end
33+
34+
%w{
35+
certbot
36+
certbot-dns-cloudflare
37+
}.each do |pkg|
38+
execute "install #{pkg} python package" do
39+
command "/opt/certbot/venv/bin/python -m pip install #{pkg}"
40+
not_if "/opt/certbot/venv/bin/python -m pip list installed | grep ^#{pkg}"
41+
end
42+
43+
execute "update #{pkg} python package" do
44+
command "/opt/certbot/venv/bin/python -m pip install --upgrade #{pkg}"
45+
only_if "/opt/certbot/venv/bin/python -m pip list --outdated | grep ^#{pkg}"
46+
end
47+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
# Cookbook:: boxcutter_acme
3+
# Spec:: certbot
4+
#
5+
# Copyright:: 2024, Boxcutter
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+
require 'spec_helper'
20+
21+
describe 'boxcutter_acme::certbot' do
22+
context 'When all attributes are default, on Ubuntu 20.04' do
23+
# for a complete list of available platforms and versions see:
24+
# https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md
25+
platform 'ubuntu', '20.04'
26+
27+
it 'converges successfully' do
28+
expect { chef_run }.to_not raise_error
29+
end
30+
end
31+
32+
context 'When all attributes are default, on CentOS 8' do
33+
# for a complete list of available platforms and versions see:
34+
# https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md
35+
platform 'centos', '8'
36+
37+
it 'converges successfully' do
38+
expect { chef_run }.to_not raise_error
39+
end
40+
end
41+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: boxcutter_acme_test
3+
# Recipe:: certbot
4+
#
5+
6+
include_recipe 'boxcutter_acme::certbot'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Cookbook:: boxcutter_acme_test
3+
# Recipe:: lego
4+
#
5+
6+
node.default['boxcutter_acme']['lego']['config'] = {
7+
'nexus' => {
8+
'certificate_name' => 'hq0-nexus01.sandbox.polymathrobotics.dev',
9+
'data_path' => '/etc/lego/tmp',
10+
'renew_script_path' => '/opt/lego/lego_renew.sh',
11+
'renew_days' => '30',
12+
'server' => 'https://acme-staging-v02.api.letsencrypt.org/directory',
13+
'email' => 'letsencrypt@polymathrobotics.com',
14+
'domains' => %w{
15+
hq0-nexus01.sandbox.polymathrobotics.dev
16+
*.hq0-nexus01.sandbox.polymathrobotics.dev
17+
},
18+
'extra_parameters' => [
19+
'--dns cloudflare',
20+
# There's are issues resolving apex domain servers over tailscale, so
21+
# override the DNS resolver lego uses, in case we're running tailscale
22+
'--dns.resolvers 1.1.1.1',
23+
],
24+
'extra_environment' => {
25+
'export CF_DNS_API_TOKEN' => '<token>',
26+
},
27+
},
28+
}
29+
30+
include_recipe 'boxcutter_acme::lego'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Chef InSpec test for recipe boxcutter_acme::certbot
2+
3+
# The Chef InSpec reference, with examples and extensive documentation, can be
4+
# found at https://docs.chef.io/inspec/resources/
5+
6+
unless os.windows?
7+
# This is an example test, replace with your own test.
8+
describe user('root'), :skip do
9+
it { should exist }
10+
end
11+
end
12+
13+
# This is an example test, replace it with your own test.
14+
describe port(80), :skip do
15+
it { should_not be_listening }
16+
end

0 commit comments

Comments
 (0)