Using secrets or sensitive information in Docker encompasses two potential timeframes:
- Build time: When the Docker image is being constructed.
- Runtime: When a container from the Docker image is executing.
For runtime secrets in AWS Elastic Beanstalk:
Elastic Beanstalk environment variables can be used to pass runtime secrets to the application. These variables can be set via the AWS Management Console, EB CLI, or AWS SDKs and are injected into the Docker container at runtime. Your application can then read these environment variables.
However, for build time secrets:
Docker has a native mechanism to pass build-time secrets using the --build-arg
parameter during the docker build
command. That approach uses the ARG
instruction in the Dockerfile.
Yet, Elastic Beanstalk's Docker integration, as of the last update, does not allow for the passing of build arguments during the image build process. That means you cannot use the ARG
mechanism for build-time secrets when deploying with Elastic Beanstalk.
As such, if your use case specifically requires build-time secrets with Elastic Beanstalk, you might need to consider alternative strategies:
- Pre-built Images: Build your Docker images in a secure environment where you can use build-time secrets. Push these pre-built images to a private registry (like Amazon ECR) and then reference these images in Elastic Beanstalk.
Remember: Storing or baking secrets into Docker images is a security risk. Instead, prefer methods that inject secrets at runtime or grant permissions without explicit credentials.
- IAM roles: For AWS specific secrets (like access to S3 or DynamoDB), instead of passing secrets, attach an IAM role to your Elastic Beanstalk environment's EC2 instances that grants the necessary permissions. AWS SDKs inside your container will automatically use these permissions without needing explicit credentials.
This is used for instance here for accessing the AWS secret Manager