|
6 | 6 | . "github.com/onsi/gomega" //revive:disable:dot-imports |
7 | 7 |
|
8 | 8 | instancehav1 "github.com/openstack-k8s-operators/infra-operator/apis/instanceha/v1beta1" |
| 9 | + corev1 "k8s.io/api/core/v1" |
9 | 10 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
10 | 11 | ) |
11 | 12 |
|
@@ -101,6 +102,51 @@ func TestDeploymentSecurityContext(t *testing.T) { |
101 | 102 | g.Expect(container.SecurityContext.ReadOnlyRootFilesystem).NotTo(BeNil()) |
102 | 103 | g.Expect(*container.SecurityContext.ReadOnlyRootFilesystem).To(BeTrue()) |
103 | 104 |
|
| 105 | + g.Expect(container.SecurityContext.RunAsNonRoot).NotTo(BeNil()) |
| 106 | + g.Expect(*container.SecurityContext.RunAsNonRoot).To(BeTrue()) |
| 107 | + |
| 108 | + g.Expect(container.SecurityContext.RunAsUser).NotTo(BeNil()) |
| 109 | + g.Expect(*container.SecurityContext.RunAsUser).To(Equal(int64(42401))) |
| 110 | + |
| 111 | + g.Expect(container.SecurityContext.RunAsGroup).NotTo(BeNil()) |
| 112 | + g.Expect(*container.SecurityContext.RunAsGroup).To(Equal(int64(42401))) |
| 113 | + |
| 114 | + g.Expect(container.SecurityContext.AllowPrivilegeEscalation).NotTo(BeNil()) |
| 115 | + g.Expect(*container.SecurityContext.AllowPrivilegeEscalation).To(BeFalse()) |
| 116 | + |
| 117 | + g.Expect(container.SecurityContext.Capabilities).NotTo(BeNil()) |
| 118 | + g.Expect(container.SecurityContext.Capabilities.Drop).To(ContainElement(corev1.Capability("ALL"))) |
| 119 | + |
| 120 | + g.Expect(container.SecurityContext.SeccompProfile).NotTo(BeNil()) |
| 121 | + g.Expect(container.SecurityContext.SeccompProfile.Type).To(Equal(corev1.SeccompProfileTypeRuntimeDefault)) |
| 122 | + |
| 123 | + // Verify AutomountServiceAccountToken is disabled |
| 124 | + g.Expect(dep.Spec.Template.Spec.AutomountServiceAccountToken).NotTo(BeNil()) |
| 125 | + g.Expect(*dep.Spec.Template.Spec.AutomountServiceAccountToken).To(BeFalse()) |
| 126 | + |
| 127 | + // Verify kube-api-access projected volume exists |
| 128 | + var kubeAPIVolumeFound bool |
| 129 | + for _, vol := range dep.Spec.Template.Spec.Volumes { |
| 130 | + if vol.Name == "kube-api-access" { |
| 131 | + kubeAPIVolumeFound = true |
| 132 | + g.Expect(vol.VolumeSource.Projected).NotTo(BeNil()) |
| 133 | + g.Expect(vol.VolumeSource.Projected.Sources).To(HaveLen(3)) |
| 134 | + break |
| 135 | + } |
| 136 | + } |
| 137 | + g.Expect(kubeAPIVolumeFound).To(BeTrue(), "kube-api-access projected volume should exist") |
| 138 | + |
| 139 | + // Verify kube-api-access mount exists |
| 140 | + var kubeAPIMountFound bool |
| 141 | + for _, mount := range container.VolumeMounts { |
| 142 | + if mount.Name == "kube-api-access" && mount.MountPath == "/var/run/secrets/kubernetes.io/serviceaccount" { |
| 143 | + kubeAPIMountFound = true |
| 144 | + g.Expect(mount.ReadOnly).To(BeTrue()) |
| 145 | + break |
| 146 | + } |
| 147 | + } |
| 148 | + g.Expect(kubeAPIMountFound).To(BeTrue(), "kube-api-access volume mount should exist") |
| 149 | + |
104 | 150 | // Verify /tmp emptyDir volume exists |
105 | 151 | var tmpVolumeFound bool |
106 | 152 | for _, vol := range dep.Spec.Template.Spec.Volumes { |
|
0 commit comments