glsec

Rules / GL092

GL092 OIDC publish job without environment:

Severity: info
OWASP: CICD-SEC-5 – Insufficient PBAC (Pipeline-Based Access Controls)
CWE: CWE-284 – Improper Access Control

Risk

PyPI and npm let a GitLab CI/CD job publish without a stored token: the job asks GitLab for an OIDC token (id_tokens:), and the registry's trusted publisher accepts it when the token comes from the configured project and pipeline file. Both registries can also bind the publisher to a GitLab environment, so that only a job in that environment can publish. PyPI calls configuring one "optional, but strongly recommended" (adding a trusted publisher); npm offers the same field (trusted publishers).

A publish job without environment: can't be bound. Then any pipeline that runs the job can publish: a tag pushed by any Developer, a branch pipeline if the job's rules: allow it, or a pipeline started through the API. With an environment, the registry rejects tokens from other jobs, and a protected environment decides who may deploy to it, with approvals if needed.

What glsec checks

Jobs GitLab runs, with their extends: and default: resolved, that

The finding is reported at the token's name, as info: glsec can't see whether the registry side names an environment, or whether the environment is protected.

Not covered yet: registries whose GitLab trusted publishing is in beta or not documented, such as crates.io and RubyGems. A job that extends a template from another file is skipped, since its environment: may come from there.

Trigger example

publish-pypi:
  stage: deploy
  id_tokens:
    PYPI_ID_TOKEN:
      aud: pypi
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - python -m pip install twine==5.1.1
    - twine upload dist/*

Safe alternative

Give the job an environment, name the same environment in the trusted publisher's settings on PyPI or npm, and protect it in GitLab (Settings → CI/CD → Protected environments):

publish-pypi:
  stage: deploy
  environment: release
  id_tokens:
    PYPI_ID_TOKEN:
      aud: pypi
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - python -m pip install twine==5.1.1
    - twine upload dist/*

See also

Documentation for glsec 1.29.0. Source of this page · Rule implementation