Search code examples
google-cloud-platformgoogle-cloud-storagegcloudgsutil

List files in Google Cloud Storage throws: AccessDeniedException: 403


Good day,

I am new to GCS and trying to access a partner's bucket using CLI. I have installed gsutil using documentation provided here (NOTE: I'm using macOS) and now I am trying to list files within a bucket. Access id key and secret have been provided which I use them to create a config file using:

gsutil config -a

which outputs:

Boto config file "/path/to/.boto" created. If you need to
use a proxy to access the Internet please see the instructions in that
file.

However, when I use the following command to list files within a bucket:

gsutil ls gs://bucket-name

It says:

AccessDeniedException: 403 myemail@domain.com does not have storage.objects.list access to the Google Cloud Storage bucket.

I think it's probably because of a sign in that I did as part of initializing google cloud using:

gcloud init

I'm wondering if there is a way to force ls command to use stored credentials instead of my email address and login that I did earlier. Any help is much appreciated.


Solution

  • So here is what fixed the issue for me on my laptop. I ran this first:

    gcloud config set pass_credentials_to_gsutil false
    

    And then the ls command would work just fine. What is strange to me is that adding / to the original ls command that I posted fixed the issue on another instance:

    gsutil ls gs://bucket-name/