-
Notifications
You must be signed in to change notification settings - Fork 124
fix(state): resolve DirectDeliverer source by digest when present #637
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,22 +86,43 @@ func (d *DirectDeliverer) Deliver(ctx context.Context, entities []Entity) error | |
| continue | ||
| } | ||
|
|
||
| srcRef := fmt.Sprintf("%s/%s/%s:%s", d.srcRegistry, entity.Repository, entity.Name, entity.Tag) | ||
| ref, err := name.ParseReference(srcRef, nameOpts...) | ||
| identifier := entity.Tag | ||
| if entity.Digest != "" { | ||
| identifier = entity.Digest | ||
| if _, dgst, ok := strings.Cut(entity.Digest, "@"); ok { | ||
| identifier = dgst | ||
| } | ||
| } | ||
| separator := ":" | ||
| if strings.Contains(identifier, ":") { | ||
| separator = "@" | ||
| } | ||
| srcRef := fmt.Sprintf("%s/%s/%s%s%s", d.srcRegistry, entity.Repository, entity.Name, separator, identifier) | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| pullRef, err := name.ParseReference(srcRef, nameOpts...) | ||
| if err != nil { | ||
| log.Warn().Err(err).Str("ref", srcRef).Msg("Direct delivery: failed to parse reference, skipping") | ||
| continue | ||
| } | ||
|
|
||
| opts := []remote.Option{remote.WithAuth(auth), remote.WithContext(ctx)} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🌐 Web query:
💡 Result: For github.com/google/go-containerregistry v0.21.7, the behavior regarding credentials with insecure references and authenticated redirects is as follows: 1. Credential Handling with name.Insecure: The Citations:
Sensitive Data Exposure (CWE-319): Cleartext Transmission of Sensitive Information Reachability: Internal · Exploitability: Moderate Reject credentialed insecure registry requests. When 🤖 Prompt for AI Agents |
||
| img, err := remote.Image(ref, opts...) | ||
| img, err := remote.Image(pullRef, opts...) | ||
| if err != nil { | ||
| log.Warn().Err(err).Str("ref", srcRef).Msg("Direct delivery: failed to pull image, skipping") | ||
| continue | ||
| } | ||
|
|
||
| // Use a tag-based reference for the tarball's RepoTags so k3s | ||
| // imports the image under the expected name:tag. | ||
| tagRef := pullRef | ||
| if entity.Tag != "" { | ||
| tagSrcRef := fmt.Sprintf("%s/%s/%s:%s", d.srcRegistry, entity.Repository, entity.Name, entity.Tag) | ||
| if parsed, err := name.ParseReference(tagSrcRef, nameOpts...); err == nil { | ||
| tagRef = parsed | ||
| } | ||
| } | ||
|
|
||
| dstPath := filepath.Join(d.imageDir, filename) | ||
| if err := d.writeAtomically(dstPath, ref, img); err != nil { | ||
| if err := d.writeAtomically(dstPath, tagRef, img); err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The digest-map skip check runs before the new tagRef write, so a tarball delivered before this change with a matching digest is never rewritten and retains its old digest-labeled RepoTags. The fix therefore only applies to newly written tarballs. If this migration matters, bump the recorded value (or invalidate the digest map) so existing up-to-date tarballs get re-labeled once. Prompt for AI agents |
||
| log.Warn().Err(err).Str("file", filename).Msg("Direct delivery: failed to write tarball, skipping") | ||
| continue | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: This duplicates the shared artifact-reference rules, so future digest or reference-format changes can make
DirectDelivererresolve a different source than the registry stores. Extract or reuse one shared reference helper instead of maintaining this second implementation.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional for now — the description flags this as an open question for reviewers: keep inline, or export
store.sourceIdentifierfor cross-package reuse. Happy to extract a shared helper if that's the preferred shape.