Skip to content
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

IT-4010: add http/secret parameter #8

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ We use the [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/late
In dev the secret is named `registry-dev-DockerFargateStack/dev/ecs` and in the prod stack,
`registry-prod-DockerFargateStack/prod/ecs`

A secret is a collection of key-value pairs. For this application there is just one pair. The key should be `notification_auth` and the value is the
A secret is a collection of key-value pairs. For this application there are two pairs. The key for the first should be `notification_auth` and the value is the
Base64 encoded "Basic auth" credentials which are a shared-secret with Synapse as the event notification recipient.
The key for the second should be 'http_secret' and the value is a cryptogrphically generated string for use by the
server as described [here](https://distribution.github.io/distribution/about/configuration/).

### Registry container
We use the open source Docker `registry`, available on DockerHub. This container requires several configuration files to be mounted.
Expand Down
14 changes: 9 additions & 5 deletions docker_fargate/docker_fargate_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

BUCKET_NAME = "BUCKET_NAME"

SECRET_JSON_KEY="notification_auth"
NOTIFICATION_AUTH_SECRET_JSON_KEY="notification_auth"
HTTP_SECRET_SECRET_JSON_KEY="http_secret"

def get_secret(scope: Construct, id: str, name: str, secret_json_key) -> str:
isecret = sm.Secret.from_secret_name_v2(scope, id, name)
return ecs.Secret.from_secrets_manager(isecret, secret_json_key)
def get_secret(scope: Construct, id: str, name: str) -> str:
return sm.Secret.from_secret_name_v2(scope, id, name)
# see also: https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_ecs/Secret.html
# see also: ecs.Secret.from_ssm_parameter(ssm.IParameter(parameter_name=name))

Expand Down Expand Up @@ -92,8 +92,12 @@ def __init__(self, scope: Construct, context: str, env: dict, vpc: ec2.Vpc, **kw
container_insights=True)

secret_name = f'{env.get(config.STACK_NAME_PREFIX_CONTEXT)}-DockerFargateStack/{context}/ecs'
sm_secret = get_secret(self, secret_name, secret_name)
secrets = {
SECRET_JSON_KEY: get_secret(self, secret_name, secret_name, SECRET_JSON_KEY),
NOTIFICATION_AUTH_SECRET_JSON_KEY:
ecs.Secret.from_secrets_manager(sm_secret, NOTIFICATION_AUTH_SECRET_JSON_KEY),
HTTP_SECRET_SECRET_JSON_KEY:
ecs.Secret.from_secrets_manager(sm_secret, HTTP_SECRET_SECRET_JSON_KEY),
"AWS_SECRET_ACCESS_KEY": ecs.Secret.from_secrets_manager(secret_stored_access_key)
}

Expand Down
1 change: 1 addition & 0 deletions resources/dev/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ http:
tls:
certificate: /etc/docker/registry/ssl/certificate.pem
key: /etc/docker/registry/ssl/privatekey.pem
secret: http_secret

storage:
cache:
Expand Down
1 change: 1 addition & 0 deletions resources/prod/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ http:
tls:
certificate: /etc/docker/registry/ssl/certificate.pem
key: /etc/docker/registry/ssl/privatekey.pem
secret: http_secret

storage:
cache:
Expand Down
5 changes: 5 additions & 0 deletions startup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/sh

# Inject http_secret into config.yml
# The value is taken from the environment variable, `http_secret` which,
# during ECS deployment comes from the AWS Secrets Manager.
sed -i "s/http_secret/$http_secret/g" /etc/docker/registry/config.yml

# Inject notification listener authorization credentials into config.yml
# The value is taken from the environment variable, `notification_auth` which,
# during ECS deployment comes from the AWS Secrets Manager.
Expand Down
Loading