Skip to content

Commit 539eea5

Browse files
committed
FIPS support for RabbitMQ
When the OCP cluster is deployed in FIPS mode RabbitMQ needs to be deployed with specific parameters to also enable its FIPS mode. This patch checks when OCP is running in FIPS mode using lib-common and changes the environmental variables used to deploy RabbitMQ just like we did in TripleO [1]. [1]: https://opendev.org/openstack/puppet-tripleo/src/commit/019ec495180d2065a172861554df2ba2a76b5b17/manifests/profile/base/rabbitmq.pp#L176 Jira: #OSPRH-4668 Depends-On: openstack-k8s-operators/lib-common#448
1 parent 3eaeac7 commit 539eea5

File tree

1 file changed

+53
-32
lines changed

1 file changed

+53
-32
lines changed

pkg/openstack/rabbitmq.go

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/openstack-k8s-operators/lib-common/modules/certmanager"
1010
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
1111
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
12+
"github.com/openstack-k8s-operators/lib-common/modules/common/ocp"
1213
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
1314
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
1415
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
@@ -113,6 +114,57 @@ func reconcileRabbitMQ(
113114
return mqReady, ctrl.Result{}, nil
114115
}
115116

117+
envVars := []corev1.EnvVar{
118+
{
119+
// The upstream rabbitmq image has /var/log/rabbitmq mode 777, so when
120+
// openshift runs the rabbitmq container as a random uid it can still write
121+
// the logs there. The OSP image however has the directory more constrained,
122+
// so the random uid cannot write the logs there. Force it into /var/lib
123+
// where it can create the file without crashing.
124+
Name: "RABBITMQ_UPGRADE_LOG",
125+
Value: "/var/lib/rabbitmq/rabbitmq_upgrade.log",
126+
},
127+
{
128+
// For some reason HOME needs to be explictly set here even though the entry
129+
// for the random user in /etc/passwd has the correct homedir set.
130+
Name: "HOME",
131+
Value: "/var/lib/rabbitmq",
132+
},
133+
{
134+
// The various /usr/sbin/rabbitmq* scripts are really all the same
135+
// wrapper shell-script that performs some "sanity checks" and then
136+
// invokes the corresponding "real" program in
137+
// /usr/lib/rabbitmq/bin. The main "sanity check" is to ensure that
138+
// the user running the command is either root or rabbitmq. Inside
139+
// of an openshift pod, however, the user is neither of these, so
140+
// the wrapper script will always fail.
141+
142+
// By putting the real programs ahead of the wrapper in PATH we can
143+
// avoid the unnecessary check and just run things directly as
144+
// whatever user the pod has graciously generated for us.
145+
Name: "PATH",
146+
Value: "/usr/lib/rabbitmq/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
147+
},
148+
}
149+
150+
if instance.Spec.TLS.PodLevel.Enabled {
151+
fipsEnabled, err := ocp.IsFipsCluster(ctx, helper)
152+
if err != nil {
153+
return mqFailed, ctrl.Result{}, err
154+
}
155+
if fipsEnabled {
156+
fipsModeStr := "-crypto fips_mode true"
157+
158+
envVars = append(envVars, corev1.EnvVar{
159+
Name: "RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS",
160+
Value: fipsModeStr,
161+
}, corev1.EnvVar{
162+
Name: "RABBITMQ_CTL_ERL_ARGS",
163+
Value: fipsModeStr,
164+
})
165+
}
166+
}
167+
116168
defaultStatefulSet := rabbitmqv2.StatefulSet{
117169
Spec: &rabbitmqv2.StatefulSetSpec{
118170
Template: &rabbitmqv2.PodTemplateSpec{
@@ -127,38 +179,7 @@ func reconcileRabbitMQ(
127179
// NOTE(gibi): without this the second RabbitMqCluster
128180
// will fail as the Pod will have no image.
129181
Image: spec.Image,
130-
Env: []corev1.EnvVar{
131-
{
132-
// The upstream rabbitmq image has /var/log/rabbitmq mode 777, so when
133-
// openshift runs the rabbitmq container as a random uid it can still write
134-
// the logs there. The OSP image however has the directory more constrained,
135-
// so the random uid cannot write the logs there. Force it into /var/lib
136-
// where it can create the file without crashing.
137-
Name: "RABBITMQ_UPGRADE_LOG",
138-
Value: "/var/lib/rabbitmq/rabbitmq_upgrade.log",
139-
},
140-
{
141-
// For some reason HOME needs to be explictly set here even though the entry
142-
// for the random user in /etc/passwd has the correct homedir set.
143-
Name: "HOME",
144-
Value: "/var/lib/rabbitmq",
145-
},
146-
{
147-
// The various /usr/sbin/rabbitmq* scripts are really all the same
148-
// wrapper shell-script that performs some "sanity checks" and then
149-
// invokes the corresponding "real" program in
150-
// /usr/lib/rabbitmq/bin. The main "sanity check" is to ensure that
151-
// the user running the command is either root or rabbitmq. Inside
152-
// of an openshift pod, however, the user is neither of these, so
153-
// the wrapper script will always fail.
154-
155-
// By putting the real programs ahead of the wrapper in PATH we can
156-
// avoid the unnecessary check and just run things directly as
157-
// whatever user the pod has graciously generated for us.
158-
Name: "PATH",
159-
Value: "/usr/lib/rabbitmq/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
160-
},
161-
},
182+
Env: envVars,
162183
Args: []string{
163184
// OSP17 runs kolla_start here, instead just run rabbitmq-server directly
164185
"/usr/lib/rabbitmq/bin/rabbitmq-server",

0 commit comments

Comments
 (0)