trivy icon indicating copy to clipboard operation
trivy copied to clipboard

fix(checks): False positive for AVD-KSV-0033 and AVD-KSV-0035 when using Azure CR

Open simar7 opened this issue 8 months ago • 1 comments

Discussed in https://github.com/aquasecurity/trivy/discussions/8726

Originally posted by creste April 11, 2025

IDs

AVD-KSV-0033 AVD-KSV-0035

Description

With this job:

apiVersion: batch/v1
kind: Job
metadata:
  name: test
  namespace: test
spec:
  template:
    spec:
      containers:
        - name: test
          image:  test.azurecr.io/test:latest

The latest version of trivy-checks reports:

AVD-KSV-0035 (MEDIUM): Container 'test' of Job 'test' should restrict images to own ECR repository. See the full ECR list here: https://docs.aws.amazon.com/general/latest/gr/ecr.html
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Container images from non-ECR registries should be forbidden.

See https://avd.aquasec.com/misconfig/ksv035
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 kubernetes/test.yaml:10-11
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  10 ┌         - name: test
  11 └           image:  test.azurecr.io/test:latest
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

The job does not use ECR. It uses Azure CR instead. trivy-checks should not report this issue for non-AWS environments.

Reproduction Steps

1. Create a `test.yaml` file containing the k8s job specified in the Description above.
2. Run `trivy config test.yaml` to scan the YAML file.

Target

Filesystem

Scanner

Misconfiguration

Target OS

No response

Debug Output

$ trivy config --debug test.yaml 
2025-04-11T10:21:14-04:00	DEBUG	No plugins loaded
2025-04-11T10:21:14-04:00	DEBUG	Default config file "file_path=trivy.yaml" not found, using built in values
2025-04-11T10:21:14-04:00	DEBUG	Cache dir	dir="/home/test/.cache/trivy"
2025-04-11T10:21:14-04:00	DEBUG	Cache dir	dir="/home/test/.cache/trivy"
2025-04-11T10:21:14-04:00	DEBUG	Parsed severities	severities=[UNKNOWN LOW MEDIUM HIGH CRITICAL]
2025-04-11T10:21:14-04:00	INFO	[misconfig] Misconfiguration scanning is enabled
2025-04-11T10:21:14-04:00	DEBUG	[misconfig] Checks successfully loaded from disk
2025-04-11T10:21:14-04:00	DEBUG	Enabling misconfiguration scanners	scanners=[azure-arm cloudformation dockerfile helm kubernetes terraform terraformplan-json terraformplan-snapshot]
2025-04-11T10:21:14-04:00	DEBUG	Initializing scan cache...	type="memory"
2025-04-11T10:21:14-04:00	DEBUG	[fs] Analyzing...	root="test.yaml"
2025-04-11T10:21:14-04:00	DEBUG	[fs] Random cache key will be used	err="failed to open git repository: stat /home/test/test.yaml/.git: not a directory"
2025-04-11T10:21:14-04:00	DEBUG	[misconfig] Scanning files for misconfigurations...	scanner="Kubernetes"
2025-04-11T10:21:15-04:00	DEBUG	[rego] Overriding filesystem for checks
2025-04-11T10:21:15-04:00	DEBUG	[rego] Embedded libraries are loaded	count=17
2025-04-11T10:21:15-04:00	DEBUG	[rego] Embedded checks are loaded	count=516
2025-04-11T10:21:15-04:00	DEBUG	[rego] Checks from disk are loaded	count=533
2025-04-11T10:21:15-04:00	DEBUG	[rego] Overriding filesystem for data
2025-04-11T10:21:15-04:00	DEBUG	[kubernetes scanner] Scanning files...	count=1
2025-04-11T10:21:15-04:00	DEBUG	[rego] Scanning inputs	count=1
2025-04-11T10:21:15-04:00	DEBUG	[misconfig] Scanning files for misconfigurations...	scanner="Helm"
2025-04-11T10:21:15-04:00	DEBUG	[rego] Overriding filesystem for checks
2025-04-11T10:21:15-04:00	DEBUG	[rego] Embedded libraries are loaded	count=17
2025-04-11T10:21:15-04:00	DEBUG	[rego] Embedded checks are loaded	count=516
2025-04-11T10:21:15-04:00	DEBUG	[rego] Checks from disk are loaded	count=533
2025-04-11T10:21:15-04:00	DEBUG	[rego] Overriding filesystem for data
2025-04-11T10:21:15-04:00	DEBUG	OS is not detected.
2025-04-11T10:21:15-04:00	INFO	Detected config files	num=1
2025-04-11T10:21:15-04:00	DEBUG	Scanned config file	file_path="test.yaml"
2025-04-11T10:21:15-04:00	DEBUG	Specified ignore file does not exist	file=".trivyignore"
2025-04-11T10:21:15-04:00	DEBUG	[vex] VEX filtering is disabled

