-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56c36cc
commit 3c6c2cc
Showing
6 changed files
with
184 additions
and
96 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## 0.0.2 | ||
|
||
- errors handling #3 | ||
- complete readme #2 | ||
- better configuration #1 |
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 |
---|---|---|
|
@@ -13,53 +13,105 @@ At first create following K/V structure in Consul: | |
``` | ||
letsconsul | ||
|_ | ||
| \_domains | ||
| |_ | ||
| | \_example.com | ||
| | |_ | ||
| | | \_domain_list = ["www.example.com", "example.com"] | ||
| | |_ | ||
| | | \_email = [email protected] | ||
| | |_ | ||
| | | \_timestamp = 0 | ||
| | |_ | ||
| | | \_private_key = | ||
| | |_ | ||
| | \_fullchain = | ||
| |_ | ||
| \_qlean.ru | ||
| |_ | ||
| | \_domain_list = ["qlean.ru", "www.qlean.ru", "assets.qlean.ru"] | ||
| |_ | ||
| | \email = [email protected] | ||
| |_ | ||
| | \_timestamp = 0 | ||
| |_ | ||
| | \_private_key = | ||
| |_ | ||
| \_fullchain = | ||
| \_renew_interval = 168h | ||
|_ | ||
\_domains_enabled = ["example.com", "qlean.ru"] | ||
| \_reload_interval = 10s | ||
|_ | ||
| \_service = letsconsul | ||
|_ | ||
| \_domains_enabled = ["example.com", "qlean.ru"] | ||
|_ | ||
\_domains | ||
|_ | ||
| \_example.com | ||
| |_ | ||
| | \_domain_list = ["www.example.com", "example.com"] | ||
| |_ | ||
| | \_email = [email protected] | ||
| |_ | ||
| | \_timestamp = 0 | ||
| |_ | ||
| | \_private_key = | ||
| |_ | ||
| \_fullchain = | ||
|_ | ||
\_qlean.ru | ||
|_ | ||
| \_domain_list = ["qlean.ru", "www.qlean.ru", "assets.qlean.ru"] | ||
|_ | ||
| \email = [email protected] | ||
|_ | ||
| \_timestamp = 0 | ||
|_ | ||
| \_private_key = | ||
|_ | ||
\_fullchain = | ||
``` | ||
|
||
When letsconsul starting it reading particular environment variables: | ||
Consul configuration keys: | ||
|
||
- `renew_interval` - domain certificate expiration time | ||
- `reload_interval` - time after letsconsul reloading domains information from consul | ||
- `service` - consul service name | ||
- `domains_enabled` - domains from `letsconsul/domains` that can be validated and renewed with certs/keys | ||
|
||
When letsconsul starting it reading particular command line arguments: | ||
|
||
- `-b` - host:port variable that validation web-server will listen (by default 0.0.0.0:8080) | ||
- `-c` - consul address (by default 127.0.0.1:8500) | ||
|
||
- `BIND` - host:port variable that server will listen (e.g BIND=0.0.0.0:21234) | ||
- `RENEW_INTERVAL` - domain certificate expiration time (e.g. RENEW_INTERVAL=168h) | ||
- `RELOAD_INTERVAL` - time after letsconsul reloading domains information from consul (e.g. RELOAD_INTERVAL=10s) | ||
- `CONSUL_SERVICE` - consul service name and k/v folder where domains serving (e.g. CONSUL_SERVICE=letsconsul) | ||
- `CONSUL_TOKEN` - consul ACL token | ||
Also, you can specifly consul ACL token with CONSUL_TOKEN environment variable. | ||
|
||
Example of usage: | ||
|
||
``` | ||
$ go build | ||
$ BIND=0.0.0.0:21234 RENEW_INTERVAL=168h RELOAD_INTERVAL=10s CONSUL_SERVICE=letsconsul letsconsul | ||
$ wget https://github.com/hypersleep/letsconsul/releases/download/0.0.2/letsconsul-linux-64.zip | ||
$ unzip letsconsul-linux-64.zip | ||
$ ./letsconsul -b 0.0.0.0:8080 -c 127.0.0.1:8500 | ||
``` | ||
|
||
## Workflow description | ||
|
||
After app starts, it fetching domains information from consul by given `consul_service` key, checking certificate expiration time and if more than `renew_interval` then starts certificate renew process. | ||
|
||
Updating and receiving certificates is based on LetsEncrypt HTTP validation. | ||
|
||
After validation request has sent to LetsEncrypt, letsconsul starts a validation web-server on address `-b` that should receive a LetsEncrypt validation request. | ||
|
||
Ensure that validation web-server available from internet! You can simply do this with combination of nginx proxy and consul-template: | ||
|
||
``` | ||
server { | ||
listen 80; | ||
server_name www.example.com example.com; | ||
{{range service "letsconsul"}} | ||
location /.well-known/acme-challenge { | ||
proxy_set_header Host $host; | ||
proxy_pass http://{{.Address}}:{{.Port}}; | ||
} | ||
{{end}} | ||
} | ||
``` | ||
|
||
If validation will be made successfully, letsconsul writes received certificates and keys to `fullchain` and `private_key` consul keys. | ||
|
||
After that you can use values of `fullchain` and `private_key` as cert/key files for nginx using consul-template: | ||
|
||
/etc/ssl/example.com.crt.ctmpl: | ||
``` | ||
{{key "letsconsul/domains/example.com/fullchain"}} | ||
``` | ||
rendering to: /etc/ssl/example.com.crt | ||
|
||
/etc/ssl/example.com.key.ctmpl: | ||
``` | ||
{{key "letsconsul/domains/example.com/private_key"}} | ||
``` | ||
rendering to: /etc/ssl/example.com.key | ||
|
||
After app starts, it fetching domains information from consul by given `CONSUL_SERVICE` env variable, checking certificate expiration time and if more than `RENEW_INTERVAL` then starts certificate renew process. | ||
Finally, you're got fully automated and distributed by many servers/proxies HTTPS certificates! | ||
|
||
You can see full workflow on following chart: | ||
|
||
![Workflow](workflow.png) | ||
|
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
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