-
Notifications
You must be signed in to change notification settings - Fork 1.7k
chore(auth): unblock tests #16481
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
Merged
Merged
chore(auth): unblock tests #16481
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4feb644
chore(auth): add test scripts back to repo
daniel-sanche e1e6626
emptied out default values
daniel-sanche a712ba9
improve token handling
daniel-sanche 6e2830e
refresh token
daniel-sanche 033f17e
Apply suggestions from code review
daniel-sanche 0d72206
removed scripts
daniel-sanche 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright 2015 Google Inc. All rights reserved. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we update the copyright here and in other places? |
||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
| ROOT=$( dirname "$DIR" ) | ||
|
|
||
| # Work from the project root. | ||
| cd $ROOT | ||
|
daniel-sanche marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Create working directory if not exists. system_tests/data is not tracked by | ||
| # Git to prevent the secrets from being leaked online. | ||
| mkdir -p system_tests/data | ||
|
|
||
| gcloud kms decrypt \ | ||
| --location=global \ | ||
| --keyring=ci \ | ||
| --key=kokoro-secrets \ | ||
| --ciphertext-file=system_tests/secrets.tar.enc \ | ||
| --plaintext-file=system_tests/secrets.tar | ||
| tar xvf system_tests/secrets.tar | ||
| rm system_tests/secrets.tar | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
| ROOT=$( dirname "$DIR" ) | ||
|
|
||
| # Work from the project root. | ||
| cd $ROOT | ||
|
|
||
| tar cvf system_tests/secrets.tar system_tests/data | ||
|
|
||
| gcloud kms encrypt \ | ||
| --location=global \ | ||
| --keyring=ci \ | ||
| --key=kokoro-secrets \ | ||
| --plaintext-file=system_tests/secrets.tar \ | ||
| --ciphertext-file=system_tests/secrets.tar.enc | ||
|
|
||
| rm system_tests/secrets.tar | ||
|
|
||
| rm system_tests/data | ||
|
daniel-sanche marked this conversation as resolved.
Outdated
|
||
113 changes: 113 additions & 0 deletions
113
packages/google-auth/scripts/setup_external_accounts.sh
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/bin/bash | ||
|
daniel-sanche marked this conversation as resolved.
Outdated
|
||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # This file is a mostly common setup file to ensure all workload identity | ||
| # federation integration tests are set up in a consistent fashion across the | ||
| # languages in our various client libraries. It assumes that the current user | ||
| # has the relevant permissions to run each of the commands listed. | ||
|
|
||
| # This script needs to be run once. It will do the following: | ||
| # 1. Create a random workload identity pool. | ||
| # 2. Create a random OIDC provider in that pool which uses the | ||
| # accounts.google.com as the issuer and the default STS audience as the | ||
| # allowed audience. This audience will be validated on STS token exchange. | ||
| # 3. Enable OIDC tokens generated by the current service account to impersonate | ||
| # the service account. (Identified by the OIDC token sub field which is the | ||
| # service account client ID). | ||
| # 4. Create a random AWS provider in that pool which uses the provided AWS | ||
| # account ID. | ||
| # 5. Enable AWS provider to impersonate the service account. (Principal is | ||
| # identified by the AWS role name). | ||
| # 6. Print out the STS audience fields associated with the created providers | ||
| # after the setup completes successfully so that they can be used in the | ||
| # tests. These will be copied and used as the global _AUDIENCE_OIDC and | ||
| # _AUDIENCE_AWS constants in system_tests/system_tests_sync/test_external_accounts.py. | ||
| # | ||
| # It is safe to run the setup script again. A new pool is created and new | ||
| # audiences are printed. If run multiple times, it is advisable to delete | ||
| # unused pools. Note that deleted pools are soft deleted and may remain for | ||
| # a while before they are completely deleted. The old pool ID cannot be used | ||
| # in the meantime. | ||
| # | ||
| # For AWS tests, an AWS developer account is needed. | ||
| # The following AWS prerequisite setup is needed. | ||
| # 1. An OIDC Google identity provider needs to be created with the following: | ||
| # issuer: accounts.google.com | ||
| # audience: Use the client_id of the service account. | ||
| # 2. A role for OIDC web identity federation is needed with the created Google | ||
| # provider as a trusted entity: | ||
| # "accounts.google.com:aud": "$CLIENT_ID" | ||
| # The steps are documented at: | ||
| # https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-idp_oidc.html | ||
|
|
||
| suffix="" | ||
|
|
||
| function generate_random_string () { | ||
| local valid_chars=abcdefghijklmnopqrstuvwxyz0123456789 | ||
| for i in {1..8} ; do | ||
| suffix+="${valid_chars:RANDOM%${#valid_chars}:1}" | ||
| done | ||
| } | ||
|
|
||
| generate_random_string | ||
|
|
||
| pool_id="pool-"$suffix | ||
| oidc_provider_id="oidc-"$suffix | ||
| aws_provider_id="aws-"$suffix | ||
|
|
||
| # TODO: Fill in. | ||
| project_id="stellar-day-254222" | ||
| project_number="79992041559" | ||
| aws_account_id="077071391996" | ||
| aws_role_name="ci-python-test" | ||
| service_account_email="kokoro@stellar-day-254222.iam.gserviceaccount.com" | ||
| sub="104692443208068386138" | ||
|
daniel-sanche marked this conversation as resolved.
Outdated
|
||
|
|
||
| oidc_aud="//iam.googleapis.com/projects/$project_number/locations/global/workloadIdentityPools/$pool_id/providers/$oidc_provider_id" | ||
| aws_aud="//iam.googleapis.com/projects/$project_number/locations/global/workloadIdentityPools/$pool_id/providers/$aws_provider_id" | ||
|
|
||
| gcloud config set project $project_id | ||
|
|
||
| # Create the Workload Identity Pool. | ||
| gcloud beta iam workload-identity-pools create $pool_id \ | ||
| --location="global" \ | ||
| --description="Test pool" \ | ||
| --display-name="Test pool for Python" | ||
|
|
||
| # Create the OIDC Provider. | ||
| gcloud beta iam workload-identity-pools providers create-oidc $oidc_provider_id \ | ||
| --workload-identity-pool=$pool_id \ | ||
| --issuer-uri="https://accounts.google.com" \ | ||
| --location="global" \ | ||
| --attribute-mapping="google.subject=assertion.sub" | ||
|
|
||
| # Create the AWS Provider. | ||
| gcloud beta iam workload-identity-pools providers create-aws $aws_provider_id \ | ||
| --workload-identity-pool=$pool_id \ | ||
| --account-id=$aws_account_id \ | ||
| --location="global" | ||
|
|
||
| # Give permission to impersonate the service account. | ||
| gcloud iam service-accounts add-iam-policy-binding $service_account_email \ | ||
| --role roles/iam.workloadIdentityUser \ | ||
| --member "principal://iam.googleapis.com/projects/$project_number/locations/global/workloadIdentityPools/$pool_id/subject/$sub" | ||
|
|
||
| gcloud iam service-accounts add-iam-policy-binding $service_account_email \ | ||
| --role roles/iam.workloadIdentityUser \ | ||
| --member "principalSet://iam.googleapis.com/projects/$project_number/locations/global/workloadIdentityPools/$pool_id/attribute.aws_role/arn:aws:sts::$aws_account_id:assumed-role/$aws_role_name" | ||
|
|
||
| echo "OIDC audience: "$oidc_aud | ||
| echo "AWS audience: "$aws_aud | ||
| echo "AWS role: arn:aws:iam::$aws_account_id:role/$aws_role_name" | ||
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.
Uh oh!
There was an error while loading. Please reload this page.