RHOAIENG-96081: Core BFF caller identity and credentials on every transport #10796
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #10796"
general
weight: 0.35
paulovmr
Fixes: https://redhat.atlassian.net/browse/RHOAIENG-96081
RHOAIENG-101218 (caller credentials on xKS, no silent service-account fallback) was closed as a duplicate and folded into RHOAIENG-96081, now "Core BFF caller identity and credentials on every transport"; this PR implements both halves. The final RHAII manifest RBAC (removing the service-account permissions this PR makes unnecessary) is tracked in RHOAIENG-104119.
Problem
On xKS (AKS with Entra ID), the gateway forwards the caller's Entra access token in both
Authorization: Bearerandx-forwarded-access-token. Which of the two becomes the contract is not decided. Core BFF reads exactly one configurable header, so whichever one we pick, a gateway that sends only the other gets a 401 on every route.The Kubernetes proxies had two gaps where a missing or wrong credential could be replaced by something else:
Authorizationheader.The proxies also passed
Impersonate-UidandX-Remote-through to the API server.The RHAII EA journey on xKS (a non-admin signs in, deploys a model, deletes it) also reaches REST handlers that check the caller first and then let the dashboard service account do the write. The namespace serving-platform mutation is the main one. RHOAIENG-96081 (which absorbed RHOAIENG-101218) needs every supported user-initiated access to use the caller's credentials, and never to fall back to the service account.
Solution
One caller identity on every transport (RHOAIENG-96081).
internal/callerauthextractor is now the only place the caller token is read.InjectRequestIdentitycalls it once per request, and REST handlers, the Kubernetes HTTP and WebSocket proxies, the model-serving proxy and the module proxies all use the result. The package does not depend on the Kubernetes package, so the identity provider can be swapped later.AUTH_TOKEN_HEADERS/--auth-token-headers, takes an ordered list of headers. The RHAII xKS manifest (manifests/distributions/rhaii/deployment.yaml) and the xKS contract suite useAuthorization,x-forwarded-access-token; it replaces the manifest's--auth-token-header=x-forwarded-access-token --auth-token-prefix=. It is documented indistributions/core-bff/AGENTS.md,bff/README.mdanddocs/runtime-contract.md. When the setting is unset, the existingAUTH_TOKEN_HEADER/AUTH_TOKEN_PREFIXbehaviour is unchanged (this is the OpenShift path). A module proxy entry withauthorize: truereceives the resolved token in every configured credential header (and inx-forwarded-access-token), with theBearerprefix only inAuthorization.-
Authorizationmust use the Bearer scheme. Other headers carry the bare token.- A header that is present but malformed fails the request. It does not fall through to the next header, because the edge may have authenticated exactly that header.
- A repeated header, or a value with embedded whitespace or a comma, fails.
- Two different tokens fail closed.
- No credential returns 401.
- The rules are in
docs/runtime-contract.md, under "Caller credentials".- a prefix is set next to the list;
- a header name is invalid or listed twice;
- the list is set but names no header (
,or whitespace only), instead of silently falling back to single-header mode;- an identity or session header (
Cookie,Impersonate-, anyX-Remote-,X-Forwarded-User, …) or a header the correlation middleware strips (X-Request-ID,Audit-ID) is configured as a credential header.-
AUTH_TOKEN_HEADERis trimmed at startup and in the extractor, so a padded value that passes validation also matches requests.- The name and forbidden-header checks apply to the legacy
AUTH_TOKEN_HEADERtoo, in both modes: module proxies still forward it, so it is checked even when the list is set. A rejected entry is reported by setting and position, never by value, so a token pasted into either setting by mistake stays out of the startup log. A forbidden prefix match is named by the prefix alone, and the startup log records only whether the legacy header is set and how many token headers are listed.Vary. Token values never appear in error text.- The proxies now also strip
Impersonate-Uidand the wholeX-Remote-family, matched case-insensitively (X-Remote-User,X-Remote-Group,X-Remote-Extra-,X-Remote-Uidand any otherX-Remote-header).- The Kubernetes HTTP and WebSocket proxies return 401 rather than forward a request that has no caller token.
- The proxies never present a kubeconfig client certificate with a caller credential. Outside
DEV_MODEthey don't present it at all. InDEV_MODEthey present it only for the kubeconfig fallback identity (no credential sent), on a separate transport and connection pool. In-cluster configs carry no certificate, so OpenShift in-cluster behaviour does not change.DEV_MODEfalls back to the kubeconfig identity only when no credential was sent. A malformed or conflicting credential gets 401, as in production.make dev-bffprofile (disabled auth,DEV_MODE, mock Kubernetes), the Kubernetes proxy runs the fallback identity as the envtest admin, as the mocked REST clients do, instead of impersonating the dev user.Caller credentials for user-initiated access (RHOAIENG-96081, formerly RHOAIENG-101218).
repositories.CredentialPolicysets whose credentials run a user-initiated operation. OpenShift keeps the RHOAI privileged-watcher model: the service account performs the operation after the handler has authorized the caller. On xKS, the caller's own clients perform it. This covers:- the namespace serving-platform mutation;
- ServingRuntime create;
- connection-type create, update, patch and delete, including the existence check before each;
- component removal;
- cluster settings;
- OdhDashboardConfig admin read and patch.
- Dry-run requests follow the same policy.
ErrIdentityUnresolved). No code path leads to the service account.200 {"success": false}, but they no longer fold a denial into that shape.PUT /api/cluster-settingsmakes several separate writes with no transaction. On xKS it first runs a self access review, with the caller's credentials, for every write it will make (OdhDashboardConfig patch, culler and segment-key ConfigMaps, notebook-controller rollout). It returns 403 before the first write if any is denied, so a partially permitted caller cannot leave a partial change. The writes are planned once and only the planned writes run: if the culler ConfigMap appears or disappears after the review, the planned create or update fails instead of switching to a write that was not reviewed. A ConfigMap write is planned only when it changes the stored value (no delete for an absent culler map, no update for a map that already holds the requested value), so a change to another setting needs no ConfigMap write access. Every ConfigMap operation is bound to the resourceVersion the plan read: a ConfigMap changed, created or deleted since the plan is a conflict rather than success, so an older save cannot overwrite a newer value, and the rollout decision comes from that same read. The segment-key ConfigMap is handled before the culler ConfigMap, so a conflict leaves the culler change for the retry to roll out; when the PVC size changed, the planned rollout still runs after a later conflict. A failed read is an error, never a change that triggers a rollout. When the caller finds no OdhDashboardConfig instance,GETbuilds the defaults directly, without a service-account read. An access review the authorizer could not evaluate (neither allowed nor denied, withevaluationError) also stops the save before any write, but is reported as200 {"success": false}, not 403. A tracking opt-in while the OdhDashboardConfig setsdisableTrackingis refused the same way instead of reporting success for a setting left off.GETandPUT /api/cluster-settingsshare one caller-scoped read (defaults only when no instance exists), and the cluster-settings patch is computed from the caller's own read of OdhDashboardConfig, and the update aborts if that read fails. It is never diffed against the defaults that the service-account bootstrap read falls back to.GET /api/cluster-settingsreturns 403 when the caller may not read the segment-key ConfigMap, instead of reporting tracking as disabled.PATCH /api/configbuilds its response from the patched object rather than re-reading through the bootstrap path.{"applied": false}fromGET /api/namespaces/:name/:context. The service account used to apply the label for them. The deploy flow already toleratesapplied: false. Only that denial (any403from the API server) isapplied: falseon xKS; any other failure of the caller's patch (timeout, 5xx, missing namespace) is returned as that error. OpenShift keepsapplied: falsefor every failed patch.docs/bootstrap-contract.md, under "Service-account permissions":-
odhdashboardconfigsget;-
odhapplicationslist;- connection-type ConfigMaps
getandlistin the dashboard namespace.- On a confirmed xKS platform the service account needs no write verb, and no access to
namespaces,servingruntimes,deploymentsorauths. This list is the input for the final RHAII manifest RBAC in RHOAIENG-104119.Contract and compatibility.
Unauthorizedenvelope.AUTH_TOKEN_HEADERSunset, OpenShift behaviour does not change. The OpenShift contract suite and the live-cluster run below pin this, including the service account applying the namespace mutation.AUTH_TOKEN_HEADERS. Rejecting two different tokens assumes the gateway, and kube-rbac-proxy from #10199, put the same token in both headers.Evidence
Automated (run locally, on the rebased head)
go test ./...passes indistributions/core-bff/bff, withENVTEST_ASSETSfrommake envtest.golangci-lint run ./...reports 0 issues, andgo vet -tags contract ./internal/...is clean.pnpm run test:contractpasses both suites indistributions/core-bff:- OpenShift: 14 suites, 291 tests (289 before this change).
- xKS: 15 suites, 286 tests (271 before this change).
-
internal/callerauth/credentials_test.go: precedence, every rejection (missing, empty, whitespace-only, non-Bearer, empty bearer, embedded whitespace or comma, repeated, conflicting, malformed-does-not-fall-through) and the legacy single-header behaviour. Every error is asserted to contain no token.-
internal/api/caller_auth_transport_test.go: drives the realapp.Routes()tree.- It checks that REST (plain and
/core-bff-prefixed), the Kubernetes HTTP proxy, the WebSocket proxy, the model-serving proxy and the module proxy all see the same caller.- It checks that each one fails closed on no credential, conflicting credentials, a malformed header, or identity headers alone.
- It also covers redaction, CORS and
Varywith a custom header, client certificates kept only for theDEV_MODEfallback, theDEV_MODEfallback being limited to missing credentials, and a caller resolver that has no service-account fallback.-
internal/proxy/caller_auth_test.go: caller-supplied impersonation, front-proxy and credential headers never reach the API server, and requests without a caller token are not forwarded. A TLS upstream that records client certificates shows both proxies present theDEV_MODEcertificate only for the fallback identity, never with a caller token.-
internal/repositories/cluster_settings_authz_test.goandinternal/api/cluster_settings_caller_test.go: on xKS, every planned cluster-settings write is reviewed; a denied one returns 403 with nothing written; only planned writes run, so a culler ConfigMap that appears after a planned create fails the create and is never updated (TestUpdateClusterSettings_CullerAppearsAfterPreflight_NoUncheckedUpdate,TestClusterSettings_UpdateConfigMaps_ExecutesPlanned); a ConfigMap changed after the plan is a conflict that keeps the newer value (TestClusterSettings_UpdateConfigMaps_CullerChangedAfterPlan_Conflict); unchanged ConfigMaps need no write review (TestClusterSettings_PlanUpdate_UnchangedConfigMapsNeedNoWrite); a retry after a conflict still restarts the controller (TestClusterSettings_SegmentKeyConflict_RetryStillRollsOut,TestClusterSettings_ConflictAfterPVCChange_StillRollsOut); an API-server denial during a write is 403; other failures keep the legacy shape; OpenShift makes no review. The patch is computed from the caller's read even when the service account is forbidden; a caller who cannot read the configuration gets 403 with nothing written; a segment-key denial onGETis 403; thePATCH /api/configresponse reflects the patch when the service-account read would fall back to defaults.-
internal/config/validate_test.goandcmd/startup_test.go: the legacy header is checked in list mode; a forbidden prefix match never echoes its suffix;X-Remote-Uidis refused; a blank list fails startup; the startup log shows onlytokenHeaderSetandtokenHeaderCount, never a token-shaped header name.caller_auth_test.goalso sendsX-Remote-Uid, an arbitraryX-Remote-*and a mixed-case variant, and none reaches the API server.-
internal/repositories/credentials_test.goruns every policy-governed operation, dry-runs included, and checks that:- the caller's clients are used and the service account is untouched;
- a missing credential, a nil resolver or nil clients fail the operation without touching the service account;
- a forbidden caller gets a Forbidden error even when the service account in the fixture could have done the operation;
- OpenShift still uses the service account.
- A mutation check confirms the fallback test is not vacuous: temporarily making
clientSource.typedfall back to the service account makesTestCallerPolicy_NoServiceAccountFallbackfail.xks/testCoreBffCallerAuthandopenshift/testCoreBffCallerAuthuse a new mock user,FAKE_SERVING_EDITOR_TOKEN. That user may create ServingRuntimes intest-ns-abut may not patch Namespaces. The same request returnsapplied: falseon xKS andapplied: trueon OpenShift.Live cluster (OpenShift, ODH 3.6.0)
scripts/validate-caller-auth.sh(new) does the setup and teardown:- It creates a throwaway namespace and a ServiceAccount that may create ServingRuntimes and list/watch pods there, but holds no cluster-scoped permissions.
- It runs the checks with that ServiceAccount's token and with a cluster-admin token.
- It deletes the namespace afterwards, by the UID its create returned (so a namespace recreated under that name is never deleted), and never prints a token. The check against
default(M4) is a dry run, so it cannot changedefaulteven if existing RBAC admits the caller.- A check fails when curl exits nonzero (for example a timeout after a
200status), before the status or body is compared.distributions/core-bffagainst any logged-in cluster:- Header precedence: both headers are accepted alone or together; different tokens, Basic with a valid fallback, a rejected token, or identity headers alone all get 401. In OpenShift mode only
x-forwarded-access-tokenis read.- Kubernetes HTTP proxy:
- The ServiceAccount lists pods in its own namespace (200) but cannot list all namespaces (403), so the request runs as the caller and not as the kubeconfig cluster-admin.
- An
Impersonate-User: system:admin/Impersonate-Group: system:mastersorX-Remote-Userspoof still gets 403.- With no credential the proxy returns 401.
- A dry-run ServingRuntime create returns 201 in the ServiceAccount's own namespace and 403 in
default.- WebSocket proxy: a watch on the ServiceAccount's own pods upgrades (101); a cluster-wide watch gets 403; no credential gets 401.
- Namespace mutation, xKS: the ServiceAccount gets
{"applied":false}(real and dry-run) and the label is not written. Cluster-admin gets{"applied":true}.- Namespace mutation, OpenShift: the same ServiceAccount gets
{"applied":true}with the label written by the service account, unchanged from before.- Debug log: the ServiceAccount and admin token values appear 0 times.
<details>
<summary>xKS-mode output</summary>
</details>
Vanilla Kubernetes (Kind, the RHAII Tilt cluster
rhaii-tilt, Kubernetes 1.35, no OpenShift APIs)make setup-kindfromdistributions/rhaii/developing, plus the KServe v0.19.0 CRDs only (the KServe controllers andcloud-provider-kindwere not needed for these checks).rhaii-dashboardDeployment with--platform-type=XKS --auth-token-headers=Authorization,x-forwarded-access-tokenand no--dev-mode. Its ServiceAccount can list namespaces cluster-wide, so P2 (403) shows no caller request falls back to the pod's own identity.tilt up) fails onmaintoday, independent of this PR:distributions/rhaii/Dockerfilepinsgolang:1.25whiledistributions/core-bff/bff/go.modrequires Go 1.26. I built the image with--build-arg GOLANG_BASE_IMAGE=golang:1.26for the in-cluster run.AUTH_METHOD=disabledandDEV_MODE, every request is the kubeconfig fallback identity, so the proxies present the kubeconfig certificate and real-cluster local runs keep working. WithoutDEV_MODE, disabled auth is mock-only.DEV_MODEcertificate fix, live on Kind:--dev-modewith the cluster-admin certificate kubeconfig and a caller token scoped to one namespace, listing all namespaces through/api/k8s. Before the fix (eb3bd5225f) this returned 200, because the request ran as the certificate. With the fix it returns 403. The caller's own pods and the no-credential fallback still return 200.Validated vs. deferred for AKS / Entra
Validated in this PR, with real API-server tokens and RBAC:
AUTH_TOKEN_HEADERS=Authorization,x-forwarded-access-token(the RHAII manifest value) was exercised with each header alone, both carrying the same token, and two different tokens (rejected).scripts/validate-caller-auth.shreproduces the run against any cluster.kind-xks-10199-bare). Every row passed, including the M7/M8 positive control (a ServiceAccount that may patch only the test Namespace applies the mutation with its own credentials). The ServingRuntime rows were skipped because that cluster has no ServingRuntime CRD, and the admin rows because no admin token was set; no cluster-scoped objects were left behind, and the namespace was removed on exit. After review 6072972056, stubbed-kubectl runs on that cluster checked the namespace cleanup too: an ambiguous namespace create is deleted only after its label is confirmed, a failed label read or a UID-precondition conflict is reported and fails the run, anddefaultkeeps its labels after M4. Earlier runs also checked the guards: an occupiedPORTexits before touching the cluster, and a BFF that dies on startup ends the run with its log tail and cleans up the namespace. Credentials now reach curl, the WebSocket client and the log scan only through 0600 files, never as process arguments.Deferred, not proven here:
The Entra gateway and kube-rbac-proxy hop is the only piece the runs above don't cover. It is tracked in RHOAIENG-67109 (validate the RHAII production deployment through the shared Gateway on AKS). Broader independently runnable xKS contract coverage is in RHOAIENG-96086.
httpcontract/proxy_redaction.go) recognises the two well-known token headers but not a customAUTH_TOKEN_HEADERSname. The generic Bearer pattern still catches an echoed token.Known limitations and follow-ups
resourceVersionbinding covers concurrent saves inside one request. Fixing it needs versions in the API and the frontend.success: falsebodies. Connection types, components and cluster settings keep the pre-existing shape that puts the upstream error text inerror.403from the API server, including an admission webhook or policy that denies with403, is treated as a denial (applied: false, or 403 on cluster settings); the status cannot tell them apart.callerthe caller needspatchon that Deployment even where it does not exist (a missing Deployment is now nothing to restart). Gating it on a platform capability is the existing TODO.kubelogin): the Kubernetes proxies have no kubeconfig credential to present for the fallback identity (documented).getondeployments; that is a separate change.Authorization: Bearer Tplus an emptyx-forwarded-access-tokenis callerT. Under DEV_MODE any sent credential header disables the fallback. Rejecting them in production waits for the xKS gateway header decision.MOCK_K8S_CLIENT, a mapped mock user's WebSocket runs as the envtest identity. Unmapped tokens are refused (401). This affects local mocks only.AUTH_TOKEN_HEADERSname (see Evidence).BFF_URLtrailing slash, origin trailing-dot and IPv6 forms,RelaxedServiceNameValidation, two doc fixes), plus review 6059203374's P3s (OpenShift branding when the ClusterVersion instance is missing, bounded waits inws_identity_test.go), go to a follow-up task.