gcrhelper: add automatic GCR/Artifact Registry auth on GCE#1124
Open
jossy wants to merge 9 commits intocloudfoundry:developfrom
Open
gcrhelper: add automatic GCR/Artifact Registry auth on GCE#1124jossy wants to merge 9 commits intocloudfoundry:developfrom
jossy wants to merge 9 commits intocloudfoundry:developfrom
Conversation
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
./scripts/test-in-docker.bash: all tests passSummary
Diego cells running on Google Cloud (GCE) have a VM service account that can be granted access to GCR / Artifact Registry via IAM. Despite this,
cf push --docker-image gcr.io/...currently requires the operator or developer to explicitly pass--docker-username/--docker-passwordand store those credentials with the app. This creates unnecessary credential management overhead and makes credential rotation difficult.ECR already has equivalent automatic auth via
ecrhelper. This PR mirrors that pattern for GCR and Artifact Registry.We have deployed these changes successfully in one of our own GCE-hosted CF environments and confirmed end-to-end that
cf push --docker-image eu.gcr.io/...works without credentials.Dependency: cloudfoundry/rep#82 must be merged with this PR, as it contains the
conversion_helpers.gochange for the runtime path.Changes
New package:
gcrhelperMirrors the structure of
ecrhelper. Provides aGCRHelperinterface with two methods:IsGCRRepo(url): regex match against*.gcr.ioand*.pkg.dev(Artifact Registry's domain)GetGCRCredentials(): calls the GCE instance metadata server (http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token) to get a short-lived OAuth2 token, returned as the password alongside the fixed usernameoauth2accesstokenOn first metadata server failure (non-GCE environment or unreachable network),
notOnGCEis set on the helper and subsequent calls return empty credentials immediately without a network attempt. The token is fetched on every call rather than cached, since the GCE metadata server always returns a token with the correct remaining TTL and handles refresh transparently.The
Metadata-Flavor: Googlerequest header is set as required by the metadata server.rep/conversion_helpers.goIn
convertCredentials(), before the existing ECR check: if no credentials are stored for a docker image (username == "" && password == ""), check whether the image is on GCR/Artifact Registry and, if so, callGetGCRCredentials(). Falls back to the existing path (empty credentials → unauthenticated pull) if gcrhelper returns nothing.dockerapplifecycle/builder/builder_runner.goandmain.goSame guard added to
getCredentials()in the staging path.GCRHelperfield added to theBuilderstruct; wired inmain.gowithNewGCRHelper().BOSH package specs
gcrhelper/*.goadded as agosubdependency to all six affected packages:rep,auctioneer,bbs,cfdot,rep_windows,docker_app_lifecycle.Operator notes
dockerapplifecyclebuilder) runs inside a Garden container and cannot reach169.254.169.254without a staging ASG. Operators on GCE will need to add{"protocol":"tcp","destination":"169.254.169.254/32","ports":"80"}as a staging security group rule. The runtime path (rep) runs on the host VM via BPM and is unaffected.roles/artifactregistry.readeron the relevant repository is an operator responsibility.Backward Compatibility
Breaking Change? No
The new code only runs when no credentials are stored for the image (
username == "" && password == ""). All existing deployments that pass credentials are completely unaffected. On non-GCE environments, the metadata server call fails within 1 second,notOnGCEis set, and all subsequent calls return empty credentials immediately, identical behaviour to the current code path.