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

[wip] Move server certificates to /etc/pki #923

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func PostgresqlDeployment(cr *miqv1alpha1.ManageIQ, client client.Client, scheme
}
deployment.Spec.Template.Spec.Volumes = addOrUpdateVolume(deployment.Spec.Template.Spec.Volumes, corev1.Volume{Name: "env-file", VolumeSource: corev1.VolumeSource{Secret: &secret}})

addInternalCertificate(cr, deployment, client, "postgresql", "/opt/app-root/src/certificates")
addPkiCertificate(cr, deployment, client, "postgresql")

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func postgresqlSslConf() string {
#------------------------------------------------------------------------------

ssl = on
ssl_cert_file = '/var/lib/pgsql/data/userdata/server.crt' # server certificate
ssl_key_file = '/var/lib/pgsql/data/userdata/server.key' # server private key
ssl_cert_file = '/etc/pki/tls/certs/server.crt' # server certificate
ssl_key_file = '/etc/pki/tls/private/server.key' # server private key
#ssl_ca_file # trusted certificate authorities
#ssl_crl_file # certificates revoked by certificate authorities

Expand Down
14 changes: 14 additions & 0 deletions manageiq-operator/api/v1alpha1/helpers/miq-components/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ func addInternalCertificate(cr *miqv1alpha1.ManageIQ, d *appsv1.Deployment, clie
}
}

func addPkiCertificate(cr *miqv1alpha1.ManageIQ, d *appsv1.Deployment, client client.Client, name string) {
secret := InternalCertificatesSecret(cr, client)
if secret.Data[fmt.Sprintf("%s_crt", name)] != nil && secret.Data[fmt.Sprintf("%s_key", name)] != nil {
volumeName := fmt.Sprintf("%s-certificate", name)

volumeMount := corev1.VolumeMount{Name: volumeName, MountPath: "/etc/pki/tls", ReadOnly: true}
d.Spec.Template.Spec.Containers[0].VolumeMounts = addOrUpdateVolumeMount(d.Spec.Template.Spec.Containers[0].VolumeMounts, volumeMount)

var mode int32 = 0o440
secretVolumeSource := corev1.SecretVolumeSource{SecretName: secret.Name, Items: []corev1.KeyToPath{corev1.KeyToPath{Key: fmt.Sprintf("%s_crt", name), Path: "certs/server.crt", Mode: &mode}, corev1.KeyToPath{Key: fmt.Sprintf("%s_key", name), Path: "private/server.key", Mode: &mode}}}
d.Spec.Template.Spec.Volumes = addOrUpdateVolume(d.Spec.Template.Spec.Volumes, corev1.Volume{Name: volumeName, VolumeSource: corev1.VolumeSource{Secret: &secretVolumeSource}})
}
}

func addOrUpdateEnvVar(environment []corev1.EnvVar, variable corev1.EnvVar) []corev1.EnvVar {
index := -1
for i, env := range environment {
Expand Down