Skip to content

Add support for Google Artifact Registry #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions binderhub/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,35 @@ async def get_credentials(self, image, tag):
return None


class GoogleArtifactRegistry(DockerRegistry):
"""
A registry for Google Artifact Registry.

At present, the only way to generate credentials without having to use the gcloud cli
is the metadata server. The metadata server uses the Compute Engine default service account.

For more information, see https://cloud.google.com/docs/authentication/rest#metadata-server.
"""

@default("token_url")
def _default_token_url(self):
return "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token"

async def _get_token(self, client, token_url, service, scope):
auth_req = httpclient.HTTPRequest(
token_url, headers={"Metadata-Flavor": "Google"}
)
self.log.debug(f"Getting registry token from {token_url}")
auth_resp = await client.fetch(auth_req)
response_body = json.loads(auth_resp.body.decode("utf-8", "replace"))

if "access_token" in response_body.keys():
token = response_body["access_token"]
else:
raise ValueError(f"No token in response from registry: {response_body}")
return token


class FakeRegistry(DockerRegistry):
"""
Fake registry that contains no images
Expand Down
Loading