Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict a Google Service Account to a single bucket in Google Cloud Storage?

Is it possible to do this?

The analogous feature in AWS using IAM does support restricting access to a single bucket, but from looking https://cloud.google.com/compute/docs/access/service-accounts it doesnt look like it is possible in GCP.

like image 721
donatello Avatar asked Aug 03 '18 19:08

donatello


People also ask

What GCP Tool is used to control access to a Cloud Storage bucket?

In most cases, IAM is the recommended method for controlling access to your resources. IAM controls permissioning throughout Google Cloud and allows you to grant permissions at the bucket and project levels.

How do I change permissions for a service account in GCP?

Open the Service Accounts page in the GCP Console and select the required Project. Click on Create Service Account and enter a service account name and select a role with desired permissions for the service account. Note: Make a note of the email ID of the service account. Click Save.


2 Answers

To restrict access for a service account to a specific bucket using IAM permissions you can use gsutil:

    gsutil iam ch serviceAccount:${SERVICE_ACCOUNT}@${PROJECT}.iam.gserviceaccount.com:objectViewer gs://${BUCKET}

And repeat for each role you want to grant (eg objectAdmin).

The docs are here Using Cloud IAM with buckets. If you need finer control on specific objects, you have to use ACLs.

like image 150
David Palita Avatar answered Sep 29 '22 12:09

David Palita


The Identity and Access Management (IAM) and service account permissions are the recommended methods for controlling access to your resources for a general scope; However, you should rather use Access Control Lists in case you want to customize the access scope to individual buckets and it's objects.

I recommend you to take a look on the Creating and Managing Access Control Lists guide that contains detail information about the usage of ACLs as well as the step-by-step instructions to set ACL permissions to an existing bucket.

like image 33
Armin_SC Avatar answered Sep 29 '22 11:09

Armin_SC