googleapis / googleapis/google-cloud-python

Support AIP-4114 GOOGLE_API_USE_MTLS_ENDPOINT overrides for IAM and STS credentials fetching

Đang mở
#17,282 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
auth priority: p2 type: bug
Ngôn ngữ chính
Python
Star
5.4k
Fork
1.8k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
122

Mô tả

### 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`)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.