Skip to main content

SKY-D319 · CI/CD pipelines

GitLab CI OIDC token in a job that runs repository scripts

High

A GitLab job with id_tokens: (or identity:) receives OpenID Connect (OIDC) tokens it can trade for cloud or registry credentials. SKY-D319 reports such a job when it also runs scripts kept in the repository, such as ./scripts/release.sh, make or npm run build.

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

Why it matters

Anyone who can change those scripts, including a merge request author on a branch that runs this job, decides what runs next to the token. A changed build script can send the token to an outside server, which can then publish a package or deploy as your project.

What Skylos flags

.gitlab-ci.yml · YAMLReported on line 14
stages: [release] release-pypi:  stage: release  image: python:3.12-slim  environment: pypi  timeout: 15 minutes  id_tokens:    PYPI_ID_TOKEN:      aud: pypi  rules:    - if: $CI_COMMIT_TAG  script:    - ./scripts/build-and-publish.sh

What Skylos leaves alone

.gitlab-ci.yml · YAML
stages: [build, release] build:  stage: build  image: python:3.12-slim  script:    - ./scripts/build.sh  artifacts:    paths: [dist/] release-pypi:  stage: release  image: python:3.12-slim  environment: pypi  timeout: 15 minutes  needs: [build]  id_tokens:    PYPI_ID_TOKEN:      aud: pypi  rules:    - if: $CI_COMMIT_TAG  script:    - python -m pip install twine==6.1.0 id==1.5.0    - python -m twine upload dist/*

Why Skylos leaves it alone

The repository script still runs, but in the build job, which gets no OIDC token. The job that holds the token only installs pinned tools and uploads the files the build job left behind.

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 except hidden .template jobs. A job counts when it has id_tokens or identity, its own or from default:.
  3. Reads the job's before_script, script and after_script (its own, else from default:, else top-level) and hooks:pre_get_sources_script.
  4. Reports the job when a command line starts with ./scripts/, ./ci/, ./build/, ./tools/, ./release/ or ./deploy/, runs a file in those folders with bash, sh, python, node, ruby or pwsh, or runs npm, pnpm, yarn or bun run, or make.
  5. One HIGH finding per job, on the first line of the file that holds the first matching command.

How to fix it

Split the job. Build in a job without id_tokens, pass the result on as artifacts, and give the token only to a small publish job that runs pinned tools on those files.

.gitlab-ci.yml · YAML · the fix, against the flagged file
Removed: stages: [release]Added: stages: [build, release] Added: build:Added:   stage: buildAdded:   image: python:3.12-slimAdded:   script:Added:     - ./scripts/build.shAdded:   artifacts:Added:     paths: [dist/]Added:  release-pypi:  stage: release  image: python:3.12-slim  environment: pypi  timeout: 15 minutesAdded:   needs: [build]  id_tokens:    PYPI_ID_TOKEN:      aud: pypi  rules:    - if: $CI_COMMIT_TAG  script:Removed:     - ./scripts/build-and-publish.shAdded:     - python -m pip install twine==6.1.0 id==1.5.0Added:     - python -m twine upload dist/*

When it can be wrong

  • Any make or npm run counts, also a short, reviewed target that only calls a pinned tool.
  • Missed: a script outside the listed folders (./publish.sh, bash release.sh) or one called through a variable.
  • If the same command text appears earlier in the file, 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-D319] 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
    script:  # skylos: ignore[SKY-D319] script is protected by CODEOWNERS  - ./scripts/build-and-publish.sh
  • [tool.skylos] ignore = ["SKY-D319"] turns the rule off for the whole project.

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