Skip to content

gitlab lexicon security: scope CI_JOB_TOKEN and OIDC to least privilege #298

Closed

Description

@lex00

Problem

GitLab jobs carry CI_JOB_TOKEN and any configured id_tokens (OIDC). A job-token allowlist that's too broad, or an OIDC audience scoped wider than needed, lets a compromised or injected step reach other projects and cloud roles. There's no per-job permission block — scoping lives in token allowlists, id_tokens, and protected/unprotected context.

Proposed checks

  • Flag id_tokens with missing or overly broad audience scoping.
  • Flag reliance on broad CI_JOB_TOKEN access where a narrower allowlist would do.
  • Flag protected-only secrets/variables consumed in jobs reachable from unprotected refs.

Caveat

Project-level CI_JOB_TOKEN allowlist is project settings, not pipeline YAML — that part needs project settings modeled as a resource, or is out of scope for the emitted .gitlab-ci.yml.

Mechanism

Static on emitted YAML for id_tokens and rules-reachable scoping.

GitHub counterpart: #287

Implementation

  • Layer: post-synth checks (pure build). Add one file per check at lexicons/gitlab/src/lint/post-synth/wgl0NN.ts, each exporting a PostSynthCheck — check(ctx): PostSynthDiagnostic[], synchronous, no I/O; input ctx.outputs is the emitted .gitlab-ci.yml. Auto-discovered via discoverPostSynthChecks in plugin.ts — no manual registration.
  • IDs: assign sequential IDs from WGL029 onward, one per acceptance-criteria item (existing IDs are 001–028).
  • Helpers: reuse/extend lint/post-synth/yaml-helpers.ts (extractJobs, extractStages, hasInclude, extractGlobalVariables, extractJobSection, extractJobRules).
  • Extend existing checks where noted rather than duplicating: WGL016 (hardcoded secrets), WGL017 (non-HTTPS registry), WGL026 (DinD-TLS), WGL011 / WGL023 (rules reachability).
  • Vendored data (where a reference list is needed): create lexicons/gitlab/src/lint/rules/data/ (none today) following the github lexicon's data/ pattern.
  • Closest pattern to copy: any existing lint/post-synth/wgl0NN.ts + its test; suite entry in post-synth.test.ts.

Definition of done

  • Each acceptance-criteria item is its own WGL0NN check with a unique ID (no collision with 001–028).
  • Positive and negative fixture test per check.
  • npx vitest run green for the gitlab lexicon; just build / just lint clean.
  • Generated check docs include the new IDs.
  • Each diagnostic names the exact job and the fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions