Skip to content

Commit

Permalink
Run manila services using manila user/group
Browse files Browse the repository at this point in the history
This patch represents an improvment of the existing code to make sure we
run manila services using the manila user instead of root.

Jira: https://issues.redhat.com/browse/OSPRH-9115

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Aug 14, 2024
1 parent c5c6218 commit e0cd251
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
5 changes: 5 additions & 0 deletions pkg/manila/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const (
// is to be generated, e.g. "manila_e5a4", "manila_78bc", etc
DatabaseUsernamePrefix = "manila"

// Manila's uid and gid magic numbers come from the 'manila-user' in
// https://github.com/openstack/kolla/blob/master/kolla/common/users.py
ManilaUserID int64 = 42429
ManilaGroupID int64 = 42429

// ManilaPublicPort -
ManilaPublicPort int32 = 8786
// ManilaInternalPort -
Expand Down
8 changes: 4 additions & 4 deletions pkg/manilaapi/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

const (
// ServiceCommand -
ServiceCommand = "/usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start"
ServiceCommand = "/usr/local/bin/kolla_start"
)

// StatefulSet func
Expand All @@ -37,7 +37,7 @@ func StatefulSet(
labels map[string]string,
annotations map[string]string,
) (*appsv1.StatefulSet, error) {
runAsUser := int64(0)
manilaUser := manila.ManilaUserID

livenessProbe := &corev1.Probe{
TimeoutSeconds: 10,
Expand Down Expand Up @@ -134,7 +134,7 @@ func StatefulSet(
},
Image: instance.Spec.ContainerImage,
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsUser: &manilaUser,
},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: []corev1.VolumeMount{GetLogVolumeMount()},
Expand All @@ -154,7 +154,7 @@ func StatefulSet(
},
Image: instance.Spec.ContainerImage,
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsUser: &manilaUser,
},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: volumeMounts,
Expand Down
11 changes: 4 additions & 7 deletions pkg/manilascheduler/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

const (
// ServiceCommand -
ServiceCommand = "/usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start"
ServiceCommand = "/usr/local/bin/kolla_start"
)

// StatefulSet func
Expand All @@ -35,11 +35,8 @@ func StatefulSet(
labels map[string]string,
annotations map[string]string,
) *appsv1.StatefulSet {
rootUser := int64(0)
// manila's uid and gid magic numbers come from the 'manila-user' in
// https://github.com/openstack/kolla/blob/master/kolla/common/users.py
manilaUser := int64(42429)
manilaGroup := int64(42429)
manilaUser := manila.ManilaUserID
manilaGroup := manila.ManilaGroupID

livenessProbe := &corev1.Probe{
// TODO might need tuning
Expand Down Expand Up @@ -115,7 +112,7 @@ func StatefulSet(
},
Image: instance.Spec.ContainerImage,
SecurityContext: &corev1.SecurityContext{
RunAsUser: &rootUser,
RunAsUser: &manilaUser,
},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: volumeMounts,
Expand Down
12 changes: 5 additions & 7 deletions pkg/manilashare/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

const (
// ServiceCommand -
ServiceCommand = "/usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start"
ServiceCommand = "/usr/local/bin/kolla_start"
)

// StatefulSet func
Expand All @@ -36,11 +36,9 @@ func StatefulSet(
annotations map[string]string,
) *appsv1.StatefulSet {
trueVar := true
rootUser := int64(0)
// Manila's uid and gid magic numbers come from the 'manila-user' in
// https://github.com/openstack/kolla/blob/master/kolla/common/users.py
manilaUser := int64(42429)
manilaGroup := int64(42429)

manilaUser := manila.ManilaUserID
manilaGroup := manila.ManilaGroupID

// TODO until we determine how to properly query for these
livenessProbe := &corev1.Probe{
Expand Down Expand Up @@ -129,7 +127,7 @@ func StatefulSet(
},
Image: instance.Spec.ContainerImage,
SecurityContext: &corev1.SecurityContext{
RunAsUser: &rootUser,
RunAsUser: &manilaUser,
Privileged: &trueVar,
},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
Expand Down
1 change: 1 addition & 0 deletions templates/manila/config/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-A
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog /dev/stdout combined env=!forwarded
CustomLog /dev/stdout proxy env=forwarded
ErrorLog /dev/stdout

# XXX: To disable SSL
#Include conf.d/*.conf
Expand Down
11 changes: 8 additions & 3 deletions templates/manila/config/manila-api-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
{
"source": "/var/lib/config-data/default/ssl.conf",
"dest": "/etc/httpd/conf.d/ssl.conf",
"owner": "root",
"owner": "manila",
"perm": "0644"
},
{
"source": "/var/lib/config-data/tls/certs/*",
"dest": "/etc/pki/tls/certs/",
"owner": "root",
"owner": "manila",
"perm": "0640",
"optional": true,
"merge": true
},
{
"source": "/var/lib/config-data/tls/private/*",
"dest": "/etc/pki/tls/private/",
"owner": "root",
"owner": "manila",
"perm": "0600",
"optional": true,
"merge": true
Expand All @@ -41,6 +41,11 @@
"path": "/var/log/manila",
"owner": "manila:apache",
"recurse": true
},
{
"path": "/etc/httpd/run",
"owner": "manila:apache",
"recurse": true
}
]
}
6 changes: 3 additions & 3 deletions test/kuttl/tests/manila-tls/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ spec:
- --
- /bin/bash
- -c
- /usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start
- /usr/local/bin/kolla_start
command:
- /usr/bin/dumb-init
volumeMounts:
Expand Down Expand Up @@ -365,7 +365,7 @@ spec:
- --
- /bin/bash
- -c
- /usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start
- /usr/local/bin/kolla_start
command:
- /usr/bin/dumb-init
volumeMounts:
Expand Down Expand Up @@ -488,7 +488,7 @@ spec:
- --
- /bin/bash
- -c
- /usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start
- /usr/local/bin/kolla_start
command:
- /usr/bin/dumb-init
volumeMounts:
Expand Down

0 comments on commit e0cd251

Please sign in to comment.