Skip to content

Anonymous auth to GCS #416

Open
Open
@TomAugspurger

Description

@TomAugspurger

I'm trying to make an anonymous request to a Google Cloud Storage bucket. I'm not too familiar with GCS, but I did find google.auth.credentials.AnonymousCredentials: https://googleapis.dev/python/google-auth/1.7.0/reference/google.auth.credentials.html#google.auth.credentials.AnonymousCredentials. However, the following raises an error:

import obstore
import obstore.auth.google
import google.auth.credentials


def main():
    g_credentials = google.auth.credentials.AnonymousCredentials()
    credential_provider = obstore.auth.google.GoogleCredentialProvider(g_credentials)
    store = obstore.store.GCSStore(
        bucket="weatherbench2",
        prefix="datasets/era5/1959-2023_01_10-full_37-1h-0p25deg-chunk-1.zarr",
        credential_provider=credential_provider)

    xs = store.list_with_delimiter()
    print(next(xs))


if __name__ == "__main__":
    main()

with

Traceback (most recent call last):
  File "torch_dataloader.py", line 19, in <module>
    main()
  File "torch_dataloader.py", line 14, in main
    xs = store.list_with_delimiter()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/obstore/store.py", line 364, in list_with_delimiter
    return obs.list_with_delimiter(
           ^^^^^^^^^^^^^^^^^^^^^^^^
obstore.exceptions.UnauthenticatedError: The operation lacked valid authentication credentials for path External GCP credential provider: InvalidOperation: Anonymous credentials cannot be refreshed.

Debug source:
Unauthenticated {
    path: "External GCP credential provider",
    source: PyErr {
        type: <class 'google.auth.exceptions.InvalidOperation'>,
        value: InvalidOperation('Anonymous credentials cannot be refreshed.'),
        traceback: Some(
            "Traceback (most recent call last):\n  File \".venv/lib/python3.12/site-packages/obstore/auth/google.py\", line 76, in __call__\n    self.credentials.refresh(self.request)\n  File \.venv/lib/python3.12/site-packages/google/auth/credentials.py\", line 322, in refresh\n    raise exceptions.InvalidOperation(\"Anonymous credentials cannot be refreshed.\")\n",
        ),
    },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions