Secrets

Secrets in CI/CD and deployment: GitHub Actions, GitLab CI, Docker

Updated: 26 October 2026

Pipelines need secrets: database passwords for migrations, registry tokens for images, SSH keys for deployment. The question is not whether they are there, but for how long, how many copies exist and who can read them.

Principles

  • No plaintext in the repository. Only the encrypted secrets.enc belongs in the repository; .env, identity.key and key files belong in .gitignore.
  • Values at runtime. Decryption happens in the step that needs the value – not in the build, not in the image, not in a file that stays behind.
  • One access per pipeline. Every pipeline and every server has its own API token and its own key. If one is compromised, you revoke exactly that one.
  • Separate environments. Test and production are separate stages with their own authorized people.

One-time setup: key and token for the pipeline

  1. On a trusted computer, create a separate key for the pipeline: secrets-tool --key ci.identity.key init. The CLI asks for a password that encrypts the file.
  2. Print the public key (secrets-tool --key ci.identity.key pubkey) and add it in the project under Access as an external key – ideally only in the stage the pipeline needs (Access and roles).
  3. In the web app under My access → API tokens, create a token just for this pipeline.
  4. Create three protected variables in your CI: the content of ci.identity.key, its password as SECRETS_TOOL_PASSWORD, and the token. Then store the local copy of the key file safely or delete it.

On every run, the pipeline then fetches the current encrypted file from the server (remote pull) and decrypts it with its own key. If someone changes a value in the web app, it is there on the next run – without a commit.

GitHub Actions

The secrets live as repository or environment secrets at GitHub and reach the step through env, not directly in the script text:

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v4
      - name: Install secrets-tool
        run: curl -fsSL https://secret.sareba.com/install.sh | sh
      - name: Deploy
        env:
          SECRETS_TOKEN: ${{ secrets.SECRETS_TOKEN }}
          SECRETS_IDENTITY: ${{ secrets.SECRETS_IDENTITY_KEY }}
          SECRETS_TOOL_PASSWORD: ${{ secrets.SECRETS_TOOL_PASSWORD }}
          SECRETS_TOOL_STAGE: prod
        run: |
          mkdir -p ~/.config/sareba && install -m 600 /dev/null ~/.config/sareba/identity.key
          printf '%s\n' "$SECRETS_IDENTITY" > ~/.config/sareba/identity.key
          secrets-tool remote login https://secret.sareba.com "$SECRETS_TOKEN"
          secrets-tool remote pull shop-backend
          eval "$(secrets-tool export | sed 's/^/export /')"
          ./deploy.sh

The values only exist in the environment of this one step. With SECRETS_TOOL_STAGE=prod, all commands apply to the prod stage without --stage everywhere.

GitLab CI

In GitLab, add the key file as a variable of type File (GitLab then provides a path) and mark all three variables as protected and – where possible – masked:

deploy:
  stage: deploy
  environment: production
  script:
    - curl -fsSL https://secret.sareba.com/install.sh | sh
    - mkdir -p ~/.config/sareba && install -m 600 "$SECRETS_IDENTITY_KEY" ~/.config/sareba/identity.key
    - secrets-tool remote login https://secret.sareba.com "$SECRETS_TOKEN"
    - SECRETS_TOOL_STAGE=prod secrets-tool remote pull shop-backend
    - eval "$(SECRETS_TOOL_STAGE=prod secrets-tool export | sed 's/^/export /')"
    - ./deploy.sh
  rules:
    - if: $CI_COMMIT_BRANCH == "main"

PowerShell deployments

If the deployment runs on Windows or with PowerShell, load replaces export:

secrets-tool remote pull shop-backend
Invoke-Expression (secrets-tool load)
.\deploy.ps1

On your own computer, secrets-tool unlock --device unlocks the key permanently without a password in the script; revocable in the web app under My access.

Docker and docker compose

No secrets in the image

Whatever gets into the image at build time via ARG, ENV or COPY .env is stored in its layers and readable by anyone who gets the image – even after the file is deleted later. Secrets belong in the running container, not in the image.

No values in the one-liner

docker run -e DB_PASSWORD=… writes the value into the command line, the shell history and docker inspect. secrets-tool check reports such lines in deploy scripts.

Docker host without the CLI: hostenv

Recommended for hosts that only run Docker: secrets-tool hostenv writes the env files onto the host from your own computer, with mode 600 and without any value appearing in a command line or console. Before the deployment, --guard checks that the file matches the current state of secrets.enc:

secrets-tool hostenv --target /opt/app/api.env --map DB_PW=SPRING_DATASOURCE_PASSWORD --map JWT_SECRET --ssh root@server
$guard = secrets-tool hostenv --guard --target /opt/app/api.env --map DB_PW=SPRING_DATASOURCE_PASSWORD --map JWT_SECRET
# then: "$guard && docker pull … && docker run -d --env-file /opt/app/api.env …"

If the file no longer matches, the line stops before any container is stopped. Guide: Bring env files to the host.

docker compose with the CLI on the host

If secrets-tool is set up on the host, the deployment can load the values into the environment at runtime and let docker compose substitute them via ${VARIABLE} in docker-compose.yml:

secrets-tool remote pull shop-backend
eval "$(secrets-tool export | sed 's/^/export /')"
docker compose up -d

docker-compose.yml then only contains DB_PASSWORD: ${DB_PASSWORD}, no value.

Check the repository in the pipeline

A separate step with secrets-tool check --json --offline fails the pipeline with exit code 1 if a plaintext value, a private key or a token is in the repository. With a key and SECRETS_TOOL_PASSWORD it additionally searches for every value from the secrets*.enc files in plaintext. See Check a repository.

When something goes wrong

  • A pipeline's token is compromised: revoke it under My access → API tokens and create a new one.
  • A pipeline's key is compromised: remove it in the project under Access, add a new key and rotate the values the pipeline could read.
  • A value ended up in a log: rotate it. Logs get copied and retained.

More in the docs on deployment, servers and CI and stages. Why pipelines are a popular target is explained under supply chain attacks.