Skip to content

Trivy SARIF output includes non-existent file paths causing GitHub Code Scanning upload failures #471

@gabrielss4ntos

Description

@gabrielss4ntos

Hi,

We are encountering two distinct issues when trying to perform IaC scanning with Trivy and subsequently upload the results to GitHub Security Code Scanning.

Issue 1: When attempting to upload SARIF results generated by aquasecurity/trivy-action to GitHub Security Code Scanning, the github/codeql-action/upload-sarif action consistently fails with the error message: Code Scanning could not process the submitted SARIF file:

Code Scanning could not process the submitted SARIF file: locationFromSarifResult: expected artifact location

Image

I Think the issue occurs because Trivy generates SARIF entries for file paths that do not exist in the repository filesystem, causing GitHub Code Scanning to fail when attempting to compute fingerprints for these non-existent files.

Issue 2: In some executions, in this same Trivy repo, the scan fails with a fatal error indicating a timeout. I don't know if this timeout is specifically linked to the inability to download remote Terraform modules, I see several "Failed to load module" errors in the logs.

 - fs scan error:
    github.com/aquasecurity/trivy/pkg/commands/artifact.Run
        /home/runner/work/trivy/trivy/pkg/commands/artifact/run.go:402
  - scan error:
    github.com/aquasecurity/trivy/pkg/commands/artifact.(*runner).scanArtifact
        /home/runner/work/trivy/trivy/pkg/commands/artifact/run.go:261
  - scan failed:
    github.com/aquasecurity/trivy/pkg/commands/artifact.(*runner).scan
        /home/runner/work/trivy/trivy/pkg/commands/artifact/run.go:629
  - failed analysis:
    github.com/aquasecurity/trivy/pkg/scanner.Scanner.ScanArtifact
        /home/runner/work/trivy/trivy/pkg/scanner/scan.go:158
  - post analysis error:
    github.com/aquasecurity/trivy/pkg/fanal/artifact/local.Artifact.Inspect
        /home/runner/work/trivy/trivy/pkg/fanal/artifact/local/fs.go:205
  - post analysis error:
    github.com/aquasecurity/trivy/pkg/fanal/analyzer.AnalyzerGroup.PostAnalyze
        /home/runner/work/trivy/trivy/pkg/fanal/analyzer/analyzer.go:510
  - terraform scan error:
    github.com/aquasecurity/trivy/pkg/fanal/analyzer/config.(*Analyzer).PostAnalyze
        /home/runner/work/trivy/trivy/pkg/fanal/analyzer/config/config.go:46
  - scan config error:
    github.com/aquasecurity/trivy/pkg/misconf.(*Scanner).Scan
        /home/runner/work/trivy/trivy/pkg/misconf/scanner.go:158
  - context deadline exceeded

Has anyone encountered these two distinct issues and know how to fix them?

Any recommended way to run trivy+code-scanning in pipelines?

Environment

  • Trivy action version: aquasecurity/[email protected]
  • GitHub Actions runner: ubuntu-latest
  • Scan type: config
  • Output format: SARIF
  • Trigger: Pull Request workflows
  • Checkout: actions/checkout@v4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions