feat(gcs): support explicit access token via GOBUILDCACHE_GCS_ACCESS_TOKEN#19
Open
odsod wants to merge 1 commit into
Open
feat(gcs): support explicit access token via GOBUILDCACHE_GCS_ACCESS_TOKEN#19odsod wants to merge 1 commit into
odsod wants to merge 1 commit into
Conversation
…TOKEN When set, the GCS backend uses the provided OAuth2 access token directly instead of relying on Application Default Credentials (ADC). This is useful in environments where the GCE metadata server is unreachable but a token can be obtained externally — for example, docker run containers on bridge networks in Google Cloud Build.
c70f325 to
464ddad
Compare
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.
Summary
When
GOBUILDCACHE_GCS_ACCESS_TOKENis set, the GCS backend uses the provided OAuth2 access token directly viaoption.WithTokenSourceinstead of relying on Application Default Credentials (ADC).Motivation
In Google Cloud Build,
docker runcontainers on thecloudbuildbridge network cannot reach the GCE metadata server at169.254.169.254(link-local addresses are not routable from Docker bridge networks). This causesstorage.NewClient(ctx)to hang indefinitely waiting for ADC via metadata, which in turn causes Go's GOCACHEPROG to print "still waiting for GOCACHEPROG gobuildcache" until the build times out.The fix allows the Cloud Build step script (which CAN reach metadata) to fetch a token and pass it explicitly:
Changes
pkg/backends/gcs.go: CheckGOBUILDCACHE_GCS_ACCESS_TOKENenv var; if set, passoption.WithTokenSource(oauth2.StaticTokenSource(...))tostorage.NewClientmain.go: Document the new env var in help text