Any way to use Komodo with encrypted .env via SOPS? #934
Replies: 7 comments 4 replies
|
I was just going to propose this idea as well. My solution right now is to simply extend the Komodo image and install SOPS and age, and attach the age key to the Komodo container in read only mode. Then for each compose stack I add a pre-deploy command to:
and deploy the stack in Komodo as usual. This is the Dockerbuild file I'm using: FROM ghcr.io/moghtech/komodo-periphery:latest
# Install age
RUN apt-get update \
&& apt-get install -y --no-install-recommends age
# Clean up
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install sops
RUN curl -LO https://github.com/getsops/sops/releases/download/v3.11.0/sops-v3.11.0.linux.amd64 \
&& chmod +x sops-v3.11.0.linux.amd64 \
&& mv sops-v3.11.0.linux.amd64 /usr/local/bin/sops
# Create the sops directory
RUN mkdir -p $HOME/.config/sops/ageThe only tedious part is keeping up with both Komodo and SOPS development to make sure everything is up to date. |
|
I just looked it up a few days ago if anyone proposed something like that lol I also would love to see this implemented! |
|
Would love to see this as well, trying to set up something similar and for a project so integration into GitOps, this seems like a no brainer. |
|
I've created an image, which contains Komodo-Periphery, SOPS and age so you don't have to do it yourselves. Every night CET it's being checked, if an update of Komodo, SOPS or age has been released. If that's the case, a new image is being built automatically. You can use a I'm encrypting the .env file locally in VSC and only push the encrypted file to git. Then Komodo is picking up Compose and encrypted .env file. I run a pre-deploy command in Komodo so the file is decrypted and usable for deployment. You can find more information here: https://github.com/smoochy/komodo-periphery-sops-age/ Hope that helps. |
|
Created a pull request to add sops and age to the periphery and core images: If it gets merged should be easy to implement this kind of workflow. |
|
I’ve ended up with a working Komodo + SOPS + AGE setup that is deploy-time only, and it’s been stable so far. From Komodo’s side, the important part is that the stack definition does not store plaintext secrets; it just tells Komodo how to resolve an encrypted env file at deploy time. git repo tree Sanitized version of what I’m using: The workflow is:
My remaining questions are from the Komodo product side:
Thanks for any insight on this topic! |
|
Here's what I've figured out, and allows for not needing a custom image at all. These both use Two options via Option A, export variables at runtime out of docker: eval "$(docker run --rm -e SOPS_AGE_KEY="[[SOPS_AGE_KEY]]" -v "$(pwd):/app" -w /app \
ghcr.io/getsops/sops:v3.13.0-alpine -d compose.env | sed 's/^/export /')" && [[COMPOSE_COMMAND]]Problem here, is you need to define your env variables form shell in all compose files. So I am using option B: # decrypt
docker run --rm -e SOPS_AGE_KEY="[[SOPS_AGE_KEY]]" -v "$(pwd)/compose.env:/compose.env" \
ghcr.io/getsops/sops:v3.13.0-alpine -d -i /compose.env
# run compose
[[COMPOSE_COMMAND]]
# reset
git checkout -- compose.env
# make sure you set a `env_file_path` to `compose.env` for this optionThis decrypts in place with the docker container and then resets it afterwards with git so no secrets are left on disk. All in all, seems to be working decently for me, and doesn't create an attack vector of a custom docker image like above, or require me to build my own image, and manage that. If anyone improves this idea even further lmk, I would rather just export variables in shell with option B, but due to the way [[COMPOSE_COMMAND]] injects is flags, I am not able to use <() to run this command inline. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Currently running one large docker compose file for all my containers that stores sensitive data (database passwords, bypass keys, etc) in an encrypted .env file using SOPS.
When I run my compose file, i use the following command:
sops exec-file --no-fifo .env "docker compose --env-file {} up -d"Overall this works great for me, but I'm interested in Komodo and I'd like to be able to maintain keeping my secrets encrypted via SOPS. I don't want to deploy a Hashicorp / OpenBao vault as it is extremely overkill for this purpose.
Is there a way for me to use SOPS and Komodo together? Does anyone have a similar setup?
All reactions