Skip to content

Exception: Invalid Credentials for Cloud SQL #955

Description

@shamal

In which file did you encounter the issue?

java-docs-samples/appengine-java8/cloudsql

Did you change the file? If so, how?

No changes.

Describe the issue

I run the demo locally with
mvn clean appengine:run -DINSTANCE_CONNECTION_NAME=_<my-instance-name>_ -Duser=root -Dpassword=_<my-root-password>_ -Ddatabase=database1

I get exception as below:

javax.servlet.ServletException: Unable to connect to Cloud SQL
	at com.example.appengine.cloudsql.CloudSqlServlet.init(CloudSqlServlet.java:116)
	..........
	... 65 more
Caused by: java.lang.RuntimeException: Unable to retrieve information about Cloud SQL instance [shamalk:us-central1:db-1]
	at com.google.cloud.sql.core.SslSocketFactory.obtainInstanceMetadata(SslSocketFactory.java:411)
	.............
	... 78 more
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
  "code" : 401,
  "errors" : [ {
    "domain" : "global",
    "location" : "Authorization",
    "locationType" : "header",
    "message" : "Invalid Credentials",
    "reason" : "authError"
  } ],
  "message" : "Invalid Credentials"
}
	at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
	..............
	... 86 more

I have allowed 0.0.0.0/0 for my DB instance.
And I'm able to connect using gcloud sql connect db-1 --user=root without any issues.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions