diff --git a/cmd/nginx-ingress/main.go b/cmd/nginx-ingress/main.go index 45697b747..aa3c1946f 100644 --- a/cmd/nginx-ingress/main.go +++ b/cmd/nginx-ingress/main.go @@ -567,7 +567,7 @@ func processDefaultServerSecret(ctx context.Context, kubeClient *kubernetes.Clie var sslRejectHandshake bool if *defaultServerSecret != "" { - secret, err := getAndValidateSecret(kubeClient, *defaultServerSecret) + secret, err := getAndValidateSecret(kubeClient, *defaultServerSecret, api_v1.SecretTypeTLS) if err != nil { nl.Fatalf(l, "Error trying to get the default server TLS secret %v: %v", *defaultServerSecret, err) } @@ -591,7 +591,7 @@ func processDefaultServerSecret(ctx context.Context, kubeClient *kubernetes.Clie func processWildcardSecret(ctx context.Context, kubeClient *kubernetes.Clientset, nginxManager nginx.Manager) bool { l := nl.LoggerFromContext(ctx) if *wildcardTLSSecret != "" { - secret, err := getAndValidateSecret(kubeClient, *wildcardTLSSecret) + secret, err := getAndValidateSecret(kubeClient, *wildcardTLSSecret, api_v1.SecretTypeTLS) if err != nil { nl.Fatalf(l, "Error trying to get the wildcard TLS secret %v: %v", *wildcardTLSSecret, err) } @@ -661,7 +661,8 @@ func getSocketClient(sockPath string) *http.Client { } // getAndValidateSecret gets and validates a secret. -func getAndValidateSecret(kubeClient *kubernetes.Clientset, secretNsName string) (secret *api_v1.Secret, err error) { +// nolint:unparam +func getAndValidateSecret(kubeClient *kubernetes.Clientset, secretNsName string, secretType api_v1.SecretType) (secret *api_v1.Secret, err error) { ns, name, err := k8s.ParseNamespaceName(secretNsName) if err != nil { return nil, fmt.Errorf("could not parse the %v argument: %w", secretNsName, err) @@ -670,9 +671,12 @@ func getAndValidateSecret(kubeClient *kubernetes.Clientset, secretNsName string) if err != nil { return nil, fmt.Errorf("could not get %v: %w", secretNsName, err) } - err = secrets.ValidateTLSSecret(secret) - if err != nil { - return nil, fmt.Errorf("%v is invalid: %w", secretNsName, err) + switch secretType { + case api_v1.SecretTypeTLS: + err = secrets.ValidateTLSSecret(secret) + if err != nil { + return nil, fmt.Errorf("%v is invalid: %w", secretNsName, err) + } } return secret, nil } @@ -779,7 +783,7 @@ func createPlusAndLatencyCollectors( syslogListener = metrics.NewSyslogFakeServer() if *prometheusTLSSecretName != "" { - prometheusSecret, err = getAndValidateSecret(kubeClient, *prometheusTLSSecretName) + prometheusSecret, err = getAndValidateSecret(kubeClient, *prometheusTLSSecretName, api_v1.SecretTypeTLS) if err != nil { nl.Fatalf(l, "Error trying to get the prometheus TLS secret %v: %v", *prometheusTLSSecretName, err) } @@ -831,7 +835,7 @@ func createHealthProbeEndpoint(kubeClient *kubernetes.Clientset, plusClient *cli var err error if *serviceInsightTLSSecretName != "" { - serviceInsightSecret, err = getAndValidateSecret(kubeClient, *serviceInsightTLSSecretName) + serviceInsightSecret, err = getAndValidateSecret(kubeClient, *serviceInsightTLSSecretName, api_v1.SecretTypeTLS) if err != nil { nl.Fatalf(l, "Error trying to get the service insight TLS secret %v: %v", *serviceInsightTLSSecretName, err) }