diff --git a/docs/configuration.md b/docs/configuration.md index cd1dff8..401e1d6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -118,6 +118,49 @@ In testing, an `api` container with 2 CPUs and 2 GB answered about 2 agent inves - One render thread runs at a time, so more CPUs make quick reads faster but not animations. - Past capacity, trace requests answer `503` with `Retry-After: 5`, and agents retry. +### CI OIDC Token Exchange (Optional) + +A CI job can get a record key from the OIDC token its CI provider gives it, so no record key is stored as a CI secret. The reporters ask for a key this way only when no record key is set. The key is valid for 6 hours unless the trust policy sets another lifetime, from 15 minutes to 24 hours, and works for the whole organization that owns the project the job names (the project only picks the organization and its trust policy), and the reporter revokes it when the job ends. An organization admin adds a trust policy for each repository or owner in the dashboard; a job without a matching policy is refused. + +The routes `/oidc/token` and `/oidc/revoke` (record keys) and `/oidc/api/token` and `/oidc/api/revoke` (API tokens) are served by the `director` (port 1234), not by the `api` (port 4000). The bundled Traefik (`tls` profile) puts them on the director host (`TRAEFIK_DIRECTOR_SUBDOMAIN`); a proxy you run yourself has to route them to the director. + +The exchange is off. Set `OIDC_TOKEN_EXCHANGE_ENABLED=true` in `.env` and run `docker compose up -d` once the requirements below are met. It needs the images of a release that includes the exchange. + +A job can also exchange its token for an API token, to call the REST API without an API key stored as a CI secret. This is off too, and has its own settings: it does not need `OIDC_TOKEN_EXCHANGE_ENABLED`, and `OIDC_TOKEN_EXCHANGE_ENABLED` does not turn it on. An API token carries the scopes and the lifetime of the API trust policy that matched the job (the lifetime is 15 minutes unless the policy sets another, from 5 minutes to 6 hours), and the job names the policy it wants by its ID. An organization admin adds an API trust policy in the dashboard, once `OIDC_API_POLICIES_ENABLED` is on. Unlike a record key policy, which can trust a whole owner, an API policy names one repository or project, or one Google Cloud service account. It needs the images of a release that includes API tokens. + +| Variable | Type | Default | Description | +|----------|------|---------|-------------| +| `OIDC_TOKEN_EXCHANGE_ENABLED` | bool | _(unset)_ | Read by `director`. Turn the record key exchange on. Off, `POST /oidc/token` answers 404. On with no `OIDC_TOKEN_AUDIENCE`, it answers 503 | +| `OIDC_TOKEN_AUDIENCE` | string | _(empty)_ | Read by `director`. **Required when the exchange is on.** A name you choose for this install, such as `currents:record-key:acme`. It is not a URL, so a change of DNS does not affect it. A token is accepted only when its audience is exactly this string. The CI jobs have to ask for a token with this audience, see Requirements. Do not use `currents:record-key`, the name Currents cloud uses: a token made for the cloud would then be accepted here. A token made for another install is refused | +| `OIDC_API_TOKEN_EXCHANGE_ENABLED` | bool | _(unset)_ | Read by `director`. Turn the API token exchange on. Off, `POST /oidc/api/token` answers 404. On with no `OIDC_API_TOKEN_AUDIENCE`, it answers 503. `POST /oidc/api/revoke` is served either way, so a token issued before you turned it off can still be revoked | +| `OIDC_API_TOKEN_AUDIENCE` | string | _(empty)_ | Read by `director`. **Required when the API token exchange is on.** The audience a CI token must have to be exchanged for an API token, compared as an exact string after trimming. Choose a name for this install, such as `currents:api:acme`; it is not a URL. It must differ from `OIDC_TOKEN_AUDIENCE`: the director does not start when they are equal, also while the exchange is off, because a CI token requested for recording could then be exchanged for an API token. CI jobs ask for this audience when they request a token for the API | +| `OIDC_API_POLICIES_ENABLED` | bool | _(unset)_ | Read by `api`. Let organization admins add API trust policies in the dashboard. Off, the dashboard offers no form to add one and the API refuses to create one; policies that exist are still listed and can be removed. Setting it does not turn the API token exchange on: without `OIDC_API_TOKEN_EXCHANGE_ENABLED` and `OIDC_API_TOKEN_AUDIENCE`, a job cannot get a token from a policy. The dashboard has no setting of its own: it learns the value from the API | +| `OIDC_EXTRA_ISSUERS` | string | _(empty)_ | Self-managed GitLab and GitHub Enterprise Server instances whose jobs may exchange tokens, besides the cloud providers. Comma-separated `provider=issuer` entries, for example `gitlab=https://gitlab.acme.internal,github=https://ghes.acme.internal/_services/token`. Read by `director` and `api`, and both refuse to start with an invalid value. Unset: cloud providers only. See Requirements | +| `OIDC_ADDRESS_LIMIT_PER_MINUTE` | number | `120` | Read by `director`. Requests to the exchange and revoke routes per client address per minute, counted together, before the token is checked. A whole number; `0` turns the limit off. In production (`CURRENTS_ENV=production`) a value below the default, `0` included, is ignored with a warning in the log. A value that is not a whole number stops the director at start | +| `OIDC_ORG_LIMIT_PER_MINUTE` | number | `600` | Read by `director`. Credentials issued per organization per minute, counted apart for record keys and for API tokens. A whole number; `0` turns the limit off. Production and a bad value behave as for `OIDC_ADDRESS_LIMIT_PER_MINUTE` | +| `OIDC_TRUST_FORWARDED_FOR` | bool | _(unset)_ | Read by `director`. Count the requests of the exchange and revoke routes, for record keys and API tokens, per client address by the last entry of `X-Forwarded-For`. Set it to `true` only when a proxy in front of the director appends the client's address to that header and passes on none that the caller wrote. Otherwise a caller writes the header and gets a new count for each request, so the limit does nothing. Unset, the limit counts the address of the connection, which behind a proxy is the proxy's: every caller then shares 120 requests a minute. Check what your proxy writes before setting it | + +Requirements: + +- **Network.** The director checks a token with the CI provider's public signing keys, which it fetches over https through the provider's OpenID Connect discovery document (Google Cloud excepted). It needs outbound access to the providers you use: GitHub Actions (`token.actions.githubusercontent.com`), GitLab.com (`gitlab.com`), CircleCI (`oidc.circleci.com`), Buildkite (`agent.buildkite.com`), Bitbucket Pipelines (`api.bitbucket.org`) and Google Cloud (`www.googleapis.com`, where the director fetches the signing keys from a fixed address, without a discovery document). It does not work on an install without internet access, unless the only issuers are self-hosted ones you list in `OIDC_EXTRA_ISSUERS`. For each listed instance the director needs outbound https access to its host, which can be private or internal; only the listed hosts are fetched. +- **Self-managed GitLab and GitHub Enterprise Server.** Tokens from these are accepted when you list their issuers in `OIDC_EXTRA_ISSUERS`: `gitlab=` followed by the URL of the GitLab instance, and `github=` followed by `https:///_services/token` for GitHub Enterprise Server. The issuer is compared with the `iss` claim of the token as an exact string. Write each as `https`, with the host in lowercase, no default port, and no user, password, trailing slash, query or fragment. An issuer of a cloud provider, an issuer listed twice, an unknown provider and more than 20 entries are refused. The director and the API do not start with an entry they cannot use, so check `docker compose logs director api` after you change it. The `.env` file reaches both services, so you set it once. A trust policy stores the issuer it was made for and matches only tokens of that issuer, because a self-hosted instance chooses its own owner and project IDs, which can equal IDs on GitLab.com or github.com. In the dashboard, the form for adding a policy shows a Server selector for a provider that has listed issuers. This part needs the images of a release that includes self-hosted issuers. +- **Internal certificate authority.** When a listed instance uses a certificate from your own authority, give the director that authority with `NODE_EXTRA_CA_CERTS`, the path of a PEM file inside the container. Only the director fetches signing keys, so only it needs the file. Put the file on the host and mount it into the director, for example in a `docker-compose.override.yml` next to `docker-compose.yml`, which `docker compose` reads on its own: + + ```yaml + services: + director: + environment: + NODE_EXTRA_CA_CERTS: /certs/internal-ca.pem + volumes: + - ./certs/internal-ca.pem:/certs/internal-ca.pem:ro + ``` + + Node.js adds the file to its built-in authorities; it does not replace them. If you start the stack with `-f`, add the same lines to a file you pass with `-f`. +- **Audience of API tokens.** There is no default. Set `OIDC_API_TOKEN_AUDIENCE` to a name that differs from `OIDC_TOKEN_AUDIENCE`, and have the jobs that call the API ask their CI provider for a token with that audience, the same way as for the record key audience below. The exchange takes the policy ID in the request, so the job needs the ID of the API trust policy from the dashboard. +- **Audience.** There is no default. Pick a name for your install, such as `currents:record-key:`, and set it as `OIDC_TOKEN_AUDIENCE`. On GitHub Actions the reporter requests the token itself, with the audience in `CURRENTS_OIDC_AUDIENCE` (or the `oidcAudience` option of `@currents/playwright`, or `--oidc-audience` of the `currents` CLI, which win over the variable), which defaults to `currents:record-key`, the name Currents cloud uses: set it to your name in those jobs. On the other providers the job supplies the token, so the audience is whatever the job asks the provider for (`aud` in a GitLab CI `id_tokens` entry, and the commands on CircleCI, Buildkite and Bitbucket Pipelines): use your name there. The hint the reporter prints when it has neither a record key nor a token shows `CURRENTS_OIDC_AUDIENCE` when it is set. +- **Indexes.** The scheduler creates the indexes the exchange needs when it starts, with the other indexes the release declares: a unique partial index on `recordKeys.recordKeyHash`, which finds a record key by its hash; a TTL index on `recordKeys.expiresAt` that removes expired keys; a partial index on `recordKeys.issuedFor.policyId` that finds the keys of a removed trust policy; and the unique index of the `oidcTrustPolicies` collection, which the exchange reads through. There is nothing to build by hand. Keys from the exchange expire after the lifetime of their trust policy (six hours unless the policy sets another), and MongoDB's TTL cleanup removes their documents later. +- **Limits.** By default the director counts at most 120 requests a minute from one address before it checks a token, and at most 600 credentials a minute for one organization for each kind; see `OIDC_ADDRESS_LIMIT_PER_MINUTE` and `OIDC_ORG_LIMIT_PER_MINUTE`. When Redis is down it refuses the requests. + ### AI Explanations and Chat (Optional) The `ai-queue-worker` service runs the AI tasks (test explanations, chat) from the `ai-bmq` queue. `webhooks` does not run AI tasks. diff --git a/docs/quickstart.md b/docs/quickstart.md index df59ab7..0542ac0 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -172,6 +172,10 @@ SSO_SAML_ISSUER=currents-onprem:your-org See [Enable SAML SSO](./sso-saml.md) for the full walkthrough. +### CI OIDC token exchange (optional) + +To let CI jobs get a record key from the OIDC token their CI provider issues, instead of storing a record key as a CI secret, set `OIDC_TOKEN_EXCHANGE_ENABLED=true` and `OIDC_TOKEN_AUDIENCE` to a name you choose, such as `currents:record-key:`, and ask for the same name as the audience in the CI jobs. It is off by default, needs the director to reach the CI providers over the internet (or the self-managed GitLab and GitHub Enterprise Server instances you list in `OIDC_EXTRA_ISSUERS`), and has requirements to read first: see [CI OIDC Token Exchange](./configuration.md#ci-oidc-token-exchange-optional). The same page covers exchanging the token for an API token, which has its own switches: `OIDC_API_TOKEN_EXCHANGE_ENABLED`, `OIDC_API_TOKEN_AUDIENCE` and `OIDC_API_POLICIES_ENABLED`. + See [Configuration Reference](./configuration.md) for all available options. ## Step 4: Start Services diff --git a/on-prem/.env.example b/on-prem/.env.example index c1e66b6..eabc94d 100644 --- a/on-prem/.env.example +++ b/on-prem/.env.example @@ -184,6 +184,62 @@ OAUTH_DYNAMIC_CLIENT_REGISTRATION_ENABLED=true # OAUTH_RATE_LIMIT_AUTHORIZE_MAX=30 # OAUTH_RATE_LIMIT_USERINFO_MAX=60 +# ============================================================================= +# CI OIDC token exchange (Optional) +# ============================================================================= +# Lets a CI job get a record key, valid for 6 hours unless its trust policy sets +# another lifetime, in exchange for the OIDC token its CI provider gives it, so +# no record key is stored as a CI secret. The routes are served by the director +# (port 1234), not the API; a proxy you run must route them there. +# Off unless OIDC_TOKEN_EXCHANGE_ENABLED=true. The director must reach the CI +# provider's public OIDC endpoints over https (GitHub Actions, GitLab.com, +# CircleCI, Buildkite, Bitbucket Pipelines, Google Cloud), so it does not work without +# internet access. Self-managed GitLab and GitHub Enterprise Server work when +# you list them in OIDC_EXTRA_ISSUERS. Read docs/configuration.md before +# turning it on. +# OIDC_TOKEN_EXCHANGE_ENABLED=true +# Required when the exchange is on, with no default: a name you choose for this +# install, such as currents:record-key:acme. It is not a URL. A token is accepted +# only when its audience is exactly this string. CI jobs ask for it: GitHub +# Actions jobs set CURRENTS_OIDC_AUDIENCE to it, and on other providers the job +# names it as the audience of its token. +# OIDC_TOKEN_AUDIENCE=currents:record-key: +# Lets a CI job exchange its OIDC token for an API token, to call the REST API +# without an API key stored as CI secret. Read by the director. Off unless set to +# true; independent of OIDC_TOKEN_EXCHANGE_ENABLED. POST /oidc/api/revoke is +# served either way. +# OIDC_API_TOKEN_EXCHANGE_ENABLED=true +# Required when the API token exchange is on, with no default: the audience a CI +# token needs to be exchanged for an API token, such as currents:api:acme. Read +# by the director, which does not start when it equals OIDC_TOKEN_AUDIENCE. +# OIDC_API_TOKEN_AUDIENCE=currents:api: +# Read by the API. Lets organization admins add API trust policies in the +# dashboard, which set the scopes and lifetime (default 15 minutes) of the API +# tokens. A policy names one repository or project, or one Google Cloud service +# account. Off: policies that exist stay listed and can be removed, but none can +# be added. Does not turn on the exchange above. +# OIDC_API_POLICIES_ENABLED=true +# Self-managed GitLab and GitHub Enterprise Server instances whose jobs may +# exchange tokens: comma-separated provider=issuer entries, at most 20, read by +# the director and the API. A GitLab issuer is the URL of the instance, a GitHub +# Enterprise Server issuer is https:///_services/token. Each is https, +# with the host in lowercase and no trailing slash, query or fragment. An invalid value stops +# both services at start. Unset: only the cloud providers. The director must +# reach each listed host. For a certificate from an internal CA, mount the CA +# file into the director and set NODE_EXTRA_CA_CERTS there: see +# docs/configuration.md. +# OIDC_EXTRA_ISSUERS=gitlab=https://gitlab.acme.internal,github=https://ghes.acme.internal/_services/token +# Only behind a proxy that appends the client address to X-Forwarded-For and +# passes on none that the caller wrote. Unset, the limit per address counts the +# address of the connection. +# OIDC_TRUST_FORWARDED_FOR=true +# Limits of the director, whole numbers, 0 turns a limit off. In production a +# value below the default is ignored with a warning. Requests to the exchange +# and revoke routes per client address per minute (default 120), and credentials +# issued per organization per minute for each kind (default 600). +# OIDC_ADDRESS_LIMIT_PER_MINUTE=120 +# OIDC_ORG_LIMIT_PER_MINUTE=600 + # ============================================================================= # AI explanations and chat (Optional) # ============================================================================= diff --git a/on-prem/CHANGELOG.md b/on-prem/CHANGELOG.md index cba9aff..3d780ba 100644 --- a/on-prem/CHANGELOG.md +++ b/on-prem/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added - **Test steps in ClickHouse, off by default.** `STEPS_CLICKHOUSE_DUAL_WRITE_FROM` and `STEPS_CLICKHOUSE_ONLY_FROM` in `.env` choose, by the time a test starts, whether its steps go to ClickHouse as well as object storage, or to ClickHouse only. `STEPS_RETENTION_DAYS` sets how long `write-worker` keeps them (default 21). Nothing changes until you set a time. Needs images that include the feature; see Test Steps in ClickHouse in the [Configuration Reference](../docs/configuration.md#test-steps-in-clickhouse-optional). +- **CI OIDC token exchange, off by default.** `OIDC_TOKEN_EXCHANGE_ENABLED` and `OIDC_TOKEN_AUDIENCE` let a CI job get a record key from its CI provider's OIDC token; `OIDC_API_TOKEN_EXCHANGE_ENABLED` and `OIDC_API_TOKEN_AUDIENCE` do the same for an API token; `OIDC_API_POLICIES_ENABLED` lets admins add API trust policies in the dashboard. `OIDC_EXTRA_ISSUERS` adds self-managed GitLab and GitHub Enterprise Server, and `OIDC_TRUST_FORWARDED_FOR` sets how the director counts requests per address. The services read them from `.env`; nothing changes until you set them. Needs images that include the feature; see CI OIDC Token Exchange in the [Configuration Reference](../docs/configuration.md#ci-oidc-token-exchange-optional). ## [2026-11-10-003] - 2026-11-13