Google Cloud SQL import - ERROR: HTTPError 403: The client is not authorized to make this request

10,096

Solution 1

Make sure the instance-name is correct. I had the same error, it went away as soon as I corrected the instance-name.

Solution 2

I had this problem, my instance name was correct. Turns out I was in the wrong GCP project. Make sure you switch to the correct [target] project or use the project argument:

gcloud sql instances export my-cloud-sql-instance gs://connect-to-the-cloud-sql.appspot.com/my-cloud-sql-instance-backup --project=<your target project>

Solution 3

In my case it was because the cloud sql instance service account didn't have the correct permissions on the storage bucket I was trying to import from.

From the docs:

  1. Describe the instance you are importing to:

    gcloud sql instances describe [INSTANCE_NAME]
    
  2. Copy the serviceAccountEmailAddress field.

  3. Use gsutil iam to grant the legacyBucketWriter and objectViewer Cloud IAM roles to the service account for the bucket.

  4. Import the database:

    gcloud sql import sql [INSTANCE_NAME] gs://[BUCKET_NAME]/[IMPORT_FILE_NAME] \
                            --database=[DATABASE_NAME]
    

Solution 4

It might sound too obvious, but your service account really may be missing access rights for importing data. Check that it has correct cloudsql.instances.import policy installed on IAM&Admin page.

Share:
10,096
Beginner
Author by

Beginner

Updated on June 13, 2022

Comments

  • Beginner
    Beginner almost 2 years

    I trying to import a database stored in the Cloud Storage using the command:

    gcloud sql instances import instance-name gs://connect-to-the-cloud-sql.appspot.com/my-cloud-sql-instance-backup
    

    But, I am getting error:

    ERROR: (gcloud.sql.instances.import) HTTPError 403: The client is not authorized to make this request.
    

    I've already logged in using:

    gcloud auth login