Quader Docs 0.176.0

GitLab CI federation

Let GitLab CI jobs trade their ID token for a Quader token that lives minutes: trust a GitLab instance, write mappings, test them, revoke tokens.

On this page

How the exchange works

The pipeline's side, the id_tokens: block and the exchange call, is in GitLab CI pipelines.

The CI token exchange inside QuaderQuader keeps the GitLab instance's signing keys current. A job posts its ID token; Quader picks the issuer by iss, verifies signature, audience and times, takes the first matching mapping of each tier, writes an issuance record and answers with a CI token, or with a reason and a request ID.QuaderCI jobGitLab instanceQuaderCI jobGitLab instancediscovery document and signing keys, refreshedID token to /api/v1/auth/oidc/tokenissuer by iss, signature, audience, timesfirst matching mapping of each tier, grants added upissuance record of project, pipeline, job, refqdr_cit_ token, or reason and requestId

A CI issuer is a GitLab instance trusted for the exchange; nobody signs in with it. A mapping is an ordered rule of one issuer: a condition on the ID token's claims and the grants a matching job gets. Each mapping is a principal, ci:<issuer>/<mapping>, or ci:<issuer>/<projectKey>/<mapping> in a project. A CI token acts as its mappings only: no group, no role, never manage, and like every signed-in caller it reads what is Internal.

Who does what

Task Who
Trust a GitLab instance The Helm values, or holders of ci:write (admin, security-admin)
Mappings of the tier system Holders of ci:write; holders of ci:read read them
Mappings of a project's tier Its Owners and holders of ci:write
Issuance records, revoking tokens Holders of tokens:read, tokens:revoke; Owners read their project's records

The screens are Admin area › Identity › CI identity and a project's Access › CI identity; the API is in the reference (ci). A script needs a token with the administrator scope, or an Owner acts as a Maintainer and is refused.

Register a GitLab instance

Who
the operator in the Helm values, or holders of ci:write with New issuer
yaml
config:
  ci:
    issuers:
      - name: gitlab-main                  # example
        kind: gitlab                       # the only kind
        issuer: https://gitlab.example.com # example: exactly its iss
        public_issuer: false               # example: no open sign-up
        # example: a private CA's bundle, mounted with extraVolumes
        ca_bundle_ref: file:/var/run/secrets/gitlab-ca/ca.crt

Every field with its default: ci.issuers.

  • quader migrate applies the list at every upgrade; such issuers are read-only elsewhere (Helm configuration). A removed entry is disabled, its tokens revoked, its mappings kept. name, issuer and kind never change.
  • New issuer checks the discovery document and the keys before it saves. The worker replicas keep the keys current.
  • Public instances. On gitlab.com or any instance with open sign-up, anyone can get an ID token for Quader's audience. There every mapping must be pinned: its top-level all holds an equals or in leaf on an ID claim such as project_id (pin_required).
  • An ID token that also names another service is refused: one id_tokens: entry per service.

How mappings are evaluated

  • Mappings sit in tiers: system, and one per project. Within a tier the lowest priority whose condition holds is the match; the matches of all tiers add up. No match anywhere refuses the exchange.
  • Because the first match decides, a mapping lists everything its jobs need, reading included: narrow rules at low numbers, broad ones at high numbers.
  • A mapping grants by inline grants, frozen into the token, and by policies that name it and, in the system tier, groups, both read at use. Saving a mapping that lists a policy adds its entry with read, recorded as the policy's own authz.policy.updated; widen the entry in the policy to let the mapping write.
  • A project's mapping names its project's repositories by bare key (@any is all of them), its project's policies, no groups.
Saving refuses When
unprotected_write A grant writes and the condition lacks {"claim": "ref_protected", "equals": true}
unpinned_write On a private issuer, an unpinned mapping writes through a policy, a group, or a grant without ownership: bind_project
pin_required, catch_all_condition, empty_grant A public issuer's mapping without a pin; a condition without a leaf; nothing granted
action_not_allowed manage in a grant

Conditions combine all, any and not over leaves with equals, in, glob, regex or present. IDs and booleans compare as strings. Prefer project_id, ref_protected, ref_type and pipeline_source to sub.

Let a GitLab project's pipelines publish

