Skip to content

Commit

Permalink
Run httpd using kolla
Browse files Browse the repository at this point in the history
Instead of running the httpd -DFOREGROUND command as entrypoint for the
-httpd sidecar container, this change moves the file copy and deployment
logic to kolla.
This is a requirement to not run the container as root user, because
kolla helps to apply the right permissions to the config files (and pid)
used by the process.
The switch from root user to GlanceUID (already present as const) will
be part of a different patch.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Sep 9, 2024
1 parent 33fe3c0 commit 79def76
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 63 deletions.
35 changes: 25 additions & 10 deletions pkg/glance/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,13 @@ func GetHttpdVolumeMount() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: "config-data",
MountPath: "/etc/httpd/conf/httpd.conf",
SubPath: "httpd.conf",
ReadOnly: true,
},
{
Name: "config-data",
MountPath: "/etc/httpd/conf.d/10-glance.conf",
SubPath: "10-glance-httpd.conf",
MountPath: "/var/lib/config-data/default",
ReadOnly: true,
},
{
Name: "config-data",
MountPath: "/etc/httpd/conf.d/ssl.conf",
SubPath: "ssl.conf",
MountPath: "/var/lib/kolla/config_files/config.json",
SubPath: "glance-httpd-config.json",
ReadOnly: true,
},
}
Expand Down Expand Up @@ -339,3 +332,25 @@ func GetScriptVolumeMount() []corev1.VolumeMount {
},
}
}

// GetAPIVolumeMount -
func GetAPIVolumeMount(cacheSize string) []corev1.VolumeMount {
apiVolumeMounts := []corev1.VolumeMount{
{
Name: "config-data",
MountPath: "/var/lib/kolla/config_files/config.json",
SubPath: "glance-api-config.json",
ReadOnly: true,
},
}
// Append LogVolume to apiVolumes: this will be used to stream logging
apiVolumeMounts = append(apiVolumeMounts, GetLogVolumeMount()...)
// Append ScriptsVolume to apiVolumes
apiVolumeMounts = append(apiVolumeMounts, GetScriptVolumeMount()...)
// If cache is provided, we expect the main glance_controller to request a
// PVC that should be used for that purpose (according to ImageCache.Size)
if len(cacheSize) > 0 {
apiVolumeMounts = append(apiVolumeMounts, GetCacheVolumeMount()...)
}
return apiVolumeMounts
}
35 changes: 6 additions & 29 deletions pkg/glanceapi/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ import (
)

const (
// GlanceAPIServiceCommand -
GlanceAPIServiceCommand = "/usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start"
// GlanceAPIHttpdCommand -
GlanceAPIHttpdCommand = "/usr/sbin/httpd -DFOREGROUND"
// GlanceServiceCommand -
GlanceServiceCommand = "/usr/local/bin/kolla_start"
)

// StatefulSet func
Expand Down Expand Up @@ -122,30 +120,9 @@ func StatefulSet(
},
},
}
// Append LogVolume to the apiVolumes: this will be used to stream
// logging
apiVolumes = append(apiVolumes, glance.GetLogVolume()...)
apiVolumeMounts := []corev1.VolumeMount{
{
Name: "config-data",
MountPath: "/var/lib/kolla/config_files/config.json",
SubPath: "glance-api-config.json",
ReadOnly: true,
},
}

// Append LogVolume to the apiVolumes: this will be used to stream logging
apiVolumeMounts = append(apiVolumeMounts, glance.GetLogVolumeMount()...)

// Append scripts
apiVolumes = append(apiVolumes, glance.GetScriptVolume()...)
apiVolumeMounts = append(apiVolumeMounts, glance.GetScriptVolumeMount()...)

// If cache is provided, we expect the main glance_controller to request a
// PVC that should be used for that purpose (according to ImageCacheSize)
if len(instance.Spec.ImageCache.Size) > 0 {
apiVolumeMounts = append(apiVolumeMounts, glance.GetCacheVolumeMount()...)
}
apiVolumes = append(apiVolumes, glance.GetLogVolume()...)
apiVolumeMounts := glance.GetAPIVolumeMount(instance.Spec.ImageCache.Size)

