Securely configure secrets
Environment variables in the agent configuration
Adjust agent configuration - AgentConfig.yaml
If you prefer to pass your secrets with environment variables, that's no problem.
Instead of your secret, specify the name of an environment variable in the corresponding field.
${env:VARIABLE_NAME}
When you have downloaded your configuration. It should look something like this.
type: AWS
agentToken: 12:72211049-cfbc-4ba7-9f45-7139a14e302b
accessKey: ${env:ACCESS_KEY}
secretAccessKey: ${env:SECRET_ACCESS_KEY}
region: eu-central-1
stage: test
Adjust the agent - docker-compose.yml
Now you just need to tell Docker to forward the environment variables. To do this, add the following for each environment variable.
VARIABLE_NAME=${VARIABLE_NAME}
The docker-compose file should look something like this.
Set the environment variables in your system
Now you just have to set the environment variables in your system.
Using docker secrets in the agent configuration
In terms of Docker Swarm services, a secret is a blob of data, such as a password, SSH private key, SSL certificate, or another piece of data that should not be transmitted over a network or stored unencrypted in a Dockerfile or in your application’s source code. You can use Docker secrets to centrally manage this data and securely transmit it to only those containers that need access to it. Secrets are encrypted during transit and at rest in a Docker swarm. A given secret is only accessible to those services which have been granted explicit access to it, and only while those service tasks are running.
https://docs.docker.com/engine/swarm/secrets/
Adjust agent configuration - AgentConfig.yaml
Docker secrets are mounted into the container as files. In the agent's configuration we just need to enter where it can find it.
When you have downloaded your configuration. It should look something like this.
Create docker secrets
The first thing you need to do is enable Swarm mode if you are not already using it.
https://docs.docker.com/engine/swarm/
After that, you can create your secrets.
Adjust the agent - docker-compose.yml
After that, we need to make a few changes in docker-compose. First, we need to remove the container_name. This is not supported in Swarm mode.
After that, we need to tell docker which Secrets to use for this service (lines 11-13) and where they are located (lines 15-19).
Now we can start our agent