fix: key Eventarc publisher client cache by source principal for impersonated credentials - #7364
Open
ibondarenko1 wants to merge 3 commits into
Open
ibondarenko1 wants to merge 3 commits into
ibondarenko1 wants to merge 3 commits into
Conversation
…rsonated credentials _get_credential_id() returned only the target service account email for impersonated credentials. Two callers with different source principals that impersonate the same target therefore shared one cached PublisherAsyncClient, so a caller that cannot impersonate the target could publish through a client bound to another caller's authorized credential. Include the source credentials' identity in the key so each source principal gets its own client.
Added a test for impersonated credentials to verify that they are keyed by source principal and that the credential ID is correctly generated based on the source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_get_credential_id()in the Eventarc client returns only the targetservice_account_emailforgoogle.auth.impersonated_credentials.Credentials. Two different source principals impersonating the same target service account therefore produce the same cache key and share one cachedPublisherAsyncClient, so the second caller publishes using the first caller's source credentials.Fix
For impersonated credentials, the credential id now includes the source principal:
Impersonated:<target>:<id of source credentials>. If the source cannot be determined, it falls back toid(credentials), so no sharing occurs.Tests
Updated the existing impersonated-credentials assertion to use an explicit source credential. Added
test_impersonated_credentials_are_keyed_by_source_principal: the same source gives equal ids, a different source gives different ids, and_get_cache_keydiffers between them.tests/unittests/integrations/eventarc: 64 passed. The new test fails without the fix.