Steve Jobs
Steve Jobs

Reputation: 95

Access JSON in bucket via API key

I have created a bucket on Google Cloud which contains one JSON file. I wish to access this JSON via some BASIC form of authentication, such as an API key

I have created an API key on google cloud with no restrictions

When I attempt a GET request using my API key, in the documented format, for example:

https://storage.googleapis.com/BUCKETNAME/JSONNAME?API_KEY=APIKEYNAME

It returns the following

"Anonymous caller does not have storage.objects.get access to bucket"

I am not sure why, since I am sending the API key

As an alternative, if I make the bucket/JSON file "public", I can access the JSON easily, via the following URL:

https://storage.googleapis.com/BUCKETNAME/JSONNAME

I don't really want to leave it completely open though..

Is there anything I can do here? I would like a basic key to be required (either on header or URL) to access the JSON

Thanks!

Upvotes: 0

Views: 2852

Answers (2)

takryo
takryo

Reputation: 439

No, you can not use basic key to access file on private Google Cloud Storage bucket.
There are two options to access file in private bucket.

  1. Use REST-API of Google Cloud Storage.
    AccessToken(OAuth2.0) is required to issue the request.
    Make sure to configure IAM or ACL to access bucket.
  2. Use signed URL to access the file. Signed URL is short-lived-url that allow to download / upload file.

1. Downloading object in Google Cloud Storage.
2. Signing URL to access file on your program.

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317352

According to the documentation on API keys:

After you have an API key, your application can append the query parameter key=yourAPIKey to all request URLs.

In your question, you said you're passing the API key with a parameter called "API_KEY", but the documentation says to use "key".

Upvotes: 1

Related Questions