-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhologram-letsencrypt.pkg.toml
More file actions
186 lines (159 loc) · 5.2 KB
/
hologram-letsencrypt.pkg.toml
File metadata and controls
186 lines (159 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
[package]
name = "hologram-letsencrypt"
version = "1.4.6"
description = "Pluggable letsencrypt-based certificate auto-issuance"
requires = [
"certbot",
"nginx",
]
################################################################################
# run an nginx under port 80 for the ACME challenge, and to upgrade all HTTP
# requests to HTTPS
[[file]]
path = "/usr/share/letsencrypt-allofthem/nginx.conf"
content = """
user http;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
access_log off;
server {
# IPv4
listen 80 default_server;
# IPv6
listen [::]:80 default_server;
# upgrade HTTP requests to HTTPS...
location / {
return 301 https://$host$request_uri;
}
# ...except for ACME challenges
location /.well-known/acme-challenge/ {
root /srv/letsencrypt;
}
}
}
"""
[[file]]
path = "/etc/systemd/system/nginx-for-letsencrypt.service"
contentFrom = "/dev/null" # initially empty, will be rendered by holoscript below
# I tried to add a drop-in into
# /etc/systemd/system/nginx-for-letsencrypt.service.d/ to modify the default
# nginx.service to reference the custom nginx.conf from above, but apparently
# if you symlink one unit to another one, it will only use the drop-ins for the
# target unit. Therefore, use a holoscript to render the unit.
[[file]]
path = "/usr/share/holo/files/10-letsencrypt/etc/systemd/system/nginx-for-letsencrypt.service.holoscript"
mode = "0755"
content = '''
#!/bin/bash
cat /usr/lib/systemd/system/nginx.service | sed "
/^Description=/ s+=.*+=HTTP server for HTTPS upgrade and ACME challenges+
/^ExecStart=/ s+=.*+=/usr/bin/nginx -c /usr/share/letsencrypt-allofthem/nginx.conf -g 'pid /run/nginx-for-letsencrypt.pid; error_log stderr;'+
/^PIDFile=/ s+=.*+=/run/nginx-for-letsencrypt.pid+
"
'''
# nginx-for-letsencrypt.service needs to be running all the time for the
# HTTP->HTTPS upgrading to work
[[symlink]]
path = "/etc/systemd/system/multi-user.target.wants/nginx-for-letsencrypt.service"
target = "/etc/systemd/system/nginx-for-letsencrypt.service"
################################################################################
# run letsencrypt under restricted user
[[group]]
name = "letsencrypt"
system = true
[[user]]
name = "letsencrypt"
group = "letsencrypt"
system = true
home = "/var/lib/letsencrypt"
# nginx needs to be able to read the acme-challenge directory
[[user]]
name = "http"
groups = ["letsencrypt"]
# fix UID/GID on directories provided by letsencrypt package
[[directory]]
path = "/etc/letsencrypt"
owner = "letsencrypt"
group = "letsencrypt"
[[directory]]
path = "/var/lib/letsencrypt"
owner = "letsencrypt"
group = "letsencrypt"
[[directory]]
path = "/var/log/letsencrypt"
mode = "0700"
owner = "letsencrypt"
group = "letsencrypt"
# filesystem location for the webroot challenge method
[[directory]]
path = "/srv/letsencrypt/.well-known"
mode = "0755"
owner = "letsencrypt"
group = "letsencrypt"
[[directory]]
path = "/srv/letsencrypt/.well-known/acme-challenge"
mode = "0750"
owner = "letsencrypt"
group = "letsencrypt"
# script to interactively (and after that, automatically) issue certificates
#
# To select domains for auto-issuance, place a script below
# /etc/letsencrypt-allofthem that prints the domains that need a certificate.
[[file]]
path = "/usr/bin/letsencrypt-allofthem"
mode = "0755"
content = '''
#!/bin/sh
if [ "$(id -u)" != 0 ]; then
echo "!! Run this as user root." >&2
exit 1
fi
set -e
find /etc/letsencrypt-allofthem/ -maxdepth 1 -type f -executable | while read collector; do
"$collector"
done | sort -u | while read domain; do
echo ">> domain: $domain"
sudo -u letsencrypt -g letsencrypt certbot certonly --quiet --non-interactive --agree-tos --keep-until-expiring --webroot -w /srv/letsencrypt/ -d "$domain"
done
find /etc/letsencrypt-allofthem/then/ -maxdepth 1 -type f -executable | while read hook; do
"$hook"
done
'''
[[directory]]
path = "/etc/letsencrypt-allofthem"
[[directory]]
path = "/etc/letsencrypt-allofthem/then"
[[file]]
path = "/usr/lib/systemd/system/letsencrypt-allofthem.service"
content = """
[Unit]
Description=Provision and renew TLS certificates automatically
After=network-online.target nginx-for-letsencrypt.service
Wants=network-online.target
Requires=nginx-for-letsencrypt.service
[Service]
Type=oneshot
ExecStart=/usr/bin/letsencrypt-allofthem
"""
[[file]]
path = "/usr/lib/systemd/system/letsencrypt-allofthem.timer"
content = """
[Unit]
Description=Provision and renew TLS certificates once a week
After=network-online.target
Wants=network-online.target
[Timer]
OnCalendar=weekly
[Install]
WantedBy=timers.target
"""
[[symlink]]
path = "/etc/systemd/system/timers.target.wants/letsencrypt-allofthem.timer"
target = "/usr/lib/systemd/system/letsencrypt-allofthem.timer"