Skip to content
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

Ignore stage names in dockerfile verify #3881

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cmd/cosign/cli/dockerfile/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"strings"

"github.com/google/go-containerregistry/pkg/logs"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/verify"
"github.com/sigstore/cosign/v2/internal/ui"
)
Expand Down Expand Up @@ -110,7 +111,15 @@ func (fc *finderCache) getImagesFromDockerfile(ctx context.Context, dockerfile i
if err := fileScanner.Err(); err != nil {
return nil, err
}
return images, nil
validImages := []string{}
for _, image := range images {
if fc.isStage(image) {
logs.Debug.Printf("Ignoring stage name: %s", image)
continue
}
validImages = append(validImages, image)
}
return validImages, nil
}

func (fc *finderCache) getImageFromLine(line string) string {
Expand Down
10 changes: 10 additions & 0 deletions cmd/cosign/cli/dockerfile/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ CMD bin`,
},
expected: []string{"gcr.io/gauntlet/test/one", "gcr.io/gauntlet/test/two:latest", "gcr.io/gauntlet/test/runtime", "gcr.io/someorg/someimage"},
},
{
name: "from-stage-ignored",
fileContents: `
FROM gcr.io/someorg/sometool:sometag AS tools_image
FROM gcr.io/someorg/someimage AS base_image
FROM base_image
COPY --from=tools_image /bin/sometool
CMD bin`,
expected: []string{"gcr.io/someorg/sometool:sometag", "gcr.io/someorg/someimage"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Loading