Skip to content

Include extra attributes in SubjectAccessReview#14768

Merged
adleong merged 3 commits intolinkerd:mainfrom
Tolsto:include-extra-attributes-in-sar
Mar 2, 2026
Merged

Include extra attributes in SubjectAccessReview#14768
adleong merged 3 commits intolinkerd:mainfrom
Tolsto:include-extra-attributes-in-sar

Conversation

@Tolsto
Copy link
Contributor

@Tolsto Tolsto commented Nov 29, 2025

Problem

Kubernetes authorization plugins can rely on extra attributes on a user, provided via X-Remote-Extra- headers, e.g. AWS EKS with AccessEntry authentication. Currently, the Linkerd Viz tap API doesn't include these attributes when making SubjectAccessReview requests, preventing tap from working in clusters that use authorization plugins relying on these extra attributes.

Solution

Updated the tap API to extract X-Remote-Extra- headers from incoming requests and include them in SubjectAccessReview calls. The header prefix is read from the extension-apiserver-authentication ConfigMap to support custom configurations.

This implementation is based on the original work by David Symons in PR #13170.

Changes:

  • Modified ResourceAuthzForUser in pkg/k8s/authz.go to accept extra attributes as map[string]authV1.ExtraValue
  • Updated viz/tap/api/handlers.go to extract and URL-decode extra headers
  • Modified viz/tap/api/server.go to read the configurable header prefix from the Kubernetes ConfigMap
  • Added tests to verify extra attributes are correctly passed through

Validation

Ran go test ./viz/tap/api/... ./pkg/k8s/... and all tests pass. Added TestHandleTap_ExtraHeaders to verify extra attributes are correctly extracted and passed to the Kubernetes client.
Tested with an actual EKS cluster with AccessEntry authentication.

Fixes #13169

@Tolsto Tolsto requested a review from a team as a code owner November 29, 2025 17:13
Problem

Kubernetes authorization plugins can rely on extra attributes on a user,
provided via X-Remote-Extra- headers, e.g. AWS EKS with AccessEntry authentication.
Currently, the Linkerd Viz tap API doesn't include these attributes when making
SubjectAccessReview requests, preventing tap from working in clusters that use
authorization plugins relying on these extra attributes.

Solution

Updated the tap API to extract X-Remote-Extra- headers from incoming requests
and include them in SubjectAccessReview calls. The header prefix is read from
the extension-apiserver-authentication ConfigMap to support custom configurations.

This implementation is based on the original work by David Symons in PR linkerd#13170.

Changes:
- Modified ResourceAuthzForUser in pkg/k8s/authz.go to accept extra attributes
  as map[string]authV1.ExtraValue
- Updated viz/tap/api/handlers.go to extract and URL-decode extra headers
- Modified viz/tap/api/server.go to read the configurable header prefix from
  the Kubernetes ConfigMap
- Added tests to verify extra attributes are correctly passed through

Validation

Ran go test ./viz/tap/api/... ./pkg/k8s/... and all tests pass. Added
TestHandleTap_ExtraHeaders to verify extra attributes are correctly extracted
and passed to the Kubernetes client.
Tested with an actual EKS cluster with AccessEntry authentication.

Fixes linkerd#13169

Signed-off-by: Nils Mueller <20240901+Tolsto@users.noreply.github.com>
@Tolsto Tolsto force-pushed the include-extra-attributes-in-sar branch from d650bb1 to 5757502 Compare February 12, 2026 13:16
@Tolsto
Copy link
Contributor Author

Tolsto commented Feb 12, 2026

@olix0r Anything I can do to get this closer to being merged?

Copy link
Member

@adleong adleong left a comment

Choose a reason for hiding this comment

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

Hey @Tolsto

Thanks for your extreme patience and I apologize for the long delay in getting this reviewed. This looks great and fixes a clear deficiency in our auth handling here. I left a couple small comments about header handling but otherwise this looks good to go.

Thanks again!


extra := make(map[string]authV1.ExtraValue)
for key, values := range req.Header {
if strings.HasPrefix(key, h.extraHeaderPrefix) {
Copy link
Member

Choose a reason for hiding this comment

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

if the extraHeaderPrefix is the empty string (if, for example, extra header prefix was not specified in the configmap) then does this treat every header as an extra auth header?

Copy link
Member

Choose a reason for hiding this comment

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

do we also need to ignore case here since HTTP headers are case insensitive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On “empty prefix” concern:
Implemented. extractExtraHeaders now returns early when extraHeaderPrefix == "", so we no longer treat all headers as extra auth headers. I also added a server-side default (X-Remote-Extra-) when requestheader-extra-headers-prefix is missing/empty in the configmap, plus tests for both paths.

On “case-insensitive headers” concern:
Implemented. Extra-header prefix matching is now case-insensitive (strings.ToLower on both header key and prefix), while preserving the original suffix for URL decoding. Added a test covering mixed-case header handling.

Tolsto added a commit to Tolsto/linkerd2 that referenced this pull request Mar 2, 2026
Problem\n\nReview comments on linkerd#14768 called out two header-handling gaps: an empty extra-header prefix could match every request header, and prefix matching did not account for case-insensitive HTTP header names.\n\nSolution\n\nAdd centralized extra-header extraction that bails out when the prefix is empty and matches prefixes case-insensitively. Also default the server auth extra-header prefix to X-Remote-Extra- when the configmap omits it or provides an empty value. Extend tap API tests to cover case-insensitive matching, empty-prefix behavior, and default-prefix parsing.\n\nValidation\n\ngo test ./viz/tap/api/... ./pkg/k8s/...
@Tolsto Tolsto force-pushed the include-extra-attributes-in-sar branch from 551eb36 to 8a6849b Compare March 2, 2026 01:40
Copy link
Member

@adleong adleong left a comment

Choose a reason for hiding this comment

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

Thanks @Tolsto, this is great!

@adleong adleong merged commit cd7d7e4 into linkerd:main Mar 2, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linkerd Tap doesn't seem to work with EKS Access Entries authentication

2 participants