Quader Docs 0.176.0

GitLab CI pipelines

Let a GitLab CI job install and publish with a Quader token that lives minutes, exchanged for its ID token, with no secret in GitLab.

On this page

How it works

The token exchange of a GitLab CI jobThe job gets an ID token from GitLab addressed to Quader, posts it to Quader's token exchange, and gets a CI token that lives minutes; Quader decides its grants from the mappings that match the job. The job installs and publishes with it and revokes it as its last step.QuaderCI jobGitLabQuaderCI jobGitLabID token (aud = Quader's URL)POST /api/v1/auth/oidc/tokenverify, match the identity mappingsqdr_cit_… token, 15 minutesnpm install, npm publish, dotnet nuget pushDELETE /api/v1/tokens/current

Quader grants the token from verified facts about the job: its GitLab project, whether the branch or tag is protected, how the pipeline started. The rules are identity mappings, written by an Owner of your Quader project or an administrator (GitLab CI federation).

Before you start

You need From
A mapping for your GitLab project (its numeric ID, CI_PROJECT_ID), the refs that publish, the repositories An Owner of your Quader project
Quader's base URL, the audience of your ID token The same Owner
curl 7.55 or later and jq in the job's image Your image

Publishing needs a protected branch or tag unless the mapping allows unprotected refs.

Request and exchange the ID token

This hidden job asks GitLab for the ID token, exchanges it, and exports the Quader token as QUADER_TOKEN:

yaml
variables:
  QUADER_URL: "https://quader.example.com"           # example

.quader:
  id_tokens:
    QUADER_ID_TOKEN:
      aud: https://quader.example.com                # example: Quader's base URL, one service only
  before_script:
    - |
      response="$(printf '%s' "$QUADER_ID_TOKEN" | curl -sS --retry 3 \
        --data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
        --data-urlencode 'subject_token_type=urn:ietf:params:oauth:token-type:id_token' \
        --data-urlencode 'subject_token@-' \
        "$QUADER_URL/api/v1/auth/oidc/token")"
      QUADER_TOKEN="$(printf '%s' "$response" | jq -er '.access_token // empty')" \
        || { printf '%s\n' "$response" | jq '{error, error_description, reason, requestId}' >&2; exit 1; }
      export QUADER_TOKEN
      unset response QUADER_ID_TOKEN
  • The ID token reaches curl on standard input, so it never stands in the process list; --retry 3 repeats after a 429 or 503.
  • aud names Quader alone: a list with another service is refused. A job's own id_tokens replaces those of default:.
  • The token lives 15 minutes unless you ask for less, at most one hour and never past the ID token (ci.token). Keep QUADER_ID_TOKEN if a later step exchanges again.

To narrow the token, add --data-urlencode 'scope=read:@any:npm deploy:web/npm-internal' (example): items <action>:<repository> with the project in every key, at most 50. Asking for more than the mappings grant refuses the whole exchange. ttl=<seconds> shortens the lifetime, to no less than 30 seconds.

Use the token

npm expands ${QUADER_TOKEN} in .npmrc when it runs; NuGet expands %QUADER_TOKEN% in nuget.config. Neither file holds the value.

yaml
publish-npm:
  extends: .quader
  image: node:24-bookworm                               # example
  rules:
    - if: $CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"
  script:
    - |
      cat > .npmrc <<'EOF'
      registry=https://quader.example.com/api/npm/web/npm-all/
      //quader.example.com/api/npm/web/npm-all/:_authToken=${QUADER_TOKEN}
      //quader.example.com/api/npm/web/npm-internal/:_authToken=${QUADER_TOKEN}
      EOF
    - npm ci
    - npm publish --registry https://quader.example.com/api/npm/web/npm-internal/
    - |
      printf 'Authorization: Bearer %s\n' "$QUADER_TOKEN" | curl -sS -X DELETE -H @- "$QUADER_URL/api/v1/tokens/current"
The same for NuGet
xml
<configuration>
  <packageSources>
    <clear />
    <add key="quader" value="https://quader.example.com/api/nuget/web/nuget-all/v3/index.json" />
    <add key="quader-internal" value="https://quader.example.com/api/nuget/web/nuget-internal/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <quader><add key="Username" value="ci" /><add key="ClearTextPassword" value="%QUADER_TOKEN%" /></quader>
    <quader-internal><add key="Username" value="ci" /><add key="ClearTextPassword" value="%QUADER_TOKEN%" /></quader-internal>
  </packageSourceCredentials>
</configuration>
yaml
push-nuget:
  extends: .quader
  image: mcr.microsoft.com/dotnet/sdk:10.0              # example
  rules:
    - if: $CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"
  script:
    - dotnet restore
    - dotnet pack src/Acme.InvoiceApi/Acme.InvoiceApi.csproj -c Release -o out --no-restore -p:PackageVersion="${CI_COMMIT_TAG#v}"
    - dotnet nuget push "out/*.nupkg" --source "$QUADER_URL/api/nuget/web/nuget-internal/v3/index.json" --api-key "$QUADER_TOKEN"
    - |
      printf 'Authorization: Bearer %s\n' "$QUADER_TOKEN" | curl -sS -X DELETE -H @- "$QUADER_URL/api/v1/tokens/current"

The push source is listed in nuget.config because dotnet nuget push reads its service index first, which needs credentials.

The token works on every package protocol, /files/… and the content operations of the API, as a bearer token, a Basic password or the NuGet API key. It holds no role, creates no token, and is refused every management operation with ci_token_restricted. The first publish of a package name binds it to your GitLab project.

Revoke the token as the last step

The DELETE line above ends the token at once. Write it as a block scalar (- |): a plain item with Authorization: Bearer is a YAML mapping, and GitLab refuses the job. Make it the last line of script: after_script runs in a shell without the token, and not after a timeout. A job that fails before it keeps its token until it expires.

Warning

GitLab does not mask a token created during the job. Never print it, never run set -x around it, never write its value into a file that ends in an artifact or a cache, and never send CI_JOB_TOKEN to Quader or another service.

When the exchange is refused

The job log shows reason and requestId; give both to your administrator with the time and the job.

reason What to do
audience_invalid, audience_not_exclusive Set aud to Quader's base URL alone
wrong_subject_token_type, subject_token_malformed, malformed_request Send the variable of id_tokens:; a job's own id_tokens replaces the default's
no_matching_mapping Run on a ref the mapping names, or ask the Owner
cross_project_source_denied A fork's pipeline: no token, by intent
token_expired, subject_token_expires_too_soon, ttl_below_minimum Exchange at the job's start; ask for a longer ttl
subject_token_replayed Single use is on: exchange once per job
scope_malformed, scope_not_granted Correct scope or ask for the grant
unknown_issuer, issuer_disabled, rate_limited, a 503 Ask an administrator if --retry does not help

A publish refused with 403 or E403 ran on an unprotected ref, left deploy out of scope, or names a package another owner holds. The administrator's table of every reason is in GitLab CI federation.