Skip to main content

SKY-D323 · CI/CD pipelines

GitLab CI secret that does not name its ID token

Medium

A GitLab job can fetch secrets from Vault or another secrets manager by logging in with an ID token from id_tokens:. When the job has more than one ID token, each entry under secrets: should say which one to use with token:. SKY-D323 reports an entry that does not.

Languages
GitLab CI
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
GitLab CI ambiguous secret token
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Each ID token is made for one audience, such as AWS or Vault. If the file does not say which one goes to Vault, a token meant for AWS can be the one sent, and whoever runs or watches that Vault server receives a token AWS will accept for your project's role.

What Skylos flags

.gitlab-ci.yml · YAMLReported on line 14
stages: [deploy] deploy-production:  stage: deploy  image: bitnami/kubectl:1.31.2  environment: production  timeout: 20 minutes  id_tokens:    AWS_ID_TOKEN:      aud: sts.amazonaws.com    VAULT_ID_TOKEN:      aud: https://vault.acme.example  secrets:    DATABASE_PASSWORD:      vault: production/db/password@ops      file: false  script:    - kubectl apply -f k8s/

What Skylos leaves alone

.gitlab-ci.yml · YAML
stages: [deploy] deploy-production:  stage: deploy  image: bitnami/kubectl:1.31.2  environment: production  timeout: 20 minutes  id_tokens:    VAULT_ID_TOKEN:      aud: https://vault.acme.example  secrets:    DATABASE_PASSWORD:      vault: production/db/password@ops      file: false  script:    - kubectl apply -f k8s/

Why Skylos leaves it alone

The secret names no token here either, but the job has only one ID token, made for Vault, so there is nothing else GitLab could send.

How Skylos decides

  1. Runs with --danger (and -a). Reads every file named exactly .gitlab-ci.yml in the scanned folder, skipping .git, node_modules, .venv, venv, build, dist and cache folders. Files pulled in with include: are not read, and a file PyYAML's safe loader cannot read (for example one that uses !reference) is skipped.
  2. Looks at every job, hidden .template jobs included, that has its own secrets: mapping.
  3. Counts the job's ID tokens (its own id_tokens, else the one under default:). Fewer than two: nothing to report.
  4. An entry under secrets: is ambiguous when no token key appears anywhere inside it.
  5. One MEDIUM finding per job, naming the first ambiguous entry, on the first line of the file where that entry's name is written as a key.

How to fix it

Add token: to every entry under secrets:, pointing at the ID token made for that secrets manager.

.gitlab-ci.yml · YAML · the fix, against the flagged file
stages: [deploy] deploy-production:  stage: deploy  image: bitnami/kubectl:1.31.2  environment: production  timeout: 20 minutes  id_tokens:    AWS_ID_TOKEN:      aud: sts.amazonaws.com    VAULT_ID_TOKEN:      aud: https://vault.acme.example  secrets:    DATABASE_PASSWORD:      vault: production/db/password@ops      file: falseAdded:       token: $VAULT_ID_TOKEN  script:    - kubectl apply -f k8s/

When it can be wrong

  • Only the first ambiguous entry of a job is named; fix it and the next one is reported.
  • If another job earlier in the file uses the same secret name as a key, the finding points at that earlier line.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put # skylos: ignore[SKY-D323] and a reason on the reported line, or on the line directly above it. Skylos looks for that exact text, so write one rule per marker, with the ID in upper case.

    YAML
    secrets:  # skylos: ignore[SKY-D323] both tokens have the same audience  DATABASE_PASSWORD:
  • [tool.skylos] ignore = ["SKY-D323"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.