Skip to content

fix: bind clusteradministrator status query to the authenticated caller - #516

Open
rehanxt5 wants to merge 4 commits into
kubeflow:mainfrom
rehanxt5:fix/515-kfam-clusteradmin-identity-binding
Open

rehanxt5 wants to merge 4 commits into
kubeflow:mainfrom
rehanxt5:fix/515-kfam-clusteradmin-identity-binding

Conversation

@rehanxt5

Copy link
Copy Markdown

Fixes #515.

Stacked on #506: the branch carries that PR's commit first (already under review), then the two new commits below. The stack is forced, since the QueryClusterAdmin rewrite calls the getUserEmail signature #506 introduces. Once #506 merges, the diff here shrinks to just the two new commits (worst case I'll rebase onto main).

KFAM handler

QueryClusterAdmin in components/access-management/kfam/api_default.go currently answers ?user=<anyone> for whoever asks. It now derives the caller from the identity header:

  • Missing header, or a value that fails the prefix check: 401 with an explanatory body, the same behavior fix: return 401 instead of panicking when KFAM identity header is missing #506 gives the mutating endpoints.
  • user missing from the query: defaults to the caller, so GET /v1/role/clusteradmin reads as "am I an admin". The swagger claims the param is required but nothing enforced it; optional matches real usage.
  • A non-admin querying another user: 403. Admins keep querying anyone.
  • Metrics: success counters now record the caller instead of an empty user label, query-parse failures are 403 with the caller recorded, and the write-failure path returns 500 (the old code called err.Error() on a nil err there).

Dashboard backends

Both centraldashboard and centraldashboard-angular call this endpoint in getWorkgroupInfo to decide whether the logged-in user sees admin UI, and neither forwarded any headers:

this.profilesService.v1RoleClusteradminGet(user.email, {headers: user.auth || {}}),

The identity headers captured by attachUser now travel with the call, the same way the contributor add/remove routes already forward them for bindings. Without this half, a caller-bound KFAM would 401 every dashboard request and take down the workgroup info for all logged-in users.

Docs and tests

  • swagger: 401 and 403 documented on the endpoint, user description updated to match the binding semantics
  • README: identity section describing the header config and the caller binding
  • Go: table-driven handler tests through httptest covering the matrix (missing header, prefix mismatch, self-query, admin cross-user, non-admin cross-user) plus a write-failure regression; make test green at 47.4% kfam coverage
  • Jasmine suites for both backends updated for the two-argument call (classic 80 specs, angular 53 specs, all passing)

Two deliberate behavior changes to flag: requests without the identity header get 401 where they used to get an answer, and non-admins querying other users get 403. Both are the point of the fix, but if a caller I haven't thought of depends on the old behavior, I'm happy to adjust.

…sing

getUserEmail sliced the identity header value with an unchecked offset
(header.Get(header)[len(prefix):]), which panicked with "slice bounds
out of range" on every mutating endpoint (POST/DELETE /kfam/v1/bindings,
DELETE /kfam/v1/profiles/{name}) whenever the identity header was
missing or shorter than the configured --userid-prefix. Nothing in the
process recovers handler panics, so clients received a dropped
connection instead of a status code and no request metric was
incremented. A third mode silently truncated a header value that did
not start with the prefix to a wrong identity.

- getUserEmail now returns (string, error): it errors on a missing or
  empty header value, on a value that does not start with the configured
  prefix, and when nothing remains after stripping the prefix. The three
  callers answer 401 (documented in api/swagger.yaml for all three
  endpoints) with an explanatory body and increment request_kf_failure
  with stable metric kinds.
- ReadBinding: add the missing return after the profile-list error write
  (previously dereferenced a nil list and panicked).
- QueryClusterAdmin: report a fixed kind in the write-failure branch
  instead of dereferencing a nil err.
- Regression tests: unit tests for getUserEmail across both common
  configurations (IAP-style prefix and kubeflow-userid with an empty
  prefix) and handler-level httptest through NewRouter covering the 401
  responses, prefix-mismatch rejection, the preserved owner/non-owner
  status codes, and both latent panic paths.

Behavior change: with an empty prefix (the values shipped in the repo
manifests), header-less requests to the mutating endpoints now answer
401 with a body instead of silently evaluating the caller as "" and
denying with 403.

Fixes kubeflow#505

Signed-off-by: Rehan Akhtar <rehan.xt5@gmail.com>
GET /kfam/v1/role/clusteradmin answered is-cluster-admin for any user
named in the caller-supplied ?user= query parameter without consulting
the request's authenticated identity: with no identity header at all,
?user=<admin> returned 200 true, an authenticated non-admin could ask
about any other user, and the admin roster was enumerable one username
at a time. This is the only KFAM handler that answers an authorization
question without deriving the caller from the identity header.

The handler now derives the caller via getUserEmail (the panic-safe,
prefix-validating helper introduced for the missing-identity-header
fix), defaults the queried user to the caller, and reserves cross-user
queries for cluster admins:

- no usable identity -> 401 (documented in api/swagger.yaml)
- self-query (with or without ?user=) -> 200, unchanged behavior
- non-admin cross-user query -> 403
- admin cross-user query -> 200, admin tooling preserved

Swagger documents the identity binding and the 401/403 responses; the
component README documents the identity/authorization model.

Regression tests: TestQueryClusterAdminIdentityBinding covers the three
former attack modes (now 401/403) plus the preserved self-query and
admin flows, the prefix-mismatch rejection, and the no-panic behavior
for missing/short/prefix-only headers. TestQueryClusterAdminOnWriteFailure
now carries an identity header so it still reaches the response write.

Signed-off-by: Rehan Akhtar <rehan.xt5@gmail.com>
KFAM now binds the clusteradmin status query to the caller's identity
header, so getWorkgroupInfo - which called it without forwarding any
headers - would receive 401 on identity-aware clusters. Forward the
user identity captured by attachUser (user.auth) in both the classic
and Angular dashboard backends, following the same pattern
handleContributor already uses for the binding endpoints. The call
sites are guarded by req.user.hasAuth, so user.auth is always
populated; the || {} fallback keeps a future unguarded caller safe by
surfacing KFAM's 401 instead of a silent wrong answer.

All v1RoleClusteradminGet jasmine spy matchers in both backends' test
suites are updated to the two-argument form (withArgs/toHaveBeenCalledWith
match on all arguments, so every mock and assertion gains the headers
object).

Signed-off-by: Rehan Akhtar <rehan.xt5@gmail.com>
@google-oss-prow google-oss-prow Bot added size/XL area/dashboard area - related to central dashboard labels Nov 19, 2026
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign thesuperzapper for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rehanxt5

Copy link
Copy Markdown
Author

/assign

@google-oss-prow google-oss-prow Bot added area/dashboard-angular area - related to central dashboard angular area/kfam area - releated to kubeflow access management api (kfam) labels Nov 19, 2026
@juliusvonkohout juliusvonkohout changed the title fix: bind clusteradmin status query to the authenticated caller fix: bind clusteradministrator status query to the authenticated caller Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dashboard area - related to central dashboard area/dashboard-angular area - related to central dashboard angular area/kfam area - releated to kubeflow access management api (kfam) size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KFAM clusteradmin endpoint returns any user's admin status without verifying the caller

1 participant