Docker layers hiding secrets is a big problem. Any solution other than education?
Docker layers hiding secrets is a big problem. Any solution other than education?
For a Docker container, that might look like:
1. Create an EC2 instance with no IAM permissions, and a user with ~/.ssh/authorized_keys to allow copying in files.
2. Install Docker.
3. Copy all files for your build to the host. Make sure not to copy any secrets (!).
4. Run the 'docker build'.
5. Set up remote registry authentication.
6. 'docker push' the built image to the remote registry.
In that environment, the only "secrets" you can bring along into the container came when you copied files to the EC2 instance (which shouldn't have been there, just like secrets shouldn't be in your source code). So then you also make sure the process that preps your files for copying also contains no secrets.Even for my local manual builds, I started doing this from fresh git-worktrees that I do no development in, as .env/.git/.log files tend to accumulate in your development copy and are very easy to put in the Docker image by mistake.
I'm not really sure what would be the best tool for this, but googling got me to https://sysdig.com/blog/20-docker-security-tools/ which has enough scanning tools to research. I don't think any will be foolproof though.
Maybe you can also do what this guy did, use conftest with some OPA rules to detect what seems like a secret: https://cloudberry.engineering/article/dockerfile-security-b...
If your secrets all follow RFC 8959 ( https://tools.ietf.org/html/rfc8959 ) then you could make it fool proof by just searching for secret-token: with the tool from the previous blog post. However I've yet to find a place that uses this RFC for all secrets.
- If you're using buildkit, there's secret support there https://docs.docker.com/develop/develop-images/build_enhance...
The problem is anything that's not default on or at least in the getting started guide is going to be missed by a significant chunk of the userbase, so it's important to make security as automatic as possible. GitHub token scanning is nice for limiting secrets exposure in public git repos, for instance.
The goal is defense in depth so that even if a secret is leaked the damage is minimal.