From a8ff5f06b54c1887eee0ddb51a0fc12ac56e4de5 Mon Sep 17 00:00:00 2001 From: Hirotaka Tagawa / wafuwafu13 Date: Wed, 12 Oct 2022 21:20:56 +0900 Subject: [PATCH] test(fs): add `--skip-files`, `--skip-dirs` (#2984) --- integration/fs_test.go | 32 +++++ integration/standalone_tar_test.go | 96 ++++++++++++- .../testdata/alpine-39-skip.json.golden | 49 +++++++ integration/testdata/gomod-skip.json.golden | 133 ++++++++++++++++++ 4 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 integration/testdata/alpine-39-skip.json.golden create mode 100644 integration/testdata/gomod-skip.json.golden diff --git a/integration/fs_test.go b/integration/fs_test.go index d1b5f58e3b..774d55ebb9 100644 --- a/integration/fs_test.go +++ b/integration/fs_test.go @@ -26,6 +26,8 @@ func TestFilesystem(t *testing.T) { filePatterns []string helmSet []string helmValuesFile []string + skipFiles []string + skipDirs []string } tests := []struct { name string @@ -40,6 +42,24 @@ func TestFilesystem(t *testing.T) { }, golden: "testdata/gomod.json.golden", }, + { + name: "gomod with skip files", + args: args{ + securityChecks: "vuln", + input: "testdata/fixtures/fs/gomod", + skipFiles: []string{"/testdata/fixtures/fs/gomod/submod2/go.mod"}, + }, + golden: "testdata/gomod-skip.json.golden", + }, + { + name: "gomod with skip dirs", + args: args{ + securityChecks: "vuln", + input: "testdata/fixtures/fs/gomod", + skipDirs: []string{"/testdata/fixtures/fs/gomod/submod2"}, + }, + golden: "testdata/gomod-skip.json.golden", + }, { name: "nodejs", args: args{ @@ -244,6 +264,18 @@ func TestFilesystem(t *testing.T) { } } + if len(tt.args.skipFiles) != 0 { + for _, skipFile := range tt.args.skipFiles { + osArgs = append(osArgs, "--skip-files", skipFile) + } + } + + if len(tt.args.skipDirs) != 0 { + for _, skipDir := range tt.args.skipDirs { + osArgs = append(osArgs, "--skip-dirs", skipDir) + } + } + // Setup the output file outputFile := filepath.Join(t.TempDir(), "output.json") if *update { diff --git a/integration/standalone_tar_test.go b/integration/standalone_tar_test.go index a980b950bd..f0ba2eb7ff 100644 --- a/integration/standalone_tar_test.go +++ b/integration/standalone_tar_test.go @@ -35,6 +35,101 @@ func TestTar(t *testing.T) { }, golden: "testdata/alpine-39.json.golden", }, + { + name: "alpine 3.9 with skip dirs", + testArgs: args{ + Format: "json", + Input: "testdata/fixtures/images/alpine-39.tar.gz", + SkipDirs: []string{ + "/etc", + }, + }, + golden: "testdata/alpine-39-skip.json.golden", + }, + { + name: "alpine 3.9 with skip files", + testArgs: args{ + Format: "json", + Input: "testdata/fixtures/images/alpine-39.tar.gz", + SkipFiles: []string{ + "/etc", + "/etc/TZ", + "/etc/alpine-release", + "/etc/apk", + "/etc/apk/arch", + "/etc/apk/keys", + "/etc/apk/keys/alpine-devel@lists.alpinelinux.org-4a6a0840.rsa.pub", + "/etc/apk/keys/alpine-devel@lists.alpinelinux.org-5243ef4b.rsa.pub", + "/etc/apk/keys/alpine-devel@lists.alpinelinux.org-5261cecb.rsa.pub", + "/etc/apk/protected_paths.d", + "/etc/apk/repositories", + "/etc/apk/world", + "/etc/conf.d", + "/etc/crontabs", + "/etc/crontabs/root", + "/etc/fstab", + "/etc/group", + "/etc/hostname", + "/etc/hosts", + "/etc/init.d", + "/etc/inittab", + "/etc/issue", + "/etc/logrotate.d", + "/etc/logrotate.d/acpid", + "/etc/modprobe.d", + "/etc/modprobe.d/aliases.conf", + "/etc/modprobe.d/blacklist.conf", + "/etc/modprobe.d/i386.conf", + "/etc/modprobe.d/kms.conf", + "/etc/modules", + "/etc/modules-load.d", + "/etc/motd", + "/etc/mtab", + "/etc/network", + "/etc/network/if-down.d", + "/etc/network/if-post-down.d", + "/etc/network/if-post-up.d", + "/etc/network/if-pre-down.d", + "/etc/network/if-pre-up.d", + "/etc/network/if-up.d", + "/etc/network/if-up.d/dad", + "/etc/opt", + "/etc/os-release", + "/etc/passwd", + "/etc/periodic", + "/etc/periodic/15min", + "/etc/periodic/daily", + "/etc/periodic/hourly", + "/etc/periodic/monthly", + "/etc/periodic/weekly", + "/etc/profile", + "/etc/profile.d", + "/etc/profile.d/color_prompt", + "/etc/protocols", + "/etc/securetty", + "/etc/services", + "/etc/shadow", + "/etc/shells", + "/etc/ssl", + "/etc/ssl/cert.pem", + "/etc/ssl/certs", + "/etc/ssl/ct_log_list.cnf", + "/etc/ssl/ct_log_list.cnf.dist", + "/etc/ssl/misc", + "/etc/ssl/misc/CA.pl", + "/etc/ssl/misc/tsget", + "/etc/ssl/misc/tsget.pl", + "/etc/ssl/openssl.cnf", + "/etc/ssl/openssl.cnf.dist", + "/etc/ssl/private", + "/etc/sysctl.conf", + "/etc/sysctl.d", + "/etc/sysctl.d/00-alpine.conf", + "/etc/udhcpd.conf", + }, + }, + golden: "testdata/alpine-39-skip.json.golden", + }, { name: "alpine 3.9 with high and critical severity", testArgs: args{ @@ -281,7 +376,6 @@ func TestTar(t *testing.T) { osArgs = append(osArgs, "--input", tt.testArgs.Input) } - // TODO: test skip files/dirs if len(tt.testArgs.SkipFiles) != 0 { for _, skipFile := range tt.testArgs.SkipFiles { osArgs = append(osArgs, "--skip-files", skipFile) diff --git a/integration/testdata/alpine-39-skip.json.golden b/integration/testdata/alpine-39-skip.json.golden new file mode 100644 index 0000000000..c3ad16e80c --- /dev/null +++ b/integration/testdata/alpine-39-skip.json.golden @@ -0,0 +1,49 @@ +{ + "SchemaVersion": 2, + "ArtifactName": "testdata/fixtures/images/alpine-39.tar.gz", + "ArtifactType": "container_image", + "Metadata": { + "OS": { + "Family": "none", + "Name": "" + }, + "ImageID": "sha256:055936d3920576da37aa9bc460d70c5f212028bda1c08c0879aedf03d7a66ea1", + "DiffIDs": [ + "sha256:f1b5933fe4b5f49bbe8258745cf396afe07e625bdab3168e364daf7c956b6b81" + ], + "ImageConfig": { + "architecture": "amd64", + "container": "c10d36fa368a7ea673683682666758adf35efe98e10989505f4f566b5b18538f", + "created": "2019-05-11T00:07:03.510395965Z", + "docker_version": "18.06.1-ce", + "history": [ + { + "created": "2019-05-11T00:07:03.358250803Z", + "created_by": "/bin/sh -c #(nop) ADD file:a86aea1f3a7d68f6ae03397b99ea77f2e9ee901c5c59e59f76f93adbb4035913 in / " + }, + { + "created": "2019-05-11T00:07:03.510395965Z", + "created_by": "/bin/sh -c #(nop) CMD [\"/bin/sh\"]", + "empty_layer": true + } + ], + "os": "linux", + "rootfs": { + "type": "layers", + "diff_ids": [ + "sha256:f1b5933fe4b5f49bbe8258745cf396afe07e625bdab3168e364daf7c956b6b81" + ] + }, + "config": { + "Cmd": [ + "/bin/sh" + ], + "Env": [ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + ], + "Image": "sha256:09f2bbe58e774849d74dc1391c2e01731896c745c4aba1ecf69a283bdb4b537a", + "ArgsEscaped": true + } + } + } +} diff --git a/integration/testdata/gomod-skip.json.golden b/integration/testdata/gomod-skip.json.golden new file mode 100644 index 0000000000..3d428ec00f --- /dev/null +++ b/integration/testdata/gomod-skip.json.golden @@ -0,0 +1,133 @@ +{ + "SchemaVersion": 2, + "ArtifactName": "testdata/fixtures/fs/gomod", + "ArtifactType": "filesystem", + "Metadata": { + "ImageConfig": { + "architecture": "", + "created": "0001-01-01T00:00:00Z", + "os": "", + "rootfs": { + "type": "", + "diff_ids": null + }, + "config": {} + } + }, + "Results": [ + { + "Target": "go.mod", + "Class": "lang-pkgs", + "Type": "gomod", + "Vulnerabilities": [ + { + "VulnerabilityID": "GMS-2022-20", + "PkgName": "github.com/docker/distribution", + "InstalledVersion": "2.7.1+incompatible", + "FixedVersion": "v2.8.0", + "Layer": {}, + "DataSource": { + "ID": "glad", + "Name": "GitLab Advisory Database Community", + "URL": "https://gitlab.com/gitlab-org/advisories-community" + }, + "Title": "OCI Manifest Type Confusion Issue", + "Description": "### Impact\n\nSystems that rely on digest equivalence for image attestations may be vulnerable to type confusion.", + "Severity": "UNKNOWN", + "References": [ + "https://github.com/advisories/GHSA-qq97-vm5h-rrhg", + "https://github.com/distribution/distribution/commit/b59a6f827947f9e0e67df0cfb571046de4733586", + "https://github.com/distribution/distribution/security/advisories/GHSA-qq97-vm5h-rrhg", + "https://github.com/opencontainers/image-spec/pull/411" + ] + }, + { + "VulnerabilityID": "CVE-2022-23628", + "PkgName": "github.com/open-policy-agent/opa", + "InstalledVersion": "0.35.0", + "FixedVersion": "0.37.0", + "Layer": {}, + "SeveritySource": "nvd", + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2022-23628", + "DataSource": { + "ID": "glad", + "Name": "GitLab Advisory Database Community", + "URL": "https://gitlab.com/gitlab-org/advisories-community" + }, + "Title": "Incorrect Calculation", + "Description": "OPA is an open source, general-purpose policy engine. Under certain conditions, pretty-printing an abstract syntax tree (AST) that contains synthetic nodes could change the logic of some statements by reordering array literals. Example of policies impacted are those that parse and compare web paths. **All of these** three conditions have to be met to create an adverse effect: 1. An AST of Rego had to be **created programmatically** such that it ends up containing terms without a location (such as wildcard variables). 2. The AST had to be **pretty-printed** using the `github.com/open-policy-agent/opa/format` package. 3. The result of the pretty-printing had to be **parsed and evaluated again** via an OPA instance using the bundles, or the Golang packages. If any of these three conditions are not met, you are not affected. Notably, all three would be true if using **optimized bundles**, i.e. bundles created with `opa build -O=1` or higher. In that case, the optimizer would fulfil condition (1.), the result of that would be pretty-printed when writing the bundle to disk, fulfilling (2.). When the bundle was then used, we'd satisfy (3.). As a workaround users may disable optimization when creating bundles.", + "Severity": "MEDIUM", + "CweIDs": [ + "CWE-682" + ], + "CVSS": { + "nvd": { + "V2Vector": "AV:N/AC:M/Au:N/C:N/I:P/A:N", + "V3Vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N", + "V2Score": 4.3, + "V3Score": 5.3 + } + }, + "References": [ + "https://github.com/advisories/GHSA-hcw3-j74m-qc58", + "https://github.com/open-policy-agent/opa/commit/932e4ffc37a590ace79e9b75ca4340288c220239", + "https://github.com/open-policy-agent/opa/commit/bfd984ddf93ef2c4963a08d4fdadae0bcf1a3717", + "https://github.com/open-policy-agent/opa/pull/3851", + "https://github.com/open-policy-agent/opa/security/advisories/GHSA-hcw3-j74m-qc58", + "https://nvd.nist.gov/vuln/detail/CVE-2022-23628" + ], + "PublishedDate": "2022-02-09T22:15:00Z", + "LastModifiedDate": "2022-02-17T02:37:00Z" + }, + { + "VulnerabilityID": "CVE-2021-38561", + "PkgName": "golang.org/x/text", + "InstalledVersion": "0.3.6", + "FixedVersion": "0.3.7", + "Layer": {}, + "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2021-38561", + "DataSource": { + "ID": "go-vulndb", + "Name": "The Go Vulnerability Database", + "URL": "https://github.com/golang/vulndb" + }, + "Description": "Due to improper index calculation, an incorrectly formatted language tag can cause Parse\nto panic via an out of bounds read. If Parse is used to process untrusted user inputs,\nthis may be used as a vector for a denial of service attack.\n", + "Severity": "UNKNOWN", + "References": [ + "https://go-review.googlesource.com/c/text/+/340830", + "https://go.googlesource.com/text/+/383b2e75a7a4198c42f8f87833eefb772868a56f", + "https://pkg.go.dev/vuln/GO-2021-0113" + ] + } + ] + }, + { + "Target": "submod/go.mod", + "Class": "lang-pkgs", + "Type": "gomod", + "Vulnerabilities": [ + { + "VulnerabilityID": "GMS-2022-20", + "PkgName": "github.com/docker/distribution", + "InstalledVersion": "2.7.1+incompatible", + "FixedVersion": "v2.8.0", + "Layer": {}, + "DataSource": { + "ID": "glad", + "Name": "GitLab Advisory Database Community", + "URL": "https://gitlab.com/gitlab-org/advisories-community" + }, + "Title": "OCI Manifest Type Confusion Issue", + "Description": "### Impact\n\nSystems that rely on digest equivalence for image attestations may be vulnerable to type confusion.", + "Severity": "UNKNOWN", + "References": [ + "https://github.com/advisories/GHSA-qq97-vm5h-rrhg", + "https://github.com/distribution/distribution/commit/b59a6f827947f9e0e67df0cfb571046de4733586", + "https://github.com/distribution/distribution/security/advisories/GHSA-qq97-vm5h-rrhg", + "https://github.com/opencontainers/image-spec/pull/411" + ] + } + ] + } + ] +}