trivy icon indicating copy to clipboard operation
trivy copied to clipboard

feat(k8s): filter kubernetes artifacts by REGO rules

Open afdesk opened this issue 1 year ago • 0 comments

Now Trivy k8s scan can filter k8s artifacts only by namespaces and/or kinds (nodes,pods etc).

There is an idea to add a new filter option, that allows to filter artifacts by custom REGO rules.

for example, customers can use it for skipping scan on deployments with 0 desired replicas.

reporoduction steps

Deployment with 0 replicase (replicas0.yaml)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deploy
  labels:
    app: my-k8s-application
spec:
  selector:
    matchLabels:
      project: myproj0
  replicas: 0
  template:
    metadata:
      labels:
        project: myproj0
    spec:
      containers:
      - name: container-py
        image: alpine:3.14.1
        command: [ "/bin/sh", "-c", "--" ]
        args: [ "while true; do sleep 30; done;"]
$ kind delete cluster --name zeroreplicas && kind create cluster --name zeroreplicas
$ kubectl apply -f replicas0.yaml

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

afdesk avatar Dec 11 '24 05:12 afdesk