googleapis / googleapis/google-cloud-python

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

Abierto
#17,282 1 comentario 0 reacciones 0 asignados Ver en GitHub
auth priority: p2 type: bug
Lenguaje dominante
Python
Estrellas
5.4k
Forks
1.8k
Merge medio
3 d 4 h
PR fusionados (30 d)
122

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.