I am using gsutil to upload a file to bucket.However i am getting the following error.
ServiceException: 401 Anonymous users does not have storage.objects.list access to bucket mybucket.
`$upload_command = 'CLOUDSDK_PYTHON=/usr/bin/python /usr/local/bin/google-cloud-sdk/bin/gsutil -h "Cache-Control:max-age=31536000, public" cp ' . $tmp_path . ' gs://imgsv1/' . $filename;`
My user case :
I want to use GCS for an image sharing site (think imgur style) so i need people to be available to view images provided they have the link.
I already made the bucket public
gsutil defacl set public-read gs://mybucket
It looks like you asked a similar question on #402 - I think the answer I left there is still applicable here. The error message seems to indicate that you don't have any credentials defined, which probably means that the user you're trying to run this command as (probably the user that your webserver runs under, nginx?) does not have credentials set up.
To fix this, you should be able to specify a .boto file that contains OAuth2 credentials using the BOTO_CONFIG environment variable, e.g.:
BOTO_CONFIG=/path/to/a/valid/.boto CLOUDSDK_PYTHON=/usr/bin/python /usr/local/bin/google-cloud-sdk/bin/gsutil [rest of command here]
To generate a .boto file using the gcloud-bundled version of gsutil, you can run gcloud auth <login | activate-service-account>. If you're doing this from a web server, I'd strongly recommend using a service account's credentials instead of your own (see the docs for instructions on how to do this). This will create a .boto file at a path that looks like:
/path/to/my/home/directory/.config/gcloud/legacy_credentials/123456789012-a12bc3d45ef678gh90ijklmkop1q2rst@developer.gserviceaccount.com/.boto
which you can use for the value of BOTO_CONFIG=<value> in the command above.
If you still encounter auth issues, it's likely that there's another .boto file that gcloud has created which is being loaded afterward and overriding your credentials. You can see which .boto files are being loaded by looking at the output of gsutil version -l -- make sure you're using gsutil v4.23 or above, as there was a bug in previous versions that prevented gsutil from showing all of the .boto files being loaded.
As I haven't seen a response in a couple weeks, I'm going to go ahead and close this issue.
Most helpful comment
It looks like you asked a similar question on #402 - I think the answer I left there is still applicable here. The error message seems to indicate that you don't have any credentials defined, which probably means that the user you're trying to run this command as (probably the user that your webserver runs under, nginx?) does not have credentials set up.
To fix this, you should be able to specify a .boto file that contains OAuth2 credentials using the BOTO_CONFIG environment variable, e.g.:
To generate a .boto file using the gcloud-bundled version of gsutil, you can run
gcloud auth <login | activate-service-account>. If you're doing this from a web server, I'd strongly recommend using a service account's credentials instead of your own (see the docs for instructions on how to do this). This will create a .boto file at a path that looks like:which you can use for the value of
BOTO_CONFIG=<value>in the command above.If you still encounter auth issues, it's likely that there's another .boto file that gcloud has created which is being loaded afterward and overriding your credentials. You can see which .boto files are being loaded by looking at the output of
gsutil version -l-- make sure you're using gsutil v4.23 or above, as there was a bug in previous versions that prevented gsutil from showing all of the .boto files being loaded.