gcp - granting and testing permission on gcp bucket for a service account
You can create your service account by running the following command
Assigning role to the service account with the following gcloud command:
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