@@ -22,6 +22,7 @@ package v1beta1
2222import (
2323 "context"
2424 "fmt"
25+ "strings"
2526
2627 "k8s.io/apimachinery/pkg/runtime"
2728 logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -84,7 +85,12 @@ func (spec *InstanceHaSpec) Default() {
8485 if spec .InstanceHaHeartbeatPort == 0 {
8586 spec .InstanceHaHeartbeatPort = 7411
8687 }
87-
88+ if spec .MetricsTLS .MinTLSVersion == "" {
89+ spec .MetricsTLS .MinTLSVersion = "1.2"
90+ }
91+ if spec .MetricsTLS .CipherSuites == "" {
92+ spec .MetricsTLS .CipherSuites = "HIGH:!aNULL:!MD5:!RC4:!3DES:!kRSA"
93+ }
8894}
8995
9096// ValidateCreate validates the InstanceHa resource on creation.
@@ -97,6 +103,7 @@ func (r *InstanceHa) ValidateCreate(ctx context.Context, c client.Client) (admis
97103
98104 allErrs = append (allErrs , r .Spec .ValidateTopology (basePath , r .Namespace )... )
99105 allErrs = append (allErrs , r .validateUniqueOpenStackCloud (ctx , c , basePath )... )
106+ allErrs = append (allErrs , r .validateCipherSuites (basePath )... )
100107
101108 if len (allErrs ) != 0 {
102109 return allWarn , apierrors .NewInvalid (
@@ -116,6 +123,7 @@ func (r *InstanceHa) ValidateUpdate(ctx context.Context, c client.Client, old ru
116123
117124 allErrs = append (allErrs , r .Spec .ValidateTopology (basePath , r .Namespace )... )
118125 allErrs = append (allErrs , r .validateUniqueOpenStackCloud (ctx , c , basePath )... )
126+ allErrs = append (allErrs , r .validateCipherSuites (basePath )... )
119127
120128 if len (allErrs ) != 0 {
121129 return allWarn , apierrors .NewInvalid (
@@ -159,6 +167,33 @@ func (r *InstanceHa) validateUniqueOpenStackCloud(
159167 return allErrs
160168}
161169
170+ // validateCipherSuites rejects cipher strings that would result in unencrypted connections.
171+ func (r * InstanceHa ) validateCipherSuites (basePath * field.Path ) field.ErrorList {
172+ var allErrs field.ErrorList
173+ ciphers := r .Spec .MetricsTLS .CipherSuites
174+ if ciphers == "" {
175+ return allErrs
176+ }
177+ fldPath := basePath .Child ("metricsTLS" , "cipherSuites" )
178+ upper := strings .ToUpper (ciphers )
179+ for _ , token := range strings .Split (upper , ":" ) {
180+ trimmed := strings .TrimLeft (token , "+" )
181+ switch trimmed {
182+ case "NULL" , "ENULL" , "ANULL" :
183+ allErrs = append (allErrs , field .Invalid (fldPath , ciphers ,
184+ fmt .Sprintf ("cipher string must not include %q without a '!' prefix" , token )))
185+ case "ALL" :
186+ allErrs = append (allErrs , field .Invalid (fldPath , ciphers ,
187+ "cipher string must not use 'ALL' (includes NULL ciphers); use 'HIGH' instead" ))
188+ }
189+ if strings .HasPrefix (trimmed , "@SECLEVEL=0" ) {
190+ allErrs = append (allErrs , field .Invalid (fldPath , ciphers ,
191+ "cipher string must not use '@SECLEVEL=0' (disables all security requirements)" ))
192+ }
193+ }
194+ return allErrs
195+ }
196+
162197// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
163198func (r * InstanceHa ) ValidateDelete () (admission.Warnings , error ) {
164199 instancehalog .Info ("validate delete" , "name" , r .Name )
0 commit comments