This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
/
defaultRules.yaml
4008 lines (4006 loc) · 141 KB
/
defaultRules.yaml
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# for autocompletion in VS Code
# yaml-language-server: $schema=./defaultRulesSchema.json
apiVersion: v1
aliases:
- &standardKinds
properties:
kind:
enum:
- Deployment
- Pod
- DaemonSet
- StatefulSet
- ReplicaSet
- CronJob
- Job
- ¬KindSecret
properties:
kind:
not:
enum:
- Secret
# The following alias is used to prohibit a string from matching a given regex anywhere in the manifest
# make sure to use the $ref "#/definitions/regexes" in the schema definition to populate the regexes variable
- &recursiveDontAllowValue
type: object
additionalProperties:
if:
type: object
then:
"$ref": "#"
else:
if:
type: array
then:
items:
if:
type: object
then:
"$ref": "#"
else:
if:
type: string
then:
not:
"$ref": "#/definitions/regexes"
else:
if:
type: string
then:
not:
"$ref": "#/definitions/regexes"
rules:
- id: 1
name: Ensure each container image has a pinned (tag) version
uniqueName: CONTAINERS_MISSING_IMAGE_VALUE_VERSION
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-image-pinned-version"
messageOnFailure: Incorrect value for key `image` - specify an image version to avoid unpleasant "version surprises" in the future
categories:
- cdk8s
complexity: easy
impact: When the version tag is missing, every time that the image is pulled it pulls the latest version which may break your code
schema:
definitions:
imageValuePattern:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
image:
# catch all strings with image tag version
pattern: "\\@sha.*|:(\\w|\\.|\\-)+$"
not:
# ignore `latest` as image tag version
pattern: ".*:(latest|LATEST)$"
allOf:
- $ref: "#/definitions/imageValuePattern"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 2
name: Ensure each container has a configured memory request
uniqueName: CONTAINERS_MISSING_MEMORY_REQUEST_KEY
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-memory-request"
messageOnFailure: "Missing property object `requests.memory` - value should be within the accepted boundaries recommended by the organization"
categories:
- Resources
complexity: hard
impact: Memory requests allow you to use memory resources efficiently and allocate a guaranteed minimum of computing resources for the pods running in your cluster
schema:
definitions:
memoryRequestPattern:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
resources:
properties:
requests:
type: object
properties:
memory:
type:
- string
- number
required:
- memory
required:
- requests
required:
- resources
allOf:
- $ref: "#/definitions/memoryRequestPattern"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 3
name: Ensure each container has a configured CPU request
uniqueName: CONTAINERS_MISSING_CPU_REQUEST_KEY
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-cpu-request"
messageOnFailure: "Missing property object `requests.cpu` - value should be within the accepted boundaries recommended by the organization"
categories:
- Resources
complexity: hard
impact: CPU requests allow you to use CPU resources efficiently and to allocate a guaranteed minimum of computing resources for the pods running in your cluster
schema:
definitions:
cpuRequestPattern:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
resources:
properties:
requests:
type: object
properties:
cpu:
type:
- string
- number
required:
- cpu
required:
- requests
required:
- resources
allOf:
- $ref: "#/definitions/cpuRequestPattern"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 4
name: Ensure each container has a configured memory limit
uniqueName: CONTAINERS_MISSING_MEMORY_LIMIT_KEY
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-memory-limit"
messageOnFailure: "Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization"
categories:
- Resources
complexity: hard
impact: Without memory limits, the pods running in your cluster will not have a restriction on the max amount of memory consumption, which may result with OOM failures
schema:
definitions:
memoryLimitPattern:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
resources:
properties:
limits:
type: object
properties:
memory:
type:
- string
- number
required:
- memory
required:
- limits
required:
- resources
allOf:
- $ref: "#/definitions/memoryLimitPattern"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 5
name: Ensure each container has a configured CPU limit
uniqueName: CONTAINERS_MISSING_CPU_LIMIT_KEY
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-cpu-limit"
messageOnFailure: "Missing property object `limits.cpu` - value should be within the accepted boundaries recommended by the organization"
categories:
- Resources
complexity: hard
impact: Without CPU limits, the pods running in your cluster will not have a restriction on the max amount of CPU consumption, which may cause starvation of other pods in the same node
schema:
definitions:
cpuLimitPattern:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
resources:
properties:
limits:
type: object
properties:
cpu:
type:
- string
- number
required:
- cpu
required:
- limits
required:
- resources
allOf:
- $ref: "#/definitions/cpuLimitPattern"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 6
name: "Prevent Ingress from forwarding all traffic to a single container"
uniqueName: "INGRESS_INCORRECT_HOST_VALUE_PERMISSIVE"
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-ingress-forwarding-traffic-to-single-container"
messageOnFailure: 'Incorrect value for key `host` - specify host instead of using a wildcard character ("*")'
categories:
- cdk8s
complexity: medium
impact: Misconfiguring the ingress host can cause all traffic to be forwarded to a single pod instead of leveraging load-balancing capabilities
schema:
if:
properties:
kind:
enum:
- Ingress
then:
properties:
spec:
properties:
rules:
type: array
items:
properties:
host:
type: string
not:
enum:
- "*"
- id: 7
name: Prevent Service from exposing node port
uniqueName: SERVICE_INCORRECT_TYPE_VALUE_NODEPORT
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-node-port"
messageOnFailure: "Incorrect value for key `type` - `NodePort` will open a port on all nodes where it can be reached by the network external to the cluster"
categories:
- Other
complexity: easy
impact: Exposing a NodePort will open a network port on all nodes to be reached by the cluster's external network, which poses a security threat
schema:
if:
properties:
kind:
enum:
- Service
# knative has a CRD with kind "Service", we want this rule to ignore it
not:
properties:
apiVersion:
enum:
- serving.knative.dev/v1
then:
properties:
spec:
properties:
type:
type: string
not:
enum:
- "NodePort"
- id: 8
name: Ensure CronJob scheduler is valid
uniqueName: CRONJOB_INVALID_SCHEDULE_VALUE
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-cronjob-scheduler-valid"
messageOnFailure: "Incorrect value for key `schedule` - the (cron) schedule expressions is not valid and, therefore, will not work as expected"
categories:
- cdk8s
complexity: easy
impact: An invalid cron schedule expression will prevent your jobs from being executed
schema:
if:
properties:
kind:
enum:
- "CronJob"
then:
properties:
spec:
properties:
schedule:
# use cases to test the regex - https://regex101.com/r/K4d7Ju/1
pattern: (^((\*\/)?([0-5]?[0-9])((\,|\-|\/)([0-5]?[0-9]))*|\*)\s+((\*\/)?((2[0-3]|1[0-9]|[0-9]|00))((\,|\-|\/)(2[0-3]|1[0-9]|[0-9]|00))*|\*)\s+((\*\/)?([1-9]|[12][0-9]|3[01])((\,|\-|\/)([1-9]|[12][0-9]|3[01]))*|\*)\s+((\*\/)?([1-9]|1[0-2])((\,|\-|\/)([1-9]|1[0-2]))*|\*|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|des))\s+((\*\/)?[0-6]((\,|\-|\/)[0-6])*|\*|00|(sun|mon|tue|wed|thu|fri|sat))\s*$)|@(annually|yearly|monthly|weekly|daily|hourly|reboot)
- id: 9
name: Ensure workload has valid label values
uniqueName: WORKLOAD_INVALID_LABELS_VALUE
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-labels-value-valid"
messageOnFailure: "Incorrect value for key(s) under `labels` - the value's syntax is not valid so the Kubernetes engine will not accept it"
categories:
- cdk8s
complexity: easy
impact: If an object's labels do not follow Kubernetes label syntax requirements, it will not be applied properly
schema:
if: *standardKinds
then:
properties:
metadata:
properties:
labels:
patternProperties:
^.*$:
format: hostname
additionalProperties: false
- id: 10
name: "Ensure deployment-like resource is using a valid restart policy"
uniqueName: "WORKLOAD_INCORRECT_RESTARTPOLICY_VALUE_ALWAYS"
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-valid-restart-policy"
messageOnFailure: "Incorrect value for key `restartPolicy` - any other value than `Always` is not supported by this resource"
categories:
- cdk8s
complexity: easy
impact: A workload with a 'restartPolicy' value other than 'Always' is invalid and will not be applied properly
schema:
if:
properties:
kind:
enum:
- Deployment
- ReplicaSet
- DaemonSet
- ReplicationController
then:
properties:
spec:
properties:
template:
properties:
spec:
properties:
restartPolicy:
enum:
- "Always"
- id: 11
name: Ensure each container has a configured liveness probe
uniqueName: CONTAINERS_MISSING_LIVENESSPROBE_KEY
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-liveness-probe"
messageOnFailure: "Missing property object `livenessProbe` - add a properly configured livenessProbe to catch possible deadlocks"
categories:
- Probes
complexity: hard
impact: When liveness probes aren't set, Kubernetes can't determine when a pod should be restarted, which can result with an unavailable application
schema:
definitions:
specContainers:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
items:
required:
- livenessProbe
allOf:
- $ref: "#/definitions/specContainers"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 12
name: Ensure each container has a configured readiness probe
uniqueName: CONTAINERS_MISSING_READINESSPROBE_KEY
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-readiness-probe"
messageOnFailure: "Missing property object `readinessProbe` - add a properly configured readinessProbe to notify kubelet your Pods are ready for traffic"
categories:
- Probes
complexity: hard
impact: Readiness probes allow Kubernetes to determine when a pod is ready to accept traffic. This ensures that client requests will not be routed to pods that are unable to process them
schema:
definitions:
specContainers:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
items:
required:
- readinessProbe
allOf:
- $ref: "#/definitions/specContainers"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 13
name: Ensure HPA has minimum replicas configured
uniqueName: HPA_MISSING_MINREPLICAS_KEY
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-hpa-minimum-replicas"
messageOnFailure: "Missing property object `minReplicas` - the value should be within the accepted boundaries recommended by the organization"
categories:
- Other
complexity: medium
impact: The minimum replicas range must be set to prevent unintended scaling down scenarios
schema:
if:
properties:
kind:
enum:
- HorizontalPodAutoscaler
then:
properties:
spec:
required:
- minReplicas
- id: 14
name: Ensure HPA has maximum replicas configured
uniqueName: HPA_MISSING_MAXREPLICAS_KEY
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-hpa-maximum-replicas"
messageOnFailure: "Missing property object `maxReplicas` - the value should be within the accepted boundaries recommended by the organization"
categories:
- Other
complexity: medium
impact: The maximum replicas range must be set to prevent unintended scaling up scenarios
schema:
if:
properties:
kind:
enum:
- HorizontalPodAutoscaler
then:
properties:
spec:
required:
- maxReplicas
- id: 15
name: Prevent workload from using the default namespace
uniqueName: WORKLOAD_INCORRECT_NAMESPACE_VALUE_DEFAULT
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-deafult-namespce"
messageOnFailure: Incorrect value for key `namespace` - use an explicit namespace instead of the default one (`default`)
categories:
- cdk8s
- CIS
complexity: medium
impact: All objects that do not specify an explicit namespace will be applied to the 'default' namespace. This can cause a messy cluster with configuration overlaps
schema:
if: *standardKinds
then:
properties:
metadata:
properties:
namespace:
not:
enum:
- "default"
- id: 16
name: "Ensure Deployment has more than one replica configured"
uniqueName: "DEPLOYMENT_INCORRECT_REPLICAS_VALUE"
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-minimum-two-replicas"
messageOnFailure: "Incorrect value for key `replicas` - running 2 or more replicas will increase the availability of the service"
categories:
- cdk8s
complexity: medium
impact: When running two or more replicas per service, you are increasing the availability of the containerized service by not relying on a single pod to do all of the work
schema:
if:
properties:
kind:
enum:
- Deployment
then:
properties:
spec:
properties:
replicas:
minimum: 2
- id: 17
name: "Ensure CronJob has a configured deadline"
uniqueName: "CRONJOB_MISSING_STARTINGDEADLINESECOND_KEY"
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-cronjob-deadline"
messageOnFailure: "Missing property object `startingDeadlineSeconds` - set a time limit to the cron execution to allow killing it if exceeded"
categories:
- Other
complexity: medium
impact: Setting a deadline can reduce the number of missed schedules needed to mark a CronJob as a failure while also increasing its reliability
schema:
if:
properties:
kind:
enum:
- CronJob
then:
properties:
spec:
properties:
startingDeadlineSeconds:
type: number
required:
- startingDeadlineSeconds
- id: 18
name: "Prevent deprecated APIs in Kubernetes v1.16"
uniqueName: "K8S_DEPRECATED_APIVERSION_1.16"
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-deprecated-k8s-api-116"
messageOnFailure: "Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (>=1.16)"
categories:
- Deprecation
complexity: easy
impact: Deploying a resource with a deprecated API version will cause Kubernetes to reject it
schema:
allOf:
- if:
properties:
apiVersion:
enum:
- apiextensions.k8s.io/v1beta1
then:
properties:
kind:
not:
enum:
- CustomResourceDefinition
- if:
properties:
apiVersion:
enum:
- admissionregistration.k8s.io/v1beta1
then:
properties:
kind:
not:
enum:
- MutatingWebhookConfiguration
- ValidatingWebhookConfiguration
- id: 19
name: "Prevent deprecated APIs in Kubernetes v1.17"
uniqueName: "K8S_DEPRECATED_APIVERSION_1.17"
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-deprecated-k8s-api-117"
messageOnFailure: "Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (>=1.17)"
categories:
- Deprecation
complexity: easy
impact: Deploying a resource with a deprecated API version will cause Kubernetes to reject it
schema:
allOf:
- if:
properties:
apiVersion:
enum:
- rbac.authorization.k8s.io/v1alpha1
then:
properties:
kind:
not:
enum:
- ClusterRoleBinding
- ClusterRole
- ClusterRoleBindingList
- ClusterRoleList
- Role
- RoleBinding
- RoleList
- RoleBindingList
- if:
properties:
apiVersion:
enum:
- rbac.authorization.k8s.io/v1beta1
then:
properties:
kind:
not:
enum:
- ClusterRoleBinding
- ClusterRole
- ClusterRoleBindingList
- ClusterRoleList
- Role
- RoleBinding
- RoleList
- RoleBindingList
- if:
properties:
apiVersion:
enum:
- storage.k8s.io/v1beta1
then:
properties:
kind:
not:
enum:
- CSINode
- id: 20
name: "Prevent containers from having root access capabilities"
uniqueName: "CONTAINERS_INCORRECT_PRIVILEGED_VALUE_TRUE"
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-privileged-containers"
messageOnFailure: "Incorrect value for key `privileged` - this mode will allow the container the same access as processes running on the host"
categories:
- CIS
complexity: easy
impact: Processes running in privileged containers have access to host-level resources such as the file system. These containers are much more secure when their access is limited to the pod level
schema:
definitions:
specContainers:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
securityContext:
properties:
privileged:
not:
enum:
- true
- "true"
allOf:
- $ref: "#/definitions/specContainers"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 21
name: Ensure workload has a configured `owner` label
uniqueName: WORKLOAD_MISSING_LABEL_OWNER_VALUE
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-owner-label"
messageOnFailure: "Missing label object `owner` - add a proper owner label to know which person/team to ping when needed"
categories:
- Other
complexity: easy
impact: An owner label is great for financial and operational ownership, and makes it easier to alert the relevant team or team member when necessary
schema:
if: *standardKinds
then:
properties:
metadata:
properties:
labels:
required:
- owner
- id: 22
name: Ensure Deployment has a configured `env` label
uniqueName: DEPLOYMENT_MISSING_LABEL_ENV_VALUE
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-env-label"
messageOnFailure: 'Missing label object `env` - add a proper environment description (e.g. "prod", "testing", etc.) to the Deployment config'
categories:
- Other
complexity: easy
impact: Having an env label is useful for performing bulk operations in specific environments or for filtering Deployments according to their stage
schema:
if:
properties:
kind:
enum:
- Deployment
then:
properties:
metadata:
properties:
labels:
required:
- env
required:
- labels
required:
- metadata
- id: 23
name: Ensure each container image has a digest tag
uniqueName: CONTAINERS_MISSING_IMAGE_VALUE_DIGEST
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/ensure-digest-tag"
messageOnFailure: "Incorrect value for key `image` - add a digest tag (starts with `@sha256:`) to represent an immutable version of the image"
categories:
- Other
complexity: medium
impact: The digest uniquely identifies a specific version sha of the image, so it will never be tampered
schema:
definitions:
imageValuePattern:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
image:
pattern: .*\@sha256\:\S{64}$
allOf:
- $ref: "#/definitions/imageValuePattern"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 24
name: "Prevent CronJob from executing jobs concurrently"
uniqueName: "CRONJOB_MISSING_CONCURRENCYPOLICY_KEY"
enabledByDefault: true
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-cronjob-concurrency"
messageOnFailure: Missing property object `concurrencyPolicy` - the behavior will be more deterministic if jobs won't run concurrently
categories:
- Other
complexity: easy
impact: Preventing your CronJobs from running concurrently will cause their behavior to be more deterministic and avoid race conditions
schema:
if:
properties:
kind:
enum:
- CronJob
then:
properties:
spec:
properties:
concurrencyPolicy:
enum:
- "Forbid"
- "Replace"
required:
- concurrencyPolicy
- id: 25
name: "Prevent deploying naked pods"
uniqueName: "K8S_INCORRECT_KIND_VALUE_POD"
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-naked-pods"
messageOnFailure: Incorrect value for key `kind` - raw pod won't be rescheduled in the event of a node failure
categories:
- cdk8s
complexity: medium
impact: Pods not created by workload controllers such as Deployments have no self-healing or scaling abilities and are unsuitable for production
schema:
properties:
kind:
type: string
not:
enum:
- "Pod"
- id: 26
name: Prevent containers from sharing the host's PID namespace
uniqueName: "CONTAINERS_INCORRECT_HOSTPID_VALUE_TRUE"
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-using-host-pid"
messageOnFailure: Incorrect value for key `hostPID` - running on the host's PID namespace enables access to sensitive information from processes running outside the container
categories:
- CIS
complexity: easy
impact: When a container is allowed to share its hosts PID namespace, it can see and may even kill processes running on the host outside of the container
schema:
definitions:
specContainers:
if: *standardKinds
then:
properties:
spec:
properties:
hostPID:
not:
enum:
- true
- "true"
allOf:
- $ref: "#/definitions/specContainers"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 27
name: "Prevent containers from sharing the host`s IPC namespace"
uniqueName: "CONTAINERS_INCORRECT_HOSTIPC_VALUE_TRUE"
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-using-host-ipc"
messageOnFailure: "Incorrect value for key `hostIPC` - running on the host`s IPC namespace can be (maliciously) used to interact with other processes running outside the container"
categories:
- CIS
complexity: easy
impact: When a container is allowed to share its host's IPC namespace, it has access to other processes running outside of the container
schema:
definitions:
specContainers:
if: *standardKinds
then:
properties:
spec:
properties:
hostIPC:
not:
enum:
- true
- "true"
allOf:
- $ref: "#/definitions/specContainers"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 28
name: Prevent containers from sharing the host's network namespace
uniqueName: "CONTAINERS_INCORRECT_HOSTNETWORK_VALUE_TRUE"
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-using-host-network"
messageOnFailure: Incorrect value for key `hostNetwork` - running on the host's network namespace can allow a compromised container to sniff network traffic
categories:
- CIS
complexity: easy
impact: When a container is allowed to share its host's network namespace, it can leverage the host's local network to do malicious stuff
schema:
definitions:
specContainers:
if: *standardKinds
then:
properties:
spec:
properties:
hostNetwork:
not:
enum:
- true
- "true"
allOf:
- $ref: "#/definitions/specContainers"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 29
name: "Prevent containers from accessing host files by using high UIDs"
uniqueName: "CONTAINERS_INCORRECT_RUNASUSER_VALUE_LOWUID"
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-uid-conflicts"
messageOnFailure: "Incorrect value for key `runAsUser` - value should be above 9999 to reduce the likelihood that the UID is already taken"
categories:
- NSA
complexity: medium
impact: With a high UID number, a container is blocked from accessing host-based files even if it manages to gain access to a host's file system
schema:
definitions:
specContainers:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
securityContext:
properties:
runAsUser:
minimum: 10000
allOf:
- $ref: "#/definitions/specContainers"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 30
name: "Prevent containers from mounting Docker socket"
uniqueName: "CONTAINERS_INCORRECT_PATH_VALUE_DOCKERSOCKET"
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-mounting-docker-socket"
messageOnFailure: "Incorrect value for key `path` - avoid mounting the docker.socket because it can allow container breakout"
categories:
- Other
complexity: medium
impact: When a container has access to the Docker socket, it can effectively manage other containers on the host
schema:
definitions:
specContainers:
if: *standardKinds
then:
properties:
spec:
properties:
containers:
type: array
items:
properties:
volumeMounts:
type: array
items:
properties:
mountPath:
not:
enum:
- "/var/run/docker.sock"
specVolumes:
if: *standardKinds
then:
properties:
spec:
properties:
volumes:
type: array
items:
properties:
hostPath:
properties:
path:
not:
enum:
- "/var/run/docker.sock"
allOf:
- $ref: "#/definitions/specContainers"
- $ref: "#/definitions/specVolumes"
additionalProperties:
$ref: "#"
items:
$ref: "#"
- id: 31
name: "Prevent ConfigMap security vulnerability (CVE-2021-25742)"
uniqueName: "CONFIGMAP_CVE2021_25742_INCORRECT_SNIPPET_ANNOTATIONS_VALUE"
enabledByDefault: false
documentationUrl: "https://hub.datree.io/built-in-rules/prevent-configmap-security-vulnerability-cve-2021-25742"
messageOnFailure: Missing property object `allow-snippet-annotations` - set it to "false" to override default behaviour
categories:
- CVE
complexity: easy
impact: Users with the ability to create or update NGINX ingress objects can use the custom snippets feature to obtain secrets in the cluster
schema:
if:
properties:
kind:
enum:
- ConfigMap
metadata:
anyOf:
- properties:
name:
enum:
- nginx-config
- nginx-conf