googleapis / googleapis/google-cloud-python

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

Aberta
#17,282 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

auth priority: p2 type: bug
Linguagem predominante
Python
Estrelas
5.4k
Forks
1.8k
Merge médio
2d 23h
PRs com merge (30d)
123

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece lendo google/auth/iam.py e as classes de credenciais relacionadas a STS em google/auth/external_account.py, google/auth/identity_pool.py, google/auth/aws.py e google/auth/impersonated_credentials.py, concentrando-se na construção de endpoints e em should_use_mtls_endpoint(). Adicione cobertura de testes unitários para substituições do ambiente de runtime e disponibilidade de certificados; o trabalho estará concluído quando as requisições de IAM e STS selecionarem os endpoints padrão ou mTLS esperados.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
authentication
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Pouca atividade
Clareza
Razoavelmente clara
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.