diff --git a/api/bases/core.openstack.org_openstackcontrolplanes.yaml b/api/bases/core.openstack.org_openstackcontrolplanes.yaml index f8abe9cda..ab87fb0ce 100644 --- a/api/bases/core.openstack.org_openstackcontrolplanes.yaml +++ b/api/bases/core.openstack.org_openstackcontrolplanes.yaml @@ -20089,6 +20089,14 @@ spec: type: object type: object type: object + profile: + default: None + enum: + - None + - Inherit + - Intermediate + - Modern + type: string type: object topologyRef: properties: diff --git a/api/core/v1beta1/conditions.go b/api/core/v1beta1/conditions.go index 08d73d884..a1d9250e8 100644 --- a/api/core/v1beta1/conditions.go +++ b/api/core/v1beta1/conditions.go @@ -108,6 +108,9 @@ const ( // OpenStackControlPlaneCustomTLSReadyCondition Status=True condition which indicates if custom TLS certificate secrets are configured and operational OpenStackControlPlaneCustomTLSReadyCondition condition.Type = "OpenStackControlPlaneCustomTLSReadyCondition" + // OpenStackControlPlaneTLSProfileReadyCondition Status=True condition which indicates if the APIServer TLS profile has been resolved and the SSL profile ConfigMap created + OpenStackControlPlaneTLSProfileReadyCondition condition.Type = "OpenStackControlPlaneTLSProfileReady" + // OpenStackControlPlaneTelemetryReadyCondition Status=True condition which indicates if OpenStack Telemetry service is configured and operational OpenStackControlPlaneTelemetryReadyCondition condition.Type = "OpenStackControlPlaneTelemetryReady" @@ -489,6 +492,23 @@ const ( // OpenStackControlPlaneCAReadyErrorMessage OpenStackControlPlaneCustomTLSReadyErrorMessage = "OpenStackControlPlane custom TLS cert secret %s error occured %s" + // OpenStackControlPlaneTLSProfileReadyInitMessage + OpenStackControlPlaneTLSProfileReadyInitMessage = "OpenStackControlPlane TLS profile not started" + + // OpenStackControlPlaneTLSProfileReadyMessage + OpenStackControlPlaneTLSProfileReadyMessage = "OpenStackControlPlane TLS profile ConfigMap created" + + // OpenStackControlPlaneTLSProfileReadyNoProfileMessage + OpenStackControlPlaneTLSProfileReadyNoProfileMessage = "OpenStackControlPlane TLS profile not declared by the cluster, using built-in defaults" + + // OpenStackControlPlaneTLSProfileReadyErrorMessage + OpenStackControlPlaneTLSProfileReadyErrorMessage = "OpenStackControlPlane TLS profile error occurred %s" + + // OpenStackControlPlaneTLSProfileReadyInvalidMessage - names both remedies, + // since only a human editing one of the two CRs can resolve it + OpenStackControlPlaneTLSProfileReadyInvalidMessage = "OpenStackControlPlane TLS profile cannot be resolved: %s. " + + "Set spec.tls.profile to None, Inherit, Intermediate or Modern, or correct the TLS security profile on the cluster APIServer CR" + // OpenStackControlPlaneTestCMReadyErrorMessage OpenStackControlPlaneTestCMReadyErrorMessage = "OpenStackControlPlane Test Operator CM error occured %s" diff --git a/api/core/v1beta1/openstackcontrolplane_types.go b/api/core/v1beta1/openstackcontrolplane_types.go index c4cc07b87..83fe63eb4 100644 --- a/api/core/v1beta1/openstackcontrolplane_types.go +++ b/api/core/v1beta1/openstackcontrolplane_types.go @@ -272,6 +272,16 @@ type TLSSection struct { // +kubebuilder:default={enabled: true, internal:{ca: {duration: "87600h"}, cert: {duration: "43800h"}}, libvirt: {ca: {duration: "87600h"}, cert: {duration: "43800h"}}, ovn: {ca: {duration: "87600h"}, cert: {duration: "43800h"}}} PodLevel TLSPodLevelConfig `json:"podLevel,omitempty"` + // +kubebuilder:validation:optional + // +operator-sdk:csv:customresourcedefinitions:type=spec + // Profile - The TLS security profile the OpenStack services are + // configured with. "None" (the default) publishes nothing, so the services + // keep lib-common's built-in defaults. "Inherit" follows whatever the + // cluster declares on the OpenShift APIServer CR. "Intermediate" and + // "Modern" pin that profile regardless of what the cluster declares. + // +kubebuilder:default=None + Profile TLSProfileType `json:"profile,omitempty"` + // +kubebuilder:validation:optional // +operator-sdk:csv:customresourcedefinitions:type=spec // Secret containing any additional CA certificates, which should be added to deployment pods. @@ -280,6 +290,37 @@ type TLSSection struct { tls.Ca `json:",inline"` } +// TLSProfileType - the TLS security profile the OpenStack services are +// configured with, either sourced from the cluster or named here directly. +// The named values are spelled out rather than taken from configv1 so this +// module keeps openshift/api indirect; the functional tests pin the spelling. +// "Old" is not offered, but stays reachable through "Inherit" when the +// cluster itself declares it. +// +kubebuilder:validation:Enum=None;Inherit;Intermediate;Modern +type TLSProfileType string + +const ( + // TLSProfileNone - publish nothing; the services keep lib-common's defaults. + TLSProfileNone TLSProfileType = "None" + + // TLSProfileInherit - follow the profile the cluster declares on the APIServer CR. + TLSProfileInherit TLSProfileType = "Inherit" + + // TLSProfileIntermediate - pin the OpenShift Intermediate profile. + TLSProfileIntermediate TLSProfileType = "Intermediate" + + // TLSProfileModern - pin the OpenShift Modern profile. + TLSProfileModern TLSProfileType = "Modern" +) + +// IsEnabled - whether a profile is requested at all. InitConditions and +// ReconcileTLSProfile have to agree on this, or an early-returning reconcile +// leaves an Unknown condition behind for a feature that is off. An unset +// value counts as None. +func (p TLSProfileType) IsEnabled() bool { + return p != TLSProfileNone && p != "" +} + // TLSIngressConfig defines the desired state of the TLS configuration for the ingress configuration (route) type TLSIngressConfig struct { // +kubebuilder:validation:Optional @@ -1279,6 +1320,14 @@ func (instance *OpenStackControlPlane) InitConditions() { cl.Set(condition.UnknownCondition(OpenStackControlPlaneCyborgReadyCondition, condition.InitReason, OpenStackControlPlaneCyborgReadyInitMessage)) } + // Only register the condition when a profile is requested: in None mode + // ReconcileTLSProfile removes it again, but an early return (minor update + // staging, CA requeue, first-pass finalizer) never gets that far and would + // persist an Unknown for a feature that is off. + if instance.Spec.TLS.Profile.IsEnabled() { + cl.Set(condition.UnknownCondition(OpenStackControlPlaneTLSProfileReadyCondition, condition.InitReason, OpenStackControlPlaneTLSProfileReadyInitMessage)) + } + // Init Topology condition if there's a reference if instance.Spec.TopologyRef != nil { cl.Set(condition.UnknownCondition(condition.TopologyReadyCondition, condition.InitReason, condition.TopologyReadyInitMessage)) diff --git a/bindata/crds/crds.yaml b/bindata/crds/crds.yaml index b8a190a0a..09ee8a2d2 100644 --- a/bindata/crds/crds.yaml +++ b/bindata/crds/crds.yaml @@ -21118,6 +21118,14 @@ spec: type: object type: object type: object + profile: + default: None + enum: + - None + - Inherit + - Intermediate + - Modern + type: string type: object topologyRef: properties: diff --git a/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml b/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml index f8abe9cda..ab87fb0ce 100644 --- a/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml +++ b/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml @@ -20089,6 +20089,14 @@ spec: type: object type: object type: object + profile: + default: None + enum: + - None + - Inherit + - Intermediate + - Modern + type: string type: object topologyRef: properties: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 1ff5c5fee..4f102ffed 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -318,6 +318,7 @@ rules: - apiGroups: - config.openshift.io resources: + - apiservers - clusterimagepolicies - clusteroperators - clusterversions diff --git a/go.mod b/go.mod index 81f9bb1f9..b1266378d 100644 --- a/go.mod +++ b/go.mod @@ -178,3 +178,7 @@ replace k8s.io/component-base => k8s.io/component-base v0.33.13 //allow-merging replace k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20250627150254-e9823e99808e //allow-merging replace github.com/cert-manager/cmctl/v2 => github.com/cert-manager/cmctl/v2 v2.3.0 //allow-merging + +replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20261119133733-b9adb5ae4b86 + +replace github.com/openstack-k8s-operators/lib-common/modules/test => github.com/fmount/lib-common/modules/test v0.0.0-20261119133733-b9adb5ae4b86 diff --git a/go.sum b/go.sum index 7ec899fc5..0460ff22e 100644 --- a/go.sum +++ b/go.sum @@ -27,6 +27,10 @@ github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjT github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/fmount/lib-common/modules/common v0.0.0-20261119133733-b9adb5ae4b86 h1:0JCqFK0RBAj2Uipd0w9RzTe06qjooSZ13nEHd8FgBNc= +github.com/fmount/lib-common/modules/common v0.0.0-20261119133733-b9adb5ae4b86/go.mod h1:Bs95wrakWtl9bWhWVIuN54hE8+IILqRU0QH+/AjGlDo= +github.com/fmount/lib-common/modules/test v0.0.0-20261119133733-b9adb5ae4b86 h1:TabLXSNTtKh0fSJXC4tlyd+10RW5GdPFaRAtKBc8IUw= +github.com/fmount/lib-common/modules/test v0.0.0-20261119133733-b9adb5ae4b86/go.mod h1:n8vhem98f8sW/Yd4KFmngEHA04kWWNI/WZ9mTG9tOSo= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM= @@ -180,14 +184,10 @@ github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.202611130 github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:TkZgZE92VUKHHNKXwuV8b7tT9toaxsZkcGffRafKCSA= github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20261113070913-5152d1d626f9 h1:2fbgvf5Vm4CyTkXWFlmIw0aGzyJjO/SNqLf3dnBx0BE= github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:Br9qj00P2UzWFrtlcSrxBd4eG8fXtRX9h3IN8k5iJGw= -github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20261113070913-5152d1d626f9 h1:SnR2m0LHH1k+qHT1HSwwx5c7Lc6r1U8PIQpiUj60qrw= -github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:Bs95wrakWtl9bWhWVIuN54hE8+IILqRU0QH+/AjGlDo= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20261113070913-5152d1d626f9 h1:lgbKoe9iibFLovaVKqbO6RzcTFhzD7hWW9slJr4TCpE= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:Jd4fWlkX+mMlAyY4I8TM1NAc2EJVUbJNmtKLIuXvBq0= github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20261113070913-5152d1d626f9 h1:IU4OU1ECIN0XGdHpK3u+Z5sfVGKlYVP5oArTVoilC/4= github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:a7cwXeo63Ce+d/BoQnfK5Qnwxi6B18F7zZlRvSd4XXA= -github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20261113070913-5152d1d626f9 h1:zdLGDWn8gHxLR6DgZmfq3pXx7Z7/27Uz2Ua/093K7Ks= -github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:n8vhem98f8sW/Yd4KFmngEHA04kWWNI/WZ9mTG9tOSo= github.com/openstack-k8s-operators/lib-common/modules/users v0.0.0-20261113070913-5152d1d626f9 h1:jnyHfNDI76L31tZqsCO8DyfcB8AdAL8RQsq4UnZeZKE= github.com/openstack-k8s-operators/lib-common/modules/users v0.0.0-20261113070913-5152d1d626f9/go.mod h1:jmVVRfwuFQ3fHLIOAkUrtLgOwEL6j45POzS3PBJuwyM= github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20261114142025-35eaf5975501 h1:o8NXVjmKsfufK53f+hKlTxXy83bJ4csSjX/RFHEiRDM= diff --git a/internal/controller/core/openstackcontrolplane_controller.go b/internal/controller/core/openstackcontrolplane_controller.go index abd009f0d..2440c5ecb 100644 --- a/internal/controller/core/openstackcontrolplane_controller.go +++ b/internal/controller/core/openstackcontrolplane_controller.go @@ -27,6 +27,7 @@ import ( "time" certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" + configv1 "github.com/openshift/api/config/v1" routev1 "github.com/openshift/api/route/v1" barbicanv1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1" cinderv1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1" @@ -43,6 +44,7 @@ import ( condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" common_helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper" "github.com/openstack-k8s-operators/lib-common/modules/common/tls" + "github.com/openstack-k8s-operators/lib-common/modules/common/util" "github.com/openstack-k8s-operators/lib-common/modules/common/webhook" cyborgv1 "github.com/openstack-k8s-operators/nova-operator/api/cyborg/v1beta1" corev1 "k8s.io/api/core/v1" @@ -130,9 +132,11 @@ func (r *OpenStackControlPlaneReconciler) GetLogger(ctx context.Context) logr.Lo // +kubebuilder:rbac:groups=route.openshift.io,resources=routes/custom-host,verbs=create;update;patch // +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch // +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete; +// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete; // +kubebuilder:rbac:groups=cert-manager.io,resources=issuers,verbs=get;list;watch;create;update;patch;delete; // +kubebuilder:rbac:groups=cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch;delete; // +kubebuilder:rbac:groups=config.openshift.io,resources=networks,verbs=get;list;watch; +// +kubebuilder:rbac:groups=config.openshift.io,resources=apiservers,verbs=get;list;watch; // +kubebuilder:rbac:groups=topology.openstack.org,resources=topologies,verbs=get;list;watch;update // +kubebuilder:rbac:groups=watcher.openstack.org,resources=watchers,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=cyborg.openstack.org,resources=cyborgs,verbs=get;list;watch;create;update;patch;delete @@ -546,6 +550,13 @@ func (r *OpenStackControlPlaneReconciler) reconcileNormal(ctx context.Context, i return ctrlResult, nil } + ctrlResult, err = openstack.ReconcileTLSProfile(ctx, instance, helper) + if err != nil { + return ctrl.Result{}, err + } else if (ctrlResult != ctrl.Result{}) { + return ctrlResult, nil + } + ctrlResult, err = openstack.ReconcileDNSMasqs(ctx, instance, version, helper) if err != nil { return ctrl.Result{}, err @@ -933,6 +944,23 @@ func (r *OpenStackControlPlaneReconciler) SetupWithManager( handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc), builder.WithPredicates(openstack.ServicePortOrTypeChangedPredicate()), ). + Watches( + &configv1.APIServer{}, + handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc), + builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), + ). + // The operator owns the full lifecycle of the TLS profile ConfigMap: + // if it is deleted or edited out from under it, a reconcile has to + // put it back. Without this watch, a removed ConfigMap would stay + // gone until some unrelated event happened to reconcile the + // control plane again. + Watches( + &corev1.ConfigMap{}, + handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc), + builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool { + return obj.GetName() == util.TLSProfileConfigMap + })), + ). Complete(r) } diff --git a/internal/openstack/tlsprofile.go b/internal/openstack/tlsprofile.go new file mode 100644 index 000000000..b8d005611 --- /dev/null +++ b/internal/openstack/tlsprofile.go @@ -0,0 +1,226 @@ +package openstack + +import ( + "context" + "fmt" + "slices" + "strings" + + configv1 "github.com/openshift/api/config/v1" + "github.com/openstack-k8s-operators/lib-common/modules/common/condition" + "github.com/openstack-k8s-operators/lib-common/modules/common/configmap" + "github.com/openstack-k8s-operators/lib-common/modules/common/helper" + "github.com/openstack-k8s-operators/lib-common/modules/common/util" + corev1 "github.com/openstack-k8s-operators/openstack-operator/api/core/v1beta1" + k8s_corev1 "k8s.io/api/core/v1" + k8s_errors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + ctrl "sigs.k8s.io/controller-runtime" +) + +// Let's map the httpd config with the TLSProfile gathered from the APIServer +var tlsVersionToSSLProtocol = map[configv1.TLSProtocolVersion]string{ + configv1.VersionTLS10: "all -SSLv2 -SSLv3", + configv1.VersionTLS11: "all -SSLv2 -SSLv3 -TLSv1", + configv1.VersionTLS12: "all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1", + configv1.VersionTLS13: "all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 -TLSv1.2", +} + +// ReconcileTLSProfile reads the OpenShift APIServer TLS security profile and +// publishes the resolved SSLCipherSuite and SSLProtocol values in the +// util.TLSProfileConfigMap ConfigMap. +// +// lib-common merges that ConfigMap underneath the ConfigOptions of every +// Template that EnsureConfigMaps/EnsureSecrets renders, so the keys reach the +// service operators with no code of their own. Acting on them is still opt-in +// per service: the Template has to ask for the common template it wants +// (Template.CommonTemplates, e.g. "ssl.conf") and the service's httpd config +// has to Include the rendered file. Until a service does both, the keys are +// merged and ignored and it stays on its own built-in defaults. +// +// NOTE: openstack-operator owns the object's whole lifecycle; lib-common only +// consumes it, and renders built-in defaults when it is not present. +// +// None withdraws any published ConfigMap and removes the TLSProfileReady +// condition, so the status does not describe a feature that is off. Inherit +// takes whatever the cluster declares; a profile named in the spec is +// resolved without consulting the cluster. +func ReconcileTLSProfile(ctx context.Context, instance *corev1.OpenStackControlPlane, helper *helper.Helper) (ctrl.Result, error) { + Log := GetLogger(ctx) + + // Withdrawing the ConfigMap (a no-op when absent) and dropping the + // condition makes "set back to None" converge on "never set at all". + if !instance.Spec.TLS.Profile.IsEnabled() { + if err := configmap.DeleteConfigMapWithName(ctx, helper, util.TLSProfileConfigMap, instance.Namespace); err != nil { + return ctrl.Result{}, err + } + // a no-op while InitConditions() registers it only when enabled, + // kept so this does not silently depend on that + instance.Status.Conditions.Remove(corev1.OpenStackControlPlaneTLSProfileReadyCondition) + return ctrl.Result{}, nil + } + + // Default to the profile named in the spec; Inherit replaces it below. + profile := &configv1.TLSSecurityProfile{ + Type: configv1.TLSProfileType(instance.Spec.TLS.Profile), + } + + if instance.Spec.TLS.Profile == corev1.TLSProfileInherit { + apiServer := &configv1.APIServer{} + if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: "cluster"}, apiServer); err != nil { + if k8s_errors.IsNotFound(err) { + Log.Info("APIServer CR not found, skipping TLS profile resolution (defaults will apply)") + + // The cluster declares no APIServer CR, so there is no profile to + // inherit. Drop any ConfigMap published earlier and fall back to + // the built-in defaults. If there's a pre-existing leftover, it + // would keep pinning services to a profile the cluster no longer + // declares + if err := configmap.DeleteConfigMapWithName( + ctx, helper, util.TLSProfileConfigMap, instance.Namespace, + ); err != nil { + instance.Status.Conditions.Set(condition.FalseCondition( + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + condition.ErrorReason, + condition.SeverityWarning, + corev1.OpenStackControlPlaneTLSProfileReadyErrorMessage, + err.Error())) + return ctrl.Result{}, err + } + + // Nothing was published here: the cluster mandates no profile, so + // report that rather than claiming a ConfigMap was created. + instance.Status.Conditions.MarkTrue( + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + corev1.OpenStackControlPlaneTLSProfileReadyNoProfileMessage) + return ctrl.Result{}, nil + } + instance.Status.Conditions.Set(condition.FalseCondition( + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + condition.ErrorReason, + condition.SeverityWarning, + corev1.OpenStackControlPlaneTLSProfileReadyErrorMessage, + err.Error())) + return ctrl.Result{}, err + } + profile = apiServer.Spec.TLSSecurityProfile + } + + // Covers both cases: the cluster's profile under Inherit, and the + // Intermediate/Modern named in the spec, which reach the + // configv1.TLSProfiles lookup because the enum spells them as OpenShift does. + cipherSuite, sslProtocol, minTLSVersion, err := resolveTLSProfile(profile) + if err != nil { + // Only a human editing spec.tls.profile or the APIServer CR can fix + // this, and both are watched, so requeueing would spin and hold every + // service behind it. Any ConfigMap already published is left in place. + Log.Error(err, "Unresolvable TLS profile, not publishing", + "Profile", instance.Spec.TLS.Profile) + instance.Status.Conditions.Set(condition.FalseCondition( + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + condition.ErrorReason, + condition.SeverityError, + corev1.OpenStackControlPlaneTLSProfileReadyInvalidMessage, + err.Error())) + return ctrl.Result{}, nil + } + + Log.Info("Resolved TLS profile", + "Profile", instance.Spec.TLS.Profile, "MinTLSVersion", minTLSVersion, + "SSLCipherSuite", cipherSuite, "SSLProtocol", sslProtocol) + + data := map[string]string{ + // Apache httpd directive, rendered for lib-common's ssl.conf. + "SSLProtocol": sslProtocol, + + // The minimum version in neutral form ("VersionTLS12"), passed + // through as the cluster set it. openstack-operator holds the only + // RBAC grant on config.openshift.io/apiservers in RHOSO, so galera, + // rabbitmq, ovn and haproxy cannot learn it any other way, and each + // needs its own syntax for it: SSLProtocol is useless to them. + "MinTLSVersion": string(minTLSVersion), + } + + // Left out rather than published empty, which Modern is, so that ssl.conf + // stays on its own fallback instead of being shadowed. + if cipherSuite != "" { + data["SSLCipherSuite"] = cipherSuite + } + + // Write the retrieved data to a ConfigMap controlled by openstack-operator + // This is used to push/inject a global configuration to the underlying + // openstack services + cm := &k8s_corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: util.TLSProfileConfigMap, + Namespace: instance.Namespace, + }, + Data: data, + } + + // The control plane is set as controller owner, so the ConfigMap is + // garbage-collected when the control plane is deleted. + if _, _, err := configmap.CreateOrPatchRawConfigMap(ctx, helper, instance, cm, false); err != nil { + instance.Status.Conditions.Set(condition.FalseCondition( + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + condition.ErrorReason, + condition.SeverityWarning, + corev1.OpenStackControlPlaneTLSProfileReadyErrorMessage, + err.Error())) + return ctrl.Result{}, err + } + + instance.Status.Conditions.MarkTrue( + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + corev1.OpenStackControlPlaneTLSProfileReadyMessage) + + return ctrl.Result{}, nil +} + +// resolveTLSProfile resolves a TLSSecurityProfile into the Apache httpd +// directives and the minimum TLS version the cluster mandates. If the profile +// is nil, the OpenShift default (Intermediate) is used. +// +// The resolved *TLSProfileSpec deliberately does not escape: for the named +// profiles it points into configv1.TLSProfiles, a package-level var, so handing +// it to callers would leak an alias to process-global state. +func resolveTLSProfile(profile *configv1.TLSSecurityProfile) ( + cipherSuite string, sslProtocol string, minTLSVersion configv1.TLSProtocolVersion, err error, +) { + // pick the spec the cluster asked for: a Custom profile carries its own, + // the named ones come from the table OpenShift ships + var spec *configv1.TLSProfileSpec + switch { + case profile == nil: + spec = configv1.TLSProfiles[configv1.TLSProfileIntermediateType] + + case profile.Type == configv1.TLSProfileCustomType: + if profile.Custom == nil { + return "", "", "", fmt.Errorf("custom TLS profile type specified but no custom profile provided") + } + spec = &profile.Custom.TLSProfileSpec + + default: + var ok bool + spec, ok = configv1.TLSProfiles[profile.Type] + if !ok { + return "", "", "", fmt.Errorf("unknown TLS profile type: %s", profile.Type) + } + } + + // render it as the pair of httpd directives ssl.conf templates in + sslProtocol, ok := tlsVersionToSSLProtocol[spec.MinTLSVersion] + if !ok { + return "", "", "", fmt.Errorf("unsupported minimum TLS version: %s", spec.MinTLSVersion) + } + + // SSLCipherSuite covers TLSv1.2 and below only, so TLS_* has to go: left + // in, Modern matches no cipher and httpd will not start. Safe: OpenShift's + // TLSv1.3 sets are exactly OpenSSL's defaults, bar a narrowing Custom one. + ciphers := slices.DeleteFunc(slices.Clone(spec.Ciphers), func(c string) bool { + return strings.HasPrefix(c, "TLS_") + }) + + return strings.Join(ciphers, ":"), sslProtocol, spec.MinTLSVersion, nil +} diff --git a/test/functional/ctlplane/openstacktlsprofile_test.go b/test/functional/ctlplane/openstacktlsprofile_test.go new file mode 100644 index 000000000..240b8cd10 --- /dev/null +++ b/test/functional/ctlplane/openstacktlsprofile_test.go @@ -0,0 +1,543 @@ +/* +Copyright 2026. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package functional_test + +import ( + "os" + "strings" + + . "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports + . "github.com/onsi/gomega" //revive:disable:dot-imports + + //revive:disable-next-line:dot-imports + . "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers" + + ocp_configv1 "github.com/openshift/api/config/v1" + "github.com/openstack-k8s-operators/lib-common/modules/common/condition" + "github.com/openstack-k8s-operators/lib-common/modules/common/util" + corev1 "github.com/openstack-k8s-operators/openstack-operator/api/core/v1beta1" + k8s_corev1 "k8s.io/api/core/v1" + k8s_errors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" +) + +// createAPIServer - create the cluster-scoped APIServer CR carrying the +// cluster-wide TLS security profile, and remove it again after the spec +func createAPIServer(profile *ocp_configv1.TLSSecurityProfile) *ocp_configv1.APIServer { + apiServer := &ocp_configv1.APIServer{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + Spec: ocp_configv1.APIServerSpec{TLSSecurityProfile: profile}, + } + Expect(k8sClient.Create(ctx, apiServer)).Should(Succeed()) + // tolerate specs that delete the singleton themselves + DeferCleanup(deleteAPIServer, apiServer) + return apiServer +} + +// deleteAPIServer - drop the cluster-scoped singleton, tolerating its absence +func deleteAPIServer(apiServer *ocp_configv1.APIServer) { + err := k8sClient.Delete(ctx, apiServer) + if err != nil && !k8s_errors.IsNotFound(err) { + Expect(err).ShouldNot(HaveOccurred()) + } +} + +// expectNoTLSProfileConfigMap - the operator publishes nothing, so lib-common +// renders its own built-in defaults +func expectNoTLSProfileConfigMap() { + cm := &k8s_corev1.ConfigMap{} + Eventually(func(g Gomega) { + err := k8sClient.Get(ctx, types.NamespacedName{ + Name: util.TLSProfileConfigMap, + Namespace: names.Namespace, + }, cm) + g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue()) + }, timeout, interval).Should(Succeed()) +} + +// getTLSProfileConfigMap - read back the ConfigMap the operator publishes for +// lib-common to merge into every rendered Template +func getTLSProfileConfigMap() *k8s_corev1.ConfigMap { + cm := &k8s_corev1.ConfigMap{} + Eventually(func(g Gomega) { + g.Expect(k8sClient.Get(ctx, types.NamespacedName{ + Name: util.TLSProfileConfigMap, + Namespace: names.Namespace, + }, cm)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + return cm +} + +// profileCiphers - a built-in profile's ciphers as the operator publishes +// them, TLS_* dropped. Empty for Modern, which has nothing else. +func profileCiphers(profileType ocp_configv1.TLSProfileType) string { + var ciphers []string + for _, c := range ocp_configv1.TLSProfiles[profileType].Ciphers { + if !strings.HasPrefix(c, "TLS_") { + ciphers = append(ciphers, c) + } + } + return strings.Join(ciphers, ":") +} + +// modernSSLProtocol - Modern publishes no SSLCipherSuite, so SSLProtocol is +// what identifies it in the ConfigMap. +const modernSSLProtocol = "all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 -TLSv1.2" + +// tlsProfileSpec - the default control plane spec asking for a given TLS +// profile; the CRD defaults to None, so every spec has to ask +func tlsProfileSpec(profile corev1.TLSProfileType) map[string]any { + spec := GetDefaultOpenStackControlPlaneSpec() + spec["tls"] = map[string]any{"profile": string(profile)} + return spec +} + +// defaultInheritingSpec - shorthand for the cluster-sourced path +func defaultInheritingSpec() map[string]any { + return tlsProfileSpec(corev1.TLSProfileInherit) +} + +// hasTLSProfileCondition - whether the control plane status still carries +// the TLS profile condition +func hasTLSProfileCondition(cp *corev1.OpenStackControlPlane) bool { + for _, c := range cp.Status.Conditions { + if c.Type == corev1.OpenStackControlPlaneTLSProfileReadyCondition { + return true + } + } + return false +} + +var _ = Describe("OpenStackOperator TLS profile", func() { + BeforeEach(func() { + err := os.Setenv("OPERATOR_TEMPLATES", "../../templates") + Expect(err).NotTo(HaveOccurred()) + + DeferCleanup(k8sClient.Delete, ctx, CreateClusterConfigCM()) + + // (mschuppert) create root CA secrets as there is no certmanager + // running. ReconcileCAs requeues until they all exist, and + // ReconcileTLSProfile runs right after it. + DeferCleanup(k8sClient.Delete, ctx, CreateCertSecret(names.RootCAPublicName)) + DeferCleanup(k8sClient.Delete, ctx, CreateCertSecret(names.RootCAInternalName)) + DeferCleanup(k8sClient.Delete, ctx, CreateCertSecret(names.RootCAOvnName)) + DeferCleanup(k8sClient.Delete, ctx, CreateCertSecret(names.RootCALibvirtName)) + // create cert secrets for galera instances + DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.DBCertName)) + DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.DBCell1CertName)) + // rabbitmq is reconciled before galera and errors out without these, + // which would stop the reconcile short of every later service + DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.RabbitMQCertName)) + DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.RabbitMQCell1CertName)) + DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.RabbitMQNotificationsCertName)) + }) + + // Every cluster TLS profile has to land in the ConfigMap as the httpd + // directives the service operators template into ssl.conf, plus the + // minimum version in neutral form for the services that are not httpd. + DescribeTable("publishes the resolved httpd directives as a ConfigMap", + func( + profile *ocp_configv1.TLSSecurityProfile, + cipherSuite string, + sslProtocol string, + minTLSVersion ocp_configv1.TLSProtocolVersion, + ) { + createAPIServer(profile) + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, defaultInheritingSpec()), + ) + + th.ExpectCondition( + names.OpenStackControlplaneName, + ConditionGetterFunc(OpenStackControlPlaneConditionGetter), + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + k8s_corev1.ConditionTrue, + ) + + cm := getTLSProfileConfigMap() + // a profile with no TLSv1.2-and-below ciphers, i.e. Modern, + // leaves the key out so ssl.conf stays on its fallback + if cipherSuite == "" { + Expect(cm.Data).NotTo(HaveKey("SSLCipherSuite")) + } else { + Expect(cm.Data).To(HaveKeyWithValue("SSLCipherSuite", cipherSuite)) + } + Expect(cm.Data).To(HaveKeyWithValue("SSLProtocol", sslProtocol)) + Expect(cm.Data).To(HaveKeyWithValue("MinTLSVersion", string(minTLSVersion))) + + // owned by the control plane, so it is garbage-collected + // together with it + cp := &corev1.OpenStackControlPlane{} + Expect(k8sClient.Get(ctx, names.OpenStackControlplaneName, cp)).To(Succeed()) + Expect(metav1.IsControlledBy(cm, cp)).To(BeTrue()) + }, + Entry("with no profile set, falling back to Intermediate", + nil, + profileCiphers(ocp_configv1.TLSProfileIntermediateType), + "all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1", + ocp_configv1.VersionTLS12), + Entry("with the Old profile", + &ocp_configv1.TLSSecurityProfile{Type: ocp_configv1.TLSProfileOldType}, + profileCiphers(ocp_configv1.TLSProfileOldType), + "all -SSLv2 -SSLv3", + ocp_configv1.VersionTLS10), + Entry("with the Intermediate profile", + &ocp_configv1.TLSSecurityProfile{Type: ocp_configv1.TLSProfileIntermediateType}, + profileCiphers(ocp_configv1.TLSProfileIntermediateType), + "all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1", + ocp_configv1.VersionTLS12), + // Modern is TLSv1.3 only: no plain SSLCipherSuite to publish + Entry("with the Modern profile", + &ocp_configv1.TLSSecurityProfile{Type: ocp_configv1.TLSProfileModernType}, + profileCiphers(ocp_configv1.TLSProfileModernType), + "all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 -TLSv1.2", + ocp_configv1.VersionTLS13), + Entry("with a Custom profile, carrying the administrator's own ciphers and minimum version", + &ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileCustomType, + Custom: &ocp_configv1.CustomTLSProfile{ + TLSProfileSpec: ocp_configv1.TLSProfileSpec{ + Ciphers: []string{"ECDHE-RSA-AES256-GCM-SHA384", "DHE-RSA-AES256-GCM-SHA384"}, + MinTLSVersion: ocp_configv1.VersionTLS11, + }, + }, + }, + "ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384", + "all -SSLv2 -SSLv3 -TLSv1", + ocp_configv1.VersionTLS11), + ) + + // No APIServer CR exists in these specs: the named profiles resolve from + // the OpenShift table alone. Comparing against configv1 also pins the enum + // spelling to the OpenShift constants, which corev1 writes out by hand. + DescribeTable("publishes a directly named profile without consulting the cluster", + func( + profile corev1.TLSProfileType, + ocpType ocp_configv1.TLSProfileType, + sslProtocol string, + minTLSVersion ocp_configv1.TLSProtocolVersion, + ) { + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, tlsProfileSpec(profile)), + ) + + th.ExpectCondition( + names.OpenStackControlplaneName, + ConditionGetterFunc(OpenStackControlPlaneConditionGetter), + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + k8s_corev1.ConditionTrue, + ) + + cm := getTLSProfileConfigMap() + if ciphers := profileCiphers(ocpType); ciphers == "" { + Expect(cm.Data).NotTo(HaveKey("SSLCipherSuite")) + } else { + Expect(cm.Data).To(HaveKeyWithValue("SSLCipherSuite", ciphers)) + } + Expect(cm.Data).To(HaveKeyWithValue("SSLProtocol", sslProtocol)) + Expect(cm.Data).To(HaveKeyWithValue("MinTLSVersion", string(minTLSVersion))) + }, + Entry("with the Intermediate profile", + corev1.TLSProfileIntermediate, + ocp_configv1.TLSProfileIntermediateType, + "all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1", + ocp_configv1.VersionTLS12), + Entry("with the Modern profile", + corev1.TLSProfileModern, + ocp_configv1.TLSProfileModernType, + "all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 -TLSv1.2", + ocp_configv1.VersionTLS13), + ) + + When("a profile is named directly and the cluster declares a different one", func() { + BeforeEach(func() { + createAPIServer(&ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileOldType, + }) + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane( + names.OpenStackControlplaneName, tlsProfileSpec(corev1.TLSProfileModern)), + ) + }) + + It("keeps the named profile and ignores the cluster", func() { + // the spec is authoritative outside Inherit + cm := getTLSProfileConfigMap() + Expect(cm.Data).To(HaveKeyWithValue( + "SSLProtocol", modernSSLProtocol)) + + // and stays so: the cluster's Old never takes over + Consistently(func(g Gomega) { + current := &k8s_corev1.ConfigMap{} + g.Expect(k8sClient.Get(ctx, types.NamespacedName{ + Name: util.TLSProfileConfigMap, + Namespace: names.Namespace, + }, current)).Should(Succeed()) + g.Expect(current.Data).To(HaveKeyWithValue( + "SSLProtocol", modernSSLProtocol)) + }, timeout, interval).Should(Succeed()) + }) + }) + + When("the APIServer CR does not exist", func() { + BeforeEach(func() { + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, defaultInheritingSpec()), + ) + }) + + It("publishes no ConfigMap and leaves lib-common on its own defaults", func() { + th.ExpectCondition( + names.OpenStackControlplaneName, + ConditionGetterFunc(OpenStackControlPlaneConditionGetter), + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + k8s_corev1.ConditionTrue, + ) + + cm := &k8s_corev1.ConfigMap{} + Consistently(func(g Gomega) { + err := k8sClient.Get(ctx, types.NamespacedName{ + Name: util.TLSProfileConfigMap, + Namespace: names.Namespace, + }, cm) + g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue()) + }, timeout, interval).Should(Succeed()) + }) + }) + + When("the cluster asks for a Custom profile but provides no custom section", func() { + BeforeEach(func() { + createAPIServer(&ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileCustomType, + }) + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, defaultInheritingSpec()), + ) + }) + + It("reports the profile as not ready and publishes nothing", func() { + th.ExpectCondition( + names.OpenStackControlplaneName, + ConditionGetterFunc(OpenStackControlPlaneConditionGetter), + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + k8s_corev1.ConditionFalse, + ) + + cm := &k8s_corev1.ConfigMap{} + err := k8sClient.Get(ctx, types.NamespacedName{ + Name: util.TLSProfileConfigMap, + Namespace: names.Namespace, + }, cm) + Expect(k8s_errors.IsNotFound(err)).To(BeTrue()) + }) + + It("keeps reconciling the rest of the control plane", func() { + // a cluster-level TLS mistake must not hold up every service: + // ReconcileTLSProfile runs before all of them + th.ExpectCondition( + names.OpenStackControlplaneName, + ConditionGetterFunc(OpenStackControlPlaneConditionGetter), + corev1.OpenStackControlPlaneCAReadyCondition, + k8s_corev1.ConditionTrue, + ) + mariadb.GetGalera(names.DBName) + }) + }) + + When("the cluster switches to a different TLS security profile", func() { + var apiServer *ocp_configv1.APIServer + + BeforeEach(func() { + apiServer = createAPIServer(&ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileOldType, + }) + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, defaultInheritingSpec()), + ) + }) + + It("republishes the ConfigMap with the new directives", func() { + cm := getTLSProfileConfigMap() + Expect(cm.Data).To(HaveKeyWithValue( + "SSLCipherSuite", profileCiphers(ocp_configv1.TLSProfileOldType))) + + // an admin tightening the cluster profile has to reach the + // services: the watch on the APIServer CR is what makes the + // controlplane notice + Eventually(func(g Gomega) { + g.Expect(k8sClient.Get(ctx, + types.NamespacedName{Name: "cluster"}, apiServer)).Should(Succeed()) + apiServer.Spec.TLSSecurityProfile = &ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileModernType, + } + g.Expect(k8sClient.Update(ctx, apiServer)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + updated := &k8s_corev1.ConfigMap{} + g.Expect(k8sClient.Get(ctx, types.NamespacedName{ + Name: util.TLSProfileConfigMap, + Namespace: names.Namespace, + }, updated)).Should(Succeed()) + g.Expect(updated.Data).To(HaveKeyWithValue( + "SSLProtocol", modernSSLProtocol)) + // the key Old left behind has to go, or it would pin + // ciphers the cluster no longer mandates + g.Expect(updated.Data).NotTo(HaveKey("SSLCipherSuite")) + }, timeout, interval).Should(Succeed()) + }) + }) + + When("the published ConfigMap is deleted out from under the operator", func() { + BeforeEach(func() { + createAPIServer(&ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileOldType, + }) + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, defaultInheritingSpec()), + ) + }) + + It("republishes it with the current profile", func() { + cm := getTLSProfileConfigMap() + Expect(cm.Data).To(HaveKeyWithValue( + "SSLCipherSuite", profileCiphers(ocp_configv1.TLSProfileOldType))) + + Expect(k8sClient.Delete(ctx, cm)).Should(Succeed()) + + // nothing else fires for the control plane at this point: the + // watch on the ConfigMap itself is what has to bring it back + updated := getTLSProfileConfigMap() + Expect(updated.Data).To(HaveKeyWithValue( + "SSLCipherSuite", profileCiphers(ocp_configv1.TLSProfileOldType))) + }) + }) + + When("the cluster stops declaring a TLS security profile", func() { + var apiServer *ocp_configv1.APIServer + + BeforeEach(func() { + apiServer = createAPIServer(&ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileModernType, + }) + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, defaultInheritingSpec()), + ) + }) + + It("withdraws the ConfigMap so lib-common falls back to its defaults", func() { + // the profile is published first + cm := getTLSProfileConfigMap() + Expect(cm.Data).To(HaveKeyWithValue( + "SSLProtocol", modernSSLProtocol)) + + // removing the cluster-wide profile has to withdraw it again, + // otherwise services stay pinned to a profile the cluster no + // longer declares + deleteAPIServer(apiServer) + + expectNoTLSProfileConfigMap() + + // ready, but for the "cluster mandates nothing" reason: the + // message has to say so rather than claim a ConfigMap exists + th.ExpectConditionWithDetails( + names.OpenStackControlplaneName, + ConditionGetterFunc(OpenStackControlPlaneConditionGetter), + corev1.OpenStackControlPlaneTLSProfileReadyCondition, + k8s_corev1.ConditionTrue, + condition.ReadyReason, + corev1.OpenStackControlPlaneTLSProfileReadyNoProfileMessage, + ) + }) + }) + + When("the control plane does not inherit the cluster TLS profile", func() { + BeforeEach(func() { + // the cluster declares a profile that would otherwise be + // published, and the default spec leaves inheritance off + createAPIServer(&ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileModernType, + }) + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, GetDefaultOpenStackControlPlaneSpec()), + ) + }) + + It("publishes no ConfigMap and sets no TLS profile condition", func() { + Consistently(func(g Gomega) { + err := k8sClient.Get(ctx, types.NamespacedName{ + Name: util.TLSProfileConfigMap, + Namespace: names.Namespace, + }, &k8s_corev1.ConfigMap{}) + g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue()) + + cp := &corev1.OpenStackControlPlane{} + g.Expect(k8sClient.Get(ctx, names.OpenStackControlplaneName, cp)).To(Succeed()) + g.Expect(hasTLSProfileCondition(cp)).To(BeFalse()) + }, timeout, interval).Should(Succeed()) + }) + }) + + When("inheritance is switched off while a profile is published", func() { + BeforeEach(func() { + createAPIServer(&ocp_configv1.TLSSecurityProfile{ + Type: ocp_configv1.TLSProfileOldType, + }) + DeferCleanup( + th.DeleteInstance, + CreateOpenStackControlPlane(names.OpenStackControlplaneName, defaultInheritingSpec()), + ) + }) + + It("withdraws the ConfigMap and removes the TLS profile condition", func() { + cm := getTLSProfileConfigMap() + Expect(cm.Data).To(HaveKeyWithValue( + "SSLCipherSuite", profileCiphers(ocp_configv1.TLSProfileOldType))) + + // an admin keeping the feature disabled, e.g. through a minor + // update: the services must go back to the built-in defaults + Eventually(func(g Gomega) { + cp := &corev1.OpenStackControlPlane{} + g.Expect(k8sClient.Get(ctx, names.OpenStackControlplaneName, cp)).Should(Succeed()) + cp.Spec.TLS.Profile = corev1.TLSProfileNone + g.Expect(k8sClient.Update(ctx, cp)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + err := k8sClient.Get(ctx, types.NamespacedName{ + Name: util.TLSProfileConfigMap, + Namespace: names.Namespace, + }, &k8s_corev1.ConfigMap{}) + g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue()) + + cp := &corev1.OpenStackControlPlane{} + g.Expect(k8sClient.Get(ctx, names.OpenStackControlplaneName, cp)).To(Succeed()) + g.Expect(hasTLSProfileCondition(cp)).To(BeFalse()) + }, timeout, interval).Should(Succeed()) + }) + }) +})