-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for certificates from Let's Encrypt. #13
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b7cd1ca
Add support for certificates from Let's Encrypt.
plietar a5087db
lint
plietar 8ccbf92
fix f-string
plietar 6a821fa
fix test
plietar 388eed3
fix config
plietar 61a3cd2
fix dhparam test
plietar d4d767e
switch to proxy master
plietar aecbfef
Add support for additional domain names.
plietar c402371
Add --expand argument
plietar 7c5f8cd
fixup
plietar 0371e65
Allow arbitrary arguments to be passed through to certbot
plietar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,9 @@ | ||
testGroup: | ||
testDisease: | ||
- report_name: diagnostic | ||
assignee: a.hill | ||
success_email: | ||
recipients: | ||
- [email protected] | ||
- [email protected] | ||
subject: "VIMC diagnostic report: {touchstone} - {group} - {disease}" |
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,125 @@ | ||
## Prefix for container names; we'll use {container_prefix}-(container_name) | ||
container_prefix: montagu | ||
|
||
## Set this flag to true to prevent use of --volumes in the cli to remove | ||
## volumes on stop | ||
protect_data: false | ||
|
||
## Docker org for images | ||
repo: vimc | ||
|
||
## The name of the docker network that containers will be attached to. | ||
## If you want to proxy Packit to the host, you will need to | ||
## arrange a proxy on this network | ||
network: montagu-network | ||
|
||
# Domain where this instance of Montagu will be deployed. E.g. science.montagu.dide.ic.uk | ||
hostname: montagu.org | ||
|
||
## Names of the docker volumes to use | ||
volumes: | ||
db: db_volume | ||
burden_estimates: burden_estimate_files | ||
emails: emails | ||
templates: template_volume | ||
guidance: guidance_volume | ||
mq: mq | ||
acme-challenge: acme-challenge | ||
certificates: certificates | ||
certbot: certbot | ||
|
||
api: | ||
name: montagu-api | ||
tag: master | ||
admin: | ||
name: montagu-cli | ||
tag: master | ||
db: | ||
name: montagu-db | ||
tag: master | ||
root_user: vimc | ||
migrate: | ||
name: montagu-migrate | ||
tag: master | ||
users: | ||
api: | ||
password: "apipassword" | ||
permissions: all | ||
import: | ||
password: "importpassword" | ||
permissions: all | ||
orderly: | ||
password: "orderlypassword" | ||
permissions: all | ||
readonly: | ||
password: "readonlypassword" | ||
permissions: readonly | ||
protected_tables: | ||
- gavi_support_level | ||
- activity_type | ||
- burden_outcome | ||
- gender | ||
- responsibility_set_status | ||
- impact_outcome | ||
- gavi_support_level | ||
- support_type | ||
- touchstone_status | ||
- permission | ||
- role | ||
- role_permission | ||
proxy: | ||
name: montagu-reverse-proxy | ||
tag: master | ||
port_http: 80 | ||
port_https: 443 | ||
metrics: | ||
repo: nginx | ||
name: nginx-prometheus-exporter | ||
tag: 1.3.0 | ||
acme: | ||
email: [email protected] | ||
additional_domains: | ||
- montagu-dev.org | ||
contrib: | ||
name: montagu-contrib-portal | ||
tag: master | ||
admin: | ||
name: montagu-admin-portal | ||
tag: master | ||
mq: | ||
repo: docker.io | ||
name: redis | ||
tag: latest | ||
port: 6379 | ||
flower: | ||
repo: mher | ||
name: flower | ||
tag: 0.9.5 | ||
port: 5555 | ||
task_queue: | ||
name: task-queue-worker | ||
tag: master | ||
tasks: | ||
diagnostic_reports: | ||
use_additional_recipients: false | ||
poll_seconds: 5 | ||
archive_folder_contents: | ||
min_file_age_seconds: 3600 | ||
servers: | ||
youtrack: | ||
token: faketoken | ||
orderlyweb: | ||
url: http://orderly-web-web:8888 | ||
montagu: | ||
user: [email protected] | ||
password: password | ||
smtp: | ||
from: [email protected] | ||
# If fake_smtp_server config is provided, the task_queue will use this as its smtp server | ||
# Note this will override other config provided in the task_queue section above | ||
fake_smtp_server: | ||
repo: reachfive | ||
name: fake-smtp-server | ||
tag: latest | ||
|
||
orderly_web_api_url: https://localhost/reports/api/v2 |
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
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,90 @@ | ||
# https://github.com/certbot/certbot/blob/v3.0.1/acme/examples/http01_example.py | ||
|
||
import os.path | ||
import sys | ||
import tarfile | ||
from tempfile import TemporaryFile | ||
|
||
import docker | ||
from constellation import docker_util | ||
|
||
# The Docker API uses Go's FileMode values. These are different from the | ||
# standard values, as found in eg. stat.S_IFLNK. | ||
# https://pkg.go.dev/io/fs#FileMode | ||
DOCKER_MODE_TYPE = 0x8F280000 | ||
DOCKER_MODE_SYMLINK = 0x8000000 | ||
|
||
|
||
def read_file(container, path, *, follow_links=False): | ||
stream, status = container.get_archive(path) | ||
if follow_links and (status["mode"] & DOCKER_MODE_TYPE) == DOCKER_MODE_SYMLINK: | ||
return read_file(container, status["linkTarget"], follow_links=False) | ||
else: | ||
with TemporaryFile() as f: | ||
for d in stream: | ||
f.write(d) | ||
f.seek(0) | ||
|
||
with tarfile.open(fileobj=f) as tar: | ||
return tar.extractfile(os.path.basename(path)).read() | ||
|
||
|
||
def obtain_certificate(cfg, extra_args): | ||
docker_util.ensure_volume(cfg.volumes["certbot"]) | ||
docker_util.ensure_volume(cfg.volumes["acme-challenge"]) | ||
|
||
environment = {} | ||
command = [ | ||
"certonly", | ||
"--non-interactive", | ||
"--agree-tos", | ||
"--webroot", | ||
"--webroot-path=/var/www", | ||
f"--email={cfg.acme_email}", | ||
f"--domain={cfg.hostname}", | ||
] | ||
|
||
for d in cfg.acme_additional_domains: | ||
command.append(f"--domain={d}") | ||
|
||
if cfg.acme_server: | ||
command.append(f"--server={cfg.acme_server}"), | ||
if cfg.acme_no_verify_ssl: | ||
command.append("--no-verify-ssl") | ||
environment["PYTHONWARNINGS"] = "ignore:Unverified HTTPS request" | ||
|
||
command.extend(extra_args) | ||
|
||
image = "certbot/certbot" | ||
container = docker.from_env().containers.run( | ||
image, | ||
command=command, | ||
detach=True, | ||
volumes={ | ||
cfg.volumes["acme-challenge"]: { | ||
"bind": "/var/www/.well-known/acme-challenge", | ||
"mode": "rw", | ||
}, | ||
cfg.volumes["certbot"]: { | ||
"bind": "/etc/letsencrypt", | ||
"mode": "rw", | ||
}, | ||
}, | ||
network=cfg.network, | ||
environment=environment, | ||
) | ||
|
||
try: | ||
exit_status = container.wait()["StatusCode"] | ||
|
||
sys.stderr.write(container.logs().decode("utf-8")) | ||
if exit_status != 0: | ||
raise docker.errors.ContainerError(container, exit_status, command, image, None) | ||
|
||
cert = read_file(container, f"/etc/letsencrypt/live/{cfg.hostname}/fullchain.pem", follow_links=True) | ||
key = read_file(container, f"/etc/letsencrypt/live/{cfg.hostname}/privkey.pem", follow_links=True) | ||
|
||
return (cert, key) | ||
|
||
finally: | ||
container.remove() |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is similar to https://github.com/reside-ic/constellation/blob/master/constellation/docker_util.py#L184, but supports symbol links. I'll probably upstream that functionality at some point.