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] Support variable number of fernet keys #477

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions api/bases/keystone.openstack.org_keystoneapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ spec:
description: EnableSecureRBAC - Enable Consistent and Secure RBAC
policies
type: boolean
fernetMaxActiveKeys:
default: "5"
description: FernetMaxActiveKeys - Maximum number of fernet token
keys after rotation
type: string
fernetRotationContainerImage:
description: Keystone Fernet Rotation Container Image URL (will be
set to environmental default if empty)
type: string
fernetRotationSchedule:
default: 1 0 * * *
description: FernetRotationSchedule - Schedule rotate fernet token
keys
type: string
memcachedInstance:
default: memcached
description: Memcached instance name.
Expand Down Expand Up @@ -412,6 +426,7 @@ spec:
required:
- containerImage
- databaseInstance
- fernetRotationContainerImage
- memcachedInstance
- rabbitMqClusterName
- secret
Expand Down
27 changes: 27 additions & 0 deletions api/v1beta1/keystoneapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (

// KeystoneAPIContainerImage is the fall-back container image for KeystoneAPI
KeystoneAPIContainerImage = "quay.io/podified-antelope-centos9/openstack-keystone:current-podified"

// KeystoneFernetRotationContainerImage is the fall-back container image for Keystone Fernet Rotation
KeystoneFernetRotationContainerImage = "registry.redhat.io/openshift4/ose-cli"
)

type KeystoneAPISpec struct {
Expand All @@ -53,6 +56,9 @@ type KeystoneAPISpec struct {
// +kubebuilder:validation:Required
// Keystone Container Image URL (will be set to environmental default if empty)
ContainerImage string `json:"containerImage"`
// +kubebuilder:validation:Required
// Keystone Fernet Rotation Container Image URL (will be set to environmental default if empty)
FernetRotationContainerImage string `json:"fernetRotationContainerImage"`
}

// KeystoneAPISpec defines the desired state of KeystoneAPI
Expand Down Expand Up @@ -119,6 +125,16 @@ type KeystoneAPISpecCore struct {
// TrustFlushSuspend - Suspend the cron job to purge trusts
TrustFlushSuspend bool `json:"trustFlushSuspend"`

// +kubebuilder:validation:Optional
// +kubebuilder:default="1 0 * * *"
// FernetRotationSchedule - Schedule rotate fernet token keys
FernetRotationSchedule string `json:"fernetRotationSchedule"`

// +kubebuilder:validation:Optional
// +kubebuilder:default="5"
// FernetMaxActiveKeys - Maximum number of fernet token keys after rotation
FernetMaxActiveKeys string `json:"fernetMaxActiveKeys"`

// +kubebuilder:validation:Optional
// +kubebuilder:default={admin: AdminPassword}
// PasswordSelectors - Selectors to identify the AdminUser password from the Secret
Expand Down Expand Up @@ -268,11 +284,22 @@ func (instance KeystoneAPI) RbacResourceName() string {
return "keystone-" + instance.Name
}

// KeystoneAPIFernet - used to create different role for fernet key rotation
type KeystoneAPIFernet struct {
*KeystoneAPI
}

// RbacResourceName - return the name to be used for rbac objects used for fernet key rotation (serviceaccount, role, rolebinding)
func (instance KeystoneAPIFernet) RbacResourceName() string {
return "keystone-fernet-" + instance.Name
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
func SetupDefaults() {
// Acquire environmental defaults and initialize Keystone defaults with them
keystoneDefaults := KeystoneAPIDefaults{
ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_KEYSTONE_API_IMAGE_URL_DEFAULT", KeystoneAPIContainerImage),
FernetRotationContainerImageURL: util.GetEnvVar("RELATED_IMAGE_KEYSTONE_FERNET_ROTATION_IMAGE_URL_DEFAULT", KeystoneFernetRotationContainerImage),
}

SetupKeystoneAPIDefaults(keystoneDefaults)
Expand Down
6 changes: 5 additions & 1 deletion api/v1beta1/keystoneapi_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
// KeystoneAPIDefaults -
type KeystoneAPIDefaults struct {
ContainerImageURL string
FernetRotationContainerImageURL string
}

var keystoneAPIDefaults KeystoneAPIDefaults
Expand Down Expand Up @@ -69,6 +70,9 @@ func (r *KeystoneAPI) Default() {
if r.Spec.ContainerImage == "" {
r.Spec.ContainerImage = keystoneAPIDefaults.ContainerImageURL
}
if r.Spec.FernetRotationContainerImage == "" {
r.Spec.FernetRotationContainerImage = keystoneAPIDefaults.FernetRotationContainerImageURL
}
r.Spec.Default()
}

Expand Down Expand Up @@ -151,7 +155,7 @@ func (spec *KeystoneAPISpec) ValidateUpdate(old KeystoneAPISpec, basePath *field
return spec.KeystoneAPISpecCore.ValidateUpdate(old.KeystoneAPISpecCore, basePath)
}

func (spec *KeystoneAPISpecCore) ValidateUpdate(old KeystoneAPISpecCore, basePath *field.Path) field.ErrorList {
func (spec *KeystoneAPISpecCore) ValidateUpdate(_ KeystoneAPISpecCore, basePath *field.Path) field.ErrorList {
var allErrs field.ErrorList

// validate the service override key is valid
Expand Down
20 changes: 20 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions config/crd/bases/keystone.openstack.org_keystoneapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ spec:
description: EnableSecureRBAC - Enable Consistent and Secure RBAC
policies
type: boolean
fernetMaxActiveKeys:
default: "5"
description: FernetMaxActiveKeys - Maximum number of fernet token
keys after rotation
type: string
fernetRotationContainerImage:
description: Keystone Fernet Rotation Container Image URL (will be
set to environmental default if empty)
type: string
fernetRotationSchedule:
default: 1 0 * * *
description: FernetRotationSchedule - Schedule rotate fernet token
keys
type: string
memcachedInstance:
default: memcached
description: Memcached instance name.
Expand Down Expand Up @@ -412,6 +426,7 @@ spec:
required:
- containerImage
- databaseInstance
- fernetRotationContainerImage
- memcachedInstance
- rabbitMqClusterName
- secret
Expand Down
Loading
Loading