Skip to content

backend: k8cache: Fix named resource authorization#5719

Open
harrshita123 wants to merge 1 commit into
kubernetes-sigs:mainfrom
harrshita123:issue-5718-cache-authorization
Open

backend: k8cache: Fix named resource authorization#5719
harrshita123 wants to merge 1 commit into
kubernetes-sigs:mainfrom
harrshita123:issue-5718-cache-authorization

Conversation

@harrshita123
Copy link
Copy Markdown
Contributor

Summary

Fixes cache authorization for named Kubernetes resource requests. The cache middleware now builds SelfSubjectAccessReview requests with the Kubernetes resource type, such as pods, instead of incorrectly using the object name, such as nginx.

Related Issue

Fixes #5718

Changes

  • Added structured parsing for proxied Kubernetes API paths in backend/pkg/k8cache/authorization.go.
  • Updated cache authorization to include resource, name, namespace, API group, version, and subresource in ResourceAttributes.
  • Added regression tests for named resources, subresources, and namespace paths.

Steps to Test

  1. Run GOCACHE=/private/tmp/headlamp-go-build-cache npm run backend:lint.
  2. Run GOCACHE=/private/tmp/headlamp-go-build-cache npm run backend:test.
  3. Confirm named resource paths like /api/v1/namespaces/default/pods/nginx authorize against resource pods with name nginx.

Screenshots

Not applicable. Backend-only change.

Notes for the Reviewer

This only changes cache authorization path parsing. The intent is to avoid false forbidden responses when response caching is enabled for named Kubernetes resource requests.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: harrshita123
Once this PR has been reviewed and has the lgtm label, please assign illume for approval. For more information see the 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

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 17, 2026
@k8s-ci-robot k8s-ci-robot requested a review from illume May 17, 2026 15:49
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 17, 2026
@k8s-ci-robot k8s-ci-robot requested a review from sniok May 17, 2026 15:49
@illume illume requested a review from Copilot May 17, 2026 18:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes cache authorization for proxied Kubernetes API requests by correctly parsing API paths for named resources and populating SelfSubjectAccessReview ResourceAttributes with the proper resource, name, namespace, API group/version, and subresource—avoiding false “forbidden” responses when caching is enabled.

Changes:

  • Added structured parsing of proxied Kubernetes API paths to extract group/version/namespace/resource/name/subresource.
  • Updated SSAR creation to use fully populated authorizationv1.ResourceAttributes instead of just the last path segment.
  • Added regression tests for named resources (including subresources) and namespace paths.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
backend/pkg/k8cache/authorization.go Introduces API path parsing and builds SSAR ResourceAttributes from parsed components.
backend/pkg/k8cache/authorization_test.go Adds exported-level tests covering named resource paths for GetKindAndVerb.
backend/pkg/k8cache/authorization_internal_test.go Adds white-box tests for getResourceAttributes on named resources/subresources.

Comment thread backend/pkg/k8cache/authorization.go
Copy link
Copy Markdown
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution.

There are some open Copilot review comments — could you take a look at them? Please mark each one as resolved once you've addressed it.

@harrshita123 harrshita123 force-pushed the issue-5718-cache-authorization branch 2 times, most recently from b3bb5aa to 780471d Compare May 19, 2026 15:04
@harrshita123
Copy link
Copy Markdown
Contributor Author

Thanks for the contribution.

There are some open Copilot review comments — could you take a look at them? Please mark each one as resolved once you've addressed it.

@illume
I resolved all the comments.

@illume illume requested a review from Copilot May 19, 2026 15:11
Copy link
Copy Markdown
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes.

I noticed the GitHub CI backend test job is failing. Can you please fix the failing tests? You can run cd backend && go test ./... locally to see the errors.

How to run the backend tests

Run cd backend && go test ./... to see all failures. Fix the failing tests and commit the result.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread backend/pkg/k8cache/authorization.go Outdated
Comment thread backend/pkg/k8cache/authorization_internal_test.go
@harrshita123 harrshita123 force-pushed the issue-5718-cache-authorization branch from 780471d to 5dd8da3 Compare May 19, 2026 15:36
Parse proxied Kubernetes API paths by structure before building
cache authorization SelfSubjectAccessReviews.

This keeps named object requests from using the object name as
the resource and preserves namespace, name, version, group,
and subresource attributes.
@harrshita123 harrshita123 force-pushed the issue-5718-cache-authorization branch from 5dd8da3 to 61e321b Compare May 19, 2026 15:46
@harrshita123
Copy link
Copy Markdown
Contributor Author

harrshita123 commented May 19, 2026

Thanks for these changes.

I noticed the GitHub CI backend test job is failing. Can you please fix the failing tests? You can run cd backend && go test ./... locally to see the errors.

How to run the backend tests
Run cd backend && go test ./... to see all failures. Fix the failing tests and commit the result.

@illume
I run cd backend && go test ./... , now CI test is passing .

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment on lines +290 to +304
switch parts[0] {
case "api":
request.version = parts[1]
resourceIndex = 2
case "apis":
if len(parts) < 4 {
return apiResourceRequest{}, false
}

request.group = parts[1]
request.version = parts[2]
resourceIndex = 3
default:
return apiResourceRequest{}, false
}
Copy link
Copy Markdown
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

Would you mind addressing the open Copilot review comments? Please mark each comment as resolved after addressing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backend: Cache authorization uses object name as resource for named requests

4 participants