Skip to content

Exception: Invalid Credentials for Cloud SQL #955

Closed

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

  1. jabubake commented on Jun 28, 2018

    @jabubake
    Contributor

    Hi @shamal , sorry for the late response here. It seems like you may not have configured authentication correctly.

    https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appengine-java8/cloudsql

    Please see the setup instructions in the README.md regarding authentication:

     gcloud auth application-default login
    

    If you're still running into issues, feel free to reopen.

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