feat(auth): make RAB feature production ready#17390
Conversation
…lookup Initialize impersonated credentials inside ExternalAccountCredentials.__init__() when an impersonation URL is set. This ensures that RAB lookup targets the Service Account endpoint.
There was a problem hiding this comment.
Code Review
This pull request enables the Regional Access Boundary (RAB) feature by default by removing the GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED environment variable gate. It also expands regional endpoint detection to support MTLS domains and updates external account credentials to initialize impersonated credentials immediately, delegating token and expiry management. Unit tests have been adjusted to remove obsolete environment variable mocks and to mock the RAB allowed locations endpoint. There are no review comments, so I have no feedback to provide.
lsirac
left a comment
There was a problem hiding this comment.
While the new unit tests cover the basic happy paths, there are a few critical testing gaps around backward compatibility, error handling, and subclassing that should be addressed before merging:
Backward Compatibility with Pickled States:
- The Gap: No test verifies unpickling a credential object serialized in a previous release.
- The Risk: Because
tokenandexpiryare now properties (data descriptors), they override instance__dict__lookups. Older unpickled credentials (which store'token'and'expiry'as plain keys) will have their cached tokens silently ignored, forcing redundant STS network calls.- Recommendation: Add a test that unpickles a legacy state and asserts the token is preserved.
Extensibility & Custom Subclassing:
- The Gap: No test verifies that external developers can safely subclass these credentials.
- The Risk: Triggering immediate impersonation in the base constructor calls
_constructor_args()before the subclass has finished setting up. This causes a fatalAttributeErroron subclass instantiation.- Recommendation: Add a test verifying instantiation of a mock custom subclass.
Error-Handling on Misconfiguration:
- The Gap: No test verifies that invalid/misconfigured setups fail gracefully.
- The Risk: Misconfiguring the credential source and supplier triggers the immediate copying flow, crashing with a confusing, internal
AttributeErrorinstead of raising a cleanexceptions.InvalidValuevalidation error.- Recommendation: Add a test asserting that invalid configurations raise
exceptions.InvalidValue.Programmatic Suppliers in
from_info:
- The Gap: No test verifies passing programmatic suppliers to the static
from_infomethod.- The Risk:
from_infoin bothaws.pyandidentity_pool.pyunconditionally updateskwargswithNonefrom the JSON dictionary, silently discarding the user's programmatic supplier.- Recommendation: Add a test calling
Credentials.from_info(info, supplier=my_callback)and assert the callback retention.callback)` and assert the check that the callback is preserved supplier works.
… execution. When external runners (such as gcloud CLI) load saved access tokens directly onto external account credentials, initial token renewal is skipped. Previously, this left the inner Service Account object uninitialized, forcing background boundary lookups to query outer identity pool endpoints and fail with HTTP 500 errors. This change defers Service Account initialization until an outgoing HTTP request is made (before_request) and copies active tokens downward, guaranteeing correct endpoint routing without extra network calls.
Gaps 1, 2, and 3 are not relevant anymore since I changed the way we were fixing the gcloud impersonation RAB lookup bug. I added checks and tests for gap 4 though! |
Awesome, thank you for adding the checks and tests for gap 4! re: the other gaps, let's still add these tests to prevent regressions in the future |
…azy initialization
|
|
||
| GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED = "GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED" | ||
| """Environment variable controlling whether to enable trust boundary feature. | ||
| The default value is false. Users have to explicitly set this value to true.""" |
There was a problem hiding this comment.
This looks like a publicly accessible value. I don't think it's safe to remove, in case someone imported it. Can we just leave it with a comment that it's deprecated?
This PR resolves issues identified during verification of gcloud Regional Access Boundary (RAB) flows and enables RAB verification by default:
GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED) to execute RAB lookups by default across standard credential classes..rep.mtls.googleapis.com), bypassing redundant RAB lookups on secure transport boundaries.