Skip to content

server: k8s_psat: validate pod UID & fix error message grammar#7117

Open
c4rlo wants to merge 3 commits into
spiffe:mainfrom
c4rlo:k8s-psat-pod-uid
Open

server: k8s_psat: validate pod UID & fix error message grammar#7117
c4rlo wants to merge 3 commits into
spiffe:mainfrom
c4rlo:k8s-psat-pod-uid

Conversation

@c4rlo

@c4rlo c4rlo commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

TokenReview authenticates the projected service account token and returns the pod UID bound to that token. The server then fetches the live pod by namespace and name to derive node identity, selectors, and the agent SPIFFE ID.

Reject the attestation when the fetched pod UID does not match the TokenReview pod UID so a stale or raced pod lookup cannot bind authenticated token data to a different live pod. Update the unit tests to model pod UIDs explicitly and cover the mismatch case.

This closes a TOCTOU issue, though it's probably somewhat theoretical.


While I was in there, I also fixed some error message grammar (fail tofailed to).

TokenReview authenticates the projected service account token and
returns the pod UID bound to that token. The server then fetches the
live pod by namespace and name to derive node identity, selectors, and
the agent SPIFFE ID.

Reject the attestation when the fetched pod UID does not match the
TokenReview pod UID so a stale or raced pod lookup cannot bind
authenticated token data to a different live pod. Update the unit tests
to model pod UIDs explicitly and cover the mismatch case.

Signed-off-by: Carlo Teubner <cteubner1@bloomberg.net>
@c4rlo c4rlo marked this pull request as ready for review July 4, 2026 11:43
@c4rlo c4rlo requested a review from evan2645 as a code owner July 4, 2026 11:43
Copilot AI review requested due to automatic review settings July 4, 2026 11:43

Copilot AI left a comment

Copy link
Copy Markdown

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 tightens the Kubernetes PSAT node attestation flow by ensuring the live pod fetched from the Kubernetes API is the same pod identity returned by the TokenReview, preventing a TOCTOU-style mix-up between authenticated token data and a different live pod.

Changes:

  • Add a pod UID equality check between TokenReview status and the fetched Pod object, rejecting attestation on mismatch.
  • Update unit test fixtures to include explicit pod UIDs and add a mismatch test case.

Reviewed changes

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

File Description
pkg/server/plugin/nodeattestor/k8spsat/psat.go Adds enforcement that the fetched pod UID matches the TokenReview pod UID before deriving agent identity/selectors.
pkg/server/plugin/nodeattestor/k8spsat/psat_test.go Updates pod creation helper to set pod UID and adds a test covering UID mismatch behavior.

Comment on lines +227 to +229
if string(pod.UID) != podUID {
return status.Errorf(codes.Internal, "pod UID mismatch for cluster %q", attestationData.Cluster)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, addressed in d4bc0fc.

Comment thread pkg/server/plugin/nodeattestor/k8spsat/psat_test.go
c4rlo added 2 commits July 4, 2026 13:03
Signed-off-by: Carlo Teubner <cteubner1@bloomberg.net>
Signed-off-by: Carlo Teubner <cteubner1@bloomberg.net>
@c4rlo c4rlo changed the title server: k8s_psat: validate pod UID server: k8s_psat: validate pod UID & fix error message grammar Jul 4, 2026

@amartinezfayo amartinezfayo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @c4rlo!

return status.Errorf(codes.Internal, "failed to get pod from k8s API server for cluster %q: %v", attestationData.Cluster, err)
}
if string(pod.UID) != podUID {
return status.Errorf(codes.PermissionDenied, "pod UID mismatch for cluster %q", attestationData.Cluster)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering if we could include a bit more context in this error to help operators diagnose a rejection. Including the pod name and the token's UID, for example pod UID mismatch for pod %q in cluster %q: token bound to pod UID %q, would make it clearer which pod was involved, while keeping the error limited to values the caller already presented in its token.

@github-actions github-actions Bot assigned c4rlo and unassigned amartinezfayo Jul 8, 2026
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.

3 participants