spotlight_oidc_trust
The spotlight_oidc_trust resource, and the API's oidc-trust kind: a trust
that lets a CI job or another workload exchange the OIDC token its platform
issues for a short-lived
workspace token, so no key is stored.
| Kind | Endpoint | Terraform | Address |
|---|---|---|---|
oidc-trust | /api/v1/resources/workspaces/{workspaceId}/oidc-trusts | spotlight_oidc_trust | <key> |
See Resource API for the operations, headers and errors every kind shares.
Example
resource "spotlight_oidc_trust" "github_main" {
workspace_id = spotlight_workspace.acme.id
key = "github-main"
issuer = "https://token.actions.githubusercontent.com"
subject = "repo:acme/platform:ref:refs/heads/main"
claims = {
repository_owner = "acme"
}
scopes = ["configure", "secrets"]
lifetime_minutes = 15
description = "Applies the platform from the main branch"
}Fields
| Field | Type | Default | Description |
|---|---|---|---|
key | string | required | Lowercase words joined by dashes, at most 64 characters. Immutable: an update that changes it is rejected; Terraform replaces the resource. |
issuer | string | required | The issuer the workload's token must name in iss. https, or http only for localhost, 127.0.0.1 or [::1]. No query, fragment or credentials. At most 255 characters. A localhost or 127.0.0.1 issuer needs SPOTLIGHT_OUTBOUND_ALLOW_LOOPBACK set to true and the issuer's host in SPOTLIGHT_OUTBOUND_ALLOWED_HOSTS. |
audience | string | spotlight | A value the token's aud must contain. One word, at most 255 characters. |
subject | string | required | A pattern the token's sub must match. See patterns. |
claims | map of name to string | {} | Further claims the token must carry, each matching its pattern. At most 16. See patterns. |
scopes | array of strings | required | The scopes of every token the trust issues, as for a workspace token. |
lifetimeMinutes | integer | 15 | 1 to 60. How many minutes an issued token stays valid. |
description | string | "" | Why the trust exists. Trimmed, at most 1000 characters. The trust list in the web app shows it; the web app has no field to write it. |
createdBy | string | read-only | The person who created the trust, or who issued the token that created it. |
Patterns
subject and each value of claims is one word of at most 255 characters,
with no whitespace. * matches any run of characters, colons included.
A subject with a * must name its owner before the first *: the text
before it must contain /.
subject | Accepted |
|---|---|
repo:acme/platform:ref:refs/heads/main | yes |
repo:acme/platform:* | yes |
repo:acme/* | yes |
repo:* | no |
* | no |
A rejected subject reads must name an owner before any *, as in repo:acme/* or repo:acme/platform:*.
Claim names are lowercase letters, digits and _, starting with a letter, at
most 64 characters. iss, sub, aud, exp, nbf, iat and jti may not
be named. Only claims whose value is a string can match.
Platform subjects
| Platform | Issuer | sub |
|---|---|---|
| GitHub Actions, pull request | https://token.actions.githubusercontent.com | repo:<owner>/<repository>:pull_request |
| GitHub Actions, push | https://token.actions.githubusercontent.com | repo:<owner>/<repository>:ref:refs/heads/<branch> |
| GitHub Actions, environment | https://token.actions.githubusercontent.com | repo:<owner>/<repository>:environment:<name> |
| GitLab CI/CD | https://gitlab.com, or the instance's address | set by the platform |
| CircleCI | https://oidc.circleci.com/org/<organization id> | set by the platform |
| Buildkite | https://agent.buildkite.com | set by the platform |
Trusts the setup creates
When an owner or admin starts a
setup chat, Spotlight
creates two trusts for the configuration repository's GitHub Actions. A trust
with one of these keys that a setup could have made, with this issuer, a
subject of the form below for any repository, and no claims other than
repository_id and repository_owner_id, is pointed at the repository and
branch instead, and keeps its scopes and lifetimeMinutes. A trust with
one of these keys in any other form, such as a GitHub environment subject,
stops the setup, which changes nothing; rename or delete that trust, then set
up again. <repository> is the configuration repository, as <owner>/<name>,
and <branch> is its default branch.
CI cannot change these trusts: a token issued through github-apply has no
trusts scope. An owner or admin changes them.
key | subject | scopes |
|---|---|---|
github-pull-requests | repo:<repository>:pull_request | plan |
github-apply | repo:<repository>:ref:refs/heads/<branch> | configure, secrets, runners |
Both have the issuer https://token.actions.githubusercontent.com and the
audience spotlight. Their claims pin the repository's and its owner's
GitHub ids, repository_id and repository_owner_id, so a repository created
later under the same name does not match. github-pull-requests issues tokens
for 15 minutes and github-apply for 60, so a long apply can still write its
state. A created
trust's createdBy is the person who started the setup chat. The Terraform
export holds both as spotlight_oidc_trust resources with import
blocks.
A default branch whose name contains * or : stops the setup, since a
trust's subject would read * as any text.
Who may create a trust
Writing a trust needs the trusts permission. See
Roles and permissions.
A token may create a trust only with scopes it has itself, may change a
trust only when it has both the trust's current scopes and the new ones, and
may delete a trust only when it has the trust's current scopes. Otherwise the
write or delete is forbidden with 403, as for a caller without
trusts. See Permission titles.
A person who is an owner or admin is not limited this way.
Exchange
POST /api/v1/workspace-tokens/exchangeNeeds no credentials. Takes an optional Spotlight-Client header.
| Field | Type | Description |
|---|---|---|
trust | string | The trust's id. |
token | string | The OIDC token the platform issued the workload. |
Workload token verification
The workload's token is verified against the keys the issuer publishes at
<issuer>/.well-known/openid-configuration. It must be signed with RS256,
RS384, RS512, ES256, ES384 or PS256, carry sub and exp, and be
current within 30 seconds. Spotlight reads the discovery document and the
keys under the same rules as its other outbound calls, so the deployment must
allow the issuer's host and the host of its jwks_uri. See
Calls out of Spotlight. A runner trust
verifies a host's token the same way.
A 200 response:
| Field | Type | Description |
|---|---|---|
token | string | The workspace token, sent as Authorization: Bearer <token>. |
tokenId | string | Its id. |
workspaceId | string | The workspace it acts in. |
scopes | array of strings | The trust's scopes. |
expiresAt | string | An RFC 3339 time. After this time, Spotlight does not accept the token. |
Every failed exchange gets 401 with Spotlight did not accept the exchange. Possible causes: an unknown trust, a token its issuer did not sign for the trust's audience, a workload the trust does not match, or a deleted workspace.
Each exchange is recorded as a configuration change: a created workspace token, with the trust, the subject, the scopes and the expiry.
See the trusts
Owners and admins see every trust under "OIDC trusts" on the API access page of the workspace settings: what each trust admits, its scopes, who created it, and when it last issued a token. The page only reads; Terraform and the resource API define trusts. See the web app.
Issued tokens
- An issued token acts for the trust's
createdBy, within the trust's scopes. - It is not listed among the workspace's tokens.
- Any change to the trust's settings stops every token issued before the change.
- Deleting the trust stops every token it issued, from that moment.