worker: preflight check that sandbox images are accessible#1164
Open
arpitjain099 wants to merge 1 commit into
Open
worker: preflight check that sandbox images are accessible#1164arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
The worker only found out that a sandbox container image was missing or misconfigured when it tried to run the sandbox while handling a message. By that point a message had already been received, and a failure there could lead to messages being acked errantly. Add a startup preflight that resolves each configured sandbox image (static and dynamic, with the configured tag) using go-containerregistry's remote.Get before the worker starts consuming messages. If any image is not accessible the worker logs an error naming it and exits. The check is skipped when noPull is set, since that mode relies on images already present locally. The registry lookup is injected behind a checker func so the aggregation logic is unit tested without network access. Fixes ossf#346 Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.
What this does
Adds a startup preflight check to the analysis worker that confirms every configured sandbox container image is accessible before the worker begins consuming pubsub messages.
Today the worker only discovers that a sandbox image is missing or misconfigured once it tries to pull/run it while handling a message. By then a message has already been received, and a failure there can lead to messages being acked errantly. Checking up front lets the worker fail loudly at startup instead.
Approach
Following the suggestion in the issue, the check uses
go-containerregistry'sremote.Getto resolve each image's manifest. This confirms the image is reachable and the worker is authenticated for it, without pulling the image.The images checked are the static and dynamic analysis sandbox images (
StaticSandboxOptions/DynamicSandboxOptions), combined with the configured image tag (OSSF_SANDBOX_IMAGE_TAG, defaulting tolatest).SandboxImageURLs(tag)is the single source of truth for that set.The check is wired into
cmd/workermain, after network init and beforemessageLoop. If any image cannot be accessed, the worker logs an error naming the offending image(s) and exits non-zero. The check is skipped whenOSSF_SANDBOX_NOPULLis set, since in that mode the worker deliberately relies on images that are already present locally rather than a registry.Testing
The registry resolution is injected behind an
ImageCheckerfunc so the aggregation logic is unit tested without network access:SandboxImageURLsreturns both images and defaults an empty tag tolatest.go test ./internal/worker/,gofmt -l, andgo vetare clean for the affected packages.Fixes #346