trivy: bug(misconf): False positives for ksv116 and ksv104
Describe the bug
Trivy started reporting many false positives 3 hours ago after https://github.com/aquasecurity/defsec/pull/1386 was merged into main.
To Reproduce ksv116 Steps to reproduce the behavior:
- Create
clusterrole.yamlfile with these contents:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: test
rules:
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["clusterroles", "clusterrolebindings", "roles", "rolebindings"]
verbs: ["get", "list", "watch"]
- Scan the cluster role with trivy:
trivy fs --exit-code 1 --debug --scanners config clusterrole.yaml
Expected behavior Trivy doesn’t report any failures.
Output of your tfsec command with --debug flag
Trivy reports the cluster role is missing a securityContext, which doesn’t make sense because cluster roles can’t have a securityContext:
2023-07-28T17:50:02.796-0400 DEBUG Severities: ["UNKNOWN" "LOW" "MEDIUM" "HIGH" "CRITICAL"]
2023-07-28T17:50:02.801-0400 DEBUG cache dir: /home/user/.cache/trivy
2023-07-28T17:50:02.801-0400 INFO Misconfiguration scanning is enabled
2023-07-28T17:50:02.801-0400 DEBUG Policies successfully loaded from disk
2023-07-28T17:50:02.831-0400 DEBUG Walk the file tree rooted at 'clusterrole.yaml' in parallel
2023-07-28T17:50:02.831-0400 DEBUG Scanning Kubernetes files for misconfigurations...
2023-07-28T17:50:04.065-0400 DEBUG Scanning Helm files for misconfigurations...
2023-07-28T17:50:04.098-0400 DEBUG OS is not detected.
2023-07-28T17:50:04.098-0400 INFO Detected config files: 1
2023-07-28T17:50:04.098-0400 DEBUG Scanned config file: clusterrole.yaml
clusterrole.yaml (kubernetes)
Tests: 146 (SUCCESSES: 145, FAILURES: 1, EXCEPTIONS: 0)
Failures: 1 (UNKNOWN: 0, LOW: 1, MEDIUM: 0, HIGH: 0, CRITICAL: 0)
LOW: clusterrole test in default namespace should set spec.securityContext.runAsGroup, spec.securityContext.supplementalGroups[*] and spec.securityContext.fsGroup to integer greater than 0
══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
According to pod security standard 'Non-root groups', containers should be forbidden from running with a root primary or supplementary GID.
See https://avd.aquasec.com/misconfig/ksv116
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
To Reproduce ksv104 Steps to reproduce the behavior:
- Create
pod.yamlfile with these contents:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mydeployment
namespace: mynamespace
spec:
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
serviceAccountName: myserviceaccount
automountServiceAccountToken: true
containers:
- name: container
image: myregistry/mycontainer:myversion
resources:
limits:
cpu: "1"
memory: "1Gi"
requests:
cpu: "1"
memory: "1Gi"
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
securityContext:
seccompProfile:
type: RuntimeDefault
- Scan the pod with trivy:
trivy fs --exit-code 1 --debug --scanners config pod.yaml
Expected behavior Trivy doesn’t report any failures.
Output of your tfsec command with --debug flag Trivy reports the pod cannot set a seccomp profile to Unconfined but the pod already sets a seccomp profile to RuntimeDefault:
trivy fs --exit-code 1 --debug --scanners config pod.yaml
2023-07-28T17:59:47.883-0400 DEBUG Severities: ["UNKNOWN" "LOW" "MEDIUM" "HIGH" "CRITICAL"]
2023-07-28T17:59:47.888-0400 DEBUG cache dir: /home/user/.cache/trivy
2023-07-28T17:59:47.888-0400 INFO Misconfiguration scanning is enabled
2023-07-28T17:59:47.889-0400 DEBUG Policies successfully loaded from disk
2023-07-28T17:59:47.923-0400 DEBUG Walk the file tree rooted at 'pod.yaml' in parallel
2023-07-28T17:59:47.923-0400 DEBUG Scanning Helm files for misconfigurations...
2023-07-28T17:59:47.924-0400 DEBUG Scanning Kubernetes files for misconfigurations...
2023-07-28T17:59:49.424-0400 DEBUG OS is not detected.
2023-07-28T17:59:49.424-0400 INFO Detected config files: 1
2023-07-28T17:59:49.424-0400 DEBUG Scanned config file: pod.yaml
pod.yaml (kubernetes)
Tests: 146 (SUCCESSES: 144, FAILURES: 2, EXCEPTIONS: 0)
Failures: 2 (UNKNOWN: 0, LOW: 1, MEDIUM: 1, HIGH: 0, CRITICAL: 0)
MEDIUM: container container of deployment mydeployment in mynamespace namespace should specify a seccomp profile
══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Seccomp profile must not be explicitly set to 'Unconfined'.
See https://avd.aquasec.com/misconfig/ksv104
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
LOW: deployment mydeployment in mynamespace namespace should set spec.securityContext.runAsGroup, spec.securityContext.supplementalGroups[*] and spec.securityContext.fsGroup to integer greater than 0
══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
According to pod security standard 'Non-root groups', containers should be forbidden from running with a root primary or supplementary GID.
See https://avd.aquasec.com/misconfig/ksv116
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
System Info
- trivy version:
trivy --version
Version: 0.43.1
Vulnerability DB:
Version: 2
UpdatedAt: 2023-07-07 12:09:44.26531882 +0000 UTC
NextUpdate: 2023-07-07 18:09:44.26531842 +0000 UTC
DownloadedAt: 2023-07-07 14:18:17.949251153 +0000 UTC
Java DB:
Version: 1
UpdatedAt: 2023-05-22 01:03:23.3204665 +0000 UTC
NextUpdate: 2023-05-25 01:03:23.3204662 +0000 UTC
DownloadedAt: 2023-05-22 13:52:33.823587465 +0000 UTC
Policy Bundle:
Digest: sha256:acf1cb62a4ade75773ec3d265cc4d90160d285bbacaa7b6947a34830c1e45c5c
DownloadedAt: 2023-07-28 21:33:27.321098109 +0000 UTC
- OS:
uname -a
Linux user-Precision-5570 5.19.0-46-generic aquasecurity/defsec#47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 21 15:35:31 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 18 (9 by maintainers)
Commits related to this issue
- fix: fail for irrelevant resources reported in https://github.com/aquasecurity/trivy/issues/4922 since the failRootGroupId rule is given a default value, it doesn't fail the deny rule and results in ... — committed to itaysk/trivy-checks by itaysk 3 years ago
- fix: fail for irrelevant resources reported in https://github.com/aquasecurity/trivy/issues/4922 since the failRootGroupId rule is given a default value, it doesn't fail the deny rule and results in ... — committed to itaysk/trivy-checks by itaysk 3 years ago
I get a similar problem due to rule
ksv116, but is my case, it complains about K8s objects running as root, but these k8s objects do not have a securityContexttrivy command executed:
trivy config --severity LOW,MEDIUM,HIGH,CRITICAL --exit-code 1 yaml-k8s-filesExamples:
Another minor detail, the link recommended for additional details -> https://avd.aquasec.com/misconfig/ksv116 is broken, I get HTTP 404 back.
@simar7 what about the second issue (ksv104)?
Bumping this since we have the same problem. Has anyone managed to solve this without ignore?
trivy 0.46.0 - latest db (2023-10-26)
trivy fs --scanners=config,secret,license .deployment:
tried using different uids between spec.securityContext and containers[].securityContext
I have also the same issue. Can anyone from the contributors look into that issue deeper? @simar7