extraVolPropagation := append(glance.GlanceAPIPropagation,
storage.PropagationType(instance.APIName()))
Expand Down Expand Up @@ -255,7 +232,7 @@ func StatefulSet(
"--",
"/bin/bash",
"-c",
string(GlanceAPIHttpdCommand),
string(GlanceServiceCommand),
},
Image: instance.Spec.ContainerImage,
SecurityContext: &corev1.SecurityContext{
Expand All @@ -278,7 +255,7 @@ func StatefulSet(
"--",
"/bin/bash",
"-c",
string(GlanceAPIServiceCommand),
string(GlanceServiceCommand),
},
Image: instance.Spec.ContainerImage,
SecurityContext: &corev1.SecurityContext{
Expand Down
16 changes: 0 additions & 16 deletions templates/glanceapi/config/glance-api-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@
"owner": "root:root",
"perm": "0755"
},
{
"source": "/var/lib/config-data/tls/certs/*",
"dest": "/etc/pki/tls/certs/",
"owner": "root",
"perm": "0640",
"optional": true,
"merge": true
},
{
"source": "/var/lib/config-data/tls/private/*",
"dest": "/etc/pki/tls/private/",
"owner": "root",
"perm": "0600",
"optional": true,
"merge": true
},
{
"source": "/usr/local/bin/container-scripts/kolla_extend_start",
"dest": "/usr/local/bin/kolla_extend_start",
Expand Down
49 changes: 49 additions & 0 deletions templates/glanceapi/config/glance-httpd-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"command": "/usr/sbin/httpd -DFOREGROUND",
"config_files": [
{
"source": "/var/lib/config-data/tls/certs/*",
"dest": "/etc/pki/tls/certs/",
"owner": "glance:glance",
"perm": "0640",
"optional": true,
"merge": true
},
{
"source": "/var/lib/config-data/tls/private/*",
"dest": "/etc/pki/tls/private/",
"owner": "glance:glance",
"perm": "0640",
"optional": true,
"merge": true
},
{
"source": "/var/lib/config-data/default/httpd.conf",
"dest": "/etc/httpd/conf/httpd.conf",
"owner": "glance:apache",
"optional": true,
"perm": "0644"
},
{
"source": "/var/lib/config-data/default/10-glance-httpd.conf",
"dest": "/etc/httpd/conf.d/10-glance.conf",
"owner": "glance:apache",
"optional": true,
"perm": "0644"
},
{
"source": "/var/lib/config-data/default/ssl.conf",
"dest": "/etc/httpd/conf.d/ssl.conf",
"owner": "glance:apache",
"optional": true,
"perm": "0644"
}
],
"permissions": [
{
"path": "/etc/httpd/run",
"owner": "glance:apache",
"recurse": true
}
]
}
1 change: 1 addition & 0 deletions templates/glanceapi/config/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ 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

Include conf.d/10-glance.conf
16 changes: 8 additions & 8 deletions test/functional/glanceapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var _ = Describe("Glanceapi controller", func() {
ss := th.GetStatefulSet(glanceTest.GlanceInternalStatefulSet)
// Check the resulting deployment fields
Expect(int(*ss.Spec.Replicas)).To(Equal(1))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(4))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(3))
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))

container := ss.Spec.Template.Spec.Containers[2]
Expand All @@ -205,7 +205,7 @@ var _ = Describe("Glanceapi controller", func() {
ss := th.GetStatefulSet(glanceTest.GlanceExternalStatefulSet)
// Check the resulting deployment fields
Expect(int(*ss.Spec.Replicas)).To(Equal(1))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(4))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(3))
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))

// Check the glance-api container
Expand All @@ -217,7 +217,7 @@ var _ = Describe("Glanceapi controller", func() {

// Check the glance-httpd container
container = ss.Spec.Template.Spec.Containers[1]
Expect(container.VolumeMounts).To(HaveLen(3))
Expect(container.VolumeMounts).To(HaveLen(2))
Expect(container.Image).To(Equal(glanceTest.ContainerImage))

// Check the glance-log container
Expand Down Expand Up @@ -263,7 +263,7 @@ var _ = Describe("Glanceapi controller", func() {
ss := th.GetStatefulSet(glanceTest.GlanceEdgeStatefulSet)
// Check the resulting deployment fields
Expect(int(*ss.Spec.Replicas)).To(Equal(1))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(4))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(3))
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))

container := ss.Spec.Template.Spec.Containers[2]
Expand Down Expand Up @@ -317,7 +317,7 @@ var _ = Describe("Glanceapi controller", func() {
ss := th.GetStatefulSet(glanceTest.GlanceSingle)
// Check the resulting deployment fields
Expect(int(*ss.Spec.Replicas)).To(Equal(1))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(4))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(3))
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))

container := ss.Spec.Template.Spec.Containers[2]
Expand Down Expand Up @@ -662,7 +662,7 @@ var _ = Describe("Glanceapi controller", func() {
ss := th.GetStatefulSet(glanceTest.GlanceInternalStatefulSet)
// Check the resulting deployment fields
Expect(int(*ss.Spec.Replicas)).To(Equal(1))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(6))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(5))
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))

// cert deployment volumes
Expand All @@ -688,7 +688,7 @@ var _ = Describe("Glanceapi controller", func() {
ss := th.GetStatefulSet(glanceTest.GlanceExternalStatefulSet)
// Check the resulting deployment fields
Expect(int(*ss.Spec.Replicas)).To(Equal(1))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(6))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(5))
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))

// cert deployment volumes
Expand Down Expand Up @@ -838,7 +838,7 @@ var _ = Describe("Glanceapi controller", func() {
ss := th.GetStatefulSet(glanceTest.GlanceSingle)
// Check the resulting deployment fields
Expect(int(*ss.Spec.Replicas)).To(Equal(1))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(7))
Expect(ss.Spec.Template.Spec.Volumes).To(HaveLen(6))
Expect(ss.Spec.Template.Spec.Containers).To(HaveLen(3))

// cert deployment volumes
Expand Down

0 comments on commit 79def76

Please sign in to comment.