Bug Description
The Cloud SQL Proxy fails to automatically refresh the OAuth 2.0 access token obtained via gcloud auth application-default login after a period of inactivity. This leads to authentication errors when trying query the database, with the following error:
googleapi: Error 401: Request had invalid authentication credentials.
This issue seems to occur only after prolonged periods (6-12 hours) of inactivity.
Expected behavior: The Cloud SQL Proxy should automatically refresh the access token as needed. (See: https://cloud.google.com/sql/docs/mysql/sql-proxy#benefits_of_the)
Example code (or command)
N/A
Stacktrace
date 10:44:56 [<instance-connection-name>] Accepted connection from 127.0.0.1:52346
date 10:44:56 [<instance-connection-name>] failed to connect to instance: failed to get instance: Refresh error: failed to get instance metadata (connection name = "<instance-connection-name>"): googleapi: Error 401: 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.
Details:
[
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"metadata": {
"method": "google.cloud.sql.v1beta4.SqlConnectService.GetConnectSettings",
"service": "sqladmin.googleapis.com"
},
"reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED"
}
]
More details:
Reason: authError, Message: Invalid Credentials
date 10:44:56 [<instance-connection-name>] Accepted connection from 127.0.0.1:52347
date 10:44:56 [<instance-connection-name>] failed to connect to instance: failed to get instance: Refresh error: failed to get instance metadata (connection name = "<instance-connection-name>"): googleapi: Error 401: Request had invalid authentication credentials.
Steps to reproduce?
- Authenticate using
gcloud auth application-default login.
- Start the Cloud SQL Proxy using
./cloud-sql-proxy.x64.exe --config-file config.toml
- Leave the proxy inactive for several hours.
- Attempt to reconnect and observe that the proxy encounters a 401 error due to expired credentials.
Environment
- OS type and version: Windows 11 Home
- Cloud SQL Proxy version (
./cloud-sql-proxy --version): cloud-sql-proxy version 2.11.4+windows.amd64
- Proxy invocation command (for example,
./cloud-sql-proxy --port 5432 INSTANCE_CONNECTION_NAME): ./cloud-sql-proxy.x64.exe --config-file config.toml
config.toml
# use instance-connection-name-0, instance-connection-name-1, etc.
# for multiple instances
instance-connection-name = "redacted"
auto-iam-authn = true
debug = true
debug-logs = true
port = "5432"
Additional Details
N/A
Bug Description
The Cloud SQL Proxy fails to automatically refresh the OAuth 2.0 access token obtained via
gcloud auth application-default loginafter a period of inactivity. This leads to authentication errors when trying query the database, with the following error:This issue seems to occur only after prolonged periods (6-12 hours) of inactivity.
Expected behavior: The Cloud SQL Proxy should automatically refresh the access token as needed. (See: https://cloud.google.com/sql/docs/mysql/sql-proxy#benefits_of_the)
Example code (or command)
N/A
Stacktrace
Steps to reproduce?
gcloud auth application-default login../cloud-sql-proxy.x64.exe --config-file config.tomlEnvironment
./cloud-sql-proxy --version): cloud-sql-proxy version 2.11.4+windows.amd64./cloud-sql-proxy --port 5432 INSTANCE_CONNECTION_NAME): ./cloud-sql-proxy.x64.exe --config-file config.tomlconfig.toml
Additional Details
N/A