Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run manila services using manila user/group #317

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/manila/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ 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 -
ManilaUserID int64 = 42429
// ManilaGroupID -
ManilaGroupID int64 = 42429

// ManilaPublicPort -
ManilaPublicPort int32 = 8786
// ManilaInternalPort -
Expand Down Expand Up @@ -71,6 +79,8 @@ const (
ShortDuration = time.Duration(5) * time.Second
// NormalDuration -
NormalDuration = time.Duration(10) * time.Second
//DBSyncCommand -
DBSyncCommand = "/usr/bin/manila-manage --config-dir /etc/manila/manila.conf.d db sync"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ Thanks; i do think this is a good improvement even in isolation!

)

// DbsyncPropagation keeps track of the DBSync Service Propagation Type
Expand Down
2 changes: 1 addition & 1 deletion pkg/manila/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func CronJob(
},
Args: args,
VolumeMounts: cronJobVolumeMounts,
SecurityContext: GetManilaSecurityContext(),
SecurityContext: manilaDefaultSecurityContext(),
},
},
Volumes: cronJobVolume,
Expand Down
18 changes: 5 additions & 13 deletions pkg/manila/dbsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

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

// DbSyncJob func
func DbSyncJob(instance *manilav1.Manila, labels map[string]string, annotations map[string]string) *batchv1.Job {
var config0644AccessMode int32 = 0644
Expand Down Expand Up @@ -75,7 +70,6 @@ func DbSyncJob(instance *manilav1.Manila, labels map[string]string, annotations
dbSyncMounts = append(dbSyncMounts, instance.Spec.ManilaAPI.TLS.CreateVolumeMounts(nil)...)
}

runAsUser := int64(0)
envVars := map[string]env.Setter{}
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
envVars["KOLLA_BOOTSTRAP"] = env.SetValue("TRUE")
Expand All @@ -100,13 +94,11 @@ func DbSyncJob(instance *manilav1.Manila, labels map[string]string, annotations
Command: []string{
"/bin/bash",
},
Args: args,
Image: instance.Spec.ManilaAPI.ContainerImage,
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: dbSyncMounts,
Args: args,
Image: instance.Spec.ManilaAPI.ContainerImage,
SecurityContext: manilaDefaultSecurityContext(),
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: dbSyncMounts,
},
},
Volumes: dbSyncVolume,
Expand Down
8 changes: 4 additions & 4 deletions pkg/manila/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func GetOwningManilaName(instance client.Object) string {
return ""
}

// GetManilaSecurityContext - Returns the right set of SecurityContext that
// manilaDefaultSecurityContext - Returns the right set of SecurityContext that
// does not violate the k8s requirements
func GetManilaSecurityContext() *corev1.SecurityContext {
func manilaDefaultSecurityContext() *corev1.SecurityContext {
falseVal := false
trueVal := true
runAsUser := int64(42429)
runAsGroup := int64(42429)
runAsUser := ManilaUserID
runAsGroup := ManilaGroupID
return &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
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
3 changes: 0 additions & 3 deletions templates/manila/config/db-sync-config.json

This file was deleted.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you discover this when testing capabilities? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, w/o this it fails when using manilaUser


# 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
Loading