@@ -17,6 +17,7 @@ limitations under the License.
1717package main
1818
1919import (
20+ "context"
2021 "crypto/tls"
2122 "flag"
2223 "fmt"
@@ -46,6 +47,7 @@ import (
4647 oauthv1 "github.com/openshift/api/oauth/v1"
4748 routev1 "github.com/openshift/api/route/v1"
4849 templatev1 "github.com/openshift/api/template/v1"
50+ tlspkg "github.com/openshift/controller-runtime-common/pkg/tls"
4951 operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
5052 operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
5153 monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
@@ -131,6 +133,8 @@ func main() {
131133 flag .Parse ()
132134
133135 ctrl .SetLogger (zap .New (zap .UseFlagOptions (& opts )))
136+ ctx , cancel := context .WithCancel (ctrl .SetupSignalHandler ())
137+ defer cancel ()
134138
135139 if err := util .InspectCluster (); err != nil {
136140 setupLog .Info ("unable to inspect cluster" )
@@ -142,15 +146,40 @@ func main() {
142146 }
143147 c .NextProtos = []string {"http/1.1" }
144148 }
149+
150+ restConfig := ctrl .GetConfigOrDie ()
151+ // Register config.openshift.io APIs before creating bootstrap client
152+ utilruntime .Must (configv1 .Install (scheme ))
153+ bootstrapClient , err := crclient .New (restConfig , crclient.Options {
154+ Scheme : scheme ,
155+ })
156+ if err != nil {
157+ setupLog .Error (err , "unable to create bootstrap client" )
158+ os .Exit (1 )
159+ }
160+ var profile configv1.TLSProfileSpec
161+ profile , err = tlspkg .FetchAPIServerTLSProfile (ctx , bootstrapClient )
162+ if err != nil {
163+ setupLog .Error (err , "unable to fetch cluster TLS profile" )
164+ os .Exit (1 )
165+ }
166+ tlsOpts := []func (* tls.Config ){disableHTTP2 }
167+ tlsConfigFn , unsupported := tlspkg .NewTLSConfigFromProfile (profile )
168+ if len (unsupported ) > 0 {
169+ setupLog .Info ("TLS profile contains unsupported Go cipher suites" , "ciphers" , unsupported )
170+ }
171+
172+ tlsOpts = append (tlsOpts , tlsConfigFn )
173+
145174 webhookServerOptions := webhook.Options {
146- TLSOpts : [] func ( config * tls. Config ){ disableHTTP2 } ,
175+ TLSOpts : tlsOpts ,
147176 Port : 9443 ,
148177 }
149178 webhookServer := webhook .NewServer (webhookServerOptions )
150179
151180 metricsServerOptions := metricsserver.Options {
152181 BindAddress : metricsAddr ,
153- TLSOpts : [] func ( * tls. Config ){ disableHTTP2 } ,
182+ TLSOpts : tlsOpts ,
154183 FilterProvider : filters .WithAuthenticationAndAuthorization ,
155184 }
156185
@@ -180,15 +209,35 @@ func main() {
180209 }
181210 }
182211
183- mgr , err := ctrl .NewManager (ctrl . GetConfigOrDie () , options )
212+ mgr , err := ctrl .NewManager (restConfig , options )
184213 if err != nil {
185214 setupLog .Error (err , "unable to start manager" )
186215 os .Exit (1 )
187216 }
188217
218+ watcher := & tlspkg.SecurityProfileWatcher {
219+ Client : mgr .GetClient (),
220+ InitialTLSProfileSpec : profile ,
221+ OnProfileChange : func (_ context.Context , oldProfile , newProfile configv1.TLSProfileSpec ) {
222+ if reflect .DeepEqual (oldProfile , newProfile ) {
223+ return
224+ }
225+ setupLog .Info ("cluster TLS profile changed, restarting operator" ,
226+ "oldProfileMinVersion" , oldProfile .MinTLSVersion ,
227+ "newProfileMinVersion" , newProfile .MinTLSVersion )
228+
229+ cancel ()
230+ },
231+ }
232+
233+ if err := watcher .SetupWithManager (mgr ); err != nil {
234+ setupLog .Error (err , "unable to setup TLS security profile watcher" )
235+ os .Exit (1 )
236+ }
237+
189238 var client crclient.Client
190239 if strings .ToLower (os .Getenv ("MEMORY_OPTIMIZATION_ENABLED" )) != "false" {
191- liveClient , err := crclient .New (ctrl . GetConfigOrDie () , crclient.Options {Scheme : mgr .GetScheme ()})
240+ liveClient , err := crclient .New (restConfig , crclient.Options {Scheme : mgr .GetScheme ()})
192241 if err != nil {
193242 setupLog .Error (err , "unable to create live client" )
194243 os .Exit (1 )
@@ -266,6 +315,10 @@ func main() {
266315 K8sClient : k8sClient ,
267316 LocalUsers : argocdprovisioner .NewLocalUsersInfo (),
268317 FipsConfigChecker : argoutil .NewLinuxFipsConfigChecker (),
318+ CentralTlsConfigProfile : argocdprovisioner.TlsConfigProfile {
319+ MinVersion : profile .MinTLSVersion ,
320+ Ciphers : profile .Ciphers ,
321+ },
269322 }).SetupWithManager (mgr ); err != nil {
270323 setupLog .Error (err , "unable to create controller" , "controller" , "Argo CD" )
271324 os .Exit (1 )
@@ -314,7 +367,7 @@ func main() {
314367 }
315368
316369 setupLog .Info ("starting manager" )
317- if err := mgr .Start (ctrl . SetupSignalHandler () ); err != nil {
370+ if err := mgr .Start (ctx ); err != nil {
318371 setupLog .Error (err , "problem running manager" )
319372 os .Exit (1 )
320373 }
0 commit comments