Repository navigation
test(oauth2): sign mTLS WIF OIDC test JWTs with static test key to prevent key-rotation breakage - #14914
test(oauth2): sign mTLS WIF OIDC test JWTs with static test key to prevent key-rotation breakage#14914macastelaz wants to merge 1 commit into
Conversation
…event key-rotation breakage
There was a problem hiding this comment.
Code Review
This pull request updates the workload identity federation integration tests to use a static test private key instead of the service account's private key. It modifies the setup script to append this static key to the JWK set retrieved from Google. The review feedback suggests improving the inline Python script in the setup script by adding a timeout and using a context manager for the network request to prevent potential hangs in CI/CD pipelines.
| import json, sys, urllib.request | ||
| url = f"https://www.googleapis.com/service_accounts/v1/jwk/{sys.argv[1]}" | ||
| jwks = json.loads(urllib.request.urlopen(url).read().decode()) |
There was a problem hiding this comment.
Using urllib.request.urlopen without a timeout can cause the script to hang indefinitely if there are network issues, which can block CI/CD pipelines. Additionally, it is recommended to use a context manager (with statement) to ensure the connection/socket is properly closed after reading.
| import json, sys, urllib.request | |
| url = f"https://www.googleapis.com/service_accounts/v1/jwk/{sys.argv[1]}" | |
| jwks = json.loads(urllib.request.urlopen(url).read().decode()) | |
| import json, sys, urllib.request | |
| url = f"https://www.googleapis.com/service_accounts/v1/jwk/{sys.argv[1]}" | |
| with urllib.request.urlopen(url, timeout=10) as response: | |
| jwks = json.loads(response.read().decode("utf-8")) |
Summary
Decouples
ITWorkloadIdentityFederationTest's mock external OIDC JWT signing (oidc-jwt-1) from theGOOGLE_APPLICATION_CREDENTIALSservice account private key, which is rotated every 2 months bysecret-rotator.Root Cause
ITWorkloadIdentityFederationTestpreviously signed mock external OIDC JWTs (iss: https://storage.googleapis.com/example-oidc-issuer) using the user-managed private key inGOOGLE_APPLICATION_CREDENTIALS(it-service-account@gcloud-devel.iam.gserviceaccount.com). Whensecret-rotatorrotatedGOOGLE_APPLICATION_CREDENTIALS, the newprivate_key_id(kid) no longer matched the static JWKs uploaded topool-1/providers/oidc-jwt-1, causing400 invalid_grantfailures untiloidc-jwt-1was manually updated.Fix
ITWorkloadIdentityFederationTestusing the static RSA keypair already checked intotestresources/mtls/test_key.pem(kid: "mtls-test-key"), while continuing to useGOOGLE_APPLICATION_CREDENTIALS's permanentclient_idas the JWTsubclaim andclient_emailfor service account impersonation.scripts/workloadidentityfederation-setup.shto include themtls-test-keypublic JWK inoidc-jwt-${suffix}.