0

I'm developing and testing an App Engine application locally. I would like the application to print out a list of all Bucket names in the projects Google Cloud Storage.

Some code:

Storage storage = StorageOptions.getDefaultInstance().getService();
Page<Bucket> buckets = storage.list(Storage.BucketListOption.pageSize(100));
Iterator<Bucket> bucketIterator = buckets.iterateAll();
while (bucketIterator.hasNext()) {
    Bucket bucket = bucketIterator.next();
    System.out.println("bucket name: " + bucket.getName());
}

To access Cloud Storage, I am using the google-cloud library for Java found here: http://googlecloudplatform.github.io/google-cloud-java/0.9.4/index.html

Running the above snippet results in a 401 Unauthorized.

As specified under the "What is it?" section in the above link, if the application is running inside App Engine or Compute Engine, authentication is automatic.

Since I am running locally, I assume automatic authentication does not work (please correct me if i'm wrong).

To authenticate, I followed one of the options listed under the Authentication section and issued the command gcloud auth application-default login in the terminal.

I no longer get a 401 unauthorized when trying to access Cloud Storage, however do get the following:

java.security.AccessControlException: access denied ("java.io.FilePermission" "/Users/example/.config/gcloud/active_config" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
  1. How can I resolve this AccessControlException?
  2. Is this the correct way to authenticate to Cloud Storage while developing locally? If not, what is?
Orbit
  • 2,985
  • 9
  • 49
  • 106
  • Hrm...you may be running into this issue: https://github.com/GoogleCloudPlatform/google-cloud-java/issues/680 Could you try clearing the environment variable CLOUDSDK_CONFIG or setting the GOOGLE_APPLICATION_CREDENTIALS to the location of a json credential file? – Brandon Yarbrough Mar 10 '17 at 08:54
  • @BrandonYarbrough You'll need to explain your comment. Where is this `CLOUDSDK_CONFIG` you mentioned? It is not listed in my systems env variables. After running `gcloud auth application-default login` the path to `application_default_credentials.json` is returned. I've tried setting this path in `.setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream("/path/to/my/key.json")))`, however the same access error occurs. – Orbit Mar 10 '17 at 16:07
  • Ahhh, that's different. I bet that's https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1500, which I see you've already found and commented on. – Brandon Yarbrough Mar 10 '17 at 16:36
  • I have now also tried setting a `GOOGLE_APPLICATION_CREDENTIALS` env variable, however the issue persists. Given the same issue you linked, I am now unsure whether this issue stems from my own code or whether it is an internal issue with `google-cloud`. – Orbit Mar 10 '17 at 16:39

0 Answers0