diff --git a/pkg/util/tls_config.go b/pkg/util/tls_config.go index f3ad61eb052..7e8dbd4c81f 100644 --- a/pkg/util/tls_config.go +++ b/pkg/util/tls_config.go @@ -52,9 +52,6 @@ func decryptClientKey(clientKey, clientKeyPassword string) ([]byte, error) { // and CA certificate. If clientKeyPassword is not empty the provided password will be used to // decrypt the given key. If none are appropriate, a nil *tls.Config is returned. func NewTLSConfigWithPassword(clientCert, clientKey, clientKeyPassword, caCert string) (*tls.Config, error) { - // skipVerify := true is a hack to avoid the CodeQL error related with allowing insecure certificates in production environments. - // Skipping this validation is necessary and intended in our use case in order to be able to trust in the CA. - skipVerify := true valid := false config := &tls.Config{} @@ -81,7 +78,6 @@ func NewTLSConfigWithPassword(clientCert, clientKey, clientKeyPassword, caCert s caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM([]byte(caCert)) config.RootCAs = caCertPool - config.InsecureSkipVerify = skipVerify valid = true } diff --git a/tests/scalers/pulsar/README.md b/tests/scalers/pulsar/README.md new file mode 100644 index 00000000000..ba2427d0022 --- /dev/null +++ b/tests/scalers/pulsar/README.md @@ -0,0 +1,43 @@ +# Apache Pulsar Integration Tests TLS Configuration + +In order to ensure the Apache Pulsar scaler correctly works with self-signed certificates, both tests are run using self-signed certs. + +The Subject Alternative Name on the certs is the service name that points to the broker. Since keda runs in another namespace, it is qualified by namespace. + +## Core assumptions + +Here are the assumptions under which the certificates will work: + +First, we need to establish the DNS names. Those are defined by the service, and will be `testName.testName`. Here are the test names: +* pulsar-partitioned-topic-test +* pulsar-non-partitioned-topic-test + +Second, we must only run a single broker so that `serviceName` points only to a single broker and there are not any redirects. Given that the tests are using the standalone pulsar, it already has to be a single instance, so this assumption holds. + +## Creating the self-signed certs + +Generate the relevant artifacts using the following steps. + +1. Generate a self-signed keystore. It has a long expiration to simplify test management. + ```shell + keytool \ + -keystore server.jks -storepass protected -deststoretype pkcs12 \ + -genkeypair -keyalg RSA -validity 36500 \ + -dname "CN=pulsar.apache.org,O=pulsar,OU=pulsar" \ + -ext "SAN=DNS:pulsar-partitioned-topic-test.pulsar-partitioned-topic-test,DNS:pulsar-non-partitioned-topic-test.pulsar-non-partitioned-topic-test" + ``` +2. Extract the public key. This will be used by the client and the server. (Requires entering the password: `protected`.) + ```shell + openssl pkcs12 -in server.jks -nokeys -out servercert.pem + ``` +3. Extract the private key for use by the server. (Requires entering the password: `protected`.) + ```shell + openssl pkcs12 -in server.jks -nodes -nocerts -out serverkey.pem + ``` +4. base64 encode `servercert.jks` and `serverkey.pem` and place them in the secret to be used in the tests. On MacOS, run: + ```shell + cat servercert.pem | base64 | pbcopy + ``` + ```shell + cat serverkey.pem | base64 | pbcopy + ``` diff --git a/tests/scalers/pulsar/helper/helper.go b/tests/scalers/pulsar/helper/helper.go index 06beb307ddd..f1e8751eae1 100644 --- a/tests/scalers/pulsar/helper/helper.go +++ b/tests/scalers/pulsar/helper/helper.go @@ -44,6 +44,8 @@ metadata: data: key.pub: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnkggprp2GTl/2oQgLvnspbH0Lxthhmw3O3qpcx1FVUcJeD1JlUsuK6rO8uexfY/3JuZffzEm5busJB/5zuXQqO52ph8xDRiEeHOuFY0RKv8DAfpss+oG8Ou/LdHPYCbbyjbJXK/iVE/rUhicp7n6udv2/AaqJj/9535Qo49Q+3S/fbWqhNR6r84+Q+KTHtfwuoLsE4AbZ+g7FRpnyH3iYDxC4ISr1zIJiv4o41cwglaho/cOqCpBFwRHYyZTgeEIf9+7bjTPbpPThFztxO6DOAw73ikU7iT3T0H6hgpQqKa79kw1R8PAfeTYvkeQ4juQwlYmyGePTb9F4LZ+0w7a8wIDAQAB token.jwt: ZXlKaGJHY2lPaUpTVXpJMU5pSjkuZXlKemRXSWlPaUpoWkcxcGJpSjkubEg2TEVqcDU3Y2pFc2xhdWV2Z1ZKV1NTa19IaThFLVZGb29EZHVxUHRiQ1Q0U0NJQlluV0YtRlA5NzBMVUMxRzFWWnZFMmJF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EQ3MXN4RjM4Smh1Q1FsQ09mTQpTVWxLbGo2akFRUlZrTVB4dnNQSFkzV1VoTWNKa1QzM0ZHcWhvZ0U3RnNscitYREYwYm5hQnViVjdpK1BBSVFnCnIzLzVoNUhSc283LzFWaXFnRTZZTGZuT2MycmU4TUd5aFoxVTBySTNCa3RSd2JGZis3UFBKc0svQW9HQVZxUkYKSDFpanVSR0s3MUp4WVdvZlF1RFcrVzg5SWY5QWZ3QWdtcU02Vk41OVhkN1o3WXd0eE90ZlVncytJNi9EVG1XNgp0YThWRVdYNHdCM3FVeVpFTlZaeTRBWFh0SE9BL0Jnc3NlOERMVGZnTVdGLzVnanRPU29GS2h5VHo3OFJtWC9MCnZmQ3JMTjJPMTlqZ0RCSjFaSG92TGQzaEttUVhzR3M2RXRSYXp6RUNnWUVBazBuT3lmbWd2YVVrMHZSTWJnRmEKVmIzUFdNNG0rMG5sbU4wdnpxSHBPbi9SRDc2MlZlT0cxNnNCOFpFKzVlOWFVVWxxTnUxL3M4blByajhDbGhweApmc0RkQnJKZnBHbjBJUGdKNUF4R3F1WEFEOFl3WmpodFp5RVR5bVRlRm9YemNyNVZWaC90cC9HVmlIOXB4VDhGCktKVm1ybWpiMm1HUjBHallNM2dhVGlJPQotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg== ` const pulsarStatefulsetTemplate = ` @@ -71,7 +73,7 @@ spec: imagePullPolicy: IfNotPresent volumeMounts: - name: auth-data - mountPath: "/bin/pulsar" + mountPath: "/pulsar/secrets" readOnly: true readinessProbe: tcpSocket: @@ -80,12 +82,13 @@ spec: - name: pulsar containerPort: 6650 protocol: TCP - - name: admin + - name: http containerPort: 8080 protocol: TCP + - name: https + containerPort: 8443 + protocol: TCP env: - - name: PULSAR_PREFIX_tlsRequireTrustedClientCertOnConnect - value: "true" - name: brokerDeleteInactiveTopicsEnabled value: "false" - name: authenticationEnabled @@ -93,11 +96,17 @@ spec: - name: authenticationProviders value: "org.apache.pulsar.broker.authentication.AuthenticationProviderToken" - name: PULSAR_PREFIX_tokenPublicKey - value: "/bin/pulsar/key.pub" + value: "/pulsar/secrets/key.pub" - name: brokerClientAuthenticationPlugin value: "org.apache.pulsar.client.impl.auth.AuthenticationToken" - name: brokerClientAuthenticationParameters - value: "file:///bin/pulsar/token.jwt" + value: "file:///pulsar/secrets/token.jwt" + - name: PULSAR_PREFIX_webServicePortTls + value: "8443" + - name: tlsKeyFilePath + value: "/pulsar/secrets/tls.key" + - name: tlsCertificateFilePath + value: "/pulsar/secrets/tls.crt" command: - sh - -c @@ -116,11 +125,16 @@ metadata: namespace: {{.TestName}} spec: type: ClusterIP + clusterIP: None ports: - name: http port: 8080 targetPort: 8080 protocol: TCP + - name: https + port: 8443 + targetPort: 8443 + protocol: TCP - name: pulsar port: 6650 targetPort: 6650 @@ -211,7 +225,7 @@ spec: metadata: msgBacklog: "{{.MsgBacklog}}" activationMsgBacklogThreshold: "5" - adminURL: http://{{.TestName}}.{{.TestName}}:8080 + adminURL: https://{{.TestName}}.{{.TestName}}:8443 topic: persistent://public/default/keda isPartitionedTopic: {{ if .NumPartitions }} "true" {{else}} "false" {{end}} authModes: "bearer" @@ -231,6 +245,9 @@ spec: - parameter: bearerToken name: {{.TestName}} key: token.jwt + - parameter: ca + name: {{.TestName}} + key: tls.crt ` const topicPublishJobTemplate = `