<#6998 [V2] Add AuthMetadataService + wire externa...
# flyte-github
a
#6998 [V2] Add AuthMetadataService + wire external OAuth2 auth into runs service Pull request opened by pingsutw on <!date^1773092548^{date_short}|2026-03-09T21:42:28Z> Architecture The v2 runs service acts as an OAuth2 resource server. It validates JWTs issued by a configured external OAuth2 authorization server and runs the standard OIDC code flow against an OpenID Connect IdP (e.g. Okta) for browser users. v2 does not mint tokens itself —
authCfg.AppAuth.AuthServerType
is
External
, and
externalAuthServer.baseUrl
points at the issuer whose
.well-known/oauth-authorization-server
+
jwks_uri
v2 reads at boot. graph TB Client[UI / flyte-sdk / task pods] ALB["Ingress / load balancer"] IDP["OIDC IdP (Okta)<br/>signin.example.com<br/>client id 0oak...5d6"] AUTHSRV["External OAuth2 authorization server<br/>.well-known/oauth-authorization-server<br/>jwks_uri"] MW["runs GetAuthenticationHTTPInterceptor<br/>bearer + cookie + loopback gate"] OIDC["OIDC browser handlers<br/>/login /callback /logout<br/>.well-known/openid-configuration"] RPC["v2 connect-rpc handlers<br/>RunService ProjectService TaskService<br/>TriggerService TranslatorService<br/>AuthMetadataService IdentityService ..."] INT["intra-cluster connect-rpc<br/>ActionsService InternalRunService<br/>(ClusterIP only, allowlisted)"] COOKIE["CookieManager<br/>AES-256 + HMAC-SHA256<br/>cookie_hash_key cookie_block_key"] S1["auth secret<br/>cookie_hash_key / cookie_block_key"] S2["OIDC client secret<br/>oidc_client_secret"] Client --> ALB ALB -->|"/login /callback /logout /healthcheck<br/>/flyteidl2.*/*"| MW ALB -.->|"/v2/* static SPA"| MW Client -.->|"task-pod ClusterIP calls"| INT MW --> OIDC MW --> RPC OIDC <-->|"authorization code flow"| IDP OIDC --> COOKIE MW -.->|"boots JWKS"| AUTHSRV MW -.->|"validate bearer token signature"| AUTHSRV COOKIE -.->|"reads"| S1 OIDC -.->|"reads"| S2 Loading Component data flow | Component | File(s) | Reads | Writes / Emits | When | | ----------------------------------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ | | setupAuth() bootstrap | runs/setup.go | /etc/secrets/cookie_hash_key, /etc/secrets/cookie_block_key, /etc/secrets/oidc_client_secret, authCfg.AppAuth.ExternalAuthServer.BaseURL | *AuthenticationContext, registers 4 HTTP handlers + connect-rpc services, sets sc.Middleware | Once at pod start | | ResourceServer | runs/service/auth/authzserver/resource_server.go | configured issuer .well-known/oauth-authorization-server then jwks_uri then JWKS | verifies JWT signature, parses claims, returns *IdentityContext | Once at boot (JWKS fetch), then per-request (verify) | | GetAuthenticationHTTPInterceptor | runs/service/auth/http_middleware.go | req.URL.Path, req.Header.Get("Authorization"), request cookies, req.RemoteAddr | injects IdentityContext into ctx, writes 401, or bypasses auth for loopback and public paths | Every non-public request | | IsPublicPath | same file | req.URL.Path | skips middleware for health probes, OIDC flow paths, AuthMetadataService, ActionsService, InternalRunService | Every request | | isLoopbackRequest | same file | req.RemoteAddr | bypasses middleware for intra-process connect-rpc calls from the unified binary to its own mux | Every non-public request | | IdentityContextFromRequest | runs/service/auth/handlers.go | Authorization: Bearer ... header then ResourceServer.ValidateAccessToken, or cookies then CookieManager.RetrieveTokenValues then IdentityContextFromIDToken | *IdentityContext or error | Called by middleware | | CookieManager | runs/service/auth/cookie_manager.go | cookie_hash_key + cookie_block_key (base64, at startup); flyte_at / flyte_rt / flyte_idt / flyte_user_info cookies (per request) | encrypted cookies on /login+/callback, decrypted payloads on middleware pass | Startup + per request | | GetLoginHandler | runs/service/auth/handlers.go | redirect_url query param | sets flyte_csrf_state cookie; 307 to oauth2Config.AuthCodeURL(state) | When client hits /login | | GetCallbackHandler | runs/service/auth/handlers.go | code + state query params, flyte_csrf_state cookie, oidc_client_secret | exchanges code at IdP, fetches user info, sets flyte_at/flyte_rt/flyte_idt/flyte_user_info cookies, 307 to post-login redirect | When IdP redirects back | | computeOIDCRedirectURL | runs/service/auth/auth_context.go | cfg.AuthorizedURIs[0] | returns absolute URL like https://<host>/callback | At NewAuthContext time, baked into oauth2.Config.RedirectURL | | authzserver.NewAuthMetadataService | runs/service/auth/authzserver/metadata_provider.go | authCfg.AppAuth.ExternalAuthServer.BaseURL + .MetadataEndpointURL | serves /flyteidl2.auth.AuthMetadataService/GetOAuth2Metadata and GetPublicClientConfig via connect-rpc | Client discovery calls | | Helm configmap.yaml renders 004-auth.yaml | charts/flyte-binary/templates/configmap.yaml | configuration.auth.* values … flyteorg/flyte