The protected refs of GitLab project 4242 publish @acme/* to npm-internal of Quader project web and read the project. An Owner of web builds it in New mapping, or sends it to POST /api/v1/projects/web/ci/mappings:

json
{
  "issuer": "gitlab-main",
  "name": "invoice-api-publish",
  "priority": 100,
  "match": {"all": [
    {"claim": "project_id", "equals": "4242"},
    {"claim": "ref_protected", "equals": true},
    {"claim": "pipeline_source", "in": ["push", "web"]}
  ]},
  "grants": {"inline": [
    {"repositories": ["npm-internal"],
     "packages": {"include": ["@acme/*"]},
     "actions": ["read", "deploy"], "ownership": "bind_project"},
    {"repositories": ["@any"], "packages": {"include": []},
     "actions": ["read"]}
  ]},
  "maxTtlSeconds": 1800
}
Leaf Why
project_id The pin: an ID never changes, a path can be taken by another project
ref_protected Only people allowed to push or merge there run such pipelines; a fork's merge request carries "false"
pipeline_source Pushes and pipelines started by hand; keep merge_request_event and trigger out of a writing mapping

Ownership bind_project, the default of every writing grant, binds each new package name to the GitLab project that first publishes it. Every other project gets 403 package_owned_by_other_owner, even when its pattern matches. A name with versions but no owner is never taken over: a manage holder adds the owner first.

Give a group read access

A read mapping at a higher priority number catches every other pipeline:

Who reads Condition
A group and its subgroups, by path (private instance only) {"claim": "project_path", "glob": "acme/**"}, never acme*/**
A group, by ID {"claim": "namespace_id", "in": ["4711", "4712"]}
Some projects {"claim": "project_id", "in": ["4242", "4243"]}

An ID token carries only its immediate namespace_id: list every subgroup with projects, and add new ones by hand. A fork's merge request pipeline contributes nothing unless Pipelines from other projects is read_only.

Test a mapping with the dry run

Test with claims evaluates the mappings against claims, never a token, and issues nothing. A pasted ID token is decoded in the browser and discarded. The answer shows each mapping looked at, its first failed leaf with expected and actual values, the grants and the lifetime. The claim snapshot of an issuance record, or of a refused exchange's audit event, is a ready input.

Issuance records

Issued tokens holds one record per token: GitLab project, pipeline, job, ref, mapping, grants, claims and state, kept ci.issuances.retention (one year) after expiry, never the token. A publish's audit event carries the same token ID.

Revoke CI tokens

To end Do
A job's own token Its last step calls DELETE /api/v1/tokens/current (the pipeline)
A pipeline's, job's, project's or mapping's tokens Revoke matching tokens in Issued tokens
A mapping's tokens and its matching Disable or delete the mapping
An instance's tokens Disable or delete the issuer

Warning

Disabling a mapping lets its jobs fall through to the next mapping of the tier, which may grant more: test the tier first. Editing a mapping leaves issued tokens as they are: revoke them by mapping.

A job that fails before its last step keeps its token until it expires, 15 minutes by default.

Troubleshoot refused exchanges

A refused exchange answers with error, reason and requestId, which finds the ci.exchange.denied audit event with the claim snapshot.

reason Fix
unknown_issuer, issuer_disabled Register or enable the instance; compare its URL with the event's iss
unknown_signing_key, signature_invalid, signing_keys_unavailable Check the issuer's Keys; check the worker replicas
audience_invalid, audience_not_exclusive aud is Quader's base URL alone, or an audience added to the issuer
token_expired, subject_token_expires_too_soon, ttl_below_minimum Exchange early; give the job a timeout
no_matching_mapping, grant_render_failed Dry-run the event's claim snapshot
scope_malformed, scope_not_granted The job asked for more than its mappings grant
wrong_subject_token_type, subject_token_malformed The job sent CI_JOB_TOKEN or no ID token
rate_limited List a runner network behind NAT in ci.exchange.rate_limit.exempt_cidrs

403 ci_token_restricted after the exchange: the job called a management operation, which a CI token never may.

Configuration keys

Lifetimes (ci.token.default_ttl 15 minutes, ci.token.max_ttl one hour), rate limits, key refresh, retention: ci.

Limits

  • GitLab is the only kind of issuer; CI_JOB_TOKEN is never accepted.
  • Quader trusts every token the instance signs, so a GitLab administrator can mint one for any project. Ownership binding, the short lifetime and the issuance records bound the damage.