Skip to content

Commit fe1ce87

Browse files
committed
Pass TLS settings to baremetal machine-controller webhooks.
This ensures Metal3 remediation webhooks use the configured TLS profile while keeping other controllers unchanged.
1 parent a89f6ef commit fe1ce87

2 files changed

Lines changed: 58 additions & 12 deletions

File tree

pkg/operator/sync.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,8 @@ func newContainers(config *OperatorConfig, features map[string]bool, tlsArgs []s
679679
switch config.PlatformType {
680680
case configv1.AzurePlatformType, configv1.GCPPlatformType:
681681
machineControllerArgs = append(machineControllerArgs, "--max-concurrent-reconciles=10")
682+
case configv1.BareMetalPlatformType:
683+
machineControllerArgs = append(machineControllerArgs, tlsArgs...)
682684
}
683685

684686
machineSetControllerArgs := append([]string{}, featureGateArgs...)

pkg/operator/sync_test.go

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,13 @@ func TestNewKubeProxyContainers(t *testing.T) {
620620

621621
func TestNewContainersTLSArgs(t *testing.T) {
622622
testCases := []struct {
623-
name string
624-
config *OperatorConfig
625-
tlsProfile configv1.TLSProfileSpec
623+
name string
624+
config *OperatorConfig
625+
tlsProfile configv1.TLSProfileSpec
626+
expectMachineControllerTLSArgs bool
626627
}{
627628
{
628-
name: "TLS 1.2 with cipher suites",
629+
name: "AWS: TLS 1.2 with cipher suites",
629630
config: &OperatorConfig{
630631
TargetNamespace: targetNamespace,
631632
PlatformType: configv1.AWSPlatformType,
@@ -643,9 +644,10 @@ func TestNewContainersTLSArgs(t *testing.T) {
643644
},
644645
MinTLSVersion: configv1.VersionTLS12,
645646
},
647+
expectMachineControllerTLSArgs: false,
646648
},
647649
{
648-
name: "TLS 1.3 without cipher suites",
650+
name: "GCP: TLS 1.3 without cipher suites",
649651
config: &OperatorConfig{
650652
TargetNamespace: targetNamespace,
651653
PlatformType: configv1.GCPPlatformType,
@@ -660,6 +662,28 @@ func TestNewContainersTLSArgs(t *testing.T) {
660662
Ciphers: []string{},
661663
MinTLSVersion: configv1.VersionTLS13,
662664
},
665+
expectMachineControllerTLSArgs: false,
666+
},
667+
{
668+
name: "BareMetal: TLS args passed to machine-controller for Metal3Remediation webhooks",
669+
config: &OperatorConfig{
670+
TargetNamespace: targetNamespace,
671+
PlatformType: configv1.BareMetalPlatformType,
672+
Controllers: Controllers{
673+
Provider: "provider-image:latest",
674+
MachineSet: "machineset-image:latest",
675+
NodeLink: "nodelink-image:latest",
676+
MachineHealthCheck: "mhc-image:latest",
677+
},
678+
},
679+
tlsProfile: configv1.TLSProfileSpec{
680+
Ciphers: []string{
681+
"ECDHE-ECDSA-AES128-GCM-SHA256",
682+
"ECDHE-RSA-AES128-GCM-SHA256",
683+
},
684+
MinTLSVersion: configv1.VersionTLS12,
685+
},
686+
expectMachineControllerTLSArgs: true,
663687
},
664688
}
665689

@@ -679,28 +703,48 @@ func TestNewContainersTLSArgs(t *testing.T) {
679703
g.Expect(containerArgs).To(HaveKey("machine-controller"))
680704
g.Expect(containerArgs).To(HaveKey("nodelink-controller"))
681705

682-
// Only machineset-controller should receive TLS args.
706+
// machineset-controller always receives TLS args.
683707
machineSetJoined := strings.Join(containerArgs["machineset-controller"], " ")
684708
g.Expect(machineSetJoined).To(ContainSubstring("--tls-min-version="+string(tc.tlsProfile.MinTLSVersion)),
685709
"machineset-controller should have --tls-min-version")
686710
if len(tc.tlsProfile.Ciphers) > 0 {
687711
g.Expect(machineSetJoined).To(ContainSubstring("--tls-cipher-suites="),
688712
"machineset-controller should have --tls-cipher-suites when ciphers are specified")
713+
} else {
714+
g.Expect(machineSetJoined).ToNot(ContainSubstring("--tls-cipher-suites="),
715+
"machineset-controller should not have --tls-cipher-suites when ciphers are not specified")
689716
}
690717

691-
for _, name := range []string{"machine-controller", "nodelink-controller"} {
692-
joined := strings.Join(containerArgs[name], " ")
693-
g.Expect(joined).ToNot(ContainSubstring("--tls-min-version="),
694-
"%s should not have TLS args", name)
695-
g.Expect(joined).ToNot(ContainSubstring("--tls-cipher-suites="),
696-
"%s should not have TLS args", name)
718+
// machine-controller receives TLS args only on BareMetal as it's the only platform that serves webhooks.
719+
machineControllerJoined := strings.Join(containerArgs["machine-controller"], " ")
720+
if tc.expectMachineControllerTLSArgs {
721+
g.Expect(machineControllerJoined).To(ContainSubstring("--tls-min-version="+string(tc.tlsProfile.MinTLSVersion)),
722+
"machine-controller should have --tls-min-version on BareMetal")
723+
if len(tc.tlsProfile.Ciphers) > 0 {
724+
g.Expect(machineControllerJoined).To(ContainSubstring("--tls-cipher-suites="),
725+
"machine-controller should have --tls-cipher-suites on BareMetal")
726+
}
727+
} else {
728+
g.Expect(machineControllerJoined).ToNot(ContainSubstring("--tls-min-version="),
729+
"machine-controller should not have TLS args on %s", tc.config.PlatformType)
730+
g.Expect(machineControllerJoined).ToNot(ContainSubstring("--tls-cipher-suites="),
731+
"machine-controller should not have TLS args on %s", tc.config.PlatformType)
697732
}
698733

734+
// nodelink-controller never receives TLS args.
735+
nodelinkJoined := strings.Join(containerArgs["nodelink-controller"], " ")
736+
g.Expect(nodelinkJoined).ToNot(ContainSubstring("--tls-min-version="),
737+
"nodelink-controller should not have TLS args")
738+
g.Expect(nodelinkJoined).ToNot(ContainSubstring("--tls-cipher-suites="),
739+
"nodelink-controller should not have TLS args")
740+
699741
if tc.config.Controllers.MachineHealthCheck != "" {
700742
g.Expect(containerArgs).To(HaveKey("machine-healthcheck-controller"))
701743
mhcJoined := strings.Join(containerArgs["machine-healthcheck-controller"], " ")
702744
g.Expect(mhcJoined).ToNot(ContainSubstring("--tls-min-version="),
703745
"machine-healthcheck-controller should not have TLS args")
746+
g.Expect(mhcJoined).ToNot(ContainSubstring("--tls-cipher-suites="),
747+
"machine-healthcheck-controller should not have TLS args")
704748
}
705749
})
706750
}

0 commit comments

Comments
 (0)