Skip to content
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

fix: GCECredentials - Allow retrieval of ID token #425

Merged

Conversation

StupidCodeFactory
Copy link
Contributor

@StupidCodeFactory StupidCodeFactory commented Apr 2, 2023

CONTEXT:

While deploying a couple of services on Cloud RUN:

  1. service A running with service account A
  2. service B running with service account B
  3. I added roles/run.invoker for service account B on service A.

I expected to be able to retrieve an ID token and be able to call service A from service B. After some debugging I realised I was getting an access_token rather then an id_token.
I tracked it down to the GCECredentials instantiation only passing the scope to the subclass of the Signet::Oauth2::Client, hence not being able to pass the target_audience for retrieve an id_token

I believe this should fix: #299

@StupidCodeFactory StupidCodeFactory requested a review from a team as a code owner April 2, 2023 16:04
@google-cla
Copy link

google-cla bot commented Apr 2, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@conventional-commit-lint-gcf
Copy link

conventional-commit-lint-gcf bot commented Apr 2, 2023

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@StupidCodeFactory StupidCodeFactory force-pushed the pass-options-to-gce-credentials branch 4 times, most recently from 1163c39 to 97255af Compare April 2, 2023 16:18
@StupidCodeFactory StupidCodeFactory changed the title Fix GCECredentials - Allow passing of options down to the OAuth 2 client. GCECredentials - Allow retrieval of ID token Apr 2, 2023
@StupidCodeFactory StupidCodeFactory changed the title GCECredentials - Allow retrieval of ID token fix: GCECredentials - Allow retrieval of ID token Apr 2, 2023
end

it "honors passing options to OAuth 2 client" do
stub = stub_request(:get, "http://169.254.169.254")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: since we're repeating this stub request. Can you put it in a variable?

Copy link
Contributor

@bajajneha27 bajajneha27 left a comment

Choose a reason for hiding this comment

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

Thanks for raising this PR. Just one tiny comment, overall LGTM

expect(creds).to_not be_nil
describe "when on compute engine" do
before do
@compute_metadata_server = stub_request(:get, "http://169.254.169.254")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bajajneha27 thanks for your feedback.
While one would normally use a let!(:compute_metadata_server) as it's more idiomatic to RSpec test suite, this file seems to only be using @instance_variable so for the sake of consistency I've kept the pattern used in the file.

There seem to be a mixed use of let and before { @instance_varialbe = "foo" } throughout the test suite. It's also unclear what is the preferred way.
As a long term rubyist I'd be inclined to favour the let {}.
I'd be happy to convert this file from using @instance_variable to let blocks, in this pull request or another one.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine. Thanks for implementing this.

@bajajneha27
Copy link
Contributor

@StupidCodeFactory , you'd have to update your branch with main.

  Passing of options down to the OAuth 2 client. optional options to GCEcredentials, enabling the creation of ID tokens.
@bajajneha27 bajajneha27 merged commit fd9afc7 into googleapis:main Apr 12, 2023
11 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.

Getting id-token from compute engine default service account not working
2 participants