File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11include ../../../hack/package.mk
22
3+ test :
4+ helm unittest .
5+
36generate :
47 cozyvalues-gen -m ' vmdisk' -v values.yaml -s values.schema.json -r README.md -g ../../../api/apps/v1alpha1/vmdisk/types.go
58 ../../../hack/update-crd.sh
Original file line number Diff line number Diff line change @@ -21,17 +21,26 @@ metadata:
2121 helm.sh/hook-weight : " 0"
2222 helm.sh/hook-delete-policy : hook-succeeded,before-hook-creation
2323spec :
24+ backoffLimit : 1
2425 template :
2526 metadata :
2627 labels :
2728 policy.cozystack.io/allow-to-apiserver : " true"
2829 spec :
2930 serviceAccountName : {{ .Release.Name }}-volume-resize-hook
3031 restartPolicy : Never
31- backoffLimit : 1
32+ securityContext :
33+ runAsNonRoot : true
34+ runAsUser : 65534
35+ seccompProfile :
36+ type : RuntimeDefault
3237 containers :
3338 - name : resize
3439 image : docker.io/alpine/k8s:1.36.2
40+ securityContext :
41+ allowPrivilegeEscalation : false
42+ capabilities :
43+ drop : ["ALL"]
3544 command : ["sh", "-xec"]
3645 args :
3746 - |
Original file line number Diff line number Diff line change 1+ suite : vm-disk pvc-resize hook runs non-root
2+
3+ # The resize hook only renders when an existing PVC is being grown
4+ # (lookup-gated on the PVC + a larger .Values.storage), so mock a smaller PVC
5+ # and request a larger size to drive the render, then pin the non-root
6+ # securityContext. Scope to the hook template so the chart's tenant-identifier
7+ # lookups elsewhere don't need a live cluster.
8+ release :
9+ name : test-vm-disk
10+ namespace : tenant-test
11+ templates :
12+ - templates/pvc-resize-hook.yaml
13+ set :
14+ storage : 2Gi
15+ kubernetesProvider :
16+ scheme :
17+ " v1/PersistentVolumeClaim " :
18+ gvr :
19+ group : " "
20+ version : " v1"
21+ resource : " persistentvolumeclaims"
22+ namespaced : true
23+ objects :
24+ - kind : PersistentVolumeClaim
25+ apiVersion : v1
26+ metadata :
27+ name : test-vm-disk
28+ namespace : tenant-test
29+ spec :
30+ resources :
31+ requests :
32+ storage : 1Gi
33+ tests :
34+ - it : pvc-resize hook Job runs under a restrictive non-root securityContext
35+ documentSelector :
36+ path : kind
37+ value : Job
38+ asserts :
39+ - equal :
40+ path : spec.template.spec.securityContext.runAsNonRoot
41+ value : true
42+ - equal :
43+ path : spec.template.spec.securityContext.runAsUser
44+ value : 65534
45+ - equal :
46+ path : spec.template.spec.securityContext.seccompProfile.type
47+ value : RuntimeDefault
48+ - equal :
49+ path : spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation
50+ value : false
51+ - contains :
52+ path : spec.template.spec.containers[0].securityContext.capabilities.drop
53+ content : ALL
54+
55+ - it : backoffLimit is set at Job.spec, not silently dropped under the pod spec
56+ documentSelector :
57+ path : kind
58+ value : Job
59+ asserts :
60+ - equal :
61+ path : spec.backoffLimit
62+ value : 1
63+ - notExists :
64+ path : spec.template.spec.backoffLimit
Original file line number Diff line number Diff line change 11include ../../../hack/package.mk
22
3+ test :
4+ helm unittest .
5+
36generate :
47 cozyvalues-gen -m ' vminstance' -v values.yaml -s values.schema.json -r README.md -g ../../../api/apps/v1alpha1/vminstance/types.go
58 ../../../hack/update-crd.sh
Original file line number Diff line number Diff line change 5656 spec :
5757 serviceAccountName : {{ $.Release.Name }}-update-hook
5858 restartPolicy : Never
59+ securityContext :
60+ runAsNonRoot : true
61+ runAsUser : 65534
62+ seccompProfile :
63+ type : RuntimeDefault
5964 containers :
6065 - name : update-resources
6166 image : docker.io/alpine/k8s:1.36.2
67+ securityContext :
68+ allowPrivilegeEscalation : false
69+ capabilities :
70+ drop : ["ALL"]
6271 resources :
6372 requests :
6473 memory : " 16Mi"
Original file line number Diff line number Diff line change 1+ suite : vm-instance update-hook runs non-root
2+
3+ # The update hook only renders when an existing VM/Service needs reconciling
4+ # (lookup-gated). Mock a Service whose type differs from the desired one
5+ # (existing LoadBalancer vs desired ClusterIP) to drive the render, then pin
6+ # the non-root securityContext. Scope to the hook template so the chart's
7+ # instanceType lookups elsewhere don't need a live cluster.
8+ release :
9+ name : test-vm
10+ namespace : tenant-test
11+ templates :
12+ - templates/vm-update-hook.yaml
13+ set :
14+ fullnameOverride : test-vm
15+ external : false
16+ kubernetesProvider :
17+ scheme :
18+ " v1/Service " :
19+ gvr :
20+ group : " "
21+ version : " v1"
22+ resource : " services"
23+ namespaced : true
24+ objects :
25+ - kind : Service
26+ apiVersion : v1
27+ metadata :
28+ name : test-vm
29+ namespace : tenant-test
30+ spec :
31+ type : LoadBalancer
32+ tests :
33+ - it : update-hook Job runs under a restrictive non-root securityContext
34+ documentSelector :
35+ path : kind
36+ value : Job
37+ asserts :
38+ - equal :
39+ path : spec.template.spec.securityContext.runAsNonRoot
40+ value : true
41+ - equal :
42+ path : spec.template.spec.securityContext.runAsUser
43+ value : 65534
44+ - equal :
45+ path : spec.template.spec.securityContext.seccompProfile.type
46+ value : RuntimeDefault
47+ - equal :
48+ path : spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation
49+ value : false
50+ - contains :
51+ path : spec.template.spec.containers[0].securityContext.capabilities.drop
52+ content : ALL
Original file line number Diff line number Diff line change 1616 policy.cozystack.io/allow-to-apiserver : " true"
1717 spec :
1818 serviceAccountName : " cozystack-api-hook"
19+ securityContext :
20+ runAsNonRoot : true
21+ runAsUser : 65534
22+ seccompProfile :
23+ type : RuntimeDefault
1924 containers :
2025 - name : kubectl
2126 image : docker.io/alpine/k8s:1.36.2
27+ securityContext :
28+ allowPrivilegeEscalation : false
29+ capabilities :
30+ drop : ["ALL"]
2231 command :
2332 - sh
2433 args :
Original file line number Diff line number Diff line change 1+ suite : cozystack-api post-upgrade hook runs non-root
2+
3+ # The hook only renders when the legacy cozystack-api DaemonSet still exists
4+ # (lookup-gated), so mock that DaemonSet to drive the render, then pin the
5+ # non-root securityContext so it cannot regress to running kubectl as root.
6+ release :
7+ name : cozystack-api
8+ namespace : cozy-system
9+ templates :
10+ - templates/hook.yaml
11+ kubernetesProvider :
12+ scheme :
13+ " apps/v1/DaemonSet " :
14+ gvr :
15+ group : " apps"
16+ version : " v1"
17+ resource : " daemonsets"
18+ namespaced : true
19+ objects :
20+ - kind : DaemonSet
21+ apiVersion : apps/v1
22+ metadata :
23+ name : cozystack-api
24+ namespace : cozy-system
25+ tests :
26+ - it : post-upgrade hook Job runs under a restrictive non-root securityContext
27+ documentSelector :
28+ path : kind
29+ value : Job
30+ asserts :
31+ - equal :
32+ path : spec.template.spec.securityContext.runAsNonRoot
33+ value : true
34+ - equal :
35+ path : spec.template.spec.securityContext.runAsUser
36+ value : 65534
37+ - equal :
38+ path : spec.template.spec.securityContext.seccompProfile.type
39+ value : RuntimeDefault
40+ - equal :
41+ path : spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation
42+ value : false
43+ - contains :
44+ path : spec.template.spec.containers[0].securityContext.capabilities.drop
45+ content : ALL
Original file line number Diff line number Diff line change 2424 policy.cozystack.io/allow-to-apiserver : " true"
2525 spec :
2626 serviceAccountName : seaweedfs-hook
27+ securityContext :
28+ runAsNonRoot : true
29+ runAsUser : 65534
30+ seccompProfile :
31+ type : RuntimeDefault
2732 containers :
2833 - name : kubectl
2934 image : docker.io/alpine/k8s:1.36.2
35+ securityContext :
36+ allowPrivilegeEscalation : false
37+ capabilities :
38+ drop : ["ALL"]
3039 command :
3140 - sh
3241 args :
Original file line number Diff line number Diff line change 1+ suite : seaweedfs update-hook runs non-root
2+
3+ # The update-hook Job runs kubectl from docker.io/alpine/k8s. kubectl needs no
4+ # root, so pin a restrictive non-root securityContext (mirroring the dashboard
5+ # adopt hook, uid 65534) and guard against it regressing back to running as root.
6+ release :
7+ name : seaweedfs
8+ namespace : cozy-seaweedfs
9+ tests :
10+ - it : update-hook Job runs under a restrictive non-root securityContext
11+ template : templates/hook.yaml
12+ documentSelector :
13+ path : kind
14+ value : Job
15+ asserts :
16+ - equal :
17+ path : spec.template.spec.securityContext.runAsNonRoot
18+ value : true
19+ - equal :
20+ path : spec.template.spec.securityContext.runAsUser
21+ value : 65534
22+ - equal :
23+ path : spec.template.spec.securityContext.seccompProfile.type
24+ value : RuntimeDefault
25+ - equal :
26+ path : spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation
27+ value : false
28+ - contains :
29+ path : spec.template.spec.containers[0].securityContext.capabilities.drop
30+ content : ALL
You can’t perform that action at this time.
0 commit comments