Plaintext Secrets
The Postgres password is hardcoded in the compose file — move it to a Docker secret.
The Problem
Your docker-compose.yml file currently contains this:
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: supersecretThis is dangerous. If you commit this file, the database password is in version control. If an attacker gets read access to your repository or server, they have your production credentials.
Docker Secrets provide a secure mechanism for passing sensitive information into containers without exposing them as environment variables.
What You Need to Fix
Load this challenge:
php artisan challenge:start docker-plaintext-secretsThe docker-compose.yml file is copied to your project root. Your task is to refactor it to use Docker secrets for the database password.
What You Must Do
- Define the secret: Add a top-level
secretsblock to the bottom of thedocker-compose.ymlfile that definesdb_passwordpointing to./secrets/db_password.txt. - Mount the secret: Add a
secretslist to thedbservice and reference- db_password. - Use the secret: In the
dbservice'senvironmentblock, removePOSTGRES_PASSWORD: supersecretand addPOSTGRES_PASSWORD_FILE: /run/secrets/db_password.
(Note: In a real project, you would also need to create the secrets/db_password.txt file and update your PHP application to read from /run/secrets/db_password. For this challenge, we are only validating the syntax of the compose file.)
Hints
- The top-level block looks like this:
secrets: db_password: file: ./secrets/db_password.txt - The service-level mount looks like this:
secrets: - db_password - Postgres natively supports
POSTGRES_PASSWORD_FILEand will read the file contents to set the password.
Verify
php artisan challenge:verify