Repository navigation
Closed
Labels
Description
🐞 Bug report
Describe the bug
Despite setting inheritLabels = false, the cascading Scans still include the parent scan's labels
I'm using Grafana Tanka which relies on injecting a label "tanka.dev/environment: " in order to "prune" objects within an environment, if the scans inherit this label it will force an unwanted deletion of the cascading scans
Steps To Reproduce
Execute any cascading scan with inheritlabels: false, I launched an nmap scan:
spec:
cascades:
inheritLabels: false
matchExpressions:
- key: securecodebox.io/intensive
operator: In
values:
- light
- medium
- high
- key: securecodebox.io/invasive
operator: In
values:
- non-invasive
- invasive
parameters:
- scan.me
scanType: nmap
The Scan objects that get created through cascades, include the original scan's labels
apiVersion: execution.securecodebox.io/v1
kind: Scan
metadata:
annotations:
cascading.securecodebox.io/chain: securecodebox-scanners-zap-https
cascading.securecodebox.io/matched-finding: 99652536-76a7-471e-afef-a5da7d79c62f
cascading.securecodebox.io/parent-scan: securecodebox-scanners-network
securecodebox.io/hook: cascading-scans
creationTimestamp: "2021-09-29T00:18:17Z"
finalizers:
- s3.storage.securecodebox.io
generateName: securecodebox-scanners-network-securecodebox-scanners-zap-https-
generation: 2
labels:
tanka.dev/environment: 6a2b816247aad89622120ae34db00790e8b0e49713341819
name: securecodebox-scanners-network-securecodebox-scanners-zap-6dmpw
namespace: nonprod-alldevopsservices
ownerReferences:
- apiVersion: execution.securecodebox.io/v1
blockOwnerDeletion: true
controller: true
kind: Scan
name: securecodebox-scanners-network
uid: 6069b242-e596-48a4-8e61-b52c38f8a02c
resourceVersion: "497099"
uid: 10d779f7-2fda-4bd7-ae49-0802af0e655e
spec:
cascades:
matchExpressions:
- key: securecodebox.io/intensive
operator: In
values:
- light
- medium
- high
- key: securecodebox.io/invasive
operator: In
values:
- non-invasive
- invasive
parameters:
- -t
- https://scan.me
scanType: zap-advanced-scan
status:
findingDownloadLink: ...
findings:
severities: {}
rawResultDownloadLink: ...
rawResultFile: zap-results.xml
rawResultType: zap-advanced-xml
state: ScanningExpected behavior
Not the Scan nor the backing pod should inherit the parent scan's labels when inheritLabels: false. This isnt true for the Scan
System (please complete the following information):
- secureCodeBox image: latest
- helm chart: 3.1.1
Reacted by Robert Felber
Activity
EndPositive commentedon Sep 29, 2021
Investigating 👀
EndPositive commentedon Sep 29, 2021
Hi @RixTmobilender, thanks for trying out secureCodeBox!
Unfortunately I wasn't able to reproduce your issue. There's actually a unit test for this specific scenario.
secureCodeBox/hooks/cascading-scans/hook/hook.test.js
Lines 386 to 418 in 79a279a
I have a feeling this behaviour is caused by tanka.dev 's garbage collection. As said in tanka's docs, it automatically adds this label for each created resource.
@RixTmobilender could you check whether you can reproduce the behavior with labels other than
tanka.dev/environment?Regarding the deletion of cascading scans: The cascading scans hook automatically sets the
ownerReferenceson each cascading scans, as visible in your example:With the
ownerReferenceset, if the parent scan is deleted, the Kubernetes garbage collector will automatically delete all cascaded scans.So either disable Tanka's garbage collection or we have to look into if we can run the cascading scans hook without setting
ownerReferenceson cascading scans. I don't think this reference is used anywhere else but for garbage collection, so it should be no problem to implement.RixTmobilender commentedon Sep 29, 2021
I have redeployed my project from scratch with the following changes:
test_label: helloon the parent nmap scanI am running an nmap scan that cascades into sslyze and zap-advanced, I dont think it's relevant but I have disabled the default cascading rule for zap-advanced and created my own in order to selectively drop http targets and run https-only scans.
kubectl get scans -n mynamespace -o yaml: get_scans.yaml.txtI can confirm that both cascading scans have inherited their parent's
test_labeldespiteinheritLabels: falsebeing present in the parent nmap.If there's anything else I can supply please let me know 😀.
Thanks a lot and congrats on an amazing project.
EndPositive commentedon Sep 30, 2021
@RixTmobilender Interestingly, there was a difference between the applied Scan object and the actual Scan in the cluster.
Original:
Actual:
After some more investigating, looks like the operator deletes the
inheritLabelsfield if it is set to false. Then the cascading scan hook receives an undefined value and assumes the default true. Making it impossible to setinheritLabelsto false while creating a resource. I've created #687 !Thanks for the extensive logs and detailed explanations!