googleapis / googleapis/google-cloud-python
Support AIP-4114 GOOGLE_API_USE_MTLS_ENDPOINT overrides for IAM and STS credentials fetching
- 主要言語
- Python
- スター
- 5.4k
- フォーク
- 1.8k
- 平均マージ
- 3日 4時間
- マージ済み PR(30日)
- 122
説明
### Summary of the issue
The `google-auth` library currently does not fully comply with [AIP-4114](https://google.aip.dev/auth/4114) regarding mTLS endpoint selection for its internal API calls, specifically for STS (Security Token Service) and IAM credentials fetching.
1. **IAM Credentials (`iam.py`)**: The domain hostname `_IAM_DOMAIN` is evaluated globally during module import using `_mtls_helper.check_use_client_cert()`. This static evaluation ignores the explicit overrides provided by the `GOOGLE_API_USE_MTLS_ENDPOINT` environment variable (`always`, `never`, `auto`). It also breaks late configuration bootstraps where certificates are provisioned dynamically after import.
2. **STS Endpoints (`external_account.py`, `identity_pool.py`, etc.)**: STS endpoint URLs (e.g., `https://sts.googleapis.com/v1/token`) are hardcoded or constructed without considering mTLS. In zero-trust environments where mTLS is strictly mandated (`GOOGLE_API_USE_MTLS_ENDPOINT=always`), these auth bootstrap requests must be routed to `sts.mtls.googleapis.com`. If they are not, the token exchange will be blocked by VPC Service Controls or BeyondCorp perimeters before any data-plane API calls can even be made.
### Proposed fix
Refactor `google/auth/iam.py` and the STS-related credential classes to resolve these endpoints dynamically per call or lazily upon instantiation, using the `should_use_mtls_endpoint()` helper from `google.auth.transport.mtls`.
To prevent excessive lookup overhead (such as synchronous disk I/O when verifying certificate paths on every token refresh), this runtime evaluation cloud be coupled with caching strategies (such as `@functools.lru_cache`) if the decision is decoupled from module load.
In addition, unit tests must be added to verify that the correct mTLS vs. standard endpoints (e.g., `sts.mtls.googleapis.com` and `iamcredentials.mtls.googleapis.com`) are triggered correctly based on the runtime `GOOGLE_API_USE_MTLS_ENDPOINT` environment variable and client certificate availability.
### Affected Files
* `google/auth/iam.py`
* `google/auth/impersonated_credentials.py`
* STS credential classes (e.g., `google/auth/external_account.py`, `google/auth/identity_pool.py`, `google/auth/aws.py`)
コントリビューションガイド
評価
この issue はまだ評価されていません。