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

reordering trivy command #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

loganbest
Copy link

@loganbest loganbest commented Jun 28, 2024

I'm using this command

      - name: Run trivy with reviewdog output on the PR
        uses: reviewdog/action-trivy@v1
        with:
          github_token: ${{ secrets.github_token }}
          trivy_command: filesystem
          trivy_target: .
          level: info
          reporter: github-pr-review
          filter_mode: nofilter
          fail_on_error: true
          flags: -tee
          trivy_flags: "--scanners secret,misconfig --tf-exclude-downloaded-modules"

and the action is erroring with the following:

Run reviewdog/action-trivy@v1
Run $GITHUB_ACTION_PATH/script.sh
Preparing ...
🐶 Installing reviewdog (v0.18.1) ... https://github.com/reviewdog/reviewdog
  reviewdog/reviewdog info checking GitHub for tag 'v0.18.1'
  reviewdog/reviewdog info found version: 0.18.1 for v0.18.1/Linux/x86_64
  reviewdog/reviewdog info installed /tmp/tmp.PRlLJ5iEyi/reviewdog/reviewdog
 Installing trivy (latest) ... https://github.com/aquasecurity/trivy
  Downloading https://github.com/aquasecurity/trivy/releases/download/v0.52.2/trivy_0.52.2_Linux-64bit.tar.gz to trivy.tar.gz
  URL: https://github.com/aquasecurity/trivy/releases/download/v0.52.2/trivy_0.52.2_Linux-64bit.tar.gz
  ARCHIVE: trivy.tar.gz
  trivy.tar.gz
 Print trivy details ...
  Version: 0.52.2
 Running trivy with reviewdog 🐶 ...
  + /tmp/tmp.il4JLprYw9/trivy/trivy --format sarif --scanners secret,misconfig --tf-exclude-downloaded-modules --exit-code 1 filesystem .
  + /tmp/tmp.il4JLprYw9/reviewdog/reviewdog -f=sarif -name=trivy -reporter=github-pr-review -level=info -fail-on-error=true -filter-mode=nofilter -tee
  reviewdog: parse error: EOF
  + trivy_return=1
  + reviewdog_return=1
  + exit_code=1
  + echo trivy-return-code=1
  + echo reviewdog-return-code=1
  + echo ::endgroup::
  + exit 1
  ::endgroup::
Error: Process completed with exit code 1.

When running that trivy command locally I get a fatal error due to argument order:

trivy --format sarif --tf-exclude-downloaded-modules --exit-code 1 filesystem .
Error: unknown flag: --tf-exclude-downloaded-modules
<redacted help output>
2024-06-27T21:04:14-04:00	FATAL	Fatal error	unknown flag: --tf-exclude-downloaded-modules

After reordering the command this is the cleaned and proper output:

 Running trivy with reviewdog 🐶 ...
  + echo ::endgroup::
  + echo '::group:: Running trivy with reviewdog 🐶 ...'
  + export REVIEWDOG_GITHUB_API_TOKEN=***
  + REVIEWDOG_GITHUB_API_TOKEN=***
  + set +Eeuo pipefail
  + /tmp/tmp.PKxX84DdIx/trivy/trivy --format sarif filesystem --scanners secret,misconfig --tf-exclude-downloaded-modules --exit-code 1 .
  + /tmp/tmp.PKxX84DdIx/reviewdog/reviewdog -f=sarif -name=trivy -reporter=github-pr-review -level=info -fail-on-error=true -filter-mode=nofilter -tee
  {
    "version": "2.1.0",
    "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
    "runs": [
      {
        "tool": {
          "driver": {
            "fullName": "Trivy Vulnerability Scanner",
            "informationUri": "https://github.com/aquasecurity/trivy",
            "name": "Trivy",
            "rules": [],
            "version": "0.52.2"
          }
        },
        "results": [],
        "columnKind": "utf16CodeUnits",
        "originalUriBaseIds": {
          "ROOTPATH": {
            "uri": "file:///home/runner/work/terraform-aws-vpc/terraform-aws-vpc/"
          }
        }
      }
    ]
  + trivy_return=0
  + reviewdog_return=0
  + exit_code=0
  + echo trivy-return-code=0
  }::endgroup::
  + echo reviewdog-return-code=0
  + echo ::endgroup::
  + exit 0

@loganbest
Copy link
Author

@haya14busa @shogo82148 I'm not sure how to fix the Windows check that's failing. Any ideas on what I can do there?

@shogo82148
Copy link
Collaborator

It seems to be the impact of actions/runner-images#10009

@loganbest
Copy link
Author

It seems to be the impact of actions/runner-images#10009

Is that a blocker for this PR given everything else passes and it's a trivial change?

@haya14busa
Copy link
Member

Can you add a test case? https://github.com/reviewdog/action-trivy/blob/main/.github/workflows/tests.yml

Is that a blocker for this PR given everything else passes and it's a trivial change?

It's not a blocker. I'm fine to include your change. Thanks!

@haya14busa haya14busa mentioned this pull request Jun 29, 2024
@loganbest
Copy link
Author

Can you add a test case? https://github.com/reviewdog/action-trivy/blob/main/.github/workflows/tests.yml

Is that a blocker for this PR given everything else passes and it's a trivial change?

It's not a blocker. I'm fine to include your change. Thanks!

What am I writing a test case for exactly? The only valid thing I can think of is to check return codes which there's already a test case for, and I'm surprised didn't catch this previously since that's all that was returned this error.

@haya14busa
Copy link
Member

I'm surprised didn't catch this previously since that's all that was returned this error.

Me too. That's why I'm asking adding a test case which should fail without this pr change.
Maybe if trivy_command=config, it works but it won't work with filesystem?

@nayuta
Copy link
Contributor

nayuta commented Aug 21, 2024

I found that trivy already supports filesystem command. fs command is still supported so I added the test: 53cc527

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

Successfully merging this pull request may close these issues.

4 participants