Skip to content

Secrets and access ​

Absolute rule: no password, no key, no token is written in the repository, nor in its history.

Where the secrets are ​

SecretStored inUsed byEnds up in
POSTGRES_PASSWORDGitLab CI/CD variabledeploy-dev, deploy-proddb (POSTGRES_PASSWORD) and api (DB_PASSWORD) containers
DJANGO_SECRET_KEYGitLab CI/CD variabledeploy-dev, deploy-prodapi container (SECRET_KEY)
CI_REGISTRY_PASSWORDprovided by GitLab, temporary*:build, deploy-proddocker login
gitlab_runner_tokenAnsible Vaultgitlab-runner rolethe dev server's /etc/gitlab-runner/config.toml
deploy_runner_tokensAnsible Vaultgitlab-runner roleeach server's config.toml
Vault passwordperson to person, outside Gitansible-playbook --ask-vault-pass—
Administrators' SSH keystheir machinesAnsible, manual connectionsthe servers' ~/.ssh/authorized_keys
Datadog API keyGitLab's Datadog integration, encryptedGitLab.comsending pipelines to Datadog
Mirror SSH keygenerated and kept by GitLab; its public part is on Elias's GitHub accountGitLab.compush to the school's GitHub repository

How a secret reaches a container ​

  1. GitLab injects POSTGRES_PASSWORD and DJANGO_SECRET_KEY as the job's environment variables.
  2. The Compose file references them: SECRET_KEY: ${DJANGO_SECRET_KEY}.
  3. docker compose or docker stack deploy replaces ${…} with the value at deployment time.

The value is never written in a file of the repository.

GitLab variable settings ​

In Settings → CI/CD → Variables, each secret must be:

OptionWhy
Maskedthe value is replaced by [MASKED] if it shows up in a log
Protectedthe variable is only given to pipelines of protected branches (develop, main). A feature/* branch cannot read it, even with an echo

Never print a secret in a job

No echo $DJANGO_SECRET_KEY, no env or printenv in a script. Masking does not protect against everything (an encoded or split value…).

Other security measures ​

MeasureEffect
UFW firewall: 22, 80, 443 onlyPostgreSQL, Docker and the applications are not reachable from the Internet
internal networkthe database is only reachable by the API
HTTPS everywhere, port 80 redirectedexchanges are encrypted
Non-root prod containersa flaw in the application does not give root inside the container
DEBUG=False and mandatory SECRET_KEY in prodno detailed error page, no default key
Local deploy runnersno SSH deploy key to store in GitLab
no_log: true on runner registrationtokens do not appear in Ansible's output
Root .gitignoreexcludes .env, *.pem, *.key, .vault_pass*

If a secret leaked ​

  1. Change it right away: new value in GitLab or in the Vault. Deleting the commit is not enough: the history, clones and forks already have it.
  2. Redeploy, so the containers pick up the new value.
  3. For a runner token: revoke the runner in GitLab, create a new one, put the token in the Vault, re-run the gitlab-runner role.

Changing POSTGRES_PASSWORD does not change the database password

The PostgreSQL image only uses this variable when the volume is created. You must also change the password inside PostgreSQL (ALTER USER trinity PASSWORD '…'), then redeploy.

Known limits (no automatic secret scanning, API without authentication) are in Limits and improvements.