Skip to content

Commit

Permalink
fix: handle docker's unknown/unknown platform in index manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh committed Mar 8, 2023
1 parent 7ce9478 commit 81677b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,13 @@ func parseSpec(spec []string) (*platformMatcher, error) {
}

func (pm *platformMatcher) matches(base *v1.Platform) bool {
if len(pm.spec) > 0 && pm.spec[0] == "all" {
if base != nil &&
(base.OS == "unknown" || base.Architecture == "unknown") {
return false
}

all := len(pm.spec) > 0 && pm.spec[0] == "all"
if all {
return true
}

Expand All @@ -1181,6 +1187,12 @@ func (pm *platformMatcher) matches(base *v1.Platform) bool {
}

for _, p := range pm.platforms {
// Strip out manifests with "unknown/unknown" platform, which Docker uses
// to store provenance attestations.
if p.OS == "unknown" || p.Architecture == "unknown" {
continue
}

if p.OS != "" && base.OS != p.OS {
continue
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/build/gobuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,11 @@ func TestMatchesPlatformSpec(t *testing.T) {
OSVersion: "10.0.17763.1234.5678", // this won't happen in the wild, but it shouldn't match.
},
result: false,
}, {
// Even --platform=all does not match unknown/unknown.
platform: &v1.Platform{Architecture: "unknown", OS: "unknown"},
spec: []string{"all"},
result: false,
}} {
pm, err := parseSpec(tc.spec)
if tc.err {
Expand Down

0 comments on commit 81677b2

Please sign in to comment.