-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalidate-pod-security.yaml
More file actions
166 lines (166 loc) · 5.42 KB
/
Copy pathvalidate-pod-security.yaml
File metadata and controls
166 lines (166 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Validates that pods in non-infrastructure namespaces comply with
# Pod Security Standards (restricted profile). Works in tandem with
# the add-security-context mutation policy:
# - Mutation injects defaults for empty fields (conditional anchors)
# - This policy blocks explicitly insecure overrides at admission
#
# Addresses kubescape controls: C-0013, C-0016, C-0055, C-0057
#
# NOTE: readOnlyRootFilesystem is NOT validated because several charts
# intentionally set it to false (homepage, opencost UI, actual-budget)
# and PSS restricted does not require it. It is enforced via HelmRelease
# values where possible and the mutation policy adds it as a default.
#
# Local-path-provisioner helper pods (used in local/CI clusters) are
# excluded by name pattern because they run as root with hostPath in
# app namespaces. Production uses Longhorn (excluded by namespace).
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: validate-pod-security
annotations:
policies.kyverno.io/title: Validate Pod Security (PSS Restricted)
policies.kyverno.io/category: Pod Security, Best Practices
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Pod
policies.kyverno.io/minversion: 1.6.0
policies.kyverno.io/description: >-
Validates that pods comply with Pod Security Standards restricted
profile. Blocks explicitly insecure overrides that the mutation
policy's conditional anchors would skip.
spec:
validationFailureAction: Enforce
background: true
rules:
- name: validate-container-security
match:
any:
- resources:
kinds:
- Pod
exclude:
any:
- resources:
namespaces:
- kube-system
- kube-public
- kube-node-lease
- flux-system
- longhorn-system
- local-path-storage
- kubescape
- kubevirt
- cdi
- observability
- velero
- resources:
names:
- "helper-pod-create-pvc-*"
- "helper-pod-delete-pvc-*"
validate:
message: >-
All containers must set allowPrivilegeEscalation=false,
privileged=false (or unset), runAsNonRoot=true, and drop
ALL capabilities.
pattern:
spec:
containers:
- securityContext:
allowPrivilegeEscalation: false
=(privileged): false
runAsNonRoot: true
capabilities:
drop:
- ALL
=(initContainers):
- securityContext:
allowPrivilegeEscalation: false
=(privileged): false
runAsNonRoot: true
capabilities:
drop:
- ALL
=(ephemeralContainers):
- securityContext:
allowPrivilegeEscalation: false
=(privileged): false
runAsNonRoot: true
capabilities:
drop:
- ALL
- name: require-seccomp-profile
match:
any:
- resources:
kinds:
- Pod
exclude:
any:
- resources:
namespaces:
- kube-system
- kube-public
- kube-node-lease
- flux-system
- longhorn-system
- local-path-storage
- kubescape
- kubevirt
- cdi
- observability
- velero
- resources:
names:
- "helper-pod-create-pvc-*"
- "helper-pod-delete-pvc-*"
validate:
message: "Pod must use seccomp profile RuntimeDefault or Localhost."
pattern:
spec:
securityContext:
seccompProfile:
type: "RuntimeDefault | Localhost"
- name: deny-container-seccomp-unconfined
match:
any:
- resources:
kinds:
- Pod
exclude:
any:
- resources:
namespaces:
- kube-system
- kube-public
- kube-node-lease
- flux-system
- longhorn-system
- local-path-storage
- kubescape
- kubevirt
- cdi
- observability
- velero
- resources:
names:
- "helper-pod-create-pvc-*"
- "helper-pod-delete-pvc-*"
validate:
message: >-
Container seccomp profile must be RuntimeDefault or Localhost
when set. Containers inherit the pod-level seccomp profile
unless explicitly overridden.
pattern:
spec:
containers:
- =(securityContext):
=(seccompProfile):
type: "RuntimeDefault | Localhost"
=(initContainers):
- =(securityContext):
=(seccompProfile):
type: "RuntimeDefault | Localhost"
=(ephemeralContainers):
- =(securityContext):
=(seccompProfile):
type: "RuntimeDefault | Localhost"