forked from mondoohq/cnspec-policies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mondoo-kubernetes-security.mql.yaml
6567 lines (6172 loc) · 264 KB
/
mondoo-kubernetes-security.mql.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
# Copyright (c) Mondoo, Inc.
# SPDX-License-Identifier: BUSL-1.1
policies:
- uid: mondoo-kubernetes-security
name: Kubernetes Cluster and Workload Security
version: 1.2.1
license: BUSL-1.1
tags:
mondoo.com/category: security
mondoo.com/platform: linux,kubernetes
authors:
- name: Mondoo, Inc
email: [email protected]
docs:
desc: |-
# Overview
The Kubernetes Cluster and Workload Security by Mondoo provides guidance for establishing secure Kubernetes cluster configurations and workload deployments.
If you have questions, comments, or have identified ways to improve this policy, please write us at [email protected], or reach out in [GitHub Discussions](https://github.com/orgs/mondoohq/discussions).
## Remote scan
Remote scans use cnspec providers to retrieve on-demand scan results without having to install any agents.
For a complete list of providers run:
```bash
cnspec scan --help
```
### Prerequisites
Remote scans of Kubernetes clusters requires a `KUBECONFIG` with access to the cluster you want to scan.
### Scan a Kubernetes cluster
Open a terminal and configure an environment variable with the path to your `KUBECONFIG`:
```bash
export KUBECONFIG=/path/to/kubeconfig
```
Run a scan of the Kubernetes cluster:
```bash
cnspec scan k8s
```
## Join the community!
Our goal is to build policies that are simple to deploy, accurate, and actionable.
If you have any suggestions for how to improve this policy, or if you need support, [join the community](https://github.com/orgs/mondoohq/discussions) in GitHub Discussions.
groups:
- title: Kubernetes API Server
filters: |
asset.family.contains('linux')
processes.where( executable == /kube-apiserver/ ).list != []
checks:
- uid: mondoo-kubernetes-security-api-server-no-anonymous-auth
- uid: mondoo-kubernetes-security-https-api-server
- uid: mondoo-kubernetes-security-secure-admin-conf
- uid: mondoo-kubernetes-security-secure-controller-manager_conf
- uid: mondoo-kubernetes-security-secure-etcd-data-dir
- uid: mondoo-kubernetes-security-secure-kube-apiserver-yml
- uid: mondoo-kubernetes-security-secure-pki-directory
- uid: mondoo-kubernetes-security-secure-scheduler_conf
- title: Kubernetes kubelet
filters: |
asset.family.contains('linux')
processes.where( executable == /kubelet/ ).list != []
checks:
- uid: mondoo-kubernetes-security-kubelet-anonymous-authentication
- uid: mondoo-kubernetes-security-kubelet-authorization-mode
- uid: mondoo-kubernetes-security-kubelet-event-record-qps
- uid: mondoo-kubernetes-security-kubelet-iptables-util-chains
- uid: mondoo-kubernetes-security-kubelet-protect-kernel-defaults
- uid: mondoo-kubernetes-security-kubelet-read-only-port
- uid: mondoo-kubernetes-security-kubelet-rotate-certificates
- uid: mondoo-kubernetes-security-kubelet-strong-ciphers
- uid: mondoo-kubernetes-security-kubelet-tls-certificate
- uid: mondoo-kubernetes-security-secure-kubelet-cert-authorities
- uid: mondoo-kubernetes-security-secure-kubelet-config
- title: Kubernetes CronJobs Security
filters: asset.platform == "k8s-cronjob"
checks:
- uid: mondoo-kubernetes-security-cronjob-allowprivilegeescalation
- uid: mondoo-kubernetes-security-cronjob-capability-net-raw
- uid: mondoo-kubernetes-security-cronjob-capability-sys-admin
- uid: mondoo-kubernetes-security-cronjob-containerd-socket
- uid: mondoo-kubernetes-security-cronjob-crio-socket
- uid: mondoo-kubernetes-security-cronjob-docker-socket
- uid: mondoo-kubernetes-security-cronjob-hostipc
- uid: mondoo-kubernetes-security-cronjob-hostnetwork
- uid: mondoo-kubernetes-security-cronjob-hostpath-readonly
- uid: mondoo-kubernetes-security-cronjob-hostpid
- uid: mondoo-kubernetes-security-cronjob-imagepull
- uid: mondoo-kubernetes-security-cronjob-limitcpu
- uid: mondoo-kubernetes-security-cronjob-limitmemory
- uid: mondoo-kubernetes-security-cronjob-ports-hostport
- uid: mondoo-kubernetes-security-cronjob-privilegedcontainer
- uid: mondoo-kubernetes-security-cronjob-readonlyrootfilesystem
- uid: mondoo-kubernetes-security-cronjob-runasnonroot
- uid: mondoo-kubernetes-security-cronjob-serviceaccount
- title: Kubernetes StatefulSets Security
filters: asset.platform == "k8s-statefulset"
checks:
- uid: mondoo-kubernetes-security-statefulset-allowprivilegeescalation
- uid: mondoo-kubernetes-security-statefulset-capability-net-raw
- uid: mondoo-kubernetes-security-statefulset-capability-sys-admin
- uid: mondoo-kubernetes-security-statefulset-containerd-socket
- uid: mondoo-kubernetes-security-statefulset-crio-socket
- uid: mondoo-kubernetes-security-statefulset-docker-socket
- uid: mondoo-kubernetes-security-statefulset-hostipc
- uid: mondoo-kubernetes-security-statefulset-hostnetwork
- uid: mondoo-kubernetes-security-statefulset-hostpath-readonly
- uid: mondoo-kubernetes-security-statefulset-hostpid
- uid: mondoo-kubernetes-security-statefulset-imagepull
- uid: mondoo-kubernetes-security-statefulset-limitcpu
- uid: mondoo-kubernetes-security-statefulset-limitmemory
- uid: mondoo-kubernetes-security-statefulset-ports-hostport
- uid: mondoo-kubernetes-security-statefulset-privilegedcontainer
- uid: mondoo-kubernetes-security-statefulset-readonlyrootfilesystem
- uid: mondoo-kubernetes-security-statefulset-runasnonroot
- uid: mondoo-kubernetes-security-statefulset-serviceaccount
- title: Kubernetes Deployments Security
filters: asset.platform == "k8s-deployment"
checks:
- uid: mondoo-kubernetes-security-deployment-allowprivilegeescalation
- uid: mondoo-kubernetes-security-deployment-capability-net-raw
- uid: mondoo-kubernetes-security-deployment-capability-sys-admin
- uid: mondoo-kubernetes-security-deployment-containerd-socket
- uid: mondoo-kubernetes-security-deployment-crio-socket
- uid: mondoo-kubernetes-security-deployment-docker-socket
- uid: mondoo-kubernetes-security-deployment-hostipc
- uid: mondoo-kubernetes-security-deployment-hostnetwork
- uid: mondoo-kubernetes-security-deployment-hostpath-readonly
- uid: mondoo-kubernetes-security-deployment-hostpid
- uid: mondoo-kubernetes-security-deployment-imagepull
- uid: mondoo-kubernetes-security-deployment-k8s-dashboard
- uid: mondoo-kubernetes-security-deployment-limitcpu
- uid: mondoo-kubernetes-security-deployment-limitmemory
- uid: mondoo-kubernetes-security-deployment-ports-hostport
- uid: mondoo-kubernetes-security-deployment-privilegedcontainer
- uid: mondoo-kubernetes-security-deployment-readonlyrootfilesystem
- uid: mondoo-kubernetes-security-deployment-runasnonroot
- uid: mondoo-kubernetes-security-deployment-serviceaccount
- uid: mondoo-kubernetes-security-deployment-tiller
- title: Kubernetes Jobs Security
filters: asset.platform == "k8s-job"
checks:
- uid: mondoo-kubernetes-security-job-allowprivilegeescalation
- uid: mondoo-kubernetes-security-job-capability-net-raw
- uid: mondoo-kubernetes-security-job-capability-sys-admin
- uid: mondoo-kubernetes-security-job-containerd-socket
- uid: mondoo-kubernetes-security-job-crio-socket
- uid: mondoo-kubernetes-security-job-docker-socket
- uid: mondoo-kubernetes-security-job-hostipc
- uid: mondoo-kubernetes-security-job-hostnetwork
- uid: mondoo-kubernetes-security-job-hostpath-readonly
- uid: mondoo-kubernetes-security-job-hostpid
- uid: mondoo-kubernetes-security-job-imagepull
- uid: mondoo-kubernetes-security-job-limitcpu
- uid: mondoo-kubernetes-security-job-limitmemory
- uid: mondoo-kubernetes-security-job-ports-hostport
- uid: mondoo-kubernetes-security-job-privilegedcontainer
- uid: mondoo-kubernetes-security-job-readonlyrootfilesystem
- uid: mondoo-kubernetes-security-job-runasnonroot
- uid: mondoo-kubernetes-security-job-serviceaccount
- title: Kubernetes ReplicaSets Security
filters: asset.platform == "k8s-replicaset"
checks:
- uid: mondoo-kubernetes-security-replicaset-allowprivilegeescalation
- uid: mondoo-kubernetes-security-replicaset-capability-net-raw
- uid: mondoo-kubernetes-security-replicaset-capability-sys-admin
- uid: mondoo-kubernetes-security-replicaset-containerd-socket
- uid: mondoo-kubernetes-security-replicaset-crio-socket
- uid: mondoo-kubernetes-security-replicaset-docker-socket
- uid: mondoo-kubernetes-security-replicaset-hostipc
- uid: mondoo-kubernetes-security-replicaset-hostnetwork
- uid: mondoo-kubernetes-security-replicaset-hostpath-readonly
- uid: mondoo-kubernetes-security-replicaset-hostpid
- uid: mondoo-kubernetes-security-replicaset-imagepull
- uid: mondoo-kubernetes-security-replicaset-limitcpu
- uid: mondoo-kubernetes-security-replicaset-limitmemory
- uid: mondoo-kubernetes-security-replicaset-ports-hostport
- uid: mondoo-kubernetes-security-replicaset-privilegedcontainer
- uid: mondoo-kubernetes-security-replicaset-readonlyrootfilesystem
- uid: mondoo-kubernetes-security-replicaset-runasnonroot
- uid: mondoo-kubernetes-security-replicaset-serviceaccount
- title: Kubernetes DaemonSets Security
filters: asset.platform == "k8s-daemonset"
checks:
- uid: mondoo-kubernetes-security-daemonset-allowprivilegeescalation
- uid: mondoo-kubernetes-security-daemonset-capability-net-raw
- uid: mondoo-kubernetes-security-daemonset-capability-sys-admin
- uid: mondoo-kubernetes-security-daemonset-containerd-socket
- uid: mondoo-kubernetes-security-daemonset-crio-socket
- uid: mondoo-kubernetes-security-daemonset-docker-socket
- uid: mondoo-kubernetes-security-daemonset-hostipc
- uid: mondoo-kubernetes-security-daemonset-hostnetwork
- uid: mondoo-kubernetes-security-daemonset-hostpath-readonly
- uid: mondoo-kubernetes-security-daemonset-hostpid
- uid: mondoo-kubernetes-security-daemonset-imagepull
- uid: mondoo-kubernetes-security-daemonset-limitcpu
- uid: mondoo-kubernetes-security-daemonset-limitmemory
- uid: mondoo-kubernetes-security-daemonset-ports-hostport
- uid: mondoo-kubernetes-security-daemonset-privilegedcontainer
- uid: mondoo-kubernetes-security-daemonset-readonlyrootfilesystem
- uid: mondoo-kubernetes-security-daemonset-runasnonroot
- uid: mondoo-kubernetes-security-daemonset-serviceaccount
- title: Kubernetes Pods Security
filters: asset.platform == "k8s-pod"
checks:
- uid: mondoo-kubernetes-security-pod-allowprivilegeescalation
- uid: mondoo-kubernetes-security-pod-capability-net-raw
- uid: mondoo-kubernetes-security-pod-capability-sys-admin
- uid: mondoo-kubernetes-security-pod-containerd-socket
- uid: mondoo-kubernetes-security-pod-crio-socket
- uid: mondoo-kubernetes-security-pod-docker-socket
- uid: mondoo-kubernetes-security-pod-hostipc
- uid: mondoo-kubernetes-security-pod-hostnetwork
- uid: mondoo-kubernetes-security-pod-hostpath-readonly
- uid: mondoo-kubernetes-security-pod-hostpid
- uid: mondoo-kubernetes-security-pod-imagepull
- uid: mondoo-kubernetes-security-pod-k8s-dashboard
- uid: mondoo-kubernetes-security-pod-limitcpu
- uid: mondoo-kubernetes-security-pod-limitmemory
- uid: mondoo-kubernetes-security-pod-ports-hostport
- uid: mondoo-kubernetes-security-pod-privilegedcontainer
- uid: mondoo-kubernetes-security-pod-readonlyrootfilesystem
- uid: mondoo-kubernetes-security-pod-runasnonroot
- uid: mondoo-kubernetes-security-pod-serviceaccount
- uid: mondoo-kubernetes-security-pod-tiller
scoring_system: highest impact
props:
- uid: mondooKubernetesSecurityAllowedCiphers
title: Define the hardened SSL/ TLS ciphers
mql: |
return ["TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
"TLS_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_GCM_SHA256",
"TLS_RSA_WITH_AES_256_CBC_SHA", "TLS_RSA_WITH_AES_256_GCM_SHA384"]
queries:
- uid: mondoo-kubernetes-security-kubelet-anonymous-authentication
title: Disable anonymous authentication for kubelet
impact: 100
mql: |
kubelet.configuration['authentication']['anonymous']['enabled'] == false
docs:
desc: |
Ensure that the kubelet is configured to disable anonymous requests to the kubelet server.
Otherwise the kubelet will allow unauthenticated access to its HTTPS endpoint. Request will have the privileges of the role `system:public-info-viewer`. This might expose data to an attacker.
audit: |
If running the kubelet with the CLI parameter '--anonymous-auth', or running with 'authentication.anonymous.enabled' defined in the kubelet configuration file, ensure that the value is set to 'false'.
remediation: |
Set the '--anonymous-auth' CLI parameter and/or the 'authentication.anonymous.enabled' field in the kubelet configuration file to 'false'.
refs:
- url: https://kubernetes.io/docs/reference/access-authn-authz/kubelet-authn-authz/#kubelet-authentication
title: Kubelet authentication
- uid: mondoo-kubernetes-security-kubelet-event-record-qps
title: Configure kubelet to capture all event creation
impact: 30
mql: |
kubelet.configuration['eventRecordQPS'] == 0
docs:
desc: |
Ensure that the kubelet is configured to capture all event creation so as to avoid potentially not logging important events.
Be aware that this might expose your Cluster to a DoS risk.
audit: |
If running the kubelet with the CLI parameter '--event-qps', or running with 'eventRecordQPS' defined in the kubelet configuration file, ensure that the value is set to '0'.
remediation: |
Set the '--event-qps' CLI parameter and/or the 'eventRecordQPS' field in the kubelet configuration file to '0'.
refs:
- url: https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration
title: Kubelet configuration
- uid: mondoo-kubernetes-security-kubelet-iptables-util-chains
title: Configure kubelet to ensure IPTables rules are set on host
impact: 30
mql: |
kubelet.configuration['makeIPTablesUtilChains'] == true
docs:
desc: |
Ensure that the kubelet is set up to create IPTable utility rules for various kubernetes components.
audit: |
If running the kubelet with the CLI parameter '--make-iptables-util-chains', or running with 'makeIPTablesUtilChains' defined in the kubelet configuration file, ensure that the value is set to 'true'.
remediation: |
Set the '--make-iptables-util-chains' CLI parameter and/or the 'makeIPTablesUtilChains' field in the kubelet configuration file to 'true'.
refs:
- url: https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration
title: Kubelet configuration
- uid: mondoo-kubernetes-security-kubelet-protect-kernel-defaults
title: Configure kubelet to protect kernel defaults
impact: 60
mql: |
kubelet.configuration["protectKernelDefaults"] == "true"
docs:
desc: |
Ensure that the kubelet is set up to error if the underlying kernel tunables are different than the kubelet defaults. By default the kubelet will attempt to modify the kernel as the kubelet starts up.
audit: |
If running the kubelet with the CLI parameter '--protect-kernel-defaults', or running with 'protectKernelDefaults' defined in the kubelet configuration file, ensure that the value is set to 'true'.
remediation: |
Set the '--protect-kernel-defaults' CLI parameter and/or the 'protectKernelDefaults' field in the kubelet configuration file to 'true'.
refs:
- url: https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration
title: Kubelet configuration
- uid: mondoo-kubernetes-security-kubelet-read-only-port
title: Do not allow unauthenticated read-only port on kubelet
impact: 60
mql: |
kubelet.configuration['readOnlyPort'] == 0 || kubelet.configuration['readOnlyPort'] == null
docs:
desc: |
Ensure the kubelet is not configured to serve up unauthenticated read-only access.
This would expose data to unauthenticated users.
audit: |
If running the kubelet with the CLI parameter '--read-only-port', or running with 'readOnlyPort' defined in the kubelet configuration file, ensure that the value is either '0' or simply not set ('0' is the default).
remediation: |
Set the '--read-only-port' CLI parameter or the 'readOnlyPort' field in the kubelet configuration file to '0'.
refs:
- url: https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration
title: Kubelet configuration
- uid: mondoo-kubernetes-security-kubelet-authorization-mode
title: Ensure the kubelet is not configured with the AlwaysAllow authorization mode
impact: 100
mql: |
kubelet.configuration['authorization']['mode'] != "AlwaysAllow"
docs:
desc: |
Ensure the kubelet is not configured with the AlwaysAllow authorization mode.
It would allow all requests.
audit: |
If running the kubelet with the CLI parameter '--authorization-mode', or running with 'authorization.mode' defined in the kubelet configuration file, ensure that the value is not set to 'AlwaysAllow'.
remediation: |
If the kubelet is configured with the CLI parameter '--authorization-mode', set it to something that isn't 'AlwaysAllow' (eg 'Webhook').
If the kubelet is configured via the kubelet config file with the 'authorization.mode' parameter, set it to something that isn't 'AlwaysAllow' (eg. 'Webhook').
refs:
- url: https://kubernetes.io/docs/reference/access-authn-authz/kubelet-authn-authz/#kubelet-authorization
title: Kubelet authorization
- uid: mondoo-kubernetes-security-kubelet-strong-ciphers
title: Configure kubelet to use only strong cryptography
impact: 100
props:
- uid: mondooKubernetesSecurityAllowedCiphers
title: Define the hardened SSL/ TLS ciphers
mql: |
return ["TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
"TLS_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_GCM_SHA256",
"TLS_RSA_WITH_AES_256_CBC_SHA", "TLS_RSA_WITH_AES_256_GCM_SHA384"]
mql: |
kubelet.configuration['tlsCipherSuites'] != empty
if (kubelet.configuration['tlsCipherSuites'] != empty) {
kubelet.configuration['tlsCipherSuites'].map( _.trim ).containsOnly(props.mondooKubernetesSecurityAllowedCiphers)
}
docs:
desc: |
Ensure the kubelet runs with only strong cryptography support. Weak or old ciphers might expose your data.
audit: |
If running the kubelet with the CLI parameter '--tls-cipher-suites', or running with 'tlsCipherSuites' defined in the kubelet configuration file, ensure that the list of allowed ciphers is not empty and that all included ciphers are included in the following list:
"TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", "TLS_RSA_WITH_3DES_EDE_CBC_SHA",
"TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_RSA_WITH_AES_256_CBC_SHA", "TLS_RSA_WITH_AES_256_GCM_SHA384"
remediation: |
Define the list of allowed TLS ciphers to include only items from the strong list of ciphers.
If the kubelet is configured with the CLI parameter '--tls-cipher-suites', update the list (or define the parameter) to only include strong ciphers.
If the kubelet is configured via the kubelet config file with the 'tlsCipherSuites' parameter, update the list (or create an entry for 'tlsCipherSuites') to only include string ciphers.
refs:
- url: https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration
title: Kubelet configuration
- uid: mondoo-kubernetes-security-kubelet-tls-certificate
title: Run kubelet with a user-provided certificate/key
impact: 100
mql: |
kubelet.configuration["tlsCertFile"] != empty
kubelet.configuration["tlsPrivateKeyFile"] != empty
docs:
desc: |
Ensure that the kubelet is not running with self-signed certificates generated by the kubelet itself.
audit: |
The kubelet CLI parameters override values in the kubelet configuration file.
Check the kubelet CLI parameters to see whether '--tls-cert-file' and '--tls-private-key' are set to a non-empty path/string.
Check the kubelet configuration file to see whether 'tlsCertFile' and 'tlsPrivateKeyFile' are set to a non-empty path/string.
remediation: |
Configure the kubelet to use a user-provided certificate/key pair for serving up HTTPS.
After acquiring the TLS certificate/key pair, update the kubelet configuration file
Or if using the deprecated kubelet CLI parameters, update the '--tls-cert-file' and '--tls-private-key-file' parameters to use the new certificate/key.
- uid: mondoo-kubernetes-security-kubelet-rotate-certificates
title: Run kubelet with automatic certificate rotation
impact: 80
mql: |
kubelet.configuration["rotateCertificates"] != "false"
docs:
desc: |
Ensure the kubelet is running with automatic certificate rotation so that the kubelet will automatically renew certificates with the API server as certificates near expiration.
Otherwise the communication between the kubelet and the API server will be interrupted.
audit: |
Check the kubelet CLI parameters to ensure '--rotate-certificates' is not set to false, and that the kubelet config file has not set 'rotateCertificates' to false.
remediation: |
Depending on where the configuration behavior is defined (CLI parameters override config file values), update the kubelet CLI parameters to set '--rotate-certificates' to true, and/or update the kubelet configuration to set 'rotateCertificates' to true.
refs:
- url: https://kubernetes.io/docs/tasks/tls/certificate-rotation/
title: Configure Certificate Rotation for the Kubelet
- uid: mondoo-kubernetes-security-secure-kubelet-config
title: Ownership and permissions of kubelet configuration should be restricted
impact: 80
mql: |
if (kubelet.configFile != empty) {
if (kubelet.configFile.exists) {
kubelet.configFile {
user.name == "root"
group.name == "root"
}
kubelet.configFile.permissions {
user_readable == true
user_executable == false
group_readable == false
group_writeable == false
group_executable == false
other_readable == false
other_writeable == false
other_executable == false
}
}
}
docs:
desc: |
Ensure proper file ownership and read-write-execute permissions for kubelet configuration file.
Otherwise unprivileged users might get access to sensitive information.
audit: |
View the kubelet configuration file details:
```
$ ls -l /etc/kubernetes/kubelet.conf
-rw-r--r-- 1 root root 1155 Sep 21 15:03 /etc/kubernetes/kubelet.conf
```
remediation: |
Update the ownership and permissions:
```bash
chown root:root /etc/kubernetes/kubelet.conf
chmod 600 /etc/kubernetes/kubelet.conf
```
- uid: mondoo-kubernetes-security-secure-kubelet-cert-authorities
title: Specify a kubelet certificate authorities file and ensure proper ownership and permissions
impact: 100
mql: |
kubelet.configuration['authentication']['x509']['clientCAFile'] != empty
if (kubelet.configuration['authentication']['x509']['clientCAFile'] != empty) {
cafile = kubelet.configuration["authentication"]["x509"]["clientCAFile"]
file(cafile) {
user.name == "root"
group.name == "root"
}
file(cafile).permissions {
user_readable == true
user_executable == false
group_readable == false
group_writeable == false
group_executable == false
other_readable == false
other_writeable == false
other_executable == false
}
}
docs:
desc: |
Ensure appropriate ownership and permissions for the kubelet's certificate authorities configuration file.
audit: |
View the ownership and permissions:
```
$ ls -l /etc/srv/kubernetes/pki/ca-certificates.crt
-rw------- 1 root root 1159 Sep 13 04:14 /etc/srv/kubernetes/pki/ca-certificates.crt
```
remediation: |
Update the ownership and permissions:
```bash
chown root:root /etc/srv/kubernetes/pki/ca-certificates.crt
chmod 600 /etc/srv/kubernetes/pki/ca-certificates.crt
```
- uid: mondoo-kubernetes-security-secure-kube-apiserver-yml
title: Set secure file permissions on the API server pod specification file
impact: 60
mql: |
if (file("/etc/kubernetes/manifests/kube-apiserver.yaml").exists) {
file("/etc/kubernetes/manifests/kube-apiserver.yaml") {
permissions.user_writeable == true
permissions.group_writeable == false
permissions.other_writeable == false
permissions.user_readable == true
permissions.group_readable == false
permissions.other_readable == false
permissions.user_executable == false
permissions.group_executable == false
permissions.other_executable == false
user.name == "root"
group.name == "root"
}
}
docs:
desc: |
Ensure that the API server pod specification file has permissions of `600` and is owned by `root:root`.
Otherwise unprivileged users might change it.
remediation: |-
Run this command on the Control Plane node:
```bash
chmod 600 /etc/kubernetes/manifests/kube-apiserver.yaml
chown root:root /etc/kubernetes/manifests/kube-apiserver.yaml
```
- uid: mondoo-kubernetes-security-secure-etcd-data-dir
title: |
Set secure directory permissions on the etcd data directory.
Otherwise unprivileged users might get access to sensitive data stored in etcd, i.e., Kubernetes Secrets.
impact: 60
mql: |
if (file("/var/lib/etcd").exists) {
file("/var/lib/etcd") {
permissions.user_writeable == true
permissions.group_writeable == false
permissions.other_writeable == false
permissions.user_readable == true
permissions.group_readable == false
permissions.other_readable == false
permissions.user_executable == true
permissions.group_executable == false
permissions.other_executable == false
user.name == "etcd"
group.name == "etcd"
}
} else {
dir = processes.where( executable == /etcd/ ).list[0].flags["data-dir"]
file(dir) {
permissions.user_writeable == true
permissions.group_writeable == false
permissions.other_writeable == false
permissions.user_readable == true
permissions.group_readable == false
permissions.other_readable == false
permissions.user_executable == true
permissions.group_executable == false
permissions.other_executable == false
user.name == "etcd"
group.name == "etcd"
}
}
docs:
desc: Ensure that the etcd data directory has permissions of `700` and is owned by `etcd:etcd`.
remediation: |-
On the etcd server node, get the etcd data directory, passed as an argument `--data-dir`, from the below command:
```bash
ps -ef | grep etcd
```
Run the below command:
```bash
chmod 700 /var/lib/etcd
```
refs:
- url: https://kubernetes.io/docs/concepts/configuration/secret/
title: Kubernetes Secrets
- uid: mondoo-kubernetes-security-secure-admin-conf
title: Set secure file permissions on the admin.conf file
impact: 60
mql: |
if (file("/etc/kubernetes/admin.conf").exists) {
file("/etc/kubernetes/admin.conf") {
permissions.user_writeable == true
permissions.group_writeable == false
permissions.other_writeable == false
permissions.user_readable == true
permissions.group_readable == false
permissions.other_readable == false
permissions.user_executable == false
permissions.group_executable == false
permissions.other_executable == false
user.name == "root"
group.name == "root"
}
}
docs:
desc: |
Ensure that the `admin.conf` file has permissions of `600` and is owned by root:root.
Otherwise unprivileged users might get admin access to the Kubernetes API server.
remediation: |-
Run this command on the Control Plane node:
```bash
chmod 600 /etc/kubernetes/admin.conf
chown root:root /etc/kubernetes/admin.conf
```
refs:
- url: https://kubernetes.io/docs/setup/
title: Kubernetes Setup
- uid: mondoo-kubernetes-security-secure-scheduler_conf
title: Set secure file permissions on the scheduler.conf file
impact: 60
mql: |
if (file("/etc/kubernetes/scheduler.conf").exists) {
file("/etc/kubernetes/scheduler.conf") {
permissions.user_writeable == true
permissions.group_writeable == false
permissions.other_writeable == false
permissions.user_readable == true
permissions.group_readable == false
permissions.other_readable == false
permissions.user_executable == false
permissions.group_executable == false
permissions.other_executable == false
user.name == "root"
group.name == "root"
}
}
docs:
desc: Ensure that the `scheduler.conf` file has permissions of `600` and is owned by `root:root`.
remediation: |-
Run this command on the Control Plane node:
```bash
chmod 600 /etc/kubernetes/scheduler.conf
chown root:root /etc/kubernetes/scheduler.conf
```
- uid: mondoo-kubernetes-security-secure-controller-manager_conf
title: Set secure file permissions on the controller-manager.conf file
impact: 60
mql: |
if (file("/etc/kubernetes/controller-manager.conf").exists) {
file("/etc/kubernetes/controller-manager.conf") {
permissions.user_writeable == true
permissions.group_writeable == false
permissions.other_writeable == false
permissions.user_readable == true
permissions.group_readable == false
permissions.other_readable == false
permissions.user_executable == false
permissions.group_executable == false
permissions.other_executable == false
user.name == "root"
group.name == "root"
}
}
docs:
desc: Ensure that the `controller-manager.conf` file has permissions of `600` and is owned by `root:root`.
remediation: |-
Run this command on the Control Plane node:
```bash
chmod 600 /etc/kubernetes/controller-manager.conf
chown root:root /etc/kubernetes/controller-manager.conf
```
- uid: mondoo-kubernetes-security-secure-pki-directory
title: Ensure that the Kubernetes PKI/SSL directory is owned by root:root
impact: 65
mql: |
if (processes.where(executable == /kube-apiserver/).list[0].flags["etcd-certfile"] != empty) {
clientCAFile = processes.where(executable == /kube-apiserver/).list[0].flags["etcd-certfile"]
ssldir = file(clientCAFile).dirname
file(ssldir) {
user.name == "root"
group.name == "root"
}
} else {
file("/etc/kubernetes/pki") {
user.name == "root"
group.name == "root"
}
}
docs:
desc: |
Ensure that the Kubernetes PKI/SSL directory is owned by `root:root`.
Otherwise unprivileged users could change the PKI/SSL certificates the whole encryption of the cluster relies on.
remediation: |-
Run one of these commands on the Control Plane node depending on the location of your PKI/SSL directory:
```bash
chown -R root:root /etc/kubernetes/pki/
```
or
```bash
chown -R root:root /etc/kubernetes/ssl/
````
refs:
- url: https://kubernetes.io/docs/setup/best-practices/certificates/
title: PKI certificates and requirements
- uid: mondoo-kubernetes-security-https-api-server
title: Ensure the kube-apiserver is not listening on an insecure HTTP port
impact: 70
mql: |
processes.where(executable == /kube-apiserver/).list {
flags["insecure-port"] == 0
}
docs:
desc: |
Ensure the kube-apiserver is not listening on an insecure HTTP port.
Otherwise unencrypted traffic could be intercepted and sensitive data could be leaked.
remediation: |-
Find the kube-apiserver process and check the `insecure-port` argument. If the argument is set to `0`, then the kube-apiserver is not listening on an insecure HTTP port:
```bash
ps aux | grep kube-apiserver
```
refs:
- url: https://kubernetes.io/docs/concepts/security/controlling-access/#transport-security
title: Controlling Access to the Kubernetes API - Transport security
- uid: mondoo-kubernetes-security-api-server-no-anonymous-auth
title: |
Ensure the kube-apiserver does not allow anonymous authentication.
When allowed, request will have the privileges of the role `system:public-info-viewer`. This might expose data to an attacker.
impact: 100
mql: |
processes.where(executable == /kube-apiserver/).list {
flags["anonymous-auth"] == "false"
}
docs:
desc: Ensure the kube-apiserver does not allow anonymous authentication.
remediation: |-
Find the kube-apiserver process and check the `--anonymous-auth` argument. If the argument is set to `false`, then the kube-apiserver does not allow anonymous authentication:
```bash
ps aux | grep kube-apiserver
```
refs:
- url: https://kubernetes.io/docs/reference/access-authn-authz/authentication/#anonymous-requests
title: Anonymous requests
- uid: mondoo-kubernetes-security-pod-docker-socket
title: Container should not mount the Docker socket
impact: 100
mql: |
k8s.pod {
podSpec['volumes'] == null || podSpec['volumes'].all(_['hostPath']['path'] != '/var/run/docker.sock')
}
docs:
desc: |
Do not mount the container runtime socket into any container.
This would allow direct access to the container runtime without any authentication.
This would allow to create privileged containers and to access the host file system.
Or create containers which would not show up in the Kubernetes API.
audit: |
Check for the existence of `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock
containers:
- name: app
image: images.my-company.example/app:v1.2.3
volumeMounts:
- mountPath: /var/run/docker.sock
name: vol
```
remediation: |
Ensure workloads do not have `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock # <--- this shouldn't be there
```
refs:
- url: https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html#rule-1-do-not-expose-the-docker-daemon-socket-even-to-the-containers
title: Docker security
- uid: mondoo-kubernetes-security-cronjob-docker-socket
title: Container should not mount the Docker socket
impact: 100
mql: |
k8s.cronjob {
podSpec['volumes'] == null || podSpec['volumes'].all(_['hostPath']['path'] != '/var/run/docker.sock')
}
docs:
desc: |
Do not mount the container runtime socket into any container.
This would allow direct access to the container runtime without any authentication.
This would allow to create privileged containers and to access the host file system.
Or create containers which would not show up in the Kubernetes API.
audit: |
Check for the existence of `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock
containers:
- name: app
image: images.my-company.example/app:v1.2.3
volumeMounts:
- mountPath: /var/run/docker.sock
name: vol
```
remediation: |
Ensure workloads do not have `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock # <--- this shouldn't be there
```
refs:
- url: https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html#rule-1-do-not-expose-the-docker-daemon-socket-even-to-the-containers
title: Docker security
- uid: mondoo-kubernetes-security-statefulset-docker-socket
title: Container should not mount the Docker socket
impact: 100
mql: k8s.statefulset.podSpec['volumes'] == null || k8s.statefulset.podSpec['volumes'].all(_['hostPath']['path'] != '/var/run/docker.sock')
docs:
desc: |
Do not mount the container runtime socket into any container.
This would allow direct access to the container runtime without any authentication.
This would allow to create privileged containers and to access the host file system.
Or create containers which would not show up in the Kubernetes API.
audit: |
Check for the existence of `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock
containers:
- name: app
image: images.my-company.example/app:v1.2.3
volumeMounts:
- mountPath: /var/run/docker.sock
name: vol
```
remediation: |
Ensure workloads do not have `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock # <--- this shouldn't be there
```
refs:
- url: https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html#rule-1-do-not-expose-the-docker-daemon-socket-even-to-the-containers
title: Docker security
- uid: mondoo-kubernetes-security-deployment-docker-socket
title: Container should not mount the Docker socket
impact: 100
mql: k8s.deployment.podSpec['volumes'] == null || k8s.deployment.podSpec['volumes'].all(_['hostPath']['path'] != '/var/run/docker.sock')
docs:
desc: |
Do not mount the container runtime socket into any container.
This would allow direct access to the container runtime without any authentication.
This would allow to create privileged containers and to access the host file system.
Or create containers which would not show up in the Kubernetes API.
audit: |
Check for the existence of `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock
containers:
- name: app
image: images.my-company.example/app:v1.2.3
volumeMounts:
- mountPath: /var/run/docker.sock
name: vol
```
remediation: |
Ensure workloads do not have `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock # <--- this shouldn't be there
```
refs:
- url: https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html#rule-1-do-not-expose-the-docker-daemon-socket-even-to-the-containers
title: Docker security
- uid: mondoo-kubernetes-security-job-docker-socket
title: Container should not mount the Docker socket
impact: 100
mql: k8s.job.podSpec['volumes'] == null || k8s.job.podSpec['volumes'].all(_['hostPath']['path'] != '/var/run/docker.sock')
docs:
desc: |
Do not mount the container runtime socket into any container.
This would allow direct access to the container runtime without any authentication.
This would allow to create privileged containers and to access the host file system.
Or create containers which would not show up in the Kubernetes API.
audit: |
Check for the existence of `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock
containers:
- name: app
image: images.my-company.example/app:v1.2.3
volumeMounts:
- mountPath: /var/run/docker.sock
name: vol
```
remediation: |
Ensure workloads do not have `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: vol
hostPath:
- path: /var/run/docker.sock # <--- this shouldn't be there
```
refs:
- url: https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html#rule-1-do-not-expose-the-docker-daemon-socket-even-to-the-containers
title: Docker security
- uid: mondoo-kubernetes-security-replicaset-docker-socket
title: Container should not mount the Docker socket
impact: 100
mql: k8s.replicaset.podSpec['volumes'] == null || k8s.replicaset.podSpec['volumes'].all(_['hostPath']['path'] != '/var/run/docker.sock')
docs:
desc: |
Do not mount the container runtime socket into any container.
This would allow direct access to the container runtime without any authentication.
This would allow to create privileged containers and to access the host file system.
Or create containers which would not show up in the Kubernetes API.
audit: |
Check for the existence of `hostPath.path: /var/run/docker.sock` setting in the `volumes`:
```yaml
---
apiVersion: v1