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(compute): correctly specify scopes when fetching token #735

Merged
merged 5 commits into from
Jun 18, 2019

Conversation

stephenplusplus
Copy link
Contributor

@stephenplusplus stephenplusplus commented Jun 15, 2019

Fixes googleapis/nodejs-storage#748

According to the requirements of the metadata server, this array of values was being parsed incorrectly by gaxios, which uses querystring.stringify(). The scopes query string parameter is expected as a comma-separated string value, as opposed to the ?scope=scope1&scopes=scope2 style that querystring.stringify() uses: https://cloud.google.com/functions/docs/securing/function-identity#access_tokens

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 15, 2019
@stephenplusplus stephenplusplus changed the title fix(compute): correctly build token with scopes fix(compute): correctly specify scopes when fetching token Jun 15, 2019
@codecov
Copy link

codecov bot commented Jun 15, 2019

Codecov Report

Merging #735 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #735      +/-   ##
==========================================
+ Coverage   84.37%   84.42%   +0.04%     
==========================================
  Files          18       18              
  Lines         947      950       +3     
  Branches      209      210       +1     
==========================================
+ Hits          799      802       +3     
  Misses         88       88              
  Partials       60       60
Impacted Files Coverage Δ
src/auth/computeclient.ts 91.17% <100%> (+0.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 575f4e0...60a6620. Read the comment docs.

@googleapis googleapis deleted a comment from codecov bot Jun 15, 2019
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

LGTM, good catch.

instanceOptions.params = {
scopes: this.scopes.join(','),
};
// TODO: clean up before submit, fix upstream type bug
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this TODO comment? don't quite follow it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Carried over from @JustinBeckwith, who might have intended to fix the problem this PR solves before it shipped, but forgot 🤷‍♂. Interested to see if he has a better fix in mind!

Copy link
Contributor

Choose a reason for hiding this comment

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

You're change resolves the TODO (modulo the 'upstream bug' part). It can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What upstream type bug, though? Did Justin want to change the way params were parsed upstream? I guess I would like to make sure before removing the comment or merging this PR, as the clarity could nullify either idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

At one point there was a cast here, so that can be removed 🙃

@@ -29,7 +29,7 @@ const tokenPath = `${BASE_PATH}/instance/service-accounts/default/token`;
function mockToken(statusCode = 200, scopes?: string[]) {
let path = tokenPath;
if (scopes && scopes.length > 0) {
path += '?' + qs.stringify({scopes});
path += `?scopes=${encodeURIComponent(scopes.join(','))}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, so the root of the problem is that storage required multiple scopes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Essentially, yes. Storage does, and I believe many other APIs do as well. The function that I modified is only active in GCE/GCF environments.

Copy link
Contributor

@ofrobots ofrobots left a comment

Choose a reason for hiding this comment

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

Would it be possible to have a system test for this?

instanceOptions.params = {
scopes: this.scopes.join(','),
};
// TODO: clean up before submit, fix upstream type bug
Copy link
Contributor

Choose a reason for hiding this comment

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

You're change resolves the TODO (modulo the 'upstream bug' part). It can be removed.

@stephenplusplus
Copy link
Contributor Author

Would it be possible to have a system test for this?

@JustinBeckwith are there tests that run on GC* environments?

@ofrobots I think the unit tests are an adequate way to cover this former leak. I just made a change to the unit test to make sure the intended behavior is described and covered better.

@stephenplusplus stephenplusplus merged commit 4803e3c into master Jun 18, 2019
@stephenplusplus stephenplusplus deleted the spp--scopes-fix branch June 18, 2019 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

save reports 403 after upgrading from 2.5.0 to 3.0.1
5 participants