Report Summary

┌───────────┬────────────┬───────────────────┐
│  Target   │    Type    │ Misconfigurations │
├───────────┼────────────┼───────────────────┤
│ test.yaml │ kubernetes │        20         │
└───────────┴────────────┴───────────────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)


test.yaml (kubernetes)

Tests: 100 (SUCCESSES: 80, FAILURES: 20)
Failures: 20 (UNKNOWN: 0, LOW: 12, MEDIUM: 6, HIGH: 2, CRITICAL: 0)

... SNIP ...

AVD-KSV-0035 (MEDIUM): Container 'test' of Job 'test' should restrict images to own ECR repository. See the full ECR list here: https://docs.aws.amazon.com/general/latest/gr/ecr.html
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Container images from non-ECR registries should be forbidden.

See https://avd.aquasec.com/misconfig/ksv035
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 test.yaml:10-11
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  10 ┌         - name: test
  11 └           image:  test.azurecr.io/test:latest
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

... SNIP ...

Version

$ trivy --version
Version: 0.61.0
Vulnerability DB:
  Version: 2
  UpdatedAt: 2025-03-12 12:20:38.18587118 +0000 UTC
  NextUpdate: 2025-03-13 12:20:38.185870879 +0000 UTC
  DownloadedAt: 2025-03-12 15:19:33.379000954 +0000 UTC
Java DB:
  Version: 1
  UpdatedAt: 2025-02-14 02:24:51.921228254 +0000 UTC
  NextUpdate: 2025-02-17 02:24:51.921228094 +0000 UTC
  DownloadedAt: 2025-02-24 21:53:33.569172442 +0000 UTC
Check Bundle:
  Digest: sha256:40facaecbac0958cc77e7081820f92b9a2d8c0ce2d0310a120f3275aae046863
  DownloadedAt: 2025-04-11 13:52:50.90995531 +0000 UTC

Checklist

simar7 avatar Apr 12 '25 03:04 simar7

Can this be been prioritised yet for any future release?

ankur-kapoor-uk avatar May 07 '25 07:05 ankur-kapoor-uk

Fixed via https://github.com/aquasecurity/trivy-checks/pull/391

simar7 avatar May 27 '25 05:05 simar7

@simar7 - This is still broken in trivy-checks v1.11.1:

