Federated credentials and exchange
Federated access lets an outside workload, such as a CI job, prove its identity with an OIDC token and receive a short-lived Arcane bearer token. Arcane then uses its normal session, role, environment, and edge-tunnel controls to authorize work and carry approved HTTP or WebSocket traffic to a connected resource.
Federated access boundary
The federated service is the trust boundary between an external OIDC issuer and Arcane. A configured rule says which issuer, audience, and claim value can become which Arcane service identity and role. The resulting token is an Arcane access token. It is not an edge-agent credential.
The wider system has two linked but separate paths:
| Path | Purpose | Main identity |
|---|---|---|
| Federated exchange | Turns a trusted external workload token into Arcane access | Dedicated service user |
| Edge tunnel | Connects an edge agent to the manager and carries requests | Environment agent token and optional client certificate |
| Resource proxy | Applies the caller's Arcane permissions before forwarding work | Authenticated user or service identity |
See Federated access and edge connectivity for the parent view. See Authentication and authorization flows for the common request identity and permission path.
References: backend/…/service.go• L37-49 backend/…/environment_middleware.go• L54-81 backend/…/server.go• L43-61
Federated credential lifecycle
Trust rule
The federated credential is a trust rule for one external workload identity. It binds an HTTPS issuer to one or more allowed audiences, a claim path, and either an exact value or a glob pattern. It also selects the Arcane role and optional environment scope that the issued identity receives.
The rule controls whether an exchange can happen and how long the issued Arcane token can live. New rules start disabled unless an administrator enables them. The service accepts a token lifetime from 60 to 3,600 seconds and uses 900 seconds when no lifetime is given.
| Trust field | Role in the decision |
|---|---|
| Issuer URL | Names the external OIDC provider that Arcane trusts |
| Audiences | Limits which intended token audience can use the rule |
| Subject claim and match | Identifies the workload in the verified claims |
| Role and environment | Defines the Arcane permissions and optional target scope |
| Enabled and expiry | Controls whether the rule is currently usable |
| Token lifetime | Sets the maximum life of the Arcane access token |
References: types/…/federated.go• L17-40 backend/…/credential.go• L17-39 backend/…/credential.go• L121-133
Service identity
Each rule owns a dedicated service user. The role assignment belongs to that user, so an exchange produces a normal Arcane identity with a clear permission source instead of borrowing a human user's account.
Creating a rule creates the service user, the trust rule, and its role assignment as one unit. Changing the mapped role or environment replaces that assignment. Deleting the rule also deletes its service user. When a rule is disabled, active sessions issued from that rule are revoked.
References: backend/…/service.go• L81-143 backend/…/service.go• L186-242 backend/…/service.go• L244-268
Management surface
The manager API and the authentication settings page expose the same rule lifecycle. Listing and reading require federated-credential permissions. Creating, changing, and deleting a rule require global administrator access. A caller cannot map a rule to a role or environment grant that the caller does not already hold.
The page also gives an operator a CI usage snippet after creation. The CLI can obtain the outside subject token from a flag, file, standard input, GitHub Actions, or GitLab. It sends the token to the exchange endpoint and can export, print as JSON, or persist the short-lived Arcane token.
References: backend/…/handler.go• L88-147 backend/…/credential.go• L136-155 frontend/…/federated-credentials-tab.svelte• L44-115 cli/…/federated.go• L30-137
Token exchange lifecycle
The exchange endpoint follows the OAuth token exchange form defined by RFC 8693. It is public in the sense that the caller does not yet have an Arcane token, but the submitted OIDC token must pass issuer, signature, audience, subject, rule, time, and replay checks.
When a workload requests an Arcane token, the service follows this sequence:
- Parse the form and require the token-exchange grant type plus a JWT or ID token subject type.
- Read the issuer, subject, and audience claims to find enabled, non-expired rules for that issuer.
- Discover the issuer's signing keys and verify the subject token. The verified claims, rather than only the unverified token text, drive the match.
- Match an allowed audience and the configured claim value. Exact rules compare the value directly. Glob rules use a whole-value pattern.
- Record a hash of the token identifier, or the token when no identifier exists. A second use is rejected.
- Load the rule's service user and issue a short-lived Arcane bearer token with a federated session.
- Record the result for audit and update the rule's last-used time after a successful exchange.
The flow below shows how an external token becomes a normal Arcane request identity.
sequenceDiagram
participant W as External workload
participant E as Exchange endpoint
participant O as OIDC issuer and keys
participant F as Federated service
participant A as Auth and session services
participant R as Arcane resource API
W->>E: Submit OIDC subject token
E->>F: Parse exchange request
F->>O: Discover issuer and verify signature
O-->>F: Verified claims
F->>F: Match rule and reject replay
F->>A: Create federated session and bearer token
A-->>W: Short-lived Arcane token
W->>R: Use bearer token
R->>A: Verify token and active session
A-->>R: Service identity and permissions
The response carries a bearer access token, its lifetime, and the issued token type. It does not provide a refresh token. The token records its federated source and credential ID, which lets normal session checks and audit records retain the link to the trust rule.
References: backend/…/handler.go• L54-85 backend/…/exchange.go• L25-141 backend/…/service.go• L968-1022 backend/…/service.go• L58-75
Authentication dependencies
OIDC verification
The issuer is an external dependency of every exchange. Arcane uses issuer discovery to obtain the JSON Web Key Set location, then verifies the submitted token with the issuer's keys. The issuer must be an HTTPS URL when an operator saves a rule. Issuer key sets are reused in memory so concurrent exchanges do not repeat the same discovery work.
The rule's audience check remains separate from signature verification. A valid token from a trusted issuer is not enough unless one of its audiences and its configured subject claim also match a rule.
References: backend/…/credential.go• L121-126 backend/…/exchange.go• L143-164 backend/…/exchange.go• L200-246 backend/…/exchange.go• L248-301
Arcane session verification
The exchange uses the same Arcane signing and session store used by other access tokens. Each issued token points to a persisted federated session and includes a federated source marker plus the rule ID. Later requests still need a valid signature, an existing user, and an active, unrevoked session.
This link makes rule changes effective beyond new exchanges. Disabling a rule revokes its active sessions, while deleting its service user makes tokens for that identity unusable even if their signed time has not ended.
The manager's request authentication accepts the federated bearer token through the normal bearer path. It verifies the token, loads the active session and user, then resolves the user's permissions. If permission resolution is unavailable, the safe result is deny-all access rather than an unscoped identity. API keys and environment access tokens are separate paths for infrastructure and proxy traffic.
References: backend/…/service.go• L700-791 backend/…/service.go• L854-862 backend/…/service.go• L968-1022 backend/…/handler.go• L984-1047 backend/…/handler.go• L1050-1086 backend/…/handler.go• L1099-1142 backend/…/token.go• L18-30 backend/…/service.go• L206-217
Role and environment authorization
Authentication identifies the federated service user. Authorization then resolves that user's role assignments. If the rule has an environment scope, the resulting permissions apply to that environment; otherwise the role can provide the broader access allowed by its grants.
The rule creator must already hold the selected role and environment grant. This prevents federated access from becoming a way to mint a service identity with more power than the administrator who created it.
References: backend/…/credential.go• L136-155 backend/…/service.go• L120-127 backend/…/environment_middleware.go• L208-275
Edge tunnel lifecycle
An edge tunnel is a long-lived reverse connection from an edge agent to the manager. The manager does not send a connected edge resource an arbitrary browser request until it has resolved the environment and found an accepted tunnel for that environment.
The agent starts with its environment credential and a register message. The manager resolves that credential to an environment, checks the optional client-certificate identity, and records one active tunnel in the tunnel registry. Heartbeats keep the session live. A newer valid session can replace a stale or same-agent session, while a healthy duplicate session is rejected.
The tunnel can use WebSocket or gRPC as its managed transport. Both transports expose the same logical connection contract, so request, response, stream, close, event, and heartbeat messages have the same meaning. The agent reconnects after failure and the manager removes sessions that stop sending heartbeats.
References: backend/…/server.go• L119-179 backend/…/server.go• L261-297 backend/…/registry.go• L113-187 backend/…/registry.go• L240-258 backend/…/client.go• L108-155
WebSocket proxy flow
WebSocket proxying carries live logs, statistics, and terminal traffic from a caller to a remote environment. The manager checks the caller before the upgrade. It then uses a direct remote API connection for a normal remote environment or an active edge tunnel for an edge environment.
The authorization step is part of the manager path, not an agent responsibility. The manager maps the request method and resource path to the same permission used by the local WebSocket route. Unknown paths fail closed. This matters because an edge agent accepts the manager's forwarded request as a trusted internal request.
The following flow shows the browser or CLI boundary, the manager's permission check, and the two possible remote paths.
flowchart TD
C[Caller opens WebSocket] --> M[Manager authenticates caller]
M --> P{Caller has route permission?}
P -- No --> D[Return forbidden]
P -- Yes --> T{Target is edge environment?}
T -- No --> H[Open direct remote WebSocket]
T -- Yes --> A{Active tunnel available?}
A -- No --> U[Wait for recovery or return gateway error]
A -- Yes --> S[Start stream through tunnel]
H --> R[Remote environment serves stream]
S --> R
R --> X[Forward text or binary frames and close state]
X --> C
For a tunneled stream, the manager creates a stream ID and sends a WebSocket-start message with the target path and safe request headers. The edge agent dials its local API, removes browser-only handshake data, and adds its agent credential. Text and binary frames move in both directions under the same stream ID. Ping checks and close messages end dead or completed streams instead of leaving them open.
Authentication headers have two jobs in this flow. The caller's Arcane bearer token, API key, or cookie establishes the caller at the manager. The environment access token selects and authorizes the target environment, while the configured agent token authenticates the manager-to-agent hop. These credentials must remain distinct so an edge agent does not replace the manager's permission decision with a broad internal identity.
References: backend/…/handler.go• L984-1142 backend/…/environment_middleware.go• L115-190 backend/…/environment_middleware.go• L381-418 backend/…/proxy_permissions.go• L11-43 backend/…/ws_proxy.go• L25-89 backend/…/client.go• L816-856 backend/…/client.go• L940-969
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the federated rule fields aligned across the shared DTO, database migration, management API, and settings form. In particular, preserve the issuer, audience, claim-match, role, environment, enabled, expiry, and token-lifetime meanings.
- Keep token-exchange validation aligned with issuer discovery, audience matching, subject matching, replay records, and the OAuth error response shape.
- Keep federated session creation aligned with access-token claims and session verification. A new source or claim must remain traceable to the rule that issued it.
- Keep manager authentication precedence aligned across bearer tokens, API keys, environment access tokens, and agent credentials. A resolver failure must continue to produce deny-all access.
- When changing role or environment assignment rules, review both creator privilege checks and the permission check that runs before remote proxying.
- Register every new proxied WebSocket route in both route handling and the permission matcher. A route missing from the matcher is denied by default.
- Keep the manager and agent tunnel message contracts aligned across WebSocket and gRPC transport. Stream IDs, message types, close behavior, and frame types must have the same meaning on both sides.
- When changing WebSocket header forwarding, preserve the split between caller authentication, agent authentication, and browser-only handshake headers.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The issuer cannot be discovered or its signing keys cannot verify the token | The exchange returns an invalid grant and no Arcane token is issued | Require HTTPS issuer URLs and verify the subject token against discovered keys |
| The token audience or configured subject claim does not match an enabled rule | A valid external token cannot enter Arcane | Configure the audience and exact or scoped subject match for the workload |
| The same subject token is submitted again | The second exchange is rejected as a replay | Record a hash of the token ID or token before issuing access |
| A federated rule is disabled | New exchanges fail and active sessions from the rule are revoked | Re-enable the rule only after its trust and role scope are correct |
| Permission resolution fails after a token is verified | The request is denied even though authentication succeeded | Treat an unavailable or failed permission resolver as an empty permission set |
| A caller lacks permission for a remote WebSocket route | The manager returns forbidden before any remote request is sent | Use the permission mapped to that route and environment |
| An edge agent has no active tunnel | Edge traffic cannot reach the local resource and returns a gateway error after the recovery wait | Keep the agent connected and let its heartbeat and reconnect loop restore the tunnel |
| A proxied WebSocket has no valid origin check | The manager refuses the upgrade | Use the same origin validator as local WebSocket endpoints |
| A tunnel stream stops consuming frames or the peer stops answering | The stream can close, drop data under backpressure, or release its pending request | Use bounded channels, ping checks, stream delivery limits, and close cleanup |
Key files
| File | Why to read it |
|---|---|
| backend/…/exchange.go | Shows the trust checks, OIDC verification, replay guard, service-user lookup, token issue, and audit outcome for an exchange. |
| backend/…/service.go | Shows the federated rule and service-identity lifecycle. |
| backend/…/handler.go | Shows the public token-exchange form and protected rule-management API. |
| types/…/federated.go | Defines the shared rule and RFC 8693 request and response contract. |
| backend/…/service.go | Shows how a federated access token gets a persisted session and normal Arcane signature. |
| backend/…/handler.go | Shows how bearer tokens, API keys, environment access tokens, and agent credentials enter the manager and agent request paths. |
| backend/…/environment_middleware.go | Shows the authorization-before-proxy boundary and the choice between direct and tunneled remote access. |
| backend/…/proxy_permissions.go | Shows the single mapping between proxied WebSocket routes and required permissions. |
| backend/…/server.go | Shows manager-side tunnel authentication, registration, heartbeats, and session replacement. |
| backend/…/ws_proxy.go | Shows manager-side WebSocket stream creation and frame forwarding through an edge tunnel. |
| backend/…/client.go | Shows agent-side tunnel reconnect, local WebSocket dialing, frame transfer, and stream cleanup. |
| backend/…/tunnel.proto | Defines the transport contract for registration, requests, streams, WebSocket data, and heartbeats. |
| cli/…/federated.go | Shows how CI workloads find an external OIDC token and consume the exchanged Arcane token. |