Skip to content

Enforce authorization on GcpWorkloadIdentityHttpHandler.getIdentity - #16197

Open
herdiyana256 wants to merge 2 commits into
cdapio:developfrom
herdiyana256:fix-gcp-workload-identity-getidentity-authz
Open

Enforce authorization on GcpWorkloadIdentityHttpHandler.getIdentity#16197
herdiyana256 wants to merge 2 commits into
cdapio:developfrom
herdiyana256:fix-gcp-workload-identity-getidentity-authz

Conversation

@herdiyana256

Copy link
Copy Markdown

GET /v3/namespaces/{namespace-id}/credentials/workloadIdentity (GcpWorkloadIdentityHttpHandler.getIdentity) returned a namespace's configured GCP service account with no authorization check, while the three sibling endpoints on the same handler enforce a NamespacePermission: validateIdentity (PROVISION_CREDENTIAL), createIdentity (SET_SERVICE_ACCOUNT), deleteIdentity (UNSET_SERVICE_ACCOUNT). getIdentity also calls switchToInternalUser() before the read, so any downstream enforcement is bypassed and the handler-level check is the only gate. Any authenticated caller reaching APP_FABRIC_HTTP could therefore read another namespace's workload-identity mapping.

This enforces StandardPermission.GET on the target NamespaceId before the read, mirroring the read path in CredentialProviderHttpHandler.getProfile/getIdentity and this handler's own write endpoints. The method already declares throws Exception, so the checked AccessException needs no signature change.

If a permission symmetric with the write side is preferred over StandardPermission.GET, a dedicated NamespacePermission.GET_SERVICE_ACCOUNT could be introduced instead; happy to switch.

The GET /v3/namespaces/{namespace-id}/credentials/workloadIdentity endpoint
returned a namespace's configured GCP service account without any
authorization check, while the three sibling endpoints on the same handler
(validate/create/delete) all enforce a NamespacePermission. getIdentity also
calls switchToInternalUser() before reading, so no downstream check applies
either. Any authenticated caller could read another namespace's workload
identity mapping.

Enforce StandardPermission.GET on the target NamespaceId before reading,
mirroring the read path in CredentialProviderHttpHandler.getProfile/getIdentity
and this handler's own write endpoints. The method already declares
throws Exception, so the checked AccessException needs no signature change.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the GcpWorkloadIdentityHttpHandler class to enforce access control when retrieving a workload identity. Specifically, it adds an authorization check using accessEnforcer.enforce with StandardPermission.GET on the requested namespace before retrieving the identity. There are no review comments, and the changes look appropriate, so I have no feedback to provide.

Regression test: an unprivileged principal is rejected by getIdentity, while
a principal granted StandardPermission.GET on the namespace succeeds. Uses the
real DefaultContextAccessEnforcer + InMemoryAccessController + AuthenticationTestContext
stack, mirroring the existing handler authorization tests.
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.

1 participant