Use a workspace token when a script or job needs service credentials. The
endpoint is GET /workspaces/<workspace>/token. The caller must have the
workspace’s ws_admin role; global administration alone is not sufficient.
Choose the token’s identity and access with the scope query parameter:
| Request | Identity | Workspace roles in the result |
|---|---|---|
Omit scope |
Workspace service account. | ws_api only. |
scope=ws_api |
Original caller. | ws_api only. |
| Configured profile scopes | Original caller. | ws_api and exactly the selected vcluster or S3 export roles. |
Responses use Cache-Control: no-store and contain no refresh token. Keep
bearer tokens in memory and out of logs or saved files.
Omit scope when the job should use the workspace service account:
curl -H 'Authorization: Bearer <workspace-admin-access-token>' \
https://api.example.org/workspaces/ws-alice/token
The workspace admin authorizes the request, but the returned token belongs to the service account. Use user exchange when the job needs a vcluster profile or S3 export.
User exchange keeps the caller’s identity, including its sub. The caller
needs ws_admin, ws_api, and every requested profile role in that workspace.
For service credentials without a vcluster or S3 export, request scope=ws_api:
curl --get -H 'Authorization: Bearer <workspace-admin-access-token>' \
--data-urlencode 'scope=ws_api' \
https://api.example.org/workspaces/ws-alice/token
ws_api selects this API flow; it is not sent to Keycloak as an OAuth scope.
To include profiles, use their workspace-qualified scopes:
| Profile | Request scope | Additional caller role |
|---|---|---|
demo in vc0 |
ws-alice:vclusters_vc0_demo |
vclusters_vc0_demo |
S3 export project-a |
ws-alice:s3_project-a |
s3_project-a |
Separate scopes with spaces. For example:
curl --get -H 'Authorization: Bearer <workspace-admin-access-token>' \
--data-urlencode 'scope=ws-alice:s3_project-a ws-alice:vclusters_vc0_demo' \
https://api.example.org/workspaces/ws-alice/token
The API removes duplicate scope names and rejects empty scopes, interactive scopes, and the built-in cluster-admin profile. Each profile must be ready and match its current provider configuration and status. Removed, changed, or hibernated vcluster profiles cannot be selected. S3 exports must match the declared role, scope, signing identifier, and virtual bucket.
The caller token must come from the workspace issuer and identify the
workspace in aud or as the client in azp. The API sends that token as
subject_token to Keycloak.
Before returning a token, the API checks its signature against the issuer’s HTTPS JWKS, issuer, expiry, not-before time, bearer type, and audiences. Issued-at checks allow five seconds of clock variation; expiry is strict.
The result must have exactly the API and workspace audiences and the roles
selected in the table above. Exchange must retain the caller’s subject.
Tokens with ws_access, ws_admin, cluster-admin, realm roles, roles for
other clients, authorization permissions, or unrequested profile roles or
scopes are rejected. Allowed identity scopes are openid, basic, profile,
and email; checks cover both token claims and the response’s scope field.
| Failure | HTTP status |
|---|---|
| Missing caller role or mismatched exchange identity | 403 |
| Invalid or undeclared scope | 422 |
| Unready OAuth client, vcluster profile, or S3 export | 503 |
| Invalid issued token or issuer response | 502 |
Read access_token from the response and send it as a Bearer token. For an S3
export:
curl --get -H 'Authorization: Bearer <workspace-access-token>' \
--data-urlencode 'resolve_connections=s3-export:project-a' \
https://api.example.org/workspaces/ws-alice
Permissions lists the connection selectors and credential fields. Platform admins should use the identity-provider setup if issuance fails because of client, audience, or scope configuration.