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

Add support for explicit java.security.Provider to ServiceAccountCred… #411

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stian-svedenborg-gul-katt

…entials

This enables the storage of service account credentials in external key
storage such as remote KeyVaults or HSMs.

Fixes #410

@stian-svedenborg-gul-katt stian-svedenborg-gul-katt requested a review from a team as a code owner March 2, 2020 09:08
@googlebot
Copy link

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

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Mar 2, 2020
@stian-svedenborg-gul-katt
Copy link
Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Mar 2, 2020
@@ -667,14 +691,8 @@ String createAssertion(JsonFactory jsonFactory, long currentTime, String audienc
payload.setAudience(audience);
}

String assertion;
try {
assertion = JsonWebSignature.signUsingRsaSha256(privateKey, jsonFactory, header, payload);
Copy link
Contributor

Choose a reason for hiding this comment

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

Critical: I'm not sure the new code is using this algorithm. I might need to patch this into an IDE and check.

Choose a reason for hiding this comment

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

The signing algorithm is dictated by OAuth2Utils.SIGNATURE_ALGORITHM. Which is "SHA256withRSA"

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Since this is security critical code I'm going to need go over this carefully and make sure of that. It might take a little time to review, or perhaps someone else can get to this before I do.

@elharo elharo added kokoro:run Add this label to force Kokoro to re-run the tests. priority: p2 Moderately-important priority. Fix may not be included in next release. semver: minor A new feature was added. No breaking changes. labels Mar 2, 2020
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 2, 2020
@codecov
Copy link

codecov bot commented Mar 2, 2020

Codecov Report

Merging #411 into master will increase coverage by 0.13%.
The diff coverage is 85%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #411      +/-   ##
============================================
+ Coverage     79.53%   79.66%   +0.13%     
- Complexity      397      399       +2     
============================================
  Files            27       27              
  Lines          1803     1810       +7     
  Branches        188      188              
============================================
+ Hits           1434     1442       +8     
+ Misses          269      268       -1     
  Partials        100      100
Impacted Files Coverage Δ Complexity Δ
.../google/auth/oauth2/ServiceAccountCredentials.java 83.53% <85%> (+0.88%) 50 <6> (+2) ⬆️

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 0a57cd5...256ffef. Read the comment docs.

@stian-svedenborg-gul-katt
Copy link
Author

@elharo Comments fixed or answered.

byte[] signature = this.sign(signedContentBytes);
return signedContentString + "." + Base64.encodeBase64URLSafeString(signature);

} catch (SigningException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to convert this to an IOException instead of declaring this method to throw SigningException?

Copy link
Author

Choose a reason for hiding this comment

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

No, not really, I just kept the pattern that was there before.

SigningException is unchecked. Whilst the api for refreshAccessToken declares that it throws IOException. (I'm not sure I agree that SigningException should be unchecked, but that is outside the scope of this change).

In any case I argue that a failing signature should be handled by the calling code, and as such it should be changed to an IOException before exiting refreshAccessToken.

As to whether I should keep the conversion inside signJsonWebSignature or move it to createAssertion (and duplicate it in createAssertionForIdToken) I'll follow ruling.

Choose a reason for hiding this comment

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

@elharo I'll await your answer on this before I reupload. (I'm I doing this correctly with the --amends by the way?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I honestly do not have enough git-fu to tell. Whatever you're doing seems to work fine on my end. Just commit and upload as you need to. We'll squash the commits when we merge.

@@ -667,14 +691,8 @@ String createAssertion(JsonFactory jsonFactory, long currentTime, String audienc
payload.setAudience(audience);
}

String assertion;
try {
assertion = JsonWebSignature.signUsingRsaSha256(privateKey, jsonFactory, header, payload);
Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Since this is security critical code I'm going to need go over this carefully and make sure of that. It might take a little time to review, or perhaps someone else can get to this before I do.

@elharo elharo added the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 3, 2020
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 3, 2020
…ntCredentials

This enables the storage of service account credentials in external key
storage such as remote KeyVaults or HSMs.
@stian-svedenborg-gul-katt
Copy link
Author

@elharo Hi any chance of this one getting some love soon? :)

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. priority: p2 Moderately-important priority. Fix may not be included in next release. semver: minor A new feature was added. No breaking changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for JCA Provider to ServiceAccountCredentials
4 participants