OIDC Login (interactive, tenant-driven)
agent-orca supports interactive OIDC login for browser access. Each federated TenantConfig that carries a clientSecretRef (+ redirectURI) is a selectable identity provider — so each org logs in through its own IdP (Google, Okta, Keycloak, …). On success the operator mints a short-lived agent-orca-issued JWT carried in an HttpOnly session cookie, validated by the same requireAuth / ExternalAuth middleware used by bearer tokens. RBAC is not implemented — the identity carries UserID/Groups/Roles so authorization can be added later as a handler-side check.
Multi-tenant by design. Per-tenant issuer/client_id/client_secret/redirect/ claim mappings live on the
TenantConfigCRD (in the tenant'sallowedNamespaces), not operator-wide. A browser-facingBearer/SA token does not grant UI access when login is enabled — the UI is never shown without a successful login.
Surfaces
| Surface | Port | Login endpoint | Delivery |
|---|---|---|---|
| UI API (via UIProxy) | 8080 / 8083 | /oauth/login, /oauth/callback, /oauth/logout | HttpOnly session cookie |
| External Task API | 8084 | (bearer only) | Authorization: Bearer <jwt> |
| ACP API | 8000 | (bearer only) | Authorization: Bearer <jwt> |
The External/ACP APIs already reject any request without a valid bearer token; the OIDC bearer tokens they accept come from a federated TenantConfig (issuer + JWKS verification). Interactive browser login is a UI-only feature; programmatic callers use /oauth/token (client_credentials) or a federated bearer JWT.
aoctl CLI login
aoctl login offers the same two surfaces — OAuth client_credentials and OIDC authorization-code — via an interactive selection menu when no credentials are passed (the CLI analogue of the UI picker). The OIDC flow is driven end-to-end by aoctl itself (using the shared internal/security/oidc package), not by the operator's /oauth/login handler:
aoctl -> * discover IdP via <issuerURL>/.well-known/openid-configuration
aoctl * build auth code URL (PKCE + nonce), open system browser (or --no-browser)
aoctl * start a loopback HTTP server on --redirect-uri (default 127.0.0.1:8765/callback)
Browser<-> Idp login (Google/Keycloak/…)
IdP -> 302 redirect to the loopback callback with ?code=…&state=…
aoctl * verify state (CSRF), POST code+code_verifier -> id_token (+ refresh_token)
aoctl * verify id_token (JWKS signature, iss, aud, exp, nonce)
aoctl * persist id_token as the bearer token + refresh_token for automatic refresh
aoctl -> External/ACP API: Authorization: Bearer <id_token>
operator * validateFederatedToken verifies the id_token against the federated TenantConfig's JWKSKey points:
- No server-side OIDC changes are required for this path.
aoctlobtains a standard OIDC id_token and presents it directly; the operator already validates federated bearer JWTs via the issuer's public JWKS (validateFederatedToken). - The id_token's
iss/audmust match afederatedTenantConfig(issuer-only trust admits any verified token from that issuer;matchClaim/matchValueadds a claim gate). The--client-idyou log in with is the sameclientIDconfigured on the tenant. --client-secretis optional: public/PKCE clients (e.g. a GitHub App, a Google "Web client" used from a native context) omit it. Confidential clients supply it (it is cached at0600, same as the token — see aoctl CLI Reference).- The cached
refreshTokenis used to automatically refresh the id_token when it nears expiry, soaoctlkeeps working without re-login. The OIDC config (issuerURL,clientID,clientSecret,redirectURI) is also cached so the refresh needs no further input. Refresh is skipped duringaoctl login(which establishes a fresh session) and when a token is supplied via--token. aoctl loginrequests theoffline_accessscope (plusaccess_type=offlinefor Google) so the IdP actually returns arefreshToken. Without it, most providers omit the refresh token and you'd seerefresh: none (re-login before expiry)— i.e. re-login every few hours. The long-livedaoctl acp servebridge additionally refreshes ahead of expiry and retries on any401, so an ACP session survives anid_tokenexpiry without re-login or re-acp setup.
# Interactive picker (recommended for first run)
aoctl login
# Non-interactive OIDC
aoctl login --auth-method oidc \
--issuer-url https://accounts.google.com \
--client-id <your-client-id> \
--client-secret <your-client-secret> # omit for public clientsUsing OIDC for aoctl admin
OIDC id_tokens authenticate the task and agent surfaces (they are tenant-scoped to the federated TenantConfig the user logged in through). The /admin/* surface is ServiceAccount-only by default — except that a federated id_token may read its own tenant config:
| Command | OIDC id_token | SA admin token |
|---|---|---|
aoctl admin tenants get <name> (where <name> is your federated tenant) | ✅ 200 (read-only, no secret) | ✅ |
aoctl admin tenants list / create / delete / rotate-secret | ❌ 401 (SA-only) | ✅ |
So a human who logged in with aoctl login --auth-method oidc can inspect the TenantConfig they authenticated via, but tenant lifecycle (create/delete/rotate, listed to all tenants) still requires a ServiceAccount:
# After `aoctl login --auth-method oidc`:
aoctl admin tenants get <my-federated-tenant-name> # works with the OIDC id_token
# Cluster-wide admin still needs a SA token:
SA_TOKEN=$(kubectl create token agentorca-admin -n agent-orca-system)
aoctl admin tenants list --token "$SA_TOKEN"The server authorizes the self-tenant read by matching the bearer id_token's resolved tenant (via validateFederatedToken) against the <name> in the path, so a valid token for tenant A gets a 404 against /admin/tenants/b (hidden rather than 403, so cross-tenant enumeration is not revealed). Full-admin operations (list/create/delete/rotate-secret) still require a ServiceAccount; an OIDC id_token hitting one of those now receives a 401 with a hint naming the SA-token path and the single OIDC-allowed op, instead of a bare unauthorized. The allowed self-tenant operations live in a small, method-keyed capability table (selfTenantAdminOps in internal/apiserver/external_api.go); future per-tenant RBAC appends entries there, gated on a role resolved onto TenantIdentity.Roles; see Future RBAC design.
How a browser logs in
Browser -> /oauth/login -> picker of federated (login-capable) tenants
Browser -> /oauth/login?tenant=org-x -> 302 to IdP (state carries tenant X)
Browser <-> IdP login (Google/Keycloak/…)
IdP -> /oauth/callback?code=..&state=.. (state cookie + sealed login cookie checked)
operator * state -> tenant X -> read X's client_secret from its first allowed namespace
operator * POST code+secret to IdP -> id_token
operator * verify id_token (JWKS signature, iss, aud, exp, nonce) + email_verified
operator * ResolveFederatedTenant(issuer, claims) -> TenantIdentity (tenant/namespace/agents)
operator * MintSessionForIdentity -> signed session JWT -> Set-Cookie: agentorca_session
Browser -> /api/* (cookie sent; requireAuth validates it -> 200)The pending login (tenant, nonce, PKCE verifier) lets the callback use that tenant's IdP and secret. NewProviderForTenant builds the oidc.Provider per tenant at login time.
Multiple operator replicas
The pending login is not kept in server memory, so the callback can land on any replica. /oauth/login sets two HttpOnly, SameSite=Lax cookies (Secure per --oidc-cookie-secure), each valid for 5 minutes:
agentorca_oidc_state: the randomstatevalue sent to the IdP.agentorca_oidc_login: the pending login (tenant, nonce, PKCE verifier, state, expiry), encrypted and authenticated with AES-256-GCM. About 400 bytes, well under the 4 KB cookie limit.
The AES key is derived with HKDF-SHA256 (context agent-orca/oidc-login-cookie/v1) from the JWT signing key. Every replica loads that key from the agentorca-jwt-signing-key Secret, so no Helm value or database is needed. The signing key is only HKDF input; it is never used directly as a cipher key.
The callback rejects a request when the sealed cookie fails to open (tamper, other key, expiry) or when its embedded state differs from the state the IdP returned. It clears both cookies once the sealed one has opened.
Replay. Because the payload is stateless, a callback replayed within its 5 minute lifetime is not rejected by the operator. It is limited by the IdP's single-use authorization code, which fails the second exchange.
Rotating the signing key invalidates logins in flight (users retry). If an ExternalAuth has no signing key, the handler falls back to an in-process store and logs a warning at startup; login then works only on a single replica. The operator normally always has a key, so this is not expected in a deployed chart.
Tenant config reference
apiVersion: agentorca.agentorca.io/v1alpha1
kind: TenantConfig
metadata:
name: google-oidc
namespace: agent-orca-system
spec:
authMode: federated
allowedNamespaces:
- default # where tasks run; also where the client secret lives
federated:
issuerURL: "https://accounts.google.com"
clientID: "<your-oauth-web-client-id>"
redirectURI: "http://localhost:8083/oauth/callback"
clientSecretRef:
name: oidc-client-secret # Secret in spec.allowedNamespaces[0]
key: client-secret
claimMappings:
userid: email # email -> TenantIdentity.UserID (default: sub)
# matchClaim/matchValue omitted => issuer-only trust (any verified login admitted).
# Set matchClaim/matchValue to gate on a claim (e.g. repository_owner for GitHub,
# hd for a Google Workspace domain, or an IdP "groups"/"orgs" claim).
rateLimit:
requestsPerMinute: 60
concurrentRuns: 4Fields of note:
allowedNamespaces— the set of Kubernetes namespaces whose agents/resources this tenant is authorized to access. The operator resolves each agent/run to its own namespace within this set, so a tenant can span multiple namespaces. The OAuth client secret is read from the first listed namespace (orclientSecretRef.namespaceif set).clientSecretRef— optional. Present ⇒ this tenant drives interactive login (the operator becomes an OAuth client). Absent ⇒ bearer-only federation (callers present an IdP-issued JWT; verified via the public JWKS — no secret).redirectURI— the callback URL registered at the IdP. In local dev this ishttp://localhost:8083/oauth/callback(skaffold forwards:8083). Behind TLS it's the public callback.claimMappings— which IdP claims map ontoTenantIdentity. Defaultsub/groups/email; setuserid: emailfor Google.
Enabling (Helm)
# values.yaml
operator:
oidc:
enabled: true
cookieSecure: true # true behind TLS; false for plain-HTTP local devhelm upgrade --install agent-orca charts/agent-orca \
--namespace agent-orca-system \
--set operator.oidc.enabled=true \
--set operator.oidc.cookieSecure=trueLocal dev (skaffold + your own IdP)
- Start the dev cluster:
skaffold dev -p dev(this also forwards:8083). - Deploy your IdP (e.g. Keycloak) and port-forward it yourself.
- Create the OAuth client secret in the tenant namespace and a login-capable
TenantConfig(example:config/samples/dev-tenant-google.yaml). A ready-made overlay + secret sample live atcharts/agent-orca/values-dev-oidc.yamlandconfig/samples/dev-oidc-secret.yaml:bashhelm upgrade agent-orca charts/agent-orca -n agent-orca-system \ -f charts/agent-orca/values-dev-oidc.yaml # enabled=true, cookieSecure=false kubectl apply -f config/samples/dev-tenant-google.yaml kubectl create secret generic oidc-client-secret -n default \ --from-literal=client-secret='<your-idp-client-secret>' - Open
http://localhost:8080/oauth/login(proxied by the UIProxy, which now forwards/oauth/*) and pick your tenant.
Local dev topology note
- The browser reaches the callback at
http://localhost:8083/oauth/callback(skaffold forward); that's the IdP's registered redirect URI. - The operator pod (in kind) must reach the IdP for JWKS discovery + token introspection. With both on the same host, the IdP issuer is
http://host.docker.internal:<port>/…so the kind pod can resolve it. - If your cluster enforces a default-deny egress, the operator can't reach the IdP until you allow it. Enable the opt-in egress on the operator NetworkPolicy (dev default allows everything from the pod; narrow to the IdP CIDR in production):yamlThe policy also retains egress to the kube-apiserver (443) and cluster DNS (53) so TokenReview keeps working once egress is isolated.
operator: networkPolicy: oidcEgress: enabled: true # set when the pod can't already reach the IdP cidrs: ["0.0.0.0/0"] # dev; restrict to the IdP host CIDR in production cookieSecure: falseis required forhttp://(aSecurecookie is not sent over plain HTTP).- DNS from the pod, not just egress:
test.keycloak.orgmust resolve inside the kind node (e.g. via/etc/hostson the node or a resolvable host). If it resolves on your laptop but not in the cluster, use a host-reachable issuer such ashttp://host.docker.internal:<port>/realms/masterinstead.
Cookie model & the UIProxy (BFF)
The UIProxy (cmd/ui-proxy/main.go) reverse-proxies /api/* and /oauth/*. Its Director strips only Authorization (to inject the SA token); ReverseProxy forwards Cookie/Set-Cookie by default, so the session cookie round-trips. With login enabled, requireAuth prefers the session cookie and ignores the SA token, so the UI is gated on the OIDC login (not on cluster-internal proximity).
Google OIDC bearer tokens (GitHub Actions style)
For programmatic callers, a federated bearer tenant also works. Google's OIDC issuer is https://token.actions.githubusercontent.com (Actions), with the user's login in the actor claim — see enterprise-integration.md.
Future RBAC design
This change is authentication only. TenantIdentity already carries UserID/Groups/Roles (empty until a role mapper exists). A future layer can resolve Groups → Roles from the IdP claim and gate handlers with if !slices.Contains(identity.Roles, "admin") — no auth-path rewrite, since the identity is already injected into context by requireAuth / ExternalAuth.Middleware.
