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

fix: amend base image check with regards to alpine case #514

Merged
merged 3 commits into from
Feb 8, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func (a *AllowedBaseImage) Test() *tractusx.QualityResult {
fmt.Printf("Could not read dockerfile from Path %s\n", dockerfilePath)
continue
}

if !isAllowedBaseImage(file.baseImage()) {
if !isAllowedBaseImage(strings.Split(file.baseImage(), ":")[0]) {
checkPassed = false
deniedBaseImages = append(deniedBaseImages, file.baseImage())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ func TestShouldFailIfAtLeastOneDockerfileWithUnallowedBaseImageIsFound(t *testin
}
}

func TestShouldPassAlpineAsPlainBaseImage(t *testing.T) {
tmpDir := t.TempDir()
file := dockerFileWithBaseImage("alpine:3.19.1")
_ = file.writeTo(tmpDir)

result := NewAllowedBaseImage(tmpDir).Test()
if !result.Passed {
t.Errorf("Check should pass, pure alpine base image is allowed.")
}
}

func TestShouldFailImageAlpineBased(t *testing.T) {
tmpDir := t.TempDir()
file := dockerFileWithBaseImage("postgres:15.4-alpine3.17")
_ = file.writeTo(tmpDir)

result := NewAllowedBaseImage(tmpDir).Test()
if result.Passed {
t.Errorf("Check should fail, not approved base image (alpine based).")
}
}

func TestShouldAllowBaseImagesFromWhitelist(t *testing.T) {
baseImageAllowList = []string{"my/baseimage", "my/other/baseimage"}

Expand Down Expand Up @@ -184,3 +206,4 @@ func saveMetadataConfigToSkip(dockerfilePath string, dir string) {
bytes, _ := yaml.Marshal(&metadata)
_ = os.WriteFile(path.Join(dir, ".tractusx"), bytes, 0644)
}

Loading