Skip to content

Commit

Permalink
Fix verify-dockerfile to allow lowercase FROM (#643)
Browse files Browse the repository at this point in the history
This is a simple fix to allow "from" in dockerfiles to have their
image arguments detected by verify-dockerfile command.

Signed-off-by: Michael <mlieberman85@gmail.com>
  • Loading branch information
mlieberman85 committed Sep 10, 2021
1 parent 6d2fc54 commit cb310df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/cosign/cli/verify_dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func getImagesFromDockerfile(dockerfile io.Reader) ([]string, error) {
fileScanner := bufio.NewScanner(dockerfile)
for fileScanner.Scan() {
line := strings.TrimSpace(fileScanner.Text())
if strings.HasPrefix(line, "FROM") {
if strings.HasPrefix(strings.ToUpper(line), "FROM") {
switch image := getImageFromLine(line); image {
case "scratch":
fmt.Fprintln(os.Stderr, "- scratch image ignored")
Expand Down
1 change: 1 addition & 0 deletions test/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if (./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/unsign
test_image="gcr.io/distroless/base" ./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_arg.Dockerfile
# Image exists, but is unsigned
if (test_image="ubuntu" ./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_arg.Dockerfile); then false; fi
./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_lowercase.Dockerfile

# Test `cosign verify-manifest`
./cosign verify-manifest -key ${DISTROLESS_PUB_KEY} ./test/testdata/signed_manifest.yaml
Expand Down
15 changes: 15 additions & 0 deletions test/testdata/with_lowercase.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2021 The Sigstore Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from gcr.io/distroless/base

0 comments on commit cb310df

Please sign in to comment.