Skip to content

Commit

Permalink
Use RabbitMQ user for init container instead of root (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
coro authored Jun 17, 2021
1 parent 032d28a commit 39ab8b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
19 changes: 2 additions & 17 deletions internal/resource/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,23 +540,8 @@ func (builder *StatefulSetBuilder) podTemplateSpec(previousPodAnnotations map[st
Name: "setup-container",
Image: builder.Instance.Spec.Image,
SecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64Ptr(0),
Capabilities: &corev1.Capabilities{
// drop default set from Docker except for CHOWN, FOWNER, and DAC_OVERRIDE
Drop: []corev1.Capability{
"FSETID",
"KILL",
"SETGID",
"SETUID",
"SETPCAP",
"NET_BIND_SERVICE",
"NET_RAW",
"SYS_CHROOT",
"MKNOD",
"AUDIT_WRITE",
"SETFCAP",
},
},
RunAsGroup: &rabbitmqGID,
RunAsUser: &rabbitmqUID,
},
Command: []string{
"sh", "-c", "cp /tmp/erlang-cookie-secret/.erlang.cookie /var/lib/rabbitmq/.erlang.cookie " +
Expand Down
19 changes: 3 additions & 16 deletions internal/resource/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,26 +1217,13 @@ var _ = Describe("StatefulSet", func() {
initContainers := statefulSet.Spec.Template.Spec.InitContainers
Expect(initContainers).To(HaveLen(1))

rmqGID, rmqUID := int64(999), int64(999)
initContainer := extractContainer(initContainers, "setup-container")
Expect(initContainer).To(MatchFields(IgnoreExtras, Fields{
"Image": Equal("rabbitmq-image-from-cr"),
"SecurityContext": PointTo(MatchFields(IgnoreExtras, Fields{
"Capabilities": PointTo(MatchAllFields(Fields{
"Drop": ConsistOf([]corev1.Capability{
"FSETID",
"KILL",
"SETGID",
"SETUID",
"SETPCAP",
"NET_BIND_SERVICE",
"NET_RAW",
"SYS_CHROOT",
"MKNOD",
"AUDIT_WRITE",
"SETFCAP",
}),
"Add": BeEmpty(),
})),
"RunAsUser": Equal(&rmqUID),
"RunAsGroup": Equal(&rmqGID),
})),
"Command": ConsistOf(
"sh", "-c", "cp /tmp/erlang-cookie-secret/.erlang.cookie /var/lib/rabbitmq/.erlang.cookie "+
Expand Down

0 comments on commit 39ab8b1

Please sign in to comment.