问题描述
我正在尝试使用sql代理从本地Windows计算机连接到Google Cloud sql。
我能够使用经过身份验证的Cloud SDK客户端进行连接:
C:\>cloud_sql_proxy -instances=my-proj:us-central1:my-instance=tcp:5000
2020/09/10 01:31:50 Listening on 127.0.0.1:5000 for my-proj:us-central1:my-instance
2020/09/10 01:31:50 Ready for new connections
但是,当我尝试使用服务帐户和凭据文件进行连接时,失败:
C:\>cloud_sql_proxy -instances=my-proj:us-central1:my-instance=tcp:5000 -credential_file=C:\credentials.json
2020/09/10 11:12:01 using credential file for authentication; [email protected]
2020/09/10 11:12:03 errors parsing config:
Get https://www.googleapis.com/sql/v1beta4/projects/my-proj/instances/my-instance?alt=json&prettyPrint=false: oauth2: cannot fetch token: unexpected EOF
不确定我在这里缺少什么。 请帮忙。
解决方法
听起来您的certificate.json文件无效。尝试生成一个新的,然后使用它:
gcloud iam service-accounts keys create ~/key.json \
--iam-account <sa-name>@<project-id>.iam.gserviceaccount.com