Skip to content

bug(flag): --compliance uses the previous spec when Trivy updates the checks bundle #11690

Description

@nikpivkin

Trivy loads the built-in compliance spec before checking for a bundle update. When it downloads a new bundle during a scan, it runs the new checks but generates the report using the spec from the previous bundle.

Steps to reproduce

Reproduced on the branch from PR #11675, which makes built-in compliance specs respect --cache-dir.

  1. In trivy-checks, run make start-registry. Change the title in pkg/compliance/docker-cis-1.6.0.yaml to Local bundle A and run make push-bundle.

  2. In a separate working directory, create target/Dockerfile with FROM alpine:3.20. Run the following command to populate the cache.

    $ trivy config --cache-dir ./cache --checks-bundle-repository localhost:5111/trivy-checks:latest ./target
  3. In trivy-checks, change the same title to Local bundle B and run make push-bundle again.

  4. In the scan directory, set DownloadedAt in ./cache/policy/metadata.json to 2020-01-01T00:00:00Z so Trivy checks for an update on the next run.

Actual behavior

$ grep '^  title:' ./cache/policy/content/specs/compliance/docker-cis-1.6.0.yaml
  title: Local bundle A

$ trivy config --cache-dir ./cache --checks-bundle-repository localhost:5111/trivy-checks:latest --compliance docker-cis-1.6.0 --format json --output ./report.json ./target

$ grep '^  title:' ./cache/policy/content/specs/compliance/docker-cis-1.6.0.yaml
  title: Local bundle B

$ jq -r '.Title' ./report.json
Local bundle A

Expected behavior

Trivy should use the compliance spec from the same bundle as the checks. In this example, the report title should be Local bundle B.

Activity

  1. added
    kind/bug
    on Nov 19, 2026
  2. added theissue type on Nov 19, 2026
  3. Aakarsh133 commented on Nov 20, 2026

    @Aakarsh133
    Contributor

    Hey @nikpivkin, I believe this happens because the spec is already baked into opts.Compliance when it runs first and when the report is generated the bundle update is completely invisible to the report generator. We can either defer spec loading until after bundle download Or We can Reload the spec after bundle download.

    Once the other issues are done with, I can try working on this one

  4. Aakarsh133 commented on Nov 26, 2026

    @Aakarsh133
    Contributor

    Hey @nikpivkin, what do you think about this proposal? Should I take this one?

  5. nikpivkin commented on Nov 26, 2026

    @nikpivkin
    ContributorAuthor

    Your analysis of the cause is correct, but deferring won't work because the spec selects the scanners when flags are parsed, and the scanners decide whether the bundle is downloaded at all. Reload the spec after InitBuiltinChecks succeeds instead, and make sure trivy k8s gets the new copy too. Feel free to take it.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions