Skip to content

Commit 779568d

Browse files
author
Maarten de Waard
committed
Merge branch '4-remove-installer-code-and-make-python3-and-new-certbot-compatible' into 'develop'
Resolve "remove installer code and make python3 and new certbot compatible" Closes #4 See merge request open/certbot-haproxy!1
2 parents 8a66035 + b2a251e commit 779568d

19 files changed

Lines changed: 97 additions & 1318 deletions

README.rst

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ configure HAProxy for use with the plugin. If you have a good idea on how we can
3232
implement automatic HAProxy configuration, you are welcome to create a merge
3333
request or an issue.
3434

35+
Dropped installer support in version 0.2.0+
36+
------------------------------------------
37+
38+
In version 0.2.0 the installer component is dropped. Originally the installer
39+
component made sure to place the certificates in the right directory for haproxy
40+
by combining the key and the crt. This was done because original versions of
41+
certbot executed the hooks after every domain renewal.
42+
43+
New versions of certbot have move fine grained post install hooks. With those
44+
hooks more flexibility is added for installation. An example script and command
45+
is added in version 0.2.0+
46+
47+
The example script for deploy is `certbot-deploy-hook-example`
48+
49+
3550
Installing: Requirements
3651
------------------------
3752

@@ -40,24 +55,25 @@ work on Ubuntu 14.04+ too. If you are running Debian Wheezy, you may need to
4055
take additional steps during the installation. Thus, the requirements are:
4156

4257
- Debian Jessie (or higher) or Ubuntu Trusty (or higher).
43-
- Python 2.7 (2.6 is supported by certbot and our goal is to be compatible but
58+
- Python 3.0+ (Python 2.7 is still supported to be compatible with older
59+
operating systems)
4460
it has not been tested yet).
45-
- HAProxy 1.6+ (we will configure SNI, which is not strictly required)
46-
- Certbot 0.8+
61+
- HAProxy 1.6+
62+
- Certbot 0.19+
4763

4864
Installing: Getting started
4965
---------------------------
5066

51-
The installation below assumes you are running Debian Jessie but it should be
67+
The installation below assumes you are running Debian Stretch but it should be
5268
almost entirely the same process on Ubuntu.
5369

54-
First add the backports repo for Jessie to your apt sources.
70+
If you are still using Jessie, you have to add the backports repo for Jessie.
5571

5672
.. note::
5773

5874
This will not work for Ubuntu, you will need to use another source,
5975
check which version comes with your version of Ubuntu, if it is a version
60-
below 0.8, you need to find a back port PPA or download certbot from source.
76+
below 0.19, you need to find a back port PPA or download certbot from source.
6177

6278
.. code:: bash
6379
@@ -82,7 +98,7 @@ Now update, upgrade and install some requirements:
8298
openssl ca-certificates \
8399
build-essential libffi-dev libssl-dev python-dev \
84100
python python-setuptools \
85-
haproxy
101+
haproxy python3-pip python3-setuptools
86102
87103
easy_install pip
88104
pip install --upgrade setuptools
@@ -302,23 +318,22 @@ together a configuration that works for you.
302318
303319
systemctl restart haproxy
304320
305-
Now you can try to run Certbot with the plugin as the Authenticator and
306-
Installer, if you already have websites configured in your HAProxy setup, you
321+
Now you can try to run Certbot with the plugin as the Authenticator.
322+
If you already have websites configured in your HAProxy setup, you
307323
may try to install a certificate now.
308324
309325
.. code:: bash
310326
311-
certbot run --authenticator certbot-haproxy:haproxy-authenticator \
312-
--installer certbot-haproxy:haproxy-installer
327+
certbot certonly --authenticator certbot-haproxy:haproxy-authenticator \
328+
--deploy-hook /path/to/your/install/script
313329
314-
If you want your ``certbot`` to always use our Installer and Authenticator, you
330+
If you want your ``certbot`` to always use our Authenticator, you
315331
can add this to your configuration file:
316332
317333
.. code:: bash
318334
319335
cat <<EOF >> $HOME/.config/letsencrypt/cli.ini
320336
authenticator=certbot-haproxy:haproxy-authenticator
321-
installer=certbot-haproxy:haproxy-installer
322337
EOF
323338
324339
If you need to run in unattended mode, there are a bunch of arguments you need
@@ -367,7 +382,7 @@ after the server has been offline for a long time.
367382
[Service]
368383
Type=simple
369384
User=certbot
370-
ExecStart=/usr/bin/certbot renew -q
385+
ExecStart=/usr/bin/certbot renew -q --deploy-hook /path/to/deploy/script
371386
EOF
372387
373388
# Enable the timer and start it, this is not necessary for the service,
@@ -446,7 +461,6 @@ reasons.
446461
text=True
447462
domain=example.org
448463
authenticator=certbot-haproxy:haproxy-authenticator
449-
installer=certbot-haproxy:haproxy-installer
450464
EOF
451465
452466
Setuptools version conflict
@@ -476,11 +490,11 @@ Run the following commands in your vagrant machine:
476490
.. code:: bash
477491
478492
apt-file update
479-
python setup.py sdist
493+
python3 setup.py sdist
480494
# py2dsc has a problem with vbox mounted folders
481495
mv dist/certbot-haproxy-<version>.tar.gz ~
482496
cd ~
483-
py2dsc certbot-haproxy-<version>.tar.gz
497+
py2dsc --with-python3=True certbot-haproxy-<version>.tar.gz
484498
cd deb_dist/certbot-haproxy-<version>
485499
# NOTE: Not signed, no signed changes (with -uc and -us)
486500
# NOTE: Add the package to the ghtools repo

