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

feature: mirror of security/trivy-checks:0 image #48

Merged
merged 1 commit into from
Oct 14, 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
4 changes: 4 additions & 0 deletions internal/mirror/cmd/vulndb/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func pull(_ *cobra.Command, _ []string) error {
if err != nil {
return fmt.Errorf("creating java db layout: %w", err)
}
imageLayouts.TrivyChecks, err = layouts.CreateEmptyImageLayoutAtPath(filepath.Join(VulnerabilityDBPath, "trivy-checks"))
if err != nil {
return fmt.Errorf("creating java db layout: %w", err)
}

if err := layouts.PullTrivyVulnerabilityDatabasesImages(pullContext, imageLayouts); err != nil {
return fmt.Errorf("pull vulnerability databases: %w", err)
Expand Down
1 change: 1 addition & 0 deletions internal/mirror/cmd/vulndb/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func push(_ *cobra.Command, _ []string) error {
path.Join(RegistryRepo, "security", "trivy-db"): filepath.Join(VulnerabilityDBPath, "trivy-db"),
path.Join(RegistryRepo, "security", "trivy-bdu"): filepath.Join(VulnerabilityDBPath, "trivy-bdu"),
path.Join(RegistryRepo, "security", "trivy-java-db"): filepath.Join(VulnerabilityDBPath, "trivy-java-db"),
path.Join(RegistryRepo, "security", "trivy-checks"): filepath.Join(VulnerabilityDBPath, "trivy-checks"),
}

repoCount := 0
Expand Down
4 changes: 4 additions & 0 deletions pkg/libmirror/layouts/layouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type ImageLayouts struct {
TrivyBDUImages map[string]struct{}
TrivyJavaDB layout.Path
TrivyJavaDBImages map[string]struct{}
TrivyChecks layout.Path
TrivyChecksImages map[string]struct{}

Modules map[string]ModuleImageLayout

Expand Down Expand Up @@ -90,6 +92,7 @@ func CreateOCIImageLayoutsForDeckhouse(
&layouts.TrivyDB: filepath.Join(rootFolder, "security", "trivy-db"),
&layouts.TrivyBDU: filepath.Join(rootFolder, "security", "trivy-bdu"),
&layouts.TrivyJavaDB: filepath.Join(rootFolder, "security", "trivy-java-db"),
&layouts.TrivyChecks: filepath.Join(rootFolder, "security", "trivy-checks"),
}
for layoutPtr, fsPath := range fsPaths {
*layoutPtr, err = CreateEmptyImageLayoutAtPath(fsPath)
Expand Down Expand Up @@ -183,6 +186,7 @@ func FillLayoutsWithBasicDeckhouseImages(
mirrorCtx.DeckhouseRegistryRepo + "/security/trivy-db:2": {},
mirrorCtx.DeckhouseRegistryRepo + "/security/trivy-bdu:1": {},
mirrorCtx.DeckhouseRegistryRepo + "/security/trivy-java-db:1": {},
mirrorCtx.DeckhouseRegistryRepo + "/security/trivy-checks:0": {},
}

for _, version := range deckhouseVersions {
Expand Down
1 change: 1 addition & 0 deletions pkg/libmirror/layouts/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func PullTrivyVulnerabilityDatabasesImages(
layouts.TrivyDB: path.Join(pullCtx.DeckhouseRegistryRepo, "security", "trivy-db:2"),
layouts.TrivyBDU: path.Join(pullCtx.DeckhouseRegistryRepo, "security", "trivy-bdu:1"),
layouts.TrivyJavaDB: path.Join(pullCtx.DeckhouseRegistryRepo, "security", "trivy-java-db:1"),
layouts.TrivyChecks: path.Join(pullCtx.DeckhouseRegistryRepo, "security", "trivy-checks:0"),
}

for dbImageLayout, imageRef := range dbImages {
Expand Down
6 changes: 6 additions & 0 deletions pkg/libmirror/layouts/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestPullTrivyVulnerabilityDatabaseImageSuccessSkipTLS(t *testing.T) {
deckhouseRepo + "/security/trivy-db:2",
deckhouseRepo + "/security/trivy-bdu:1",
deckhouseRepo + "/security/trivy-java-db:1",
deckhouseRepo + "/security/trivy-checks:0",
}

wantImages := make([]v1.Image, 0)
Expand All @@ -65,6 +66,7 @@ func TestPullTrivyVulnerabilityDatabaseImageSuccessSkipTLS(t *testing.T) {
TrivyDB: createEmptyOCILayout(t),
TrivyBDU: createEmptyOCILayout(t),
TrivyJavaDB: createEmptyOCILayout(t),
TrivyChecks: createEmptyOCILayout(t),
}

err := PullTrivyVulnerabilityDatabasesImages(
Expand Down Expand Up @@ -102,6 +104,7 @@ func TestPullTrivyVulnerabilityDatabaseImageSuccessInsecure(t *testing.T) {
deckhouseRepo + "/security/trivy-db:2",
deckhouseRepo + "/security/trivy-bdu:1",
deckhouseRepo + "/security/trivy-java-db:1",
deckhouseRepo + "/security/trivy-checks:0",
}

wantImages := make([]v1.Image, 0)
Expand All @@ -118,6 +121,7 @@ func TestPullTrivyVulnerabilityDatabaseImageSuccessInsecure(t *testing.T) {
TrivyDB: createEmptyOCILayout(t),
TrivyBDU: createEmptyOCILayout(t),
TrivyJavaDB: createEmptyOCILayout(t),
TrivyChecks: createEmptyOCILayout(t),
}

err := PullTrivyVulnerabilityDatabasesImages(
Expand Down Expand Up @@ -153,6 +157,8 @@ func layoutByIndex(t *testing.T, layouts *ImageLayouts, idx int) layout.Path {
return layouts.TrivyBDU
case 2:
return layouts.TrivyJavaDB
case 3:
return layouts.TrivyChecks
default:
t.Fatalf("Unexpected layout index, expected only [0-2], but got %d", idx)
return ""
Expand Down
1 change: 1 addition & 0 deletions pkg/libmirror/operations/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func findLayoutsToPush(mirrorCtx *contexts.PushContext) (map[string]layout.Path,
{"security", "trivy-db"},
{"security", "trivy-bdu"},
{"security", "trivy-java-db"},
{"security", "trivy-checks"},
}

for _, bundlePath := range bundlePaths {
Expand Down
1 change: 1 addition & 0 deletions testing/e2e/mirror/mirror_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func createTrivyVulnerabilityDatabasesInRegistry(t *testing.T, repo string, inse
repo + "/security/trivy-db:2",
repo + "/security/trivy-bdu:1",
repo + "/security/trivy-java-db:1",
repo + "/security/trivy-checks:0",
}

for _, image := range images {
Expand Down