Authentication
The Diverge ConnectRPC server uses a composable triple-authentication system, supporting OIDC (OpenID Connect), Kubernetes TokenReview, and attenuated Macaroon capability tokens. This allows flexible authentication for human users, automated CI/CD pipelines, and autonomous coding agent sandboxes.
Overview: Composable Auth Chain
Section titled “Overview: Composable Auth Chain”- OIDC (OpenID Connect): Primarily used for human developers accessing the Web Dashboard or CLI. It delegates authentication to an external identity provider (IdP).
- Kubernetes TokenReview: Primarily used for CI/CD pipelines or in-cluster services that authenticate using Kubernetes ServiceAccount tokens.
- Macaroon Capability Tokens: Used by autonomous
AgentTasksandbox pods calling back intodiverge-server(including/mcpandPOST /api/v1/agenttask/meter). Tokens carry cryptographic HMAC-SHA256 caveats (task_id,namespace,repo,branch,tools,models,max_cost_usd,max_tokens,expires) and are validated against the namespace-scopeddiverge-agenttask-tokensindexSecretand liveAgentTaskstatus.
Setting up Zitadel as OIDC Provider
Section titled “Setting up Zitadel as OIDC Provider”Setting up an OIDC provider like Zitadel follows a similar pattern to configuring SSO for tools like Argo CD.
- Create an Application: In Zitadel, create a new Web/Native application.
- Configure Redirect URIs: Configure the appropriate redirect URIs for the CLI login flow.
- Configure Helm Values: Update your Diverge Helm values with the Zitadel issuer URL and client ID.
server: auth: oidc: issuerUrl: "https://your-domain.zitadel.cloud" clientId: "<your-client-id>" groupsClaim: "urn:zitadel:iam:org:project:roles"CLI & MCP Authentication
Section titled “CLI & MCP Authentication”diverge dev: Authenticates withdiverge-serverusing--token,DIVERGE_TOKEN, or automatickubeconfigbearer credential fallback.diverge mcp: Authenticates withdiverge-serverusingDIVERGE_TOKEN,DIVERGE_MACAROON_TOKEN, or a mounted sandbox token file (/etc/diverge/token/token). It does not read credentials fromkubeconfig.
# Mint a bound Kubernetes ServiceAccount token for diverge-serverexport DIVERGE_TOKEN="$(kubectl create token my-sa --audience diverge-server)"
# Connect local dev tunnel or stdio MCP serverdiverge dev --service payments-api --server https://diverge.example.comdiverge mcp --server-url https://diverge.example.comCI/CD Authentication
Section titled “CI/CD Authentication”For automated pipelines (e.g., GitHub Actions, GitLab CI), commands that reconcile Kubernetes Custom Resources directly such as diverge preview create require KUBECONFIG:
# Example CI/CD step- name: Deploy Preview run: | diverge preview create --name pr-${{ github.event.pull_request.number }} --service payments-api=ghcr.io/acme/payments:pr-${{ github.event.pull_request.number }}CLI Tunnel Authentication (diverge dev)
Section titled “CLI Tunnel Authentication (diverge dev)”Starting in v0.10.0, reverse tunnels created via diverge dev authenticate directly against the ConnectRPC server using Kubernetes TokenReview:
- Pass credentials with
--token <token>or theDIVERGE_TOKENenvironment variable. - If omitted,
diverge devautomatically falls back to bearer credentials configured in the currentkubeconfigcontext.
Secure Cookies Behind TLS Proxies
Section titled “Secure Cookies Behind TLS Proxies”When the Diverge ConnectRPC server is deployed behind an Ingress controller, API Gateway, or reverse proxy that terminates TLS, session cookies must be protected with the Secure flag.
Diverge provides the --secure-cookies server flag (server.auth.secureCookies in Helm values):
server: auth: secureCookies: "auto" # "auto" (default) | "true" | "false"auto: Inspects theX-Forwarded-Protoheader. Ifhttps, setsSecure; SameSite=Lax. If plainhttp(such as local port-forwarding), omitsSecureso developers aren’t locked out.true: Unconditionally forces theSecureattribute on all session cookies.false: Disables theSecureattribute.
Token Lifecycle and Expiry
Section titled “Token Lifecycle and Expiry”- OIDC Tokens: Rely on the expiration policies set by your IdP. The Diverge CLI will prompt for re-authentication when the token expires.
- ServiceAccount Tokens: It is recommended to use bound ServiceAccount tokens with a set expiration in Kubernetes 1.24+, rather than static, non-expiring secrets, to ensure a secure token lifecycle.
- Macaroon Capability Tokens (
AgentTask):- Minted automatically by
diverge-controllerwhen anAgentTaskis provisioned and stored in<task>-token(mounted read-only at/etc/diverge/token/tokeninside the sandbox pod) as well as indexed in the namespace-scopeddiverge-agenttask-tokensSecret. - When a sandbox reports
tokensUsed/costUSDusage toPOST /api/v1/agenttask/meterthat exceedsmax_cost_usd,max_tokens,budgetUSD, orbudgetTokens(or when a user runs/diverge pause), the token is immediately marked"revoked"indiverge-agenttask-tokensand the task transitions toPaused. - Resuming the task (
/diverge resumeor settingspec.suspended: false) mints a fresh Macaroon capability token with the updated budget caveats.
- Minted automatically by
