Skip to content

Commit 79317b5

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 85bcf36 commit 79317b5

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
@@ -19395,6 +19395,14 @@ spec:
1939519395
type: object
1939619396
type: object
1939719397
type: object
19398+
profile:
19399+
default: None
19400+
enum:
19401+
- None
19402+
- Inherit
19403+
- Intermediate
19404+
- Modern
19405+
type: string
1939819406
type: object
1939919407
topologyRef:
1940019408
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
@@ -20424,6 +20424,14 @@ spec:
2042420424
type: object
2042520425
type: object
2042620426
type: object
20427+
profile:
20428+
default: None
20429+
enum:
20430+
- None
20431+
- Inherit
20432+
- Intermediate
20433+
- Modern
20434+
type: string
2042720435
type: object
2042820436
topologyRef:
2042920437
properties:

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19395,6 +19395,14 @@ spec:
1939519395
type: object
1939619396
type: object
1939719397
type: object
19398+
profile:
19399+
default: None
19400+
enum:
19401+
- None
19402+
- Inherit
19403+
- Intermediate
19404+
- Modern
19405+
type: string
1939819406
type: object
1939919407
topologyRef:
1940019408
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-20261116130331-ec34eb3bee03
183+
184+
replace github.com/openstack-k8s-operators/lib-common/modules/test => github.com/fmount/lib-common/modules/test v0.0.0-20261116130331-ec34eb3bee03

‎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-20261116130331-ec34eb3bee03 h1:ZLQ5OmYloiWCXqiESnvCFKyONPEW/ROy4SpCqksi13w=
31+
github.com/fmount/lib-common/modules/common v0.0.0-20261116130331-ec34eb3bee03/go.mod h1:Bs95wrakWtl9bWhWVIuN54hE8+IILqRU0QH+/AjGlDo=
32+
github.com/fmount/lib-common/modules/test v0.0.0-20261116130331-ec34eb3bee03 h1:hIqQUW1Of80YG5mveQnel2hOFGxZdt7rCCTbGRLDPPM=
33+
github.com/fmount/lib-common/modules/test v0.0.0-20261116130331-ec34eb3bee03/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.20261111093153-d3e5c656b371 h1:e+XFyE18cx6wQDFJ9WkuRzQ/cQ2q/DUYSYaPg4rz5xo=
186188
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20261111093153-d3e5c656b371/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.20261112104409-dc982a01f3a8 h1:l02Cm6VSDoCRVObT5vy7D/1zezBPc4ZoJEJ3GLeO/h4=

‎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
corev1 "k8s.io/api/core/v1"
4850

@@ -129,9 +131,11 @@ func (r *OpenStackControlPlaneReconciler) GetLogger(ctx context.Context) logr.Lo
129131
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes/custom-host,verbs=create;update;patch
130132
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch
131133
// +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete;
134+
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete;
132135
// +kubebuilder:rbac:groups=cert-manager.io,resources=issuers,verbs=get;list;watch;create;update;patch;delete;
133136
// +kubebuilder:rbac:groups=cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch;delete;
134137
// +kubebuilder:rbac:groups=config.openshift.io,resources=networks,verbs=get;list;watch;
138+
// +kubebuilder:rbac:groups=config.openshift.io,resources=apiservers,verbs=get;list;watch;
135139
// +kubebuilder:rbac:groups=topology.openstack.org,resources=topologies,verbs=get;list;watch;update
136140
// +kubebuilder:rbac:groups=watcher.openstack.org,resources=watchers,verbs=get;list;watch;create;update;patch;delete
137141

@@ -544,6 +548,13 @@ func (r *OpenStackControlPlaneReconciler) reconcileNormal(ctx context.Context, i
544548
return ctrlResult, nil
545549
}
546550

551+
ctrlResult, err = openstack.ReconcileTLSProfile(ctx, instance, helper)
552+
if err != nil {
553+
return ctrl.Result{}, err
554+
} else if (ctrlResult != ctrl.Result{}) {
555+
return ctrlResult, nil
556+
}
557+
547558
ctrlResult, err = openstack.ReconcileDNSMasqs(ctx, instance, version, helper)
548559
if err != nil {
549560
return ctrl.Result{}, err
@@ -923,6 +934,23 @@ func (r *OpenStackControlPlaneReconciler) SetupWithManager(
923934
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
924935
builder.WithPredicates(openstack.ServicePortOrTypeChangedPredicate()),
925936
).
937+
Watches(
938+
&configv1.APIServer{},
939+
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
940+
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
941+
).
942+
// The operator owns the full lifecycle of the TLS profile ConfigMap:
943+
// if it is deleted or edited out from under it, a reconcile has to
944+
// put it back. Without this watch, a removed ConfigMap would stay
945+
// gone until some unrelated event happened to reconcile the
946+
// control plane again.
947+
Watches(
948+
&corev1.ConfigMap{},
949+
handler.EnqueueRequestsFromMapFunc(r.findControlPlaneForSrc),
950+
builder.WithPredicates(predicate.NewPredicateFuncs(func(obj client.Object) bool {
951+
return obj.GetName() == util.TLSProfileConfigMap
952+
})),
953+
).
926954
Complete(r)
927955
}
928956

0 commit comments

Comments
 (0)