1

I am trying to connect to Google Cloud SQL from my local windows machine using SQL Proxy.

I am able to connect using authenticated Cloud SDK client:

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

However, when I try to connect using a service account and credential file, it fails:

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=svc-acct@my-proj.iam.gserviceaccount.com
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

Not sure what I am missing here. Please help.

TechiRik
  • 1,893
  • 6
  • 27
  • 37
  • 1
    Try to add quote around your path name. Check also your credentials.json file with a text editor. The line separator can be in linux mode and not in windows mode. – guillaume blaquiere Sep 10 '20 at 19:54
  • I ran your command and worked well for me, I think that your issue is in the `credentials.json` file, try to re-download the file. – Jan Hernandez Sep 10 '20 at 20:01

1 Answers1

2

It sounds like your credentials.json file is invalid. Try generating a new one, and using that instead:

gcloud iam service-accounts keys create ~/key.json \
  --iam-account <sa-name>@<project-id>.iam.gserviceaccount.com
kurtisvg
  • 3,412
  • 1
  • 8
  • 24
  • @kurtisvg the script works, but do you know how to get this file from the Google Cloud Console by any chance? – Samantha Létourneau Dec 29 '21 at 02:04
  • 1
    @SamanthaLétourneau this page should help you out: https://cloud.google.com/iam/docs/creating-managing-service-account-keys#iam-service-account-keys-create-console – kurtisvg Dec 29 '21 at 19:32