-
Notifications
You must be signed in to change notification settings - Fork 479
AGENT-1454: Enforce APIServer TLS profile on IRI registry #5776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import ( | |
| ) | ||
|
|
||
| func TestRunInternalReleaseImageBootstrap(t *testing.T) { | ||
| configs, err := RunInternalReleaseImageBootstrap(&mcfgv1alpha1.InternalReleaseImage{}, iriCertSecret().obj, cconfig().obj) | ||
| configs, err := RunInternalReleaseImageBootstrap(&mcfgv1alpha1.InternalReleaseImage{}, iriCertSecret().obj, cconfig().obj, nil) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about also adding a test to cover the case where the apiserver is not nil? |
||
| assert.NoError(t, err) | ||
| verifyAllInternalReleaseImageMachineConfigs(t, configs) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ( | |
|
|
||
| mcfgv1 "github.com/openshift/api/machineconfiguration/v1" | ||
| mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1" | ||
| configv1 "github.com/openshift/api/config/v1" | ||
| configinformersv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1" | ||
| configlistersv1 "github.com/openshift/client-go/config/listers/config/v1" | ||
| mcfgclientset "github.com/openshift/client-go/machineconfiguration/clientset/versioned" | ||
|
|
@@ -71,10 +72,15 @@ type Controller struct { | |
| clusterVersionLister configlistersv1.ClusterVersionLister | ||
| clusterVersionListerSynced cache.InformerSynced | ||
|
|
||
| apiServerLister configlistersv1.APIServerLister | ||
| apiServerListerSynced cache.InformerSynced | ||
|
|
||
| secretLister corelistersv1.SecretLister | ||
| secretListerSynced cache.InformerSynced | ||
|
|
||
| queue workqueue.TypedRateLimitingInterface[string] | ||
|
|
||
| lastLoggedTLSProfile string | ||
| } | ||
|
|
||
| // New returns a new InternalReleaseImage controller. | ||
|
|
@@ -83,6 +89,7 @@ func New( | |
| ccInformer mcfginformersv1.ControllerConfigInformer, | ||
| mcInformer mcfginformersv1.MachineConfigInformer, | ||
| clusterVersionInformer configinformersv1.ClusterVersionInformer, | ||
| apiServerInformer configinformersv1.APIServerInformer, | ||
| secretInformer coreinformersv1.SecretInformer, | ||
| kubeClient clientset.Interface, | ||
| mcfgClient mcfgclientset.Interface, | ||
|
|
@@ -121,6 +128,11 @@ func New( | |
| UpdateFunc: ctrl.updateSecret, | ||
| }) | ||
|
|
||
| apiServerInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
| AddFunc: ctrl.addAPIServer, | ||
| UpdateFunc: ctrl.updateAPIServer, | ||
| }) | ||
|
|
||
| ctrl.iriLister = iriInformer.Lister() | ||
| ctrl.iriListerSynced = iriInformer.Informer().HasSynced | ||
|
|
||
|
|
@@ -133,6 +145,9 @@ func New( | |
| ctrl.clusterVersionLister = clusterVersionInformer.Lister() | ||
| ctrl.clusterVersionListerSynced = clusterVersionInformer.Informer().HasSynced | ||
|
|
||
| ctrl.apiServerLister = apiServerInformer.Lister() | ||
| ctrl.apiServerListerSynced = apiServerInformer.Informer().HasSynced | ||
|
|
||
| ctrl.secretLister = secretInformer.Lister() | ||
| ctrl.secretListerSynced = secretInformer.Informer().HasSynced | ||
|
|
||
|
|
@@ -144,7 +159,7 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { | |
| defer utilruntime.HandleCrash() | ||
| defer ctrl.queue.ShutDown() | ||
|
|
||
| if !cache.WaitForCacheSync(stopCh, ctrl.iriListerSynced, ctrl.ccListerSynced, ctrl.mcListerSynced, ctrl.clusterVersionListerSynced, ctrl.secretListerSynced) { | ||
| if !cache.WaitForCacheSync(stopCh, ctrl.iriListerSynced, ctrl.ccListerSynced, ctrl.mcListerSynced, ctrl.clusterVersionListerSynced, ctrl.apiServerListerSynced, ctrl.secretListerSynced) { | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -286,6 +301,22 @@ func (ctrl *Controller) updateSecret(obj, _ interface{}) { | |
| ctrl.queue.Add(ctrlcommon.InternalReleaseImageInstanceName) | ||
| } | ||
|
|
||
| func (ctrl *Controller) addAPIServer(obj interface{}) { | ||
| apiServer := obj.(*configv1.APIServer) | ||
| klog.V(4).Infof("APIServer %s added", apiServer.Name) | ||
| ctrl.queue.Add(ctrlcommon.InternalReleaseImageInstanceName) | ||
| } | ||
|
|
||
| func (ctrl *Controller) updateAPIServer(old, cur interface{}) { | ||
| oldAPIServer := old.(*configv1.APIServer) | ||
| newAPIServer := cur.(*configv1.APIServer) | ||
| if reflect.DeepEqual(oldAPIServer.Spec.TLSSecurityProfile, newAPIServer.Spec.TLSSecurityProfile) { | ||
| return | ||
| } | ||
| klog.V(4).Infof("APIServer %s TLS profile updated", newAPIServer.Name) | ||
| ctrl.queue.Add(ctrlcommon.InternalReleaseImageInstanceName) | ||
| } | ||
|
|
||
| func (ctrl *Controller) enqueue(iri *mcfgv1alpha1.InternalReleaseImage) { | ||
| key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(iri) | ||
| if err != nil { | ||
|
|
@@ -341,8 +372,29 @@ func (ctrl *Controller) syncInternalReleaseImage(key string) error { | |
| return fmt.Errorf("could not get Secret %s: %w", ctrlcommon.InternalReleaseImageTLSSecretName, err) | ||
| } | ||
|
|
||
| // Fetch the APIServer TLS profile. If not found, use nil (defaults to Intermediate). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of maintenance/readability I think it's important to keep the root level of |
||
| apiServer, err := ctrl.apiServerLister.Get(ctrlcommon.APIServerInstanceName) | ||
| if err != nil && !errors.IsNotFound(err) { | ||
| return fmt.Errorf("could not get APIServer: %w", err) | ||
| } | ||
| var tlsProfile *configv1.TLSSecurityProfile | ||
| if apiServer != nil { | ||
| tlsProfile = apiServer.Spec.TLSSecurityProfile | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: will be this field effectively available in a GA cluster? IIUC now it's still in TP |
||
| } | ||
|
|
||
| profileType := "nil (defaulting to Intermediate)" | ||
| if tlsProfile != nil { | ||
| profileType = string(tlsProfile.Type) | ||
| } | ||
| tlsMinVersion, tlsCipherSuites := registryTLSFromProfile(tlsProfile) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really required here? IINW |
||
| tlsLogMsg := fmt.Sprintf("APIServer TLS profile: %s, IRI registry TLS minimum version: %s, cipher suites: %q", profileType, tlsMinVersion, tlsCipherSuites) | ||
| if tlsLogMsg != ctrl.lastLoggedTLSProfile { | ||
| klog.Infof("%s", tlsLogMsg) | ||
| ctrl.lastLoggedTLSProfile = tlsLogMsg | ||
| } | ||
|
|
||
| for _, role := range SupportedRoles { | ||
| r := NewRendererByRole(role, iri, iriSecret, cconfig) | ||
| r := NewRendererByRole(role, iri, iriSecret, cconfig, tlsProfile) | ||
|
|
||
| mc, err := ctrl.mcLister.Get(r.GetMachineConfigName()) | ||
| isNotFound := errors.IsNotFound(err) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: also @bfournie had a PR hitting here https://github.com/openshift/machine-config-operator/pull/5683/changes#r2983557894