Skip to content

Commit a2cf7a2

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 9527fce commit a2cf7a2

11 files changed

Lines changed: 835 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
@@ -18834,6 +18834,14 @@ spec:
1883418834
type: object
1883518835
type: object
1883618836
type: object
18837+
profile:
18838+
default: None
18839+
enum:
18840+
- None
18841+
- Inherit
18842+
- Intermediate
18843+
- Modern
18844+
type: string
1883718845
type: object
1883818846
topologyRef:
1883918847
properties:

‎api/core/v1beta1/conditions.go‎

Lines changed: 15 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

@@ -483,6 +486,18 @@ const (
483486
// OpenStackControlPlaneCAReadyErrorMessage
484487
OpenStackControlPlaneCustomTLSReadyErrorMessage = "OpenStackControlPlane custom TLS cert secret %s error occured %s"
485488

489+
// OpenStackControlPlaneTLSProfileReadyInitMessage
490+
OpenStackControlPlaneTLSProfileReadyInitMessage = "OpenStackControlPlane TLS profile not started"
491+
492+
// OpenStackControlPlaneTLSProfileReadyMessage
493+
OpenStackControlPlaneTLSProfileReadyMessage = "OpenStackControlPlane TLS profile ConfigMap created"
494+
495+
// OpenStackControlPlaneTLSProfileReadyNoProfileMessage
496+
OpenStackControlPlaneTLSProfileReadyNoProfileMessage = "OpenStackControlPlane TLS profile not declared by the cluster, using built-in defaults"
497+
498+
// OpenStackControlPlaneTLSProfileReadyErrorMessage
499+
OpenStackControlPlaneTLSProfileReadyErrorMessage = "OpenStackControlPlane TLS profile error occurred %s"
500+
486501
// OpenStackControlPlaneTestCMReadyErrorMessage
487502
OpenStackControlPlaneTestCMReadyErrorMessage = "OpenStackControlPlane Test Operator CM error occured %s"
488503

‎api/core/v1beta1/openstackcontrolplane_types.go‎

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

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

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

1288+
// Only register the condition when a profile is requested: in None mode
1289+
// ReconcileTLSProfile removes it again, but an early return (minor update
1290+
// staging, CA requeue, first-pass finalizer) never gets that far and would
1291+
// persist an Unknown for a feature that is off.
1292+
if instance.Spec.TLS.Profile.IsEnabled() {
1293+
cl.Set(condition.UnknownCondition(OpenStackControlPlaneTLSProfileReadyCondition, condition.InitReason, OpenStackControlPlaneTLSProfileReadyInitMessage))
1294+
}
1295+
12471296
// Init Topology condition if there's a reference
12481297
if instance.Spec.TopologyRef != nil {
12491298
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
@@ -19863,6 +19863,14 @@ spec:
1986319863
type: object
1986419864
type: object
1986519865
type: object
19866+
profile:
19867+
default: None
19868+
enum:
19869+
- None
19870+
- Inherit
19871+
- Intermediate
19872+
- Modern
19873+
type: string
1986619874
type: object
1986719875
topologyRef:
1986819876
properties:

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18834,6 +18834,14 @@ spec:
1883418834
type: object
1883518835
type: object
1883618836
type: object
18837+
profile:
18838+
default: None
18839+
enum:
18840+
- None
18841+
- Inherit
18842+
- Intermediate
18843+
- Modern
18844+
type: string
1883718845
type: object
1883818846
topologyRef:
1883918847
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-20260929084206-28305ffbcb79
183+
184+
replace github.com/openstack-k8s-operators/lib-common/modules/test => github.com/fmount/lib-common/modules/test v0.0.0-20260929084206-28305ffbcb79

‎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-20260929084206-28305ffbcb79 h1:WoF885AJhvvwnKLB8wbdWgYE4JASraK7SsOSqsZYgMo=
31+
github.com/fmount/lib-common/modules/common v0.0.0-20260929084206-28305ffbcb79/go.mod h1:HqF1PQbKmgDVsmSk+c9TGmusD4TrlV049qft+SLVTcI=
32+
github.com/fmount/lib-common/modules/test v0.0.0-20260929084206-28305ffbcb79 h1:8sQw7SPjPnZWvVnoe08tCPzZSpLUY8kyjj6ZPiJVkLY=
33+
github.com/fmount/lib-common/modules/test v0.0.0-20260929084206-28305ffbcb79/go.mod h1:jQx5uMv2KKxv+vGATQYEqFs+oaojQYyCi1ZG3ipUk1c=
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.202610191
180184
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20261019154344-eebbad5d5812/go.mod h1:TkZgZE92VUKHHNKXwuV8b7tT9toaxsZkcGffRafKCSA=
181185
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20261019154344-eebbad5d5812 h1:O6kmV2aEgdC17cH6vhMTjn2tFvHY6YradT5UTgX3XW4=
182186
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20261019154344-eebbad5d5812/go.mod h1:95urWJYAaHx7pl6BFE21y8FBHDLyYmRJ2H8f2zBApKg=
183-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20261019154344-eebbad5d5812 h1:TNm//euU2yhclr+yyV3A50i+Fm89FMuPfQ7d10eF+uE=
184-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20261019154344-eebbad5d5812/go.mod h1:q0N2DU1KwZT+Iez34wwkESeHKHN5pbda8G0Gg2QRWNE=
185187
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20261013151427-9b94821abb9f h1:Yiubv1TJ5s3+mKWGRSYsjGnRjBvsFYrv4tuPvJq7uGg=
186188
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20261013151427-9b94821abb9f/go.mod h1:0RZQkKhu5jCn7nUOS41YCBMuZA17r0+l8WDHEjAwOjY=
187189
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20261019154344-eebbad5d5812 h1:Zes+6xpBdekTukArcGt1cNGUYbdWaRWnAPjX8H3YK9c=
188190
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20261019154344-eebbad5d5812/go.mod h1:zPIkK2aNVGCxyf8Yg2iAaiCH3Wu2G/kjft+CAVs1cgQ=
189-
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20261019154344-eebbad5d5812 h1:f0OXYUX2N2czmtkr/Ozv/iJHvwJYtuiqKEuv2HKeU4E=
190-
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20261019154344-eebbad5d5812/go.mod h1:enei+rhzWgyEqqcrh/1V42M9exsotXPnmsj48g1nqD0=
191191
github.com/openstack-k8s-operators/lib-common/modules/users v0.0.0-20261019154344-eebbad5d5812 h1:k9dyBlzwY/uKWD8kVZMAbXMdd1NyVUJGs1pRS/Kfvew=
192192
github.com/openstack-k8s-operators/lib-common/modules/users v0.0.0-20261019154344-eebbad5d5812/go.mod h1:jmVVRfwuFQ3fHLIOAkUrtLgOwEL6j45POzS3PBJuwyM=
193193
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20261020010922-036420e3c133 h1:KDaDY9rGlmussTC8qCE4h+T0y8wieCC/z8Vwlg33JJM=

‎internal/controller/core/openstackcontrolplane_controller.go‎

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

2828
certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
29+
configv1 "github.com/openshift/api/config/v1"
2930
routev1 "github.com/openshift/api/route/v1"
3031
barbicanv1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
3132
cinderv1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1"
@@ -41,6 +42,7 @@ import (
4142
"github.com/openstack-k8s-operators/lib-common/modules/common/backup"
4243
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
4344
common_helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
45+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
4446
"github.com/openstack-k8s-operators/lib-common/modules/common/webhook"
4547
corev1 "k8s.io/api/core/v1"
4648

@@ -127,9 +129,11 @@ func (r *OpenStackControlPlaneReconciler) GetLogger(ctx context.Context) logr.Lo
127129
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes/custom-host,verbs=create;update;patch
128130
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;
129131
// +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete;
132+
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete;
130133
// +kubebuilder:rbac:groups=cert-manager.io,resources=issuers,verbs=get;list;watch;create;update;patch;delete;
131134
// +kubebuilder:rbac:groups=cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch;delete;
132135
// +kubebuilder:rbac:groups=config.openshift.io,resources=networks,verbs=get;list;watch;
136+
// +kubebuilder:rbac:groups=config.openshift.io,resources=apiservers,verbs=get;list;watch;
133137
// +kubebuilder:rbac:groups=topology.openstack.org,resources=topologies,verbs=get;list;watch;update
134138
// +kubebuilder:rbac:groups=watcher.openstack.org,resources=watchers,verbs=get;list;watch;create;update;patch;delete
135139

@@ -531,6 +535,13 @@ func (r *OpenStackControlPlaneReconciler) reconcileNormal(ctx context.Context, i
531535
return ctrlResult, nil
532536
}
533537

538+
ctrlResult, err = openstack.ReconcileTLSProfile(ctx, instance, helper)
539+
if err != nil {
540+
return ctrl.Result{}, err
541+
} else if (ctrlResult != ctrl.Result{}) {
542+
return ctrlResult, nil
543+
}
544+
534545
ctrlResult, err = openstack.ReconcileDNSMasqs(ctx, instance, version, helper)
535546
if err != nil {
536547
return ctrl.Result{}, err
@@ -900,6 +911,23 @@ func (r *OpenStackControlPlaneReconciler) SetupWithManager(
900911
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
901912
builder.WithPredicates(backup.AnnotationChangedPredicate(openstack.ServiceCertSelector)),
902913
).
914+
Watches(
915+
&configv1.APIServer{},
916+
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
917+
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
918+
).
919+
// The operator owns the full lifecycle of the TLS profile ConfigMap:
920+
// if it is deleted or edited out from under it, a reconcile has to
921+
// put it back. Without this watch, a removed ConfigMap would stay
922+
// gone until some unrelated event happened to reconcile the
923+
// control plane again.
924+
Watches(
925+
&corev1.ConfigMap{},
926+
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
927+
builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool {
928+
return obj.GetName() == util.TLSProfileConfigMap
929+
})),
930+
).
903931
Complete(r)
904932
}
905933

0 commit comments

Comments
 (0)