Skip to content

Commit 987ebac

Browse files
fmountclaude
andcommitted
Inherit the cluster TLS security profile
This patch represents the first step toward OCPSTRAT-2611. The openstack-operator reads the TLSSecurityProfile from the OpenShift APIServer CR and publish it in a well-known ConfigMap that is used to inject global defaults to the underlying OpenStack services. This ConfigMap contains the Apache httpd directives (SSLCipherSuite and SSLProtocol), plus MinTLSVersion in neutral form for the services that are not httpd based. lib-common merges that ConfigMap with global TLS defaults underneath the ConfigOptions of every Template it renders. Sharing the constant with lib-common keeps producer and consumer from drifting on the object name. Acting on the keys stays opt-in per service: a Service asks for the common template it wants (e.g. ssl.conf in this case) and the service's httpd config has to Include the rendered file. This fearure is currently off by default, and gated on spec.tls.profile, so a minor update does not change the TLS behavior. When the flag is set to None, the inheritance mechanism is not executed, and the TLSProfileReady condition is neither initialised nor set in the Status of the control plane CR. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Francesco Pantano <fpantano@redhat.com>
1 parent 087fa74 commit 987ebac

11 files changed

Lines changed: 894 additions & 4 deletions

File tree

‎api/bases/core.openstack.org_openstackcontrolplanes.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20089,6 +20089,14 @@ spec:
2008920089
type: object
2009020090
type: object
2009120091
type: object
20092+
profile:
20093+
default: None
20094+
enum:
20095+
- None
20096+
- Inherit
20097+
- Intermediate
20098+
- Modern
20099+
type: string
2009220100
type: object
2009320101
topologyRef:
2009420102
properties:

