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

impl(common): token exchange for external accounts #10328

Merged

Conversation

coryan
Copy link
Contributor

@coryan coryan commented Nov 29, 2022

To support external accounts we need to convert the "subject token" returned by the external account source (e.g. an Azure metadata service or a GitHub Actions OIDC source) into "access tokens" returned by GCP's "Security Token Service". In this change we introduce the code to perform such exchanges, including a small integration test on GitHub actions.

Part of the work for #5915


This change is Reviewable

@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: c252da70a3f89a3722f091984b29a2974e58520f

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@codecov
Copy link

codecov bot commented Nov 29, 2022

Codecov Report

Base: 93.85% // Head: 93.86% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (96bfdce) compared to base (a5ad82f).
Patch coverage: 96.75% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #10328    +/-   ##
========================================
  Coverage   93.85%   93.86%            
========================================
  Files        1597     1600     +3     
  Lines      145363   145763   +400     
========================================
+ Hits       136437   136823   +386     
- Misses       8926     8940    +14     
Impacted Files Coverage Δ
...ud/internal/oauth2_external_account_credentials.cc 94.73% <94.73%> (ø)
...ternal/oauth2_external_account_credentials_test.cc 97.07% <97.07%> (ø)
...oud/internal/oauth2_external_account_credentials.h 100.00% <100.00%> (ø)
google/cloud/internal/async_connection_ready.cc 89.36% <0.00%> (-4.26%) ⬇️
...e/cloud/pubsublite/internal/alarm_registry_impl.cc 97.05% <0.00%> (-2.95%) ⬇️
google/cloud/pubsub/subscriber_connection_test.cc 98.78% <0.00%> (-1.22%) ⬇️
...integration_tests/schema_admin_integration_test.cc 98.88% <0.00%> (-1.12%) ⬇️
...le/cloud/internal/default_completion_queue_impl.cc 96.59% <0.00%> (-0.57%) ⬇️
google/cloud/completion_queue_test.cc 97.32% <0.00%> (+0.19%) ⬆️
...cloud/pubsub/internal/subscription_session_test.cc 98.33% <0.00%> (+0.33%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@coryan coryan marked this pull request as ready for review November 30, 2022 04:47
@coryan coryan requested a review from a team as a code owner November 30, 2022 04:47
@coryan coryan force-pushed the feat-oauth2-workload-identity-federation-pr9 branch from c252da7 to 002e587 Compare November 30, 2022 18:11
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 002e5879568b8a35eb8dcf99788db0f04b1550f7

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@coryan
Copy link
Contributor Author

coryan commented Nov 30, 2022

Rebased to resolve conflicts, PTAL.

auto request = rest_internal::RestRequest(info_.token_url);

auto client = client_factory_(options_);
auto status = client->Post(request, form_data);
Copy link
Member

Choose a reason for hiding this comment

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

optional: I call this thing a sor... but I thought you didn't like that...

Copy link
Contributor

Choose a reason for hiding this comment

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

The conventional approach would be to just call this response. That might complicate and/or simplify the code below where we introduce response to hold the (moved) OK response.

Copy link
Contributor Author

@coryan coryan Dec 1, 2022

Choose a reason for hiding this comment

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

Fixed. stars

Comment on lines 47 to 54
auto client = client_factory_(options_);
auto status = client->Post(request, form_data);
if (!status) return std::move(status).status();
auto response = *std::move(status);
if (MapHttpCodeToStatus(response->StatusCode()) != StatusCode::kOk) {
return AsStatus(std::move(*response));
}
auto payload = rest_internal::ReadAll(std::move(*response).ExtractPayload());
if (!payload) return std::move(payload.status());
Copy link
Member

Choose a reason for hiding this comment

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

FYI: I am not the best reviewer of this chunk of code. Maybe @scotthart can give it the once-over?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. There is a lot of similar code elsewhere

To support external accounts we need to convert the "subject token"
returned by the external account source (e.g. an Azure metadata service
or a GitHub Actions OIDC source) into "access tokens" returned by
GCP's "Security Token Service".  In this change we introduce the code
to perform such exchanges, including a small integration test on
GitHub actions.
@coryan coryan force-pushed the feat-oauth2-workload-identity-federation-pr9 branch from 002e587 to 96bfdce Compare December 1, 2022 20:33
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 96bfdce3854cdd221bcdcb58e3085bcb003399ff

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@dbolduc dbolduc added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 1, 2022
Copy link
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

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

FYI: I applied the do not merge label, although I know you know better than to merge while the release is in progress

@coryan coryan removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 2, 2022
@coryan coryan merged commit ff0202c into googleapis:main Dec 2, 2022
@coryan coryan deleted the feat-oauth2-workload-identity-federation-pr9 branch December 2, 2022 00:10
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.

4 participants