-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from krystal/renewals-improvements
Renewals improvements
- Loading branch information
Showing
8 changed files
with
108 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
data/** | ||
config.rb | ||
manager.log | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Acme Manager | ||
This tool does management of LetsEncrypt certificates in our load balancer hosts. It does two main things: | ||
|
||
### Web Server | ||
|
||
It runs a webserver which allows certain apps to control certificates for domains externally. There are 3 API endpoints: | ||
|
||
* `/~acmemanager/list` - lists all currently valid certificates with their expiry date | ||
* `/~acmemanager/issue/example.com` - issues a certificate for example.com | ||
* `/~acmemanager/purge/example.com` - purges a certificate for example.com | ||
|
||
Requests must be authenticated by passing an API key in the X-API-KEY header. | ||
|
||
### Bulk Certificate Renewals (CRON) | ||
|
||
There's cron jobs set in the Load Balancer hosts (under the `haproxy` user) to run renewals daily at `02:00 AM`, the job looks like this: | ||
```shell | ||
0 2 * * * cd /opt/acme-manager; bundle exec ruby bin/renew.rb | ||
``` | ||
|
||
The `misc` directory contains some scripts required for the High Availability setup in the Load Balancer hosts. | ||
|
||
## Instructions | ||
* Run bundle (or bundle --deployment for production) | ||
* Copy config.rb.example to config.rb and configure as needed | ||
* Make bin/setup.rb to generate master keys, create directories, and accept the LetsEncrypt TOS | ||
* Run the web server with procodile `procodile start` | ||
* Run bin/renew.rb from time to time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
AcmeManager.directory = 'https://acme-staging-v02.api.letsencrypt.org/directory' | ||
AcmeManager.email_address = '[email protected]' | ||
AcmeManager.api_key = 'xxxxxxxxxxxxxx' | ||
AcmeManager.pre_renewal_check = proc { | ||
lock_file_path = "/var/run/renewals_cron.lock" | ||
node = File.read(lock_file_path).strip rescue nil | ||
node == "MASTER" | ||
} | ||
AcmeManager.post_commands = [ | ||
'sudo /etc/init.d/haproxy reload' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
# This script is used by Keepalived to notify all Load Balancer nodes | ||
# in the cluster of their current STATE, i.e. whether current host is | ||
# a "MASTER" or a "BACKUP". When the STATE file changes to "BACKUP" in | ||
# a given host all renewals commands are interrupted, thus preventing | ||
# multiple hosts from running renewals (via the CRON) | ||
# | ||
# This script should be located at `/usr/local/bin/` in each of the | ||
# Load Balancer hosts. | ||
# | ||
# Example Keepalived config in the Load Balancers would look like this: | ||
# | ||
# vrrp_instance CRON { | ||
# state MASTER | ||
# interface ens10 | ||
# virtual_router_id <ID> | ||
# priority 100 | ||
# advert_int 1 | ||
# notify /usr/local/bin/renewals_cron_control.sh | ||
# unicast_peer { | ||
# <IP_ADDRESS> | ||
# } | ||
# } | ||
|
||
# The path to the lock file | ||
LOCK_FILE="/var/run/renewals_cron.lock" | ||
STATE="" | ||
|
||
if [[ "$1" == "MASTER" ]]; then | ||
STATE="MASTER" | ||
elif [[ "$1" == "BACKUP" ]]; then | ||
STATE="BACKUP" | ||
elif [[ "$1" == "FAULT" ]]; then | ||
STATE="FAULT" | ||
fi | ||
|
||
echo "$STATE" > "$LOCK_FILE" | ||
|
||
# Change the owner of the lock file to 'haproxy' and make it readable | ||
chown haproxy "$LOCK_FILE" | ||
chmod 644 "$LOCK_FILE" |