Skip to content

bug(flag): --compliance ignores --cache-dir #11666

Closed
prascli/trivy
#1

Description

@nikpivkin

--compliance with a built-in spec name always loads the spec from the checks bundle in the default cache directory, even when --cache-dir is set. Checks and node-collector commands come from the bundle in --cache-dir, so the spec and the commands can come from different bundles. If the default cache has no bundle, the spec embedded in the binary is used.

Steps to reproduce

  1. Download the checks bundle into a custom cache directory.
trivy image --cache-dir ./cache --compliance docker-cis-1.6.0 --report summary alpine:3.20
  1. Change the title of the spec in that bundle.
sed -i 's/^  title: .*/  title: Spec from the cache dir/' ./cache/policy/content/specs/compliance/docker-cis-1.6.0.yaml
  1. Run the scan again with the same cache directory.
trivy image --cache-dir ./cache --skip-check-update --compliance docker-cis-1.6.0 --report summary alpine:3.20

The report header is still Summary Report for compliance: CIS Docker Community Edition Benchmark v1.6.0. The expected header is Summary Report for compliance: Spec from the cache dir.

The cause is loadComplianceTypes in pkg/flag/report_flags.go. It passes cache.DefaultDir() to spec.GetComplianceSpec instead of the cache directory from the options.

Activity

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

    @Aakarsh133
    Contributor

    Hi! I would like to take this one.

    I traced it to loadComplianceTypes in pkg/flag/report_flags.go, which passes cache.DefaultDir() to spec.GetComplianceSpec instead of the configured cache dir. I believe the fix is to hand the folder you chose to the function that loads the checklist, instead of the default one. It is a one-line change, plus a test.

    I can work on a detailed plan and a PR shortly

  4. added
    good first issue
    on Nov 18, 2026
  5. nikpivkin commented on Nov 18, 2026

    @nikpivkin
    ContributorAuthor

    @Aakarsh133 You can take this.

  6. Aakarsh133 commented on Nov 18, 2026

    @Aakarsh133
    Contributor

    @nikpivkin just opened the above mentioned PR for the fix

  7. nikpivkin commented on Nov 19, 2026

    @nikpivkin
    ContributorAuthor

    #11675 fixes the --cache-dir handling for built-in compliance specs. Testing also surfaced a separate bug. When Trivy updates the checks bundle during a scan, the compliance report can still use the spec from the old bundle. I’d open a separate issue for that and fix it in a follow-up PR.

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

Metadata

Metadata

Assignees

Labels

good first issuekind/bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions