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

add option to support only some directories #2

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8c3926d
keep system installed files in apk packages. Co-Authored-By: Sylvain …
AliDatadog Jun 23, 2023
c41fbb3
generate fixtures
AliDatadog Jun 23, 2023
efe897e
improve comment
AliDatadog Jun 23, 2023
eba1caf
update docs
AliDatadog Jun 23, 2023
631495c
test-repo.json.golden
AliDatadog Jun 23, 2023
3dc8a27
fix linting
AliDatadog Jun 23, 2023
ae19952
fix unit test broken by last commit
AliDatadog Jun 23, 2023
bf82795
update golden again
AliDatadog Jun 23, 2023
f1949f2
mage docs generate
AliDatadog Jun 26, 2023
2428082
apply suggestions from review
AliDatadog Jun 26, 2023
1a4b808
don't update golden files
AliDatadog Jun 26, 2023
cdd71bf
reupdate golden
AliDatadog Jun 26, 2023
0561e58
merge main + generate golden
AliDatadog Jun 26, 2023
6e73bbd
fix unit test
AliDatadog Jun 26, 2023
4335c27
fix unit tests
AliDatadog Jun 28, 2023
26d6e60
replace filepath.join by path.join
AliDatadog Jun 28, 2023
f934dc6
apply suggestions from code review
AliDatadog Jun 30, 2023
34e5a70
merge main
AliDatadog Jun 30, 2023
4be95a4
docs:generate
AliDatadog Jun 30, 2023
fea581b
update integration/testdata/conda-spdx.json.golden
AliDatadog Jun 30, 2023
3e70a8b
merge main
AliDatadog Jul 25, 2023
95907b5
fix unit test on macos
AliDatadog Jul 25, 2023
8a1bb06
minor code improvement
AliDatadog Jul 25, 2023
6b03699
move pkg analyzer inside the test
AliDatadog Jul 25, 2023
06f0d32
rename to retain system installed files
AliDatadog Aug 11, 2023
ed50682
merge main
AliDatadog Aug 11, 2023
3c2c22f
revert integration test change and regenerate doc without capital letter
AliDatadog Aug 11, 2023
79a64d0
Merge branch 'main' into ali/add-system-installed-files-pkg
AliDatadog Aug 16, 2023
1d5ff73
Apply suggestions from code review
AliDatadog Aug 23, 2023
27c4364
Update pkg/fanal/analyzer/pkg/apk/apk_test.go
AliDatadog Aug 24, 2023
3738931
change SystemInstalledFiles by PkgInstalledFiles almost everywhere
AliDatadog Aug 24, 2023
d948579
docs generate
AliDatadog Aug 24, 2023
a9c70e1
update golden
AliDatadog Aug 24, 2023
0fe38f9
Merge branch 'main' into ali/add-system-installed-files-pkg
AliDatadog Aug 24, 2023
ead16e7
fix unit test apk
AliDatadog Aug 24, 2023
9a78a27
keep SystemInstalledFiles name for AnalysisResult, remove RetainInsta…
AliDatadog Aug 24, 2023
b2f9bd9
Revert "keep SystemInstalledFiles name for AnalysisResult, remove Ret…
AliDatadog Aug 24, 2023
3901c9d
attempt to solve unit tests by copying the list of packages
AliDatadog Sep 7, 2023
7feadf1
Merge branch 'main' into ali/add-system-installed-files-pkg
AliDatadog Sep 29, 2023
536216f
fix unit test
AliDatadog Sep 29, 2023
442297b
add option to support only some directories
AliDatadog Sep 29, 2023
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
1 change: 1 addition & 0 deletions docs/docs/references/configuration/cli/trivy_filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ trivy filesystem [flags] PATH
--report string specify a compliance report format for the output (all,summary) (default "all")
--reset remove all caches and database
--reset-policy-bundle remove policy bundle
--retain-pkg-installed-files retains the files installed by each package in the analysis output when set to true
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (oci,rekor)
--scanners strings comma-separated list of what security issues to detect (vuln,config,secret,license) (default [vuln,secret])
--secret-config string specify a path to config file for secret scanning (default "trivy-secret.yaml")
Expand Down
1 change: 1 addition & 0 deletions docs/docs/references/configuration/cli/trivy_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ trivy image [flags] IMAGE_NAME
--report string specify a format for the compliance report. (all,summary) (default "summary")
--reset remove all caches and database
--reset-policy-bundle remove policy bundle
--retain-pkg-installed-files retains the files installed by each package in the analysis output when set to true
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (oci,rekor)
--scanners strings comma-separated list of what security issues to detect (vuln,config,secret,license) (default [vuln,secret])
--secret-config string specify a path to config file for secret scanning (default "trivy-secret.yaml")
Expand Down
1 change: 1 addition & 0 deletions docs/docs/references/configuration/cli/trivy_kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ trivy kubernetes [flags] { cluster | all | specific resources like kubectl. eg:
--report string specify a report format for the output (all,summary) (default "all")
--reset remove all caches and database
--reset-policy-bundle remove policy bundle
--retain-pkg-installed-files retains the files installed by each package in the analysis output when set to true
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (oci,rekor)
--scanners string comma-separated list of what security issues to detect (vuln,config,secret,license) (default "vuln,config,secret,rbac")
--secret-config string specify a path to config file for secret scanning (default "trivy-secret.yaml")
Expand Down
1 change: 1 addition & 0 deletions docs/docs/references/configuration/cli/trivy_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ trivy repository [flags] (REPO_PATH | REPO_URL)
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
--reset remove all caches and database
--reset-policy-bundle remove policy bundle
--retain-pkg-installed-files retains the files installed by each package in the analysis output when set to true
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (oci,rekor)
--scanners strings comma-separated list of what security issues to detect (vuln,config,secret,license) (default [vuln,secret])
--secret-config string specify a path to config file for secret scanning (default "trivy-secret.yaml")
Expand Down
1 change: 1 addition & 0 deletions docs/docs/references/configuration/cli/trivy_rootfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ trivy rootfs [flags] ROOTDIR
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
--reset remove all caches and database
--reset-policy-bundle remove policy bundle
--retain-pkg-installed-files retains the files installed by each package in the analysis output when set to true
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (oci,rekor)
--scanners strings comma-separated list of what security issues to detect (vuln,config,secret,license) (default [vuln,secret])
--secret-config string specify a path to config file for secret scanning (default "trivy-secret.yaml")
Expand Down
83 changes: 42 additions & 41 deletions docs/docs/references/configuration/cli/trivy_sbom.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,48 @@ trivy sbom [flags] SBOM_PATH
### Options

```
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--clear-cache clear image caches without scanning
--compliance string compliance report to generate
--custom-headers strings custom headers in client mode
--db-repository string OCI repository to retrieve trivy-db from (default "ghcr.io/aquasecurity/trivy-db")
--download-db-only download/update vulnerability database but don't run a scan
--download-java-db-only download/update Java index database but don't run a scan
--exit-code int specify exit code when any security issues are found
--exit-on-eol int exit with the specified code when the OS reaches end of service/life
--file-patterns strings specify config file patterns
-f, --format string format (table,json,template,sarif,cyclonedx,spdx,spdx-json,github,cosign-vuln) (default "table")
-h, --help help for sbom
--ignore-policy string specify the Rego file path to evaluate each vulnerability
--ignore-status strings comma-separated list of vulnerability status to ignore (unknown,not_affected,affected,fixed,under_investigation,will_not_fix,fix_deferred,end_of_life)
--ignore-unfixed display only fixed vulnerabilities
--ignorefile string specify .trivyignore file (default ".trivyignore")
--java-db-repository string OCI repository to retrieve trivy-java-db from (default "ghcr.io/aquasecurity/trivy-java-db")
--list-all-pkgs enabling the option will output all packages regardless of vulnerability
--no-progress suppress progress bar
--offline-scan do not issue API requests to identify dependencies
-o, --output string output file name
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
--redis-key string redis key file location, if using redis as cache backend
--redis-tls enable redis TLS with public certificates, if using redis as cache backend
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
--reset remove all caches and database
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (oci,rekor)
--server string server address in client mode
-s, --severity strings severities of security issues to be displayed (UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL) (default [UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL])
--skip-db-update skip updating vulnerability database
--skip-dirs strings specify the directories or glob patterns to skip
--skip-files strings specify the files or glob patterns to skip
--skip-java-db-update skip updating Java index database
--slow scan over time with lower CPU and memory utilization
-t, --template string output template
--token string for authentication in client/server mode
--token-header string specify a header name for token in client/server mode (default "Trivy-Token")
--vex string [EXPERIMENTAL] file path to VEX
--vuln-type strings comma-separated list of vulnerability types (os,library) (default [os,library])
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--clear-cache clear image caches without scanning
--compliance string compliance report to generate
--custom-headers strings custom headers in client mode
--db-repository string OCI repository to retrieve trivy-db from (default "ghcr.io/aquasecurity/trivy-db")
--download-db-only download/update vulnerability database but don't run a scan
--download-java-db-only download/update Java index database but don't run a scan
--exit-code int specify exit code when any security issues are found
--exit-on-eol int exit with the specified code when the OS reaches end of service/life
--file-patterns strings specify config file patterns
-f, --format string format (table,json,template,sarif,cyclonedx,spdx,spdx-json,github,cosign-vuln) (default "table")
-h, --help help for sbom
--ignore-policy string specify the Rego file path to evaluate each vulnerability
--ignore-status strings comma-separated list of vulnerability status to ignore (unknown,not_affected,affected,fixed,under_investigation,will_not_fix,fix_deferred,end_of_life)
--ignore-unfixed display only fixed vulnerabilities
--ignorefile string specify .trivyignore file (default ".trivyignore")
--java-db-repository string OCI repository to retrieve trivy-java-db from (default "ghcr.io/aquasecurity/trivy-java-db")
--list-all-pkgs enabling the option will output all packages regardless of vulnerability
--no-progress suppress progress bar
--offline-scan do not issue API requests to identify dependencies
-o, --output string output file name
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
--redis-key string redis key file location, if using redis as cache backend
--redis-tls enable redis TLS with public certificates, if using redis as cache backend
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
--reset remove all caches and database
--retain-pkg-installed-files retains the files installed by each package in the analysis output when set to true
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (oci,rekor)
--server string server address in client mode
-s, --severity strings severities of security issues to be displayed (UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL) (default [UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL])
--skip-db-update skip updating vulnerability database
--skip-dirs strings specify the directories or glob patterns to skip
--skip-files strings specify the files or glob patterns to skip
--skip-java-db-update skip updating Java index database
--slow scan over time with lower CPU and memory utilization
-t, --template string output template
--token string for authentication in client/server mode
--token-header string specify a header name for token in client/server mode (default "Trivy-Token")
--vex string [EXPERIMENTAL] file path to VEX
--vuln-type strings comma-separated list of vulnerability types (os,library) (default [os,library])
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions docs/docs/references/configuration/cli/trivy_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ trivy vm [flags] VM_IMAGE
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
--reset remove all caches and database
--reset-policy-bundle remove policy bundle
--retain-pkg-installed-files retains the files installed by each package in the analysis output when set to true
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (oci,rekor)
--scanners strings comma-separated list of what security issues to detect (vuln,config,secret,license) (default [vuln,secret])
--secret-config string specify a path to config file for secret scanning (default "trivy-secret.yaml")
Expand Down
16 changes: 8 additions & 8 deletions integration/testdata/conda-spdx.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "testdata/fixtures/repo/conda",
"documentNamespace": "http://aquasecurity.github.io/trivy/filesystem/testdata/fixtures/repo/conda-08df146c-0996-4718-8648-b2a45769ab79",
"documentNamespace": "http://aquasecurity.github.io/trivy/filesystem/testdata/fixtures/repo/conda-3ff14136-e09f-4df9-80ea-000000000001",
"creationInfo": {
"licenseListVersion": "",
"creators": [
"Organization: aquasecurity",
"Tool: trivy-dev"
],
"created": "2023-06-27T05:37:40Z"
"created": "2020-09-10T14:20:30Z"
},
"packages": [
{
Expand All @@ -23,7 +23,7 @@
},
{
"name": "openssl",
"SPDXID": "SPDXRef-Package-950f99cb9edd281",
"SPDXID": "SPDXRef-Package-c75d9dc75200186f",
"versionInfo": "1.1.1q",
"supplier": "NOASSERTION",
"downloadLocation": "NONE",
Expand All @@ -41,7 +41,7 @@
},
{
"name": "pip",
"SPDXID": "SPDXRef-Package-39020c06af94ca53",
"SPDXID": "SPDXRef-Package-195557cddf18e4a9",
"versionInfo": "22.2.2",
"supplier": "NOASSERTION",
"downloadLocation": "NONE",
Expand Down Expand Up @@ -105,21 +105,21 @@
},
{
"spdxElementId": "SPDXRef-Application-ee5ef1aa4ac89125",
"relatedSpdxElement": "SPDXRef-Package-950f99cb9edd281",
"relatedSpdxElement": "SPDXRef-Package-c75d9dc75200186f",
"relationshipType": "CONTAINS"
},
{
"spdxElementId": "SPDXRef-Package-950f99cb9edd281",
"spdxElementId": "SPDXRef-Package-c75d9dc75200186f",
"relatedSpdxElement": "SPDXRef-File-600e5e0110a84891",
"relationshipType": "CONTAINS"
},
{
"spdxElementId": "SPDXRef-Application-ee5ef1aa4ac89125",
"relatedSpdxElement": "SPDXRef-Package-39020c06af94ca53",
"relatedSpdxElement": "SPDXRef-Package-195557cddf18e4a9",
"relationshipType": "CONTAINS"
},
{
"spdxElementId": "SPDXRef-Package-39020c06af94ca53",
"spdxElementId": "SPDXRef-Package-195557cddf18e4a9",
"relatedSpdxElement": "SPDXRef-File-7eb62e2a3edddc0a",
"relationshipType": "CONTAINS"
}
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ func NewConfigCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
SkipDirs: &flag.SkipDirsFlag,
SkipFiles: &flag.SkipFilesFlag,
FilePatterns: &flag.FilePatternsFlag,
OnlyDirs: &flag.OnlyDirsFlag,
}

configFlags := &flag.Flags{
Expand Down
5 changes: 5 additions & 0 deletions pkg/commands/artifact/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi
DisabledAnalyzers: disabledAnalyzers(opts),
SkipFiles: opts.SkipFiles,
SkipDirs: opts.SkipDirs,
OnlyDirs: opts.OnlyDirs,
FilePatterns: opts.FilePatterns,
Offline: opts.OfflineScan,
NoProgress: opts.NoProgress || opts.Quiet,
Expand Down Expand Up @@ -664,6 +665,10 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi
Full: opts.LicenseFull,
ClassifierConfidenceLevel: opts.LicenseConfidenceLevel,
},

// Retains the package's installed in the package information of
// the analysis result
RetainPkgInstalledFiles: opts.RetainPkgInstalledFiles,
},
}, scanOptions, nil
}
Expand Down
27 changes: 15 additions & 12 deletions pkg/fanal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,21 @@ type PostAnalysisInput struct {
type AnalysisOptions struct {
Offline bool
FileChecksum bool

// retain package installed files in the analysis result
RetainPkgInstalledFiles bool
}

type AnalysisResult struct {
m sync.Mutex
OS types.OS
Repository *types.Repository
PackageInfos []types.PackageInfo
Applications []types.Application
Misconfigurations []types.Misconfiguration
Secrets []types.Secret
Licenses []types.LicenseFile
SystemInstalledFiles []string // A list of files installed by OS package manager
m sync.Mutex
OS types.OS
Repository *types.Repository
PackageInfos []types.PackageInfo
Applications []types.Application
Misconfigurations []types.Misconfiguration
Secrets []types.Secret
Licenses []types.LicenseFile
PkgInstalledFiles []string // A list of files installed by OS package manager

// Digests contains SHA-256 digests of unpackaged files
// used to search for SBOM attestation.
Expand All @@ -178,7 +181,7 @@ func NewAnalysisResult() *AnalysisResult {

func (r *AnalysisResult) isEmpty() bool {
return lo.IsEmpty(r.OS) && r.Repository == nil && len(r.PackageInfos) == 0 && len(r.Applications) == 0 &&
len(r.Misconfigurations) == 0 && len(r.Secrets) == 0 && len(r.Licenses) == 0 && len(r.SystemInstalledFiles) == 0 &&
len(r.Misconfigurations) == 0 && len(r.Secrets) == 0 && len(r.Licenses) == 0 && len(r.PkgInstalledFiles) == 0 &&
r.BuildInfo == nil && len(r.Digests) == 0 && len(r.CustomResources) == 0
}

Expand Down Expand Up @@ -272,7 +275,7 @@ func (r *AnalysisResult) Merge(new *AnalysisResult) {
r.Misconfigurations = append(r.Misconfigurations, new.Misconfigurations...)
r.Secrets = append(r.Secrets, new.Secrets...)
r.Licenses = append(r.Licenses, new.Licenses...)
r.SystemInstalledFiles = append(r.SystemInstalledFiles, new.SystemInstalledFiles...)
r.PkgInstalledFiles = append(r.PkgInstalledFiles, new.PkgInstalledFiles...)

if new.BuildInfo != nil {
if r.BuildInfo == nil {
Expand Down Expand Up @@ -470,7 +473,7 @@ func (ag AnalyzerGroup) PostAnalyze(ctx context.Context, compositeFS *CompositeF
continue
}

skippedFiles := result.SystemInstalledFiles
skippedFiles := result.PkgInstalledFiles
for _, app := range result.Applications {
skippedFiles = append(skippedFiles, app.FilePath)
for _, lib := range app.Libraries {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func TestAnalyzerGroup_AnalyzeFile(t *testing.T) {
},
},
},
SystemInstalledFiles: []string{
PkgInstalledFiles: []string{
"lib/libc.musl-x86_64.so.1",
"lib/ld-musl-x86_64.so.1",
},
Expand Down
Loading
Loading