certbot-deploy-hook-example

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import re
5+
import sys
6+
7+
# Certbot sets an environment variable RENEWED_LINEAGE, which points to the
8+
# path of the renewed certificate. We use that path to determine and find
9+
# the files for the currently renewed certificated
10+
lineage=os.environ.get('RENEWED_LINEAGE')
11+
12+
# If nothing renewed, exit
13+
if not lineage:
14+
sys.exit()
15+
16+
# From the linage, we strip the 'domain name', which is the last part
17+
# of the path.
18+
result = re.match(r'.*/live/(.+)$', lineage)
19+
20+
# If we can not recognize the path, we exit with 1
21+
if not result:
22+
sys.exit(1)
23+
24+
# Extract the domain name
25+
domain = result.group(1)
26+
27+
# Define a path for HAproxy where you want to write the .pem file.
28+
deploy_path="/etc/haproxy/ssl/" + domain + ".pem"
29+
30+
# The source files can be found in below paths, constructed with the lineage
31+
# path
32+
source_key = lineage + "/privkey.pem"
33+
source_chain = lineage + "/fullchain.pem"
34+
35+
# HAproxy requires to combine the key and chain in one .pem file
36+
with open(deploy_path, "w") as deploy, \
37+
open(source_key, "r") as key, \
38+
open(source_chain, "r") as chain:
39+
deploy.write(key.read())
40+
deploy.write(chain.read())
41+
42+
# Here you can add your service reload command. Which will be executed after
43+
# every renewal, which is fine if you only have a few domains.
44+
45+
# Alternative is to add the reload to the --post-hook. In that case it is only
46+
# run once after all renewals. That would be the use-case if you have a large
47+
# number of different certificates served by HAproxy.
48+
49+

certbot_haproxy/constants.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,25 @@
9090
CLI_DEFAULTS = {
9191
"debian": {
9292
'_min_version': '7',
93-
'_max_version': '8',
93+
'_max_version': '9',
9494
'7': CLI_DEFAULTS_DEBIAN_BASED_PRE_SYSTEMD_OS,
95-
'8': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS
95+
'8': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
96+
'9': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS
9697
},
9798
"ubuntu": {
9899
'_min_version': '14.04',
99-
'_max_version': '16.04',
100+
'_max_version': '18.04',
100101
'14.04': CLI_DEFAULTS_DEBIAN_BASED_PRE_SYSTEMD_OS,
101102
'14.10': CLI_DEFAULTS_DEBIAN_BASED_PRE_SYSTEMD_OS,
102103
'15.04': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
103104
'15.10': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
104-
'16.04': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS
105+
'16.04': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
106+
'16.10': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
107+
'17.04': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
108+
'17.10': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
109+
'18.04': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
110+
'18.10': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS,
111+
'19.04': CLI_DEFAULTS_DEBIAN_BASED_SYSTEMD_OS
105112
}
106113
}
107114

0 commit comments

Comments
 (0)