Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions api/bases/keystone.openstack.org_keystoneapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ spec:
description: Secret containing OpenStack password information for
keystone AdminPassword
type: string
numberFernetKeys:
default: 2
description: Number of Fernet keys
type: integer
tls:
description: TLS - Parameters related to the TLS
properties:
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/keystoneapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ type KeystoneAPISpecCore struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// TLS - Parameters related to the TLS
TLS tls.API `json:"tls,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=2
// Number of Fernet keys
FernetKeys *int32 `json:"numberFernetKeys"`
}

// APIOverrideSpec to override the generated manifest of several child resources.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/keystone.openstack.org_keystoneapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ spec:
description: Secret containing OpenStack password information for
keystone AdminPassword
type: string
numberFernetKeys:
default: 2
description: Number of Fernet keys
type: integer
tls:
description: TLS - Parameters related to the TLS
properties:
Expand Down
5 changes: 3 additions & 2 deletions controllers/keystoneapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,12 @@ func (r *KeystoneAPIReconciler) ensureFernetKeys(
return err
} else if k8s_errors.IsNotFound(err) {
fernetKeys := map[string]string{
"FernetKeys0": keystone.GenerateFernetKey(),
"FernetKeys1": keystone.GenerateFernetKey(),
"CredentialKeys0": keystone.GenerateFernetKey(),
"CredentialKeys1": keystone.GenerateFernetKey(),
}
for i := range instance.Spec.FernetKeys {
Copy link
Contributor

@xek xek Oct 7, 2024

Choose a reason for hiding this comment

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

We need to check not only if the secret exists, but also generate extra keys if they are missing or delete extra keys.

This operation shouldn't rotate the keys, so the staged key (number 0) should stay as is, but the primary (the last key on the list) and secondary keys should be moved to the tail of the list of keys.

If the list in the secret exceeds the set number of keys, the keys in the middle should be deleted, compacting it, with the first key and the tail of the list having the same keys in the same order.

fernetKeys[fmt.Sprintf("FernetKeys%d", i)] = keystone.GenerateFernetKey()
}

tmpl := []util.Template{
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/keystone/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func BootstrapJob(
}

// create Volume and VolumeMounts
volumes := getVolumes(instance.Name)
volumes := getVolumes(instance)
volumeMounts := getVolumeMounts()

// add CA cert if defined
if instance.Spec.TLS.CaBundleSecretName != "" {
volumes = append(getVolumes(instance.Name), instance.Spec.TLS.CreateVolume())
volumes = append(getVolumes(instance), instance.Spec.TLS.CreateVolume())
volumeMounts = append(getVolumeMounts(), instance.Spec.TLS.CreateVolumeMounts(nil)...)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/keystone/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func CronJob(
completions := int32(1)

// create Volume and VolumeMounts
volumes := getVolumes(instance.Name)
volumes := getVolumes(instance)
volumeMounts := getVolumeMounts()

// add CA cert if defined
if instance.Spec.TLS.CaBundleSecretName != "" {
volumes = append(getVolumes(instance.Name), instance.Spec.TLS.CreateVolume())
volumes = append(getVolumes(instance), instance.Spec.TLS.CreateVolume())
volumeMounts = append(getVolumeMounts(), instance.Spec.TLS.CreateVolumeMounts(nil)...)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/keystone/dbsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ func DbSyncJob(
envVars["KOLLA_BOOTSTRAP"] = env.SetValue("true")

// create Volume and VolumeMounts
volumes := getVolumes(instance.Name)
volumes := getVolumes(instance)
volumeMounts := getVolumeMounts()

// add CA cert if defined
if instance.Spec.TLS.CaBundleSecretName != "" {
volumes = append(getVolumes(instance.Name), instance.Spec.TLS.CreateVolume())
//TODO(afaranha): Why not reuse the 'volumes'?
volumes = append(getVolumes(instance), instance.Spec.TLS.CreateVolume())
volumeMounts = append(getVolumeMounts(), instance.Spec.TLS.CreateVolumeMounts(nil)...)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/keystone/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Deployment(
envVars["CONFIG_HASH"] = env.SetValue(configHash)

// create Volume and VolumeMounts
volumes := getVolumes(instance.Name)
volumes := getVolumes(instance)
volumeMounts := getVolumeMounts()

// add CA cert if defined
Expand Down
19 changes: 8 additions & 11 deletions pkg/keystone/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ import (
)

// getVolumes - service volumes
func getVolumes(name string) []corev1.Volume {
func getVolumes(instance *keystonev1.KeystoneAPI) []corev1.Volume {
name := instance.Name
var scriptsVolumeDefaultMode int32 = 0755
var config0640AccessMode int32 = 0640

fernetKeys := []corev1.KeyToPath{}
for i := range instance.Spec.FernetKeys {
fernetKeys = append(fernetKeys, fmt.Sprintf("FernetKeys%d", i))
}

return []corev1.Volume{
{
Name: "scripts",
Expand All @@ -48,16 +54,7 @@ func getVolumes(name string) []corev1.Volume {
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: ServiceName,
Items: []corev1.KeyToPath{
{
Key: "FernetKeys0",
Path: "0",
},
{
Key: "FernetKeys1",
Path: "1",
},
},
Items: fernetKeys,
},
},
},
Expand Down
Loading