‎api/core/v1beta1/conditions.go‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ const (
108108
// OpenStackControlPlaneCustomTLSReadyCondition Status=True condition which indicates if custom TLS certificate secrets are configured and operational
109109
OpenStackControlPlaneCustomTLSReadyCondition condition.Type = "OpenStackControlPlaneCustomTLSReadyCondition"
110110

111+
// OpenStackControlPlaneTLSProfileReadyCondition Status=True condition which indicates if the APIServer TLS profile has been resolved and the SSL profile ConfigMap created
112+
OpenStackControlPlaneTLSProfileReadyCondition condition.Type = "OpenStackControlPlaneTLSProfileReady"
113+
111114
// OpenStackControlPlaneTelemetryReadyCondition Status=True condition which indicates if OpenStack Telemetry service is configured and operational
112115
OpenStackControlPlaneTelemetryReadyCondition condition.Type = "OpenStackControlPlaneTelemetryReady"
113116

@@ -489,6 +492,23 @@ const (
489492
// OpenStackControlPlaneCAReadyErrorMessage
490493
OpenStackControlPlaneCustomTLSReadyErrorMessage = "OpenStackControlPlane custom TLS cert secret %s error occured %s"
491494

495+
// OpenStackControlPlaneTLSProfileReadyInitMessage
496+
OpenStackControlPlaneTLSProfileReadyInitMessage = "OpenStackControlPlane TLS profile not started"
497+
498+
// OpenStackControlPlaneTLSProfileReadyMessage
499+
OpenStackControlPlaneTLSProfileReadyMessage = "OpenStackControlPlane TLS profile ConfigMap created"
500+
501+
// OpenStackControlPlaneTLSProfileReadyNoProfileMessage
502+
OpenStackControlPlaneTLSProfileReadyNoProfileMessage = "OpenStackControlPlane TLS profile not declared by the cluster, using built-in defaults"
503+
504+
// OpenStackControlPlaneTLSProfileReadyErrorMessage
505+
OpenStackControlPlaneTLSProfileReadyErrorMessage = "OpenStackControlPlane TLS profile error occurred %s"
506+
507+
// OpenStackControlPlaneTLSProfileReadyInvalidMessage - names both remedies,
508+
// since only a human editing one of the two CRs can resolve it
509+
OpenStackControlPlaneTLSProfileReadyInvalidMessage = "OpenStackControlPlane TLS profile cannot be resolved: %s. " +
510+
"Set spec.tls.profile to None, Inherit, Intermediate or Modern, or correct the TLS security profile on the cluster APIServer CR"
511+
492512
// OpenStackControlPlaneTestCMReadyErrorMessage
493513
OpenStackControlPlaneTestCMReadyErrorMessage = "OpenStackControlPlane Test Operator CM error occured %s"
494514

‎api/core/v1beta1/openstackcontrolplane_types.go‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ type TLSSection struct {
272272
// +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"}}}
273273
PodLevel TLSPodLevelConfig `json:"podLevel,omitempty"`
274274

275+
// +kubebuilder:validation:optional
276+
// +operator-sdk:csv:customresourcedefinitions:type=spec
277+
// Profile - The TLS security profile the OpenStack services are
278+
// configured with. "None" (the default) publishes nothing, so the services
279+
// keep lib-common's built-in defaults. "Inherit" follows whatever the
280+
// cluster declares on the OpenShift APIServer CR. "Intermediate" and
281+
// "Modern" pin that profile regardless of what the cluster declares.
282+
// +kubebuilder:default=None
283+
Profile TLSProfileType `json:"profile,omitempty"`
284+
275285
// +kubebuilder:validation:optional
276286
// +operator-sdk:csv:customresourcedefinitions:type=spec
277287
// Secret containing any additional CA certificates, which should be added to deployment pods.
@@ -280,6 +290,37 @@ type TLSSection struct {
280290
tls.Ca `json:",inline"`
281291
}
282292

293+
// TLSProfileType - the TLS security profile the OpenStack services are
294+
// configured with, either sourced from the cluster or named here directly.
295+
// The named values are spelled out rather than taken from configv1 so this
296+
// module keeps openshift/api indirect; the functional tests pin the spelling.
297+
// "Old" is not offered, but stays reachable through "Inherit" when the
298+
// cluster itself declares it.
299+
// +kubebuilder:validation:Enum=None;Inherit;Intermediate;Modern
300+
type TLSProfileType string
301+
302+
const (
303+
// TLSProfileNone - publish nothing; the services keep lib-common's defaults.
304+
TLSProfileNone TLSProfileType = "None"
305+
306+
// TLSProfileInherit - follow the profile the cluster declares on the APIServer CR.
307+
TLSProfileInherit TLSProfileType = "Inherit"
308+
309+
// TLSProfileIntermediate - pin the OpenShift Intermediate profile.
310+
TLSProfileIntermediate TLSProfileType = "Intermediate"
311+
312+
// TLSProfileModern - pin the OpenShift Modern profile.
313+
TLSProfileModern TLSProfileType = "Modern"
314+
)
315+
316+
// IsEnabled - whether a profile is requested at all. InitConditions and
317+
// ReconcileTLSProfile have to agree on this, or an early-returning reconcile
318+
// leaves an Unknown condition behind for a feature that is off. An unset
319+
// value counts as None.
320+
func (p TLSProfileType) IsEnabled() bool {
321+
return p != TLSProfileNone && p != ""
322+
}
323+
283324
// TLSIngressConfig defines the desired state of the TLS configuration for the ingress configuration (route)
284325
type TLSIngressConfig struct {
285326
// +kubebuilder:validation:Optional
@@ -1279,6 +1320,14 @@ func (instance *OpenStackControlPlane) InitConditions() {
12791320
cl.Set(condition.UnknownCondition(OpenStackControlPlaneCyborgReadyCondition, condition.InitReason, OpenStackControlPlaneCyborgReadyInitMessage))
12801321
}
12811322

1323+
// Only register the condition when a profile is requested: in None mode
1324+
// ReconcileTLSProfile removes it again, but an early return (minor update
1325+
// staging, CA requeue, first-pass finalizer) never gets that far and would
1326+
// persist an Unknown for a feature that is off.
1327+
if instance.Spec.TLS.Profile.IsEnabled() {
1328+
cl.Set(condition.UnknownCondition(OpenStackControlPlaneTLSProfileReadyCondition, condition.InitReason, OpenStackControlPlaneTLSProfileReadyInitMessage))
1329+
}
1330+
12821331
// Init Topology condition if there's a reference
12831332
if instance.Spec.TopologyRef != nil {
12841333
cl.Set(condition.UnknownCondition(condition.TopologyReadyCondition, condition.InitReason, condition.TopologyReadyInitMessage))

‎bindata/crds/crds.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21118,6 +21118,14 @@ spec:
2111821118
type: object
2111921119
type: object
2112021120
type: object
21121+
profile:
21122+
default: None
21123+
enum:
21124+
- None
21125+
- Inherit
21126+
- Intermediate
21127+
- Modern
21128+
type: string
2112121129
type: object
2112221130
topologyRef:
2112321131
properties:

‎config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20089,6 +20089,14 @@ spec:
2008920089
type: object
2009020090
type: object
2009120091
type: object
20092+
profile:
20093+
default: None
20094+
enum:
20095+
- None
20096+
- Inherit
20097+
- Intermediate
20098+
- Modern
20099+
type: string
2009220100
type: object
2009320101
topologyRef:
2009420102
properties:

‎config/rbac/role.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ rules:
318318
- apiGroups:
319319
- config.openshift.io
320320
resources:
321+
- apiservers
321322
- clusterimagepolicies
322323
- clusteroperators
323324
- clusterversions

‎go.mod‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,7 @@ replace k8s.io/component-base => k8s.io/component-base v0.33.13 //allow-merging
178178
replace k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20250627150254-e9823e99808e //allow-merging
179179

180180
replace github.com/cert-manager/cmctl/v2 => github.com/cert-manager/cmctl/v2 v2.3.0 //allow-merging
181+
182+
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20261119133733-b9adb5ae4b86
183+
184+
replace github.com/openstack-k8s-operators/lib-common/modules/test => github.com/fmount/lib-common/modules/test v0.0.0-20261119133733-b9adb5ae4b86

‎go.sum‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjT
2727
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
2828
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
2929
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
30+
github.com/fmount/lib-common/modules/common v0.0.0-20261119133733-b9adb5ae4b86 h1:0JCqFK0RBAj2Uipd0w9RzTe06qjooSZ13nEHd8FgBNc=
31+
github.com/fmount/lib-common/modules/common v0.0.0-20261119133733-b9adb5ae4b86/go.mod h1:Bs95wrakWtl9bWhWVIuN54hE8+IILqRU0QH+/AjGlDo=
32+
github.com/fmount/lib-common/modules/test v0.0.0-20261119133733-b9adb5ae4b86 h1:TabLXSNTtKh0fSJXC4tlyd+10RW5GdPFaRAtKBc8IUw=
33+
github.com/fmount/lib-common/modules/test v0.0.0-20261119133733-b9adb5ae4b86/go.mod h1:n8vhem98f8sW/Yd4KFmngEHA04kWWNI/WZ9mTG9tOSo=
3034
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
3135
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
3236
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
180184
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:TkZgZE92VUKHHNKXwuV8b7tT9toaxsZkcGffRafKCSA=
181185
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20261113070913-5152d1d626f9 h1:2fbgvf5Vm4CyTkXWFlmIw0aGzyJjO/SNqLf3dnBx0BE=
182186
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:Br9qj00P2UzWFrtlcSrxBd4eG8fXtRX9h3IN8k5iJGw=
183-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20261113070913-5152d1d626f9 h1:SnR2m0LHH1k+qHT1HSwwx5c7Lc6r1U8PIQpiUj60qrw=
184-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:Bs95wrakWtl9bWhWVIuN54hE8+IILqRU0QH+/AjGlDo=
185187
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20261113070913-5152d1d626f9 h1:lgbKoe9iibFLovaVKqbO6RzcTFhzD7hWW9slJr4TCpE=
186188
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:Jd4fWlkX+mMlAyY4I8TM1NAc2EJVUbJNmtKLIuXvBq0=
187189
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20261113070913-5152d1d626f9 h1:IU4OU1ECIN0XGdHpK3u+Z5sfVGKlYVP5oArTVoilC/4=
188190
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:a7cwXeo63Ce+d/BoQnfK5Qnwxi6B18F7zZlRvSd4XXA=
189-
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20261113070913-5152d1d626f9 h1:zdLGDWn8gHxLR6DgZmfq3pXx7Z7/27Uz2Ua/093K7Ks=
190-
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20261113070913-5152d1d626f9/go.mod h1:n8vhem98f8sW/Yd4KFmngEHA04kWWNI/WZ9mTG9tOSo=
191191
github.com/openstack-k8s-operators/lib-common/modules/users v0.0.0-20261113070913-5152d1d626f9 h1:jnyHfNDI76L31tZqsCO8DyfcB8AdAL8RQsq4UnZeZKE=
192192
github.com/openstack-k8s-operators/lib-common/modules/users v0.0.0-20261113070913-5152d1d626f9/go.mod h1:jmVVRfwuFQ3fHLIOAkUrtLgOwEL6j45POzS3PBJuwyM=
193193
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20261114142025-35eaf5975501 h1:o8NXVjmKsfufK53f+hKlTxXy83bJ4csSjX/RFHEiRDM=

‎internal/controller/core/openstackcontrolplane_controller.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"time"
2828

2929
certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
30+
configv1 "github.com/openshift/api/config/v1"
3031
routev1 "github.com/openshift/api/route/v1"
3132
barbicanv1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
3233
cinderv1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1"
@@ -43,6 +44,7 @@ import (
4344
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
4445
common_helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
4546
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
47+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
4648
"github.com/openstack-k8s-operators/lib-common/modules/common/webhook"
4749
cyborgv1 "github.com/openstack-k8s-operators/nova-operator/api/cyborg/v1beta1"
4850
corev1 "k8s.io/api/core/v1"
@@ -130,9 +132,11 @@ func (r *OpenStackControlPlaneReconciler) GetLogger(ctx context.Context) logr.Lo
130132
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes/custom-host,verbs=create;update;patch
131133
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch
132134
// +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete;
135+
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete;
133136
// +kubebuilder:rbac:groups=cert-manager.io,resources=issuers,verbs=get;list;watch;create;update;patch;delete;
134137
// +kubebuilder:rbac:groups=cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch;delete;
135138
// +kubebuilder:rbac:groups=config.openshift.io,resources=networks,verbs=get;list;watch;
139+
// +kubebuilder:rbac:groups=config.openshift.io,resources=apiservers,verbs=get;list;watch;
136140
// +kubebuilder:rbac:groups=topology.openstack.org,resources=topologies,verbs=get;list;watch;update
137141
// +kubebuilder:rbac:groups=watcher.openstack.org,resources=watchers,verbs=get;list;watch;create;update;patch;delete
138142
// +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
546550
return ctrlResult, nil
547551
}
548552

553+
ctrlResult, err = openstack.ReconcileTLSProfile(ctx, instance, helper)
554+
if err != nil {
555+
return ctrl.Result{}, err
556+
} else if (ctrlResult != ctrl.Result{}) {
557+
return ctrlResult, nil
558+
}
559+
549560
ctrlResult, err = openstack.ReconcileDNSMasqs(ctx, instance, version, helper)
550561
if err != nil {
551562
return ctrl.Result{}, err
@@ -933,6 +944,23 @@ func (r *OpenStackControlPlaneReconciler) SetupWithManager(
933944
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
934945
builder.WithPredicates(openstack.ServicePortOrTypeChangedPredicate()),
935946
).
947+
Watches(
948+
&configv1.APIServer{},
949+
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
950+
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
951+
).
952+
// The operator owns the full lifecycle of the TLS profile ConfigMap:
953+
// if it is deleted or edited out from under it, a reconcile has to
954+
// put it back. Without this watch, a removed ConfigMap would stay
955+
// gone until some unrelated event happened to reconcile the
956+
// control plane again.
957+
Watches(
958+
&corev1.ConfigMap{},
959+
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
960+
builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool {
961+
return obj.GetName() == util.TLSProfileConfigMap
962+
})),
963+
).
936964
Complete(r)
937965
}
938966

0 commit comments

Comments
 (0)