Skip to content

fix: normalize Docker image IDs before export - #587

Closed
clbiggs wants to merge 2 commits into
neuvector:mainfrom
clbiggs:main
Closed

clbiggs wants to merge 2 commits into
neuvector:mainfrom
clbiggs:main

Conversation

@clbiggs

@clbiggs clbiggs commented Sep 14, 2026

Copy link
Copy Markdown

Description

Fix local image scanning when Docker uses the containerd image store.

With the containerd image store, Docker may return an image ID as a bare 64-character SHA-256 value. Newer Docker versions reject that value when it is passed to the image-save API without the sha256: prefix:

invalid repository name (...), cannot specify 64-byte hexadecimal strings

Fix neuvector/neuvector#2508

Test

go test ./cvetools
Result:
ok github.com/neuvector/scanner/cvetools

Additional Information

  • Prefix bare 64-character image IDs with sha256: before calling GetImageFile.
  • Preserve image IDs that already include the digest algorithm.
  • Preserve short image IDs.
  • Add unit tests for each form.
    This keeps the existing behavior for the overlay2 image store while allowing locally cached images to be scanned when Docker uses the containerd image store.

@clbiggs
clbiggs requested a review from a team as a code owner September 14, 2026 14:10
@clbiggs
clbiggs requested a review from olblak September 14, 2026 14:10

@pohanhuang pohanhuang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contribution, this is a good fouding!

Comment thread cvetools/image.go
Comment on lines +64 to +70
func dockerImageSaveID(id string) string {
if len(id) == 64 {
return "sha256:" + id
}
return id
}

@pohanhuang pohanhuang Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func dockerImageSaveID(id string) string {
if len(id) == 64 {
return "sha256:" + id
}
return id
}
const sha256Prefix = "sha256:"
func dockerImageSaveID(id string) string {
if d, err := goDigest.Parse(id); err == nil {
return d.String()
}
if d, err := goDigest.Parse(sha256Prefix + id); err == nil {
return d.String()
}
return id
}

@pohanhuang

Copy link
Copy Markdown
Contributor

@clbiggs are you still working on this issue?

@pohanhuang

Copy link
Copy Markdown
Contributor

Closing this for the issue has been resolve in #597

@pohanhuang pohanhuang closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to scan docker images when docker backend storage is in containerd

2 participants