GoogleCloudPlatform / GoogleCloudPlatform/cloud-sql-proxy
[BUG] universe-domain is not propagated to IAMCredentials client when using impersonate-service-account
- Lenguaje dominante
- Go
- Estrellas
- 1.4k
- Forks
- 352
- Merge medio
- 14 h 54 min
- PR fusionados (30 d)
- 5
Descripción
### Bug Description
When running cloud-sql-proxy in a custom universe domain (e.g., s3nsapis.fr) with service account impersonation enabled (impersonate-service-account), the proxy fails during startup when attempting to refresh instance metadata, returning HTTP 401 ACCESS_TOKEN_TYPE_UNSUPPORTED.
An analysis of the error payload indicates that while the proxy correctly targets the custom universe domain for the Cloud SQL Admin API (sqladmin.s3nsapis.fr), the underlying client created for Service Account impersonation still defaults to the public Google IAM endpoint (iamcredentials.googleapis.com).
### Environment
- Cloud SQL Proxy Version: v2.24.1
- OS: macOS / Linux
- Authentication Method: Custom Universe Domain Credentials / Workforce Identity Federation (WIF)
### Configuration Used
```toml
instance-connection-name = "s3ns:sandbox-yohan-xxxx:u-france-east1:mydatabase"
universe-domain = "s3nsapis.fr"
impersonate-service-account = "my-app@sandbox-yohan-xxxx.s3ns.iam.gserviceaccount.com"
psc = true
```
### Steps to Reproduce
1- Log in with a principal in a custom universe domain (e.g., s3nsapis.fr).
2- Run cloud-sql-proxy configured with both universe-domain and impersonate-service-account.
3- Observe the proxy initialization log.
### Observed Behavior
The proxy fails to fetch instance metadata with the following error log:
```
2026/07/28 14:27:43 Impersonating service account with gcloud user credentials
2026/07/28 14:27:44 [s3ns:sandbox-yohan-09e8:u-france-east1:demo-replatforming] could not resolve instance version: failed to get instance: refresh error: failed to get instance metadata (connection name = "s3ns:sandbox-yohan-09e8:u-france-east1:demo-replatforming"): Get "https://sqladmin.s3nsapis.fr/sql/v1beta4/projects/s3ns%3Asandbox-yohan-09e8/instances/demo-replatforming/connectSettings?alt=json&prettyPrint=false": impersonate: status code 401: {
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED",
"metadata": {
"method": "google.iam.credentials.v1.IAMCredentials.GenerateAccessToken",
"service": "iamcredentials.googleapis.com"
}
}
]
}
}
```
Notice in the error metadata:
"service": "iamcredentials.googleapis.com" (Points to public Google Cloud instead of iamcredentials.s3nsapis.fr).
### Expected Behavior
The universe-domain option should be propagated to the IAM Credentials client used by google.golang.org/api/impersonate during token generation. The proxy should call https://iamcredentials./... (e.g., iamcredentials.s3nsapis.fr) instead of iamcredentials.googleapis.com.
### Root Cause Analysis
When universe-domain is configured, it is successfully applied to the Cloud SQL Admin API client (sqladmin.). However, when initializing the credentials for impersonate-service-account, the universe-domain configuration is not passed down to the impersonate package options (option.WithUniverseDomain(...)). Consequently, the impersonate client defaults to googleapis.com, which rejects authentication tokens issued by custom universe domains.
Guía de contribución
Línea de trabajo
Empieza siguiendo cómo el universe-domain configurado llega al cliente google.golang.org/api/impersonate y compara esa ruta con el cliente de Cloud SQL Admin. Revisa las opciones de impersonate alrededor de option.WithUniverseDomain(...), luego verifica el arranque con universe-domain e impersonate-service-account configurados y confirma que las solicitudes se dirigen a iamcredentials..
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- go, google-cloud
- Área
- authentication, cloud
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 68/100