Skip to content

Commit 3413151

Browse files
Merge pull request #433 from damdo/use-centralized-tls-profile
OCPCLOUD-3348,OCPBUGS-62176: tls: use centralized TLS profile
2 parents 8f8c56e + 2898912 commit 3413151

1,391 files changed

Lines changed: 252467 additions & 9486 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/cluster-cloud-controller-manager-operator/main.go

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
21+
"crypto/tls"
2022
"errors"
2123
"flag"
2224
"os"
@@ -40,13 +42,15 @@ import (
4042
"sigs.k8s.io/controller-runtime/pkg/cache"
4143
"sigs.k8s.io/controller-runtime/pkg/client"
4244
"sigs.k8s.io/controller-runtime/pkg/healthz"
45+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
4346
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4447
"sigs.k8s.io/controller-runtime/pkg/webhook"
4548

4649
configv1 "github.com/openshift/api/config/v1"
4750
operatorv1 "github.com/openshift/api/operator/v1"
4851
configv1client "github.com/openshift/client-go/config/clientset/versioned"
4952
configinformers "github.com/openshift/client-go/config/informers/externalversions"
53+
utiltls "github.com/openshift/controller-runtime-common/pkg/tls"
5054
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
5155
"github.com/openshift/library-go/pkg/operator/events"
5256
rbacv1 "k8s.io/api/rbac/v1"
@@ -84,10 +88,16 @@ func main() {
8488

8589
metricsAddr := flag.String(
8690
"metrics-bind-address",
87-
":8080",
91+
":9258",
8892
"Address for hosting metrics",
8993
)
9094

95+
webhookPort := flag.Int(
96+
"webhook-port",
97+
9443,
98+
"Webhook Server port",
99+
)
100+
91101
healthAddr := flag.String(
92102
"health-addr",
93103
":9440",
@@ -121,13 +131,39 @@ func main() {
121131
LeaseDuration: leaderElectionConfig.LeaseDuration,
122132
})
123133

124-
ctx := ctrl.SetupSignalHandler()
134+
// Create a cancellable context so the TLS controller can trigger a shutdown
135+
ctx, cancel := context.WithCancel(ctrl.SetupSignalHandler())
136+
// Ensure the context is cancelled when the program exits.
137+
defer cancel()
138+
139+
k8sClient, err := client.New(restConfig, client.Options{Scheme: scheme})
140+
if err != nil {
141+
setupLog.Error(err, "unable to create Kubernetes client")
142+
os.Exit(1)
143+
}
144+
145+
// Fetch the TLS profile from the APIServer resource.
146+
tlsProfileSpec, err := utiltls.FetchAPIServerTLSProfile(ctx, k8sClient)
147+
if err != nil {
148+
setupLog.Error(err, "unable to get TLS profile from API server")
149+
os.Exit(1)
150+
}
151+
152+
// Create the TLS configuration function for the server endpoints.
153+
tlsConfigFunc, unsupportedCiphers := utiltls.NewTLSConfigFromProfile(tlsProfileSpec)
154+
if len(unsupportedCiphers) > 0 {
155+
setupLog.Info("Some ciphers from TLS profile are not supported", "unsupportedCiphers", unsupportedCiphers)
156+
}
157+
tlsOpts := []func(*tls.Config){tlsConfigFunc}
125158

126159
syncPeriod := 10 * time.Minute
127160
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
128161
Scheme: scheme,
129162
Metrics: metricsserver.Options{
130-
BindAddress: *metricsAddr,
163+
BindAddress: *metricsAddr,
164+
FilterProvider: filters.WithAuthenticationAndAuthorization,
165+
SecureServing: true,
166+
TLSOpts: tlsOpts,
131167
},
132168
Cache: cache.Options{
133169
// For roles/rolebindings specifically, we need to also watch kube-system.
@@ -152,16 +188,18 @@ func main() {
152188
},
153189
WebhookServer: &webhook.DefaultServer{
154190
Options: webhook.Options{
155-
Port: 9443,
191+
Port: *webhookPort,
192+
TLSOpts: tlsOpts,
156193
},
157194
},
158-
HealthProbeBindAddress: *healthAddr,
159-
LeaderElectionNamespace: leaderElectionConfig.ResourceNamespace,
160-
LeaderElection: leaderElectionConfig.LeaderElect,
161-
LeaderElectionID: leaderElectionConfig.ResourceName,
162-
LeaseDuration: &le.LeaseDuration.Duration,
163-
RetryPeriod: &le.RetryPeriod.Duration,
164-
RenewDeadline: &le.RenewDeadline.Duration,
195+
HealthProbeBindAddress: *healthAddr,
196+
LeaderElectionReleaseOnCancel: true,
197+
LeaderElectionNamespace: leaderElectionConfig.ResourceNamespace,
198+
LeaderElection: leaderElectionConfig.LeaderElect,
199+
LeaderElectionID: leaderElectionConfig.ResourceName,
200+
LeaseDuration: &le.LeaseDuration.Duration,
201+
RetryPeriod: &le.RetryPeriod.Duration,
202+
RenewDeadline: &le.RenewDeadline.Duration,
165203
})
166204
if err != nil {
167205
setupLog.Error(err, "unable to start manager")
@@ -227,10 +265,28 @@ func main() {
227265
Scheme: mgr.GetScheme(),
228266
ImagesFile: *imagesFile,
229267
FeatureGateAccess: featureGateAccessor,
268+
TLSProfileSpec: tlsProfileSpec,
230269
}).SetupWithManager(mgr); err != nil {
231270
setupLog.Error(err, "unable to create controller", "controller", "ClusterOperator")
232271
os.Exit(1)
233272
}
273+
274+
// Set up the TLS security profile watcher to watch for TLS config changes
275+
if err = (&utiltls.SecurityProfileWatcher{
276+
Client: mgr.GetClient(),
277+
InitialTLSProfileSpec: tlsProfileSpec,
278+
OnProfileChange: func(ctx context.Context, oldTLSProfileSpec, newTLSProfileSpec configv1.TLSProfileSpec) {
279+
klog.Infof("TLS profile has changed, initiating a shutdown to reload it. %q: %+v, %q: %+v",
280+
"old profile", oldTLSProfileSpec,
281+
"new profile", newTLSProfileSpec,
282+
)
283+
cancel()
284+
},
285+
}).SetupWithManager(mgr); err != nil {
286+
setupLog.Error(err, "unable to create controller", "controller", "TLSSecurityProfileWatcher")
287+
os.Exit(1)
288+
}
289+
234290
// +kubebuilder:scaffold:builder
235291

236292
if err := mgr.AddHealthzCheck("health", healthz.Ping); err != nil {

cmd/config-sync-controllers/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ func main() {
130130
restmapper.OpenshiftConfigGroup,
131131
),
132132
),
133-
LeaderElectionNamespace: leaderElectionConfig.ResourceNamespace,
134-
LeaderElection: leaderElectionConfig.LeaderElect,
135-
LeaderElectionID: leaderElectionConfig.ResourceName,
136-
LeaseDuration: &le.LeaseDuration.Duration,
137-
RetryPeriod: &le.RetryPeriod.Duration,
138-
RenewDeadline: &le.RenewDeadline.Duration,
139-
Cache: cacheOptions,
133+
LeaderElectionReleaseOnCancel: true,
134+
LeaderElectionNamespace: leaderElectionConfig.ResourceNamespace,
135+
LeaderElection: leaderElectionConfig.LeaderElect,
136+
LeaderElectionID: leaderElectionConfig.ResourceName,
137+
LeaseDuration: &le.LeaseDuration.Duration,
138+
RetryPeriod: &le.RetryPeriod.Duration,
139+
RenewDeadline: &le.RenewDeadline.Duration,
140+
Cache: cacheOptions,
140141
})
141142
if err != nil {
142143
setupLog.Error(err, "unable to start manager")

go.mod

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@ require (
66
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
77
github.com/go-logr/logr v1.4.3
88
github.com/golangci/golangci-lint v1.62.2
9-
github.com/onsi/ginkgo/v2 v2.25.1
10-
github.com/onsi/gomega v1.38.1
11-
github.com/openshift/api v0.0.0-20251015095338-264e80a2b6e7
12-
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235
9+
github.com/onsi/ginkgo/v2 v2.28.1
10+
github.com/onsi/gomega v1.39.1
11+
github.com/openshift/api v0.0.0-20260213155647-8fe9fe363807
12+
github.com/openshift/client-go v0.0.0-20260108185524-48f4ccfc4e13
1313
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20250122171707-86066d47a264
14-
github.com/openshift/library-go v0.0.0-20251029104758-277736d6f195
14+
github.com/openshift/controller-runtime-common v0.0.0-20260213175913-767fef058eca
15+
github.com/openshift/library-go v0.0.0-20260213153706-03f1709971c5
1516
github.com/spf13/cobra v1.9.1
16-
github.com/spf13/pflag v1.0.7
17+
github.com/spf13/pflag v1.0.9
1718
github.com/stretchr/testify v1.11.1
1819
gopkg.in/gcfg.v1 v1.2.3
1920
gopkg.in/ini.v1 v1.67.0
2021
gopkg.in/yaml.v2 v2.4.0
21-
k8s.io/api v0.34.1
22-
k8s.io/apiextensions-apiserver v0.34.1
23-
k8s.io/apimachinery v0.34.1
24-
k8s.io/client-go v0.34.1
22+
k8s.io/api v0.34.3
23+
k8s.io/apiextensions-apiserver v0.34.3
24+
k8s.io/apimachinery v0.34.3
25+
k8s.io/client-go v0.34.3
2526
k8s.io/cloud-provider-aws v1.34.1-0.20250912204608-8a0025b4efb1
2627
k8s.io/cloud-provider-vsphere v1.34.0
27-
k8s.io/component-base v0.34.1
28+
k8s.io/component-base v0.34.3
2829
k8s.io/controller-manager v0.34.0
2930
k8s.io/klog/v2 v2.130.1
30-
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
31+
k8s.io/utils v0.0.0-20260108192941-914a6e750570
3132
sigs.k8s.io/cloud-provider-azure v1.34.1
3233
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.9.2
33-
sigs.k8s.io/controller-runtime v0.22.4
34+
sigs.k8s.io/controller-runtime v0.22.5
3435
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20251103140007-7a1b16d039d2
3536
sigs.k8s.io/controller-tools v0.17.1
3637
sigs.k8s.io/yaml v1.6.0
@@ -39,6 +40,7 @@ require (
3940
require (
4041
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
4142
4d63.com/gochecknoglobals v0.2.1 // indirect
43+
cel.dev/expr v0.24.0 // indirect
4244
github.com/4meepo/tagalign v1.3.4 // indirect
4345
github.com/Abirdcfly/dupword v0.1.3 // indirect
4446
github.com/Antonboom/errname v1.0.0 // indirect
@@ -96,6 +98,7 @@ require (
9698
github.com/butuzov/mirror v1.2.0 // indirect
9799
github.com/catenacyber/perfsprint v0.7.1 // indirect
98100
github.com/ccojocar/zxcvbn-go v1.0.2 // indirect
101+
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
99102
github.com/cespare/xxhash/v2 v2.3.0 // indirect
100103
github.com/charithe/durationcheck v0.0.10 // indirect
101104
github.com/chavacava/garif v0.1.0 // indirect
@@ -109,12 +112,14 @@ require (
109112
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
110113
github.com/fatih/color v1.18.0 // indirect
111114
github.com/fatih/structtag v1.2.0 // indirect
115+
github.com/felixge/httpsnoop v1.0.4 // indirect
112116
github.com/firefart/nonamedreturns v1.0.5 // indirect
113117
github.com/fsnotify/fsnotify v1.9.0 // indirect
114118
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
115119
github.com/fzipp/gocyclo v0.6.0 // indirect
116120
github.com/ghostiam/protogetter v0.3.8 // indirect
117121
github.com/go-critic/go-critic v0.11.5 // indirect
122+
github.com/go-logr/stdr v1.2.2 // indirect
118123
github.com/go-logr/zapr v1.3.0 // indirect
119124
github.com/go-openapi/jsonpointer v0.21.2 // indirect
120125
github.com/go-openapi/jsonreference v0.21.0 // indirect
@@ -143,15 +148,17 @@ require (
143148
github.com/golangci/revgrep v0.5.3 // indirect
144149
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
145150
github.com/google/btree v1.1.3 // indirect
151+
github.com/google/cel-go v0.26.1 // indirect
146152
github.com/google/gnostic-models v0.7.0 // indirect
147153
github.com/google/go-cmp v0.7.0 // indirect
148-
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 // indirect
154+
github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 // indirect
149155
github.com/google/uuid v1.6.0 // indirect
150156
github.com/gordonklaus/ineffassign v0.1.0 // indirect
151157
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
152158
github.com/gostaticanalysis/comment v1.4.2 // indirect
153159
github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect
154160
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
161+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
155162
github.com/hashicorp/go-version v1.7.0 // indirect
156163
github.com/hashicorp/hcl v1.0.0 // indirect
157164
github.com/hexops/gotextdiff v1.0.3 // indirect
@@ -199,9 +206,9 @@ require (
199206
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
200207
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
201208
github.com/polyfloyd/go-errorlint v1.7.0 // indirect
202-
github.com/prometheus/client_golang v1.23.0 // indirect
209+
github.com/prometheus/client_golang v1.23.2 // indirect
203210
github.com/prometheus/client_model v0.6.2 // indirect
204-
github.com/prometheus/common v0.65.0 // indirect
211+
github.com/prometheus/common v0.66.1 // indirect
205212
github.com/prometheus/procfs v0.17.0 // indirect
206213
github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 // indirect
207214
github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
@@ -233,6 +240,7 @@ require (
233240
github.com/spf13/viper v1.19.0 // indirect
234241
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
235242
github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
243+
github.com/stoewer/go-strcase v1.3.1 // indirect
236244
github.com/stretchr/objx v0.5.2 // indirect
237245
github.com/subosito/gotenv v1.6.0 // indirect
238246
github.com/tdakkota/asciicheck v0.2.0 // indirect
@@ -253,42 +261,52 @@ require (
253261
gitlab.com/bosi/decorder v0.4.2 // indirect
254262
go-simpler.org/musttag v0.13.0 // indirect
255263
go-simpler.org/sloglint v0.7.2 // indirect
264+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
265+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 // indirect
256266
go.opentelemetry.io/otel v1.37.0 // indirect
267+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0 // indirect
268+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.37.0 // indirect
257269
go.opentelemetry.io/otel/metric v1.37.0 // indirect
270+
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
258271
go.opentelemetry.io/otel/trace v1.37.0 // indirect
272+
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
259273
go.uber.org/automaxprocs v1.6.0 // indirect
260274
go.uber.org/mock v0.6.0 // indirect
261275
go.uber.org/multierr v1.11.0 // indirect
262276
go.uber.org/zap v1.27.0 // indirect
263-
go.yaml.in/yaml/v2 v2.4.2 // indirect
277+
go.yaml.in/yaml/v2 v2.4.3 // indirect
264278
go.yaml.in/yaml/v3 v3.0.4 // indirect
265-
golang.org/x/crypto v0.42.0 // indirect
279+
golang.org/x/crypto v0.47.0 // indirect
266280
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect
267281
golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect
268-
golang.org/x/mod v0.27.0 // indirect
269-
golang.org/x/net v0.43.0 // indirect
282+
golang.org/x/mod v0.32.0 // indirect
283+
golang.org/x/net v0.49.0 // indirect
270284
golang.org/x/oauth2 v0.30.0 // indirect
271-
golang.org/x/sync v0.17.0 // indirect
272-
golang.org/x/sys v0.36.0 // indirect
273-
golang.org/x/term v0.35.0 // indirect
274-
golang.org/x/text v0.29.0 // indirect
285+
golang.org/x/sync v0.19.0 // indirect
286+
golang.org/x/sys v0.40.0 // indirect
287+
golang.org/x/term v0.39.0 // indirect
288+
golang.org/x/text v0.33.0 // indirect
275289
golang.org/x/time v0.12.0 // indirect
276-
golang.org/x/tools v0.36.0 // indirect
290+
golang.org/x/tools v0.41.0 // indirect
277291
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
292+
google.golang.org/genproto/googleapis/api v0.0.0-20250826171959-ef028d996bc1 // indirect
293+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250826171959-ef028d996bc1 // indirect
294+
google.golang.org/grpc v1.75.0 // indirect
278295
google.golang.org/protobuf v1.36.8 // indirect
279296
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
280297
gopkg.in/inf.v0 v0.9.1 // indirect
281298
gopkg.in/warnings.v0 v0.1.2 // indirect
282299
gopkg.in/yaml.v3 v3.0.1 // indirect
283300
honnef.co/go/tools v0.5.1 // indirect
284-
k8s.io/apiserver v0.34.1 // indirect
301+
k8s.io/apiserver v0.34.3 // indirect
285302
k8s.io/kube-aggregator v0.34.1 // indirect
286-
k8s.io/kube-openapi v0.0.0-20250814151709-d7b6acb124c3 // indirect
303+
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
287304
mvdan.cc/gofumpt v0.7.0 // indirect
288305
mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f // indirect
306+
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.33.0 // indirect
289307
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.8.4 // indirect
290308
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
291309
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96 // indirect
292310
sigs.k8s.io/randfill v1.0.0 // indirect
293-
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
311+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 // indirect
294312
)

0 commit comments

Comments
 (0)