@@ -68,6 +68,27 @@ func TestConfigMapUnpacker(t *testing.T) {
68
68
roleBindings []* rbacv1.RoleBinding
69
69
}
70
70
71
+ var expectedReadOnlyRootFilesystem = false
72
+ var expectedAllowPrivilegeEscalation = false
73
+ var expectedRunAsNonRoot = true
74
+ var expectedRunAsUser int64 = 1001
75
+
76
+ var expectedContainerSecurityContext = & corev1.SecurityContext {
77
+ ReadOnlyRootFilesystem : & expectedReadOnlyRootFilesystem ,
78
+ AllowPrivilegeEscalation : & expectedAllowPrivilegeEscalation ,
79
+ Capabilities : & corev1.Capabilities {
80
+ Drop : []corev1.Capability {"ALL" },
81
+ },
82
+ }
83
+
84
+ var expectedPodSecurityContext = & corev1.PodSecurityContext {
85
+ RunAsNonRoot : & expectedRunAsNonRoot ,
86
+ RunAsUser : & expectedRunAsUser ,
87
+ SeccompProfile : & corev1.SeccompProfile {
88
+ Type : corev1 .SeccompProfileTypeRuntimeDefault ,
89
+ },
90
+ }
91
+
71
92
tests := []struct {
72
93
description string
73
94
fields fields
@@ -220,6 +241,7 @@ func TestConfigMapUnpacker(t *testing.T) {
220
241
Spec : corev1.PodSpec {
221
242
RestartPolicy : corev1 .RestartPolicyNever ,
222
243
ImagePullSecrets : []corev1.LocalObjectReference {{Name : "my-secret" }},
244
+ SecurityContext : expectedPodSecurityContext ,
223
245
Containers : []corev1.Container {
224
246
{
225
247
Name : "extract" ,
@@ -243,6 +265,7 @@ func TestConfigMapUnpacker(t *testing.T) {
243
265
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
244
266
},
245
267
},
268
+ SecurityContext : expectedContainerSecurityContext ,
246
269
},
247
270
},
248
271
InitContainers : []corev1.Container {
@@ -262,6 +285,7 @@ func TestConfigMapUnpacker(t *testing.T) {
262
285
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
263
286
},
264
287
},
288
+ SecurityContext : expectedContainerSecurityContext ,
265
289
},
266
290
{
267
291
Name : "pull" ,
@@ -284,6 +308,7 @@ func TestConfigMapUnpacker(t *testing.T) {
284
308
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
285
309
},
286
310
},
311
+ SecurityContext : expectedContainerSecurityContext ,
287
312
},
288
313
},
289
314
Volumes : []corev1.Volume {
@@ -396,7 +421,8 @@ func TestConfigMapUnpacker(t *testing.T) {
396
421
Name : pathHash ,
397
422
},
398
423
Spec : corev1.PodSpec {
399
- RestartPolicy : corev1 .RestartPolicyNever ,
424
+ RestartPolicy : corev1 .RestartPolicyNever ,
425
+ SecurityContext : expectedPodSecurityContext ,
400
426
Containers : []corev1.Container {
401
427
{
402
428
Name : "extract" ,
@@ -420,6 +446,7 @@ func TestConfigMapUnpacker(t *testing.T) {
420
446
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
421
447
},
422
448
},
449
+ SecurityContext : expectedContainerSecurityContext ,
423
450
},
424
451
},
425
452
InitContainers : []corev1.Container {
@@ -439,6 +466,7 @@ func TestConfigMapUnpacker(t *testing.T) {
439
466
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
440
467
},
441
468
},
469
+ SecurityContext : expectedContainerSecurityContext ,
442
470
},
443
471
{
444
472
Name : "pull" ,
@@ -461,6 +489,7 @@ func TestConfigMapUnpacker(t *testing.T) {
461
489
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
462
490
},
463
491
},
492
+ SecurityContext : expectedContainerSecurityContext ,
464
493
},
465
494
},
466
495
Volumes : []corev1.Volume {
@@ -614,7 +643,8 @@ func TestConfigMapUnpacker(t *testing.T) {
614
643
Name : pathHash ,
615
644
},
616
645
Spec : corev1.PodSpec {
617
- RestartPolicy : corev1 .RestartPolicyNever ,
646
+ RestartPolicy : corev1 .RestartPolicyNever ,
647
+ SecurityContext : expectedPodSecurityContext ,
618
648
Containers : []corev1.Container {
619
649
{
620
650
Name : "extract" ,
@@ -638,6 +668,7 @@ func TestConfigMapUnpacker(t *testing.T) {
638
668
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
639
669
},
640
670
},
671
+ SecurityContext : expectedContainerSecurityContext ,
641
672
},
642
673
},
643
674
InitContainers : []corev1.Container {
@@ -657,6 +688,7 @@ func TestConfigMapUnpacker(t *testing.T) {
657
688
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
658
689
},
659
690
},
691
+ SecurityContext : expectedContainerSecurityContext ,
660
692
},
661
693
{
662
694
Name : "pull" ,
@@ -679,6 +711,7 @@ func TestConfigMapUnpacker(t *testing.T) {
679
711
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
680
712
},
681
713
},
714
+ SecurityContext : expectedContainerSecurityContext ,
682
715
},
683
716
},
684
717
Volumes : []corev1.Volume {
@@ -826,7 +859,8 @@ func TestConfigMapUnpacker(t *testing.T) {
826
859
Name : pathHash ,
827
860
},
828
861
Spec : corev1.PodSpec {
829
- RestartPolicy : corev1 .RestartPolicyNever ,
862
+ RestartPolicy : corev1 .RestartPolicyNever ,
863
+ SecurityContext : expectedPodSecurityContext ,
830
864
Containers : []corev1.Container {
831
865
{
832
866
Name : "extract" ,
@@ -850,6 +884,7 @@ func TestConfigMapUnpacker(t *testing.T) {
850
884
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
851
885
},
852
886
},
887
+ SecurityContext : expectedContainerSecurityContext ,
853
888
},
854
889
},
855
890
InitContainers : []corev1.Container {
@@ -869,6 +904,7 @@ func TestConfigMapUnpacker(t *testing.T) {
869
904
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
870
905
},
871
906
},
907
+ SecurityContext : expectedContainerSecurityContext ,
872
908
},
873
909
{
874
910
Name : "pull" ,
@@ -891,6 +927,7 @@ func TestConfigMapUnpacker(t *testing.T) {
891
927
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
892
928
},
893
929
},
930
+ SecurityContext : expectedContainerSecurityContext ,
894
931
},
895
932
},
896
933
Volumes : []corev1.Volume {
@@ -1008,7 +1045,8 @@ func TestConfigMapUnpacker(t *testing.T) {
1008
1045
Name : pathHash ,
1009
1046
},
1010
1047
Spec : corev1.PodSpec {
1011
- RestartPolicy : corev1 .RestartPolicyNever ,
1048
+ RestartPolicy : corev1 .RestartPolicyNever ,
1049
+ SecurityContext : expectedPodSecurityContext ,
1012
1050
Containers : []corev1.Container {
1013
1051
{
1014
1052
Name : "extract" ,
@@ -1032,6 +1070,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1032
1070
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1033
1071
},
1034
1072
},
1073
+ SecurityContext : expectedContainerSecurityContext ,
1035
1074
},
1036
1075
},
1037
1076
InitContainers : []corev1.Container {
@@ -1051,6 +1090,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1051
1090
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1052
1091
},
1053
1092
},
1093
+ SecurityContext : expectedContainerSecurityContext ,
1054
1094
},
1055
1095
{
1056
1096
Name : "pull" ,
@@ -1073,6 +1113,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1073
1113
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1074
1114
},
1075
1115
},
1116
+ SecurityContext : expectedContainerSecurityContext ,
1076
1117
},
1077
1118
},
1078
1119
Volumes : []corev1.Volume {
@@ -1201,7 +1242,8 @@ func TestConfigMapUnpacker(t *testing.T) {
1201
1242
Name : pathHash ,
1202
1243
},
1203
1244
Spec : corev1.PodSpec {
1204
- RestartPolicy : corev1 .RestartPolicyNever ,
1245
+ RestartPolicy : corev1 .RestartPolicyNever ,
1246
+ SecurityContext : expectedPodSecurityContext ,
1205
1247
Containers : []corev1.Container {
1206
1248
{
1207
1249
Name : "extract" ,
@@ -1225,6 +1267,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1225
1267
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1226
1268
},
1227
1269
},
1270
+ SecurityContext : expectedContainerSecurityContext ,
1228
1271
},
1229
1272
},
1230
1273
InitContainers : []corev1.Container {
@@ -1244,6 +1287,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1244
1287
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1245
1288
},
1246
1289
},
1290
+ SecurityContext : expectedContainerSecurityContext ,
1247
1291
},
1248
1292
{
1249
1293
Name : "pull" ,
@@ -1266,6 +1310,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1266
1310
corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
1267
1311
},
1268
1312
},
1313
+ SecurityContext : expectedContainerSecurityContext ,
1269
1314
},
1270
1315
},
1271
1316
Volumes : []corev1.Volume {
0 commit comments