trivy config --debug --checks-bundle-repository ghcr.io/aquasecurity/trivy-checks:1.11.1 test.yaml
2025-05-29T09:41:13-04:00	DEBUG	No plugins loaded
2025-05-29T09:41:13-04:00	DEBUG	Default config file "file_path=trivy.yaml" not found, using built in values
2025-05-29T09:41:13-04:00	DEBUG	Cache dir	dir="/home/user/.cache/trivy"
2025-05-29T09:41:13-04:00	DEBUG	Cache dir	dir="/home/user/.cache/trivy"
2025-05-29T09:41:13-04:00	DEBUG	Parsed severities	severities=[UNKNOWN LOW MEDIUM HIGH CRITICAL]
2025-05-29T09:41:13-04:00	INFO	[misconfig] Misconfiguration scanning is enabled
2025-05-29T09:41:13-04:00	DEBUG	[misconfig] Failed to open the check metadata	err="open /home/user/.cache/trivy/policy/metadata.json: no such file or directory"
2025-05-29T09:41:13-04:00	INFO	[misconfig] Need to update the checks bundle
2025-05-29T09:41:13-04:00	INFO	[misconfig] Downloading the checks bundle...
2025-05-29T09:41:13-04:00	DEBUG	[misconfig] Loading check bundle	repository="ghcr.io/aquasecurity/trivy-checks:1.11.1"
165.20 KiB / 165.20 KiB [-----------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s 100ms
2025-05-29T09:41:14-04:00	DEBUG	[misconfig] Digest of the built-in checks	digest="sha256:bf1d09c69083c7f3bb5934b5e375fc351ed7ce20cae69e8b29b2e18aa9e325a0"
2025-05-29T09:41:14-04:00	DEBUG	[misconfig] Checks successfully loaded from disk
2025-05-29T09:41:14-04:00	DEBUG	[rego] Overriding filesystem for checks
2025-05-29T09:41:14-04:00	DEBUG	[rego] Embedded libraries are loaded	count=17
2025-05-29T09:41:14-04:00	DEBUG	[rego] Embedded checks are loaded	count=517
2025-05-29T09:41:14-04:00	DEBUG	[rego] Checks from disk are loaded	count=536
2025-05-29T09:41:14-04:00	DEBUG	[rego] Overriding filesystem for data
2025-05-29T09:41:14-04:00	DEBUG	Enabling misconfiguration scanners	scanners=[azure-arm cloudformation dockerfile helm kubernetes terraform terraformplan-json terraformplan-snapshot]
2025-05-29T09:41:14-04:00	DEBUG	Initializing scan cache...	type="memory"
2025-05-29T09:41:14-04:00	DEBUG	[fs] Analyzing...	root="test.yaml"
2025-05-29T09:41:14-04:00	DEBUG	[fs] Random cache key will be used	err="failed to open git repository: stat /home/user/tmp/trivytest/test.yaml/.git: not a directory"
2025-05-29T09:41:14-04:00	DEBUG	[misconfig] Scanning files for misconfigurations...	scanner="Helm"
2025-05-29T09:41:14-04:00	DEBUG	[misconfig] Scanning files for misconfigurations...	scanner="Kubernetes"
2025-05-29T09:41:14-04:00	DEBUG	[kubernetes scanner] Scanning files...	count=1
2025-05-29T09:41:14-04:00	DEBUG	[rego] Scanning inputs	count=1
2025-05-29T09:41:14-04:00	DEBUG	OS is not detected.
2025-05-29T09:41:14-04:00	INFO	Detected config files	num=1
2025-05-29T09:41:14-04:00	DEBUG	Scanned config file	file_path="test.yaml"
2025-05-29T09:41:14-04:00	DEBUG	Specified ignore file does not exist	file=".trivyignore"
2025-05-29T09:41:14-04:00	DEBUG	[vex] VEX filtering is disabled
...
AVD-KSV-0033 (MEDIUM): container test of job test in test namespace should restrict container image to your specific registry domain. See the full GCR list here: https://cloud.google.com/container-registry/docs/overview#registries
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Containers should only use images from trusted GCR registries.

See https://avd.aquasec.com/misconfig/ksv033
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 test.yaml:10-11
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  10 ┌         - name: test
  11 └           image:  test.azurecr.io/test:latest
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────


AVD-KSV-0035 (MEDIUM): Container 'test' of Job 'test' should restrict images to own ECR repository. See the full ECR list here: https://docs.aws.amazon.com/general/latest/gr/ecr.html
════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Container images from non-ECR registries should be forbidden.

See https://avd.aquasec.com/misconfig/ksv035
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 test.yaml:10-11
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  10 ┌         - name: test
  11 └           image:  test.azurecr.io/test:latest
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Trivy version:

$ trivy --version
Version: 0.62.1
Check Bundle:
  Digest: sha256:bf1d09c69083c7f3bb5934b5e375fc351ed7ce20cae69e8b29b2e18aa9e325a0
  DownloadedAt: 2025-05-29 13:41:14.027317663 +0000 UTC

creste avatar May 29 '25 13:05 creste

Hi @creste !

Thanks for the find! I opened a PR with the fix.

nikpivkin avatar May 29 '25 15:05 nikpivkin

@nikpivkin - Thank you! I upgraded Trivy to 0.63.0 and confirmed this is fixed now.

creste avatar May 29 '25 18:05 creste