Add direct-serve via presigned storage URLs#97
Merged
Conversation
When storage.direct_serve is enabled and the backend supports it (S3, Azure), cached artifact downloads return a 302 redirect to a presigned URL instead of streaming bytes through the proxy. Falls back to streaming when the backend can't sign (fileblob, local filesystem) or signing fails. Adds the azureblob driver so azblob:// storage URLs work. Cache-hit accounting already happened before io.Copy so redirects are counted correctly; the metrics calls are pulled into a helper so both paths share them. Closes #96
Contributor
|
It's fairly common in other applications to provide a second configuration item for the URL to be used for constructing presigned URLs, as it is fairly common for the 'public' hostname of the storage system to be different from the 'private' name used by the proxy. In my case the 'private' name is 127.0.0.1 :-) |
When the proxy reaches storage at an internal address (127.0.0.1, a Docker service name) the presigned URLs it generates point there too, which is useless to external clients. This adds an optional base URL that replaces the scheme and host of signed URLs before they're returned, keeping the signed path and query intact.
Contributor
Author
|
@kpfleming updated |
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.
Closes #96.
When
storage.direct_serveis enabled and the backend supports URL signing (S3, Azure), cached artifact downloads return a 302 redirect to a presigned URL instead of streaming bytes through the proxy. Falls back to streaming when the backend can't sign (fileblob, local filesystem) or when signing fails for any reason, so enabling it on afile://store is harmless.Configure with
storage.direct_serve: trueand optionallystorage.direct_serve_ttl(default 15m), or viaPROXY_STORAGE_DIRECT_SERVE/PROXY_STORAGE_DIRECT_SERVE_TTL.Also registers the
gocloud.dev/blob/azureblobdriver soazblob://storage URLs work.On the cache-hit accounting point from the issue:
RecordCacheHitandRecordArtifactHitwere already called incheckCachebeforeio.Copy, so redirects are counted correctly with no refactor needed. The metric calls are pulled into a small helper so the redirect and streaming paths share them.Went with a single global flag rather than per-handler
CanDirectServe()since there's no proxy-side auth today that would make one ecosystem riskier to redirect than another. Happy to revisit if that lands.