Skip to content

feat: add support for .trivyignore.yaml - #5070

Merged
knqyf263 merged 11 commits into
aquasecurity:mainfrom
knqyf263:feat/trivyignore_yaml
Aug 31, 2023
Merged

knqyf263 merged 11 commits into
aquasecurity:mainfrom
knqyf263:feat/trivyignore_yaml

Conversation

@knqyf263

@knqyf263 knqyf263 commented Aug 30, 2023

Copy link
Copy Markdown
Collaborator

Description

Support the structured ignore file.

Example:

$ cat .trivyignore.yaml
vulnerabilities:
  - id: CVE-2023-30861
    paths:
      - "pkg/fanal/analyzer/language/python/poetry/testdata/happy/poetry.lock"
      - "pkg/fanal/analyzer/language/python/pip/testdata/requirements.txt"
    statement: Accept the risk
  - id: CVE-2023-37920
  - id: GHSA-5crp-9r3c-p9vr
     expired_at: 2023-09-01

misconfigurations:
  - id: AVD-DS-0002
  - id: AVD-DS-0003
     paths:
       - docs/Dockerfile
     statement: The container image is not deployed

It is still experimental since we're aware of more requirements around ignoring and possibly adding breaking changes. Thus, the file path must be explicitly specified as below so that it will not break compatibility.

$ trivy repo --ignorefile .trivyignore.yaml .

If the file extension is .yml or .yaml, Trivy tries to parse that in the YAML format. Otherwise, it is treated as the legacy .trivyignore.

TODOs

  • Support .trivyignore.yaml
  • Backward compatibility
  • Write tests
  • Write docs

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@knqyf263 knqyf263 self-assigned this Aug 30, 2023
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Comment thread pkg/result/ignore.go
Comment thread pkg/result/ignore.go Outdated

func (findings IgnoreFindings) Match(path, id string) bool {
for _, finding := range findings {
if len(finding.Paths) != 0 && !slices.Contains(finding.Paths, path) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we want to use wildcard for paths?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget: we need to update docs if we don't add wildcards.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added c624be4

knqyf263 and others added 8 commits August 31, 2023 09:38
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
@knqyf263
knqyf263 marked this pull request as ready for review August 31, 2023 10:14
@knqyf263
knqyf263 requested a review from simar7 as a code owner August 31, 2023 10:14
Signed-off-by: knqyf263 <knqyf263@gmail.com>

@DmitriyLewen DmitriyLewen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report vulnerability filtering: support scoped ignores

2 participants