You can't directly grant a permission to a service account, that's simply not how Google Cloud IAM works. Only roles are assigned to service accounts, users or groups which in turn usually contain a set of permissions.
If you want a role to only contain a single permission, or only permissions you're interested in, you can look into creating a custom role, which allows you to specify which permission(s) you want to give to a role of your definition in order to restrict the access on a more granular level. And then, assign that custom role to the service account:
Using the gcloud
CLI you can create a custom role with
gcloud iam roles create
, i.e:
gcloud iam roles create bucketViewer \
--project example-project-id-1 \
--title "Bucket viewer" \
--description "This role has only the storage.buckets.get permission" \
--permissions storage.buckets.get
This will create a custom role with the ID bucketViewer
, for the
project ID example-project-id-1
, containing only the permission
storage.buckets.get
. Replace these values as desired and
accordingly.
Once done, you can assign this custom role also with a single gcloud
command by using gcloud projects add-iam-policy-binding
:
gcloud projects add-iam-policy-binding example-project-id-1 \
--member='serviceAccount:test-proj1@example.domain.com' \
--role='projects/example-project-id-1/roles/bucketViewer'
Replace example-project-id-1
with your project ID, and
test-proj1@example.domain.com
with the actual name of the service
account you want to assign the role to.