-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for Impersonated Service Account Credentials #580
Open
bshaffer
wants to merge
23
commits into
main
Choose a base branch
from
add-impersonated-service-account-credentials
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
22d07e2
WIP
bshaffer 203722d
open up jsonKey to any credential class
bshaffer ba37442
fix typos
bshaffer f5a1057
support ID token impersonation
bshaffer 3b38b22
fix FetchAuthTokenInterface typehint
bshaffer 15b6c33
add support for impersonating id tokens
bshaffer acd55a3
fix phpstan and Obervability test
bshaffer 522f605
fix phpstan errors, add headers parameter for other credential types
bshaffer c50541e
fix cs and tests
bshaffer fa156fa
fix phpstan
bshaffer f9a2835
Merge branch 'main' into add-impersonated-service-account-credentials
bshaffer 20f2c56
add tests
bshaffer bdf24f8
Merge branch 'add-impersonated-service-account-credentials' of github…
bshaffer 244724f
add impersonate id token metric test
bshaffer 66b099b
fix cs and phpstan
bshaffer 58b0ed6
add tests for arbitrary credentials
bshaffer 19ae608
add test for Impersonating ExternalAccountCreds
bshaffer a70d236
ensure complete test coverage, fix cs
bshaffer c63443c
change scope to auth/iam, use constant
bshaffer b09e8c3
Merge branch 'main' into add-impersonated-service-account-credentials
bshaffer df63099
fix test
bshaffer 54b2284
fix cs
bshaffer dca23f0
fix case
bshaffer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get an error (http 400) here about the json payload in the outgoing request "Invalid JSON payload received. Unknown name "audience": Cannot find ...". When I update the url by replacing
generateAccessToken
togenerateIdToken
everything works as expected!This is what I changed:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gjvanahee that value is defined in your credentials in the
service_account_impersonation_url
JSON value. I do not want to do a string find-and-replace on values in the credentials, so I'm not sure what the appropriate approach is here.Python does seem to do some sort of templating here, so maybe this requires further consideration:
https://github.com/googleapis/google-auth-library-python/blob/484c8db151690a4ae7b6b0ae38db0a8ede88df69/google/auth/iam.py#L41-L54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the str_replace. I just wanted to make the change more explicit. I don't like to have to change a generated key file. In my PR I used
"https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/{$impersonatedServiceAccount}:generateIdToken",
but it looks a lot nicer to have all the options together in constants like in the python exampleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing we could do (and maybe this is what Python does, I need to llook into it still) is not support
service_account_impersonation_url
value injsonKey
for ID tokens (as this is tied directly to the JSON credentials file, which is not supported for ID tokens bygcloud
), and instead use the IAM endpoint template.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could
Google\Auth\Iam
class be changed to add methods for requesting an id token (and perhaps access_token)? All the actions on that endpoint would then be together in that class. Something likeand some refactoring to avoid duplication of course.
It would skip the call to
applyTokenEndpointMetrics
though or that has to be used in theIam
class too...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You seem to be describing the work I did in #581 :)
The only downside here is that we are not respecting the
service_account_impersonation_url
in the credentials, which might be fine, but we need to make sure this is okay to do. Well, we are respecting it in the sense that we are stripping out theclientEmail
from it, which I'm not sure is better or worse.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehehe, it seems I'm always one step behind... I also found it strange that the service account being impersonated is not explicitly mentioned in the key file. The endpoints for the actions are documented and discoverable, but that is your call ;)