Recipes
Where to keep the token, and how to start your app with the secrets in Docker, Kubernetes, GitHub Actions, and systemd.
The golden rule
Your app needs only two variables: COFFREBOX_URL and COFFREBOX_TOKEN. The token is the only thing to protect. It goes where your platform stores secrets, never in the repository or the image.
Never put the token in a Dockerfile ENV or ARG, or in a file that COPY brings into the image: it gets baked into the layers and leaks along with the image. Keep the file with the token outside the project folder.
Docker with the SDK
With the Node.js or Rust SDK, nothing changes in the image. Pass the variables at run time, from a file outside Git:
# /etc/my-api/coffrebox.env has COFFREBOX_URL and COFFREBOX_TOKEN (0600 permissions)
docker run --env-file /etc/my-api/coffrebox.env my-apiTo let your app start even when the Coffrebox server is down, keep the encrypted cache in a volume. The SDK must be able to write to it: create the folder in the image, owned by the process’s user, and a new volume inherits that owner.
RUN mkdir -p /var/cache/coffrebox && chown node:node /var/cache/coffrebox
USER nodedocker run --env-file /etc/my-api/coffrebox.env \
-e COFFREBOX_CACHE_DIR=/var/cache/coffrebox -v coffrebox-cache:/var/cache/coffrebox \
my-apiDocker with coffre run
For any language, copy the CLI binary into the image and use coffre run as the entrypoint:
FROM debian:bookworm-slim AS coffre
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl
ARG V=0.2.0
ARG TARGETARCH
WORKDIR /download
# The image picks the binary for its architecture (amd64 or arm64)
RUN case "$TARGETARCH" in arm64) A=aarch64 ;; *) A=x86_64 ;; esac \
&& B=https://github.com/brunosps/coffrebox-sdk/releases/download/v$V \
&& curl -fLO $B/coffre-$V-$A-unknown-linux-musl.tar.gz -fLO $B/SHA256SUMS \
&& sha256sum -c SHA256SUMS --ignore-missing \
&& tar -xzf coffre-$V-$A-unknown-linux-musl.tar.gz coffre
FROM python:3.13-slim
COPY --from=coffre /download/coffre /usr/local/bin/coffre
WORKDIR /app
COPY . .
ENTRYPOINT ["coffre", "run", "--"]
CMD ["python", "app.py"]Since COPY . . takes the whole folder, a .dockerignore makes sure no secrets file ends up in the image by accident:
**/.env
**/.env.*
**/*.env
.gitThe binary is static: it works in Debian, Alpine, or distroless images. The program takes the place of coffre in the process and receives the SIGTERM from docker stop directly. As process 1 in the container, it only stops if it handles the signal; if it doesn’t, run it with docker run --init (or init: true in Compose).
Docker Compose
services:
api:
image: my-api
# COFFREBOX_URL and COFFREBOX_TOKEN, in a 0600 file outside the project folder
env_file: /etc/my-api/coffrebox.envKubernetes
Create the Secret directly in the cluster, from the file with both variables, so the token doesn’t end up in a versioned manifest:
kubectl create secret generic coffrebox --from-env-file=/etc/my-api/coffrebox.envIn the Deployment’s container:
envFrom:
- secretRef:
name: coffreboxGitHub Actions
Store the token in Settings → Secrets and variables → Actions as COFFREBOX_TOKEN, and run the step that needs the secrets with coffre run:
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install the coffre CLI
run: |
B=https://github.com/brunosps/coffrebox-sdk/releases/download/v0.2.0
curl -fLO $B/coffre-0.2.0-x86_64-unknown-linux-musl.tar.gz -fLO $B/SHA256SUMS
sha256sum -c SHA256SUMS --ignore-missing
tar -xzf coffre-0.2.0-x86_64-unknown-linux-musl.tar.gz coffre
sudo install coffre /usr/local/bin/
- name: Deploy
run: coffre run -- ./scripts/deploy.sh
env:
COFFREBOX_URL: https://coffrebox.net
COFFREBOX_TOKEN: ${{ secrets.COFFREBOX_TOKEN }}GitHub masks the value of COFFREBOX_TOKEN in the logs, but not the secrets that coffre run hands to the script: don’t print the environment or run the script with set -x. Create an access just for CI, in a vault that holds only what the deploy needs.
systemd
[Unit]
Description=My API
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/local/bin/coffre run -- /opt/my-api/server
# COFFREBOX_URL and COFFREBOX_TOKEN, in a 0600 file owned by root
EnvironmentFile=/etc/my-api/coffrebox.env
# Encrypted cache, so the service starts even when the Coffrebox server is down
CacheDirectory=my-api
Environment=COFFREBOX_CACHE_DIR=%C/my-api
DynamicUser=yes
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.targetsystemd reads the EnvironmentFile as root before it switches users, so the file can stay readable by root only.