gcp - granting and testing permission on gcp bucket for a service account


You can create your service account by running the following command

gcloud iam service-accounts create hellworldsa --display-name "hello world sa"

Assigning role to the service account with the following gcloud command: 


gcloud iam service-accounts add-iam-policy-binding
"hellworldsa@project-id.iam.gserviceaccount.com" --member="user:myuser@gmail.com"
--role="roles/iam.serviceAccountTokenCreator"


To test ability to list storage you can use the following command:- 

gcloud storage buckets list --impersonate-service-account=your-service-account-email-name

You will get 403: HTTP permission denied. 

This is because you don't have the storage admin role assigned to the service account 

gcloud projects add-iam-policy-binding projectid --member="serviceAccount:hellworldsa@projectid-450116-r5.iam.gserviceaccount.com" --role="roles/storage.admin"

After running command above, you can re-run this command:-

gcloud storage buckets list --impersonate-service-account=your-service-account-email-name

You may need to run the following command to refresh your token

gcloud iam service-accounts add-iam-policy-binding "hellworldsa@iam.gserviceaccount.com" --member="user:your-user@gmail.com" --role="roles/iam.serviceAccountTokenCreator"







Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type