Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permissions For Google Cloud SQL Import Using Service Accounts

I've exported MySQL Database following the MySQL Export Guide successfully.

Now, I'm trying to import MySQL Database following the MySQL Import Guide.

I've checked the permissions for the service_account_email I'm using, and I have allowed both Admin SQL and Admin Storage permissions.

I was able to successfully activate my service account using this command locally:

gcloud auth activate-service-account <service_account_email> --key-file=<service_account_json_file>  

After I ran the command:

gcloud sql import sql <instance> <gstorage_file> --database=<db_name> --async

I got this information:

{
  "error": {
    "errors": Array[1][
      {
        "domain": "global",
        "reason": "required",
        "message": "Login Required",
        "locationType": "header",
        "location": "Authorization"
      }
    ],
    "code": 401,
    "message": "Login Required"
  }
}

Other Things I've Tried

I also tried using the service_account_email of my SQL instance, which came from:

gcloud sql instances describe <instance_name>

But, it seems to have the same error.

Question

Based on the REST API JSON error I'm given, how do I "login" using the service_account_email so I wouldn't get the 401 Error?

like image 501
Franz Noel Avatar asked Jun 13 '18 01:06

Franz Noel


People also ask

How do I import SQL files into Google Cloud?

In the Google Cloud console, go to the Cloud SQL Instances page. To open the Overview page of an instance, click the instance name. Click Import. In the Choose the file you'd like to import data from section, enter the path to the bucket and SQL dump file to use for the import, or browse to an existing file.

How do you check what permissions a service account has?

To see if a service account has access to a resource, call the getIamPolicy method on the target resource. For example, to view grants for a project, call the projects. getIamPolicy method." But to get organization level permissions, the service account do not have permission to do the API call.


1 Answers

Problem is about the permission of database instance service account to write on created bucket. Steps to solve this issue

1) Go to your Cloud SQL Instance and copy service account of instance (Cloud SQL->{instance name}->OVERVIEW->Service account)

2) After copy the service account, go the Cloud Storage Bucket where to want to dump and set desired permission to that account (Storage->{bucket name}->permissions->add member).

like image 84
Fahad Abid Avatar answered Sep 20 '22 17:09

Fahad Abid