So, I want to grant a user to access a folder in a bucket.
So a user with user-id `A` can access <bucket>/<folder for storing>/<user-id>/
So, the requirement
Through this IAM condition documentation, I can achieve requirements 1 and 2.
Additional permissions required to list objects in this bucket. Ask a bucket owner to grant you 'storage.objects.list' permission.
But, user can upload the files, and reupload the file if user knows the exact name.
Point to note
I have tried to look on the documentation, but I haven't get the answer.
Solved! Go to Solution.
As mentioned at documentation:
"
storage.objects.list
permission is granted at the bucket level, you cannot use the resource.name
condition attribute to restrict object listing access to a subset of objects in the bucket. Users without storage.objects.list
permission at the bucket level can experience degraded functionality for the Console and gsutil."
Following least privilege principle I'd recommend to assign storage/objectViewer at bucket level for your users accounts.
For testing the results I'd recommend to run gsutil ls gs://<bucket_name>/<folder for storing>/<user-id>/ as the user you want to have access to the bucket [1]. Then you should be able to list the folder's content.
As well you should be able to list the folder content within Cloud Console UI.
As mentioned at documentation:
"
storage.objects.list
permission is granted at the bucket level, you cannot use the resource.name
condition attribute to restrict object listing access to a subset of objects in the bucket. Users without storage.objects.list
permission at the bucket level can experience degraded functionality for the Console and gsutil."
Following least privilege principle I'd recommend to assign storage/objectViewer at bucket level for your users accounts.
For testing the results I'd recommend to run gsutil ls gs://<bucket_name>/<folder for storing>/<user-id>/ as the user you want to have access to the bucket [1]. Then you should be able to list the folder's content.
As well you should be able to list the folder content within Cloud Console UI.
Thanks a lot for the reply.
I have tried your suggestion, and yes it works, user A can view the files in the folder along with other folder in same bucket.
But, I haven't mentioned additional requirement that user A must not see files in other folder in same bucket.
So, I think it cannot be done by Google Cloud UI, and it seems we will develop other way for workaround.
Again thanks a lot for answering.
I have the same request, which needs to allow a service account to have the
I use the following steps to address the folder access requirement.
1. Add a custom IAM role to have the storage.objects.list permission only.
Here is a sample terragrunt code,
include { path = find_in_parent_folders() } terraform { source = "git@bitbucket.org:xxxxx//gcp/iam/custom_role" } inputs = { role_id = "customStorageObjectsList" title = "Custom Storage Objects List" description = "Custom Storage Objects List Role" permissions = [ "storage.objects.list" ] }
2. Grant the customStorageObjectsList role and the storage.objectViewer role to an IAM member, such as an IAM service account.
Here is a sample terragrunt code,
include { path = find_in_parent_folders() } terraform { source = "git@bitbucket.org:xxxxx//gcp/iam/member" } inputs = { conditional_roles = [ { role = "roles/customStorageObjectsList" title = "xxx service-account storage.objects-list permission" description = "xxx service-account storage.objects-list permission" expression = "resource.name.startsWith('projects/_/buckets/${bucket_name}')" }, { role = "roles/storage.objectViewer" title = "xxx service-account storage.objectViewer permission" description = "xxx service-account storage.objectViewer permission" expression = join("", [ "resource.name.startsWith('projects/_/buckets/${bucket_name}/objects/folder-a')", "resource.name.startsWith('projects/_/buckets/${bucket_name}/objects/folder-b')" ]) } ] member = "serviceAccount:${service-account.email_address}" }