Skip to content

Commit b0dfe41

Browse files
committed
chart: refactoring config keys to enable secure connection
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 4d4d286 commit b0dfe41

28 files changed

+475
-209
lines changed

Base/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ARG AUTHORS=SeleniumHQ
88
# Default value should be aligned with upstream Selenium (https://github.com/SeleniumHQ/selenium/blob/trunk/java/maven_deps.bzl)
99
ARG OPENTELEMETRY_VERSION=1.38.0
1010
ARG GRPC_VERSION=1.64.0
11+
ARG NETTY_VERSION=4.1.108.Final
1112
ARG CS_VERSION=2.1.10
1213

1314
#Arguments to define the user running Selenium
@@ -120,7 +121,7 @@ RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
120121
&& if [ -f "/tmp/cs" ]; then \
121122
java -jar /tmp/cs fetch --classpath --cache /external_jars \
122123
io.opentelemetry:opentelemetry-exporter-otlp:${OPENTELEMETRY_VERSION} \
123-
io.grpc:grpc-netty:${GRPC_VERSION} > /external_jars/.classpath.txt \
124+
io.grpc:grpc-netty:${GRPC_VERSION} io.netty:netty-codec-http:${NETTY_VERSION} > /external_jars/.classpath.txt \
124125
&& chmod 664 /external_jars/.classpath.txt ; \
125126
fi \
126127
&& rm -fr /root/.cache/* \

Makefile

+12-6
Original file line numberDiff line numberDiff line change
@@ -762,34 +762,40 @@ chart_test_template:
762762
./tests/charts/bootstrap.sh
763763

764764
chart_test_autoscaling_disabled:
765-
PLATFORMS=$(PLATFORMS) SELENIUM_GRID_AUTOSCALING=false TEST_DELAY_AFTER_TEST=15 CHART_ENABLE_TRACING=true SELENIUM_GRID_HOST=$$(hostname -i) RELEASE_NAME=selenium \
765+
PLATFORMS=$(PLATFORMS) RELEASE_NAME=selenium SELENIUM_GRID_AUTOSCALING=false TEST_DELAY_AFTER_TEST=15 CHART_ENABLE_TRACING=true \
766+
SECURE_INGRESS_ONLY_GENERATE=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -i) SELENIUM_GRID_PORT=443 \
766767
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) \
767768
./tests/charts/make/chart_test.sh NoAutoscaling
768769

769770
chart_test_autoscaling_deployment_https:
770-
PLATFORMS=$(PLATFORMS) CHART_FULL_DISTRIBUTED_MODE=true CHART_ENABLE_INGRESS_HOSTNAME=true CHART_ENABLE_BASIC_AUTH=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_PORT=443 \
771+
PLATFORMS=$(PLATFORMS) CHART_FULL_DISTRIBUTED_MODE=true CHART_ENABLE_BASIC_AUTH=true \
772+
SECURE_INGRESS_ONLY_DEFAULT=true SELENIUM_GRID_PROTOCOL=https CHART_ENABLE_INGRESS_HOSTNAME=true SELENIUM_GRID_PORT=443 \
771773
SELENIUM_GRID_AUTOSCALING_MIN_REPLICA=1 \
772774
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) \
773775
./tests/charts/make/chart_test.sh DeploymentAutoscaling
774776

775777
chart_test_autoscaling_deployment:
776-
PLATFORMS=$(PLATFORMS) CHART_ENABLE_TRACING=true SELENIUM_GRID_HOST=$$(hostname -i) RELEASE_NAME=selenium \
778+
PLATFORMS=$(PLATFORMS) RELEASE_NAME=selenium CHART_ENABLE_TRACING=true \
779+
SECURE_CONNECTION_SERVER=true SECURE_USE_EXTERNAL_CERT=true SERVICE_TYPE_NODEPORT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -i) SELENIUM_GRID_PORT=31444 \
777780
SELENIUM_GRID_AUTOSCALING_MIN_REPLICA=1 \
778781
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) \
779782
./tests/charts/make/chart_test.sh DeploymentAutoscaling
780783

781784
chart_test_autoscaling_job_https:
782-
PLATFORMS=$(PLATFORMS) SELENIUM_GRID_PROTOCOL=https CHART_ENABLE_BASIC_AUTH=true RELEASE_NAME=selenium SELENIUM_GRID_PORT=443 SUB_PATH=/ \
785+
PLATFORMS=$(PLATFORMS) RELEASE_NAME=selenium CHART_ENABLE_BASIC_AUTH=true \
786+
SECURE_CONNECTION_SERVER=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_PORT=443 SUB_PATH=/ \
783787
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) \
784788
./tests/charts/make/chart_test.sh JobAutoscaling
785789

786790
chart_test_autoscaling_job_hostname:
787-
PLATFORMS=$(PLATFORMS) CHART_ENABLE_TRACING=true CHART_ENABLE_INGRESS_HOSTNAME=true CHART_ENABLE_BASIC_AUTH=true \
791+
PLATFORMS=$(PLATFORMS) CHART_ENABLE_TRACING=true CHART_ENABLE_BASIC_AUTH=true \
792+
SECURE_INGRESS_ONLY_DEFAULT=true SECURE_USE_EXTERNAL_CERT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -i) SELENIUM_GRID_PORT=443 \
788793
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) \
789794
./tests/charts/make/chart_test.sh JobAutoscaling
790795

791796
chart_test_autoscaling_job:
792-
PLATFORMS=$(PLATFORMS) CHART_ENABLE_TRACING=true CHART_FULL_DISTRIBUTED_MODE=true CHART_ENABLE_INGRESS_HOSTNAME=true SELENIUM_GRID_HOST=selenium-grid.local RELEASE_NAME=selenium SUB_PATH=/ \
797+
PLATFORMS=$(PLATFORMS) RELEASE_NAME=selenium CHART_ENABLE_TRACING=true CHART_FULL_DISTRIBUTED_MODE=true \
798+
SECURE_INGRESS_ONLY_GENERATE=true CHART_ENABLE_INGRESS_HOSTNAME=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=selenium-grid.prod SUB_PATH=/ SELENIUM_GRID_PORT=443 \
793799
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) \
794800
./tests/charts/make/chart_test.sh JobAutoscaling
795801

charts/selenium-grid/README.md

+128-44
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ This chart enables the creation of a Selenium Grid Server in Kubernetes.
3131
* [Configuration of video recorder and video uploader](#configuration-of-video-recorder-and-video-uploader)
3232
* [Video recorder](#video-recorder)
3333
* [Video uploader](#video-uploader)
34-
* [Configuration of Secure Communication (HTTPS)](#configuration-of-secure-communication-https)
35-
* [Secure Communication](#secure-communication)
36-
* [Node Registration](#node-registration)
34+
* [Configuration of Secure Communication](#configuration-of-secure-communication)
35+
* [Create TLS Secret](#create-tls-secret)
36+
* [Secure Connection to Selenium Grid components](#secure-connection-to-selenium-grid-components)
37+
* [Secure Connection to the Ingress proxy](#secure-connection-to-the-ingress-proxy)
38+
* [Node Registration](#node-registration)
3739
* [Configuration of tracing observability](#configuration-of-tracing-observability)
3840
* [Configuration of Selenium Grid chart](#configuration-of-selenium-grid-chart)
3941
* [Configuration of KEDA](#configuration-of-keda)
@@ -600,76 +602,158 @@ videoRecorder:
600602
imageTag: latest
601603
```
602604

603-
### Configuration of Secure Communication (HTTPS)
605+
### Configuration of Secure Communication
604606

605607
Selenium Grid supports secure communication between components. Refer to the [instructions](https://github.com/SeleniumHQ/selenium/blob/trunk/java/src/org/openqa/selenium/grid/commands/security.txt) and [options](https://www.selenium.dev/documentation/grid/configuration/cli_options/#server) are able to configure the secure communication. Below is the details on how to enable secure communication in Selenium Grid chart.
606608

607-
#### Secure Communication
609+
In the chart, there is directory [certs](./certs) contains the default self-signed certificate, private key (as PKCS8 format), and Java Keystore (JKS) to teach Java about secure connection (since we are using a non-standard CA) for your trial, local testing purpose. You can generate your own self-signed certificate put them in that default directory by using script [certs/cert.sh](./certs/cert.sh) with adjust needed information. The certificate, private key, truststore are mounted to the components via `Secret`.
608610

609-
In the chart, there is directory [certs](./certs) contains the default certificate, private key (as PKCS8 format), and Java Keystore (JKS) to teach Java about secure connection (since we are using a non-standard CA) for your trial, local testing purpose. You can generate your own self-signed certificate put them in that default directory by using script [cert.sh](./certs/cert.sh) with adjust needed information. The certificate, private key, truststore are mounted to the components via `Secret`.
611+
Usage of [certs/cert.sh](./certs/cert.sh) script:
610612

611-
There are multiple ways to configure your certificate, private key, truststore to the components. You can choose one of them or combine them.
613+
```bash
614+
# Generate self-signed to target directory
615+
./certs/cert.sh -d /path/to/your/
616+
# Add current host IP to the certificate
617+
ADD_IP_ADDRESS=hostname ./certs/cert.sh -d /path/to/your/
618+
# Add multiple IP addresses to the certificate (comma-separated)
619+
ADD_IP_ADDRESS=",IP:10.10.10.10,IP:10.10.11.11" ./certs/cert.sh -d /path/to/your/
620+
# Other environment variables that script consumes
621+
# CERTNAME, STOREPASS, KEYPASS, ALIAS, SERVER_KEYSTORE, BASE64_ONLY
622+
```
612623

613-
- Use the default directory [certs](./certs). Rename your own files to be same as the default files and replace them. Give `--set tls.enabled=true` to enable secure communication.
624+
#### Create TLS Secret
614625

615-
- Use the default directory [certs](./certs). Copy your own files to there and adjust the file name under config `tls.defaultFile`, those will be picked up when installing chart. For example:
626+
There are multiple ways to insert your certificate, private key, truststore to the components. You can choose one of following ways:
616627

617-
```yaml
618-
tls:
619-
enabled: true
620-
trustStorePassword: "your_truststore_password"
621-
defaultFile:
622-
certificate: "certs/your_cert.pem"
623-
privateKey: "certs/your_private_key.pkcs8"
624-
trustStore: "certs/your_truststore.jks"
628+
1. Replace your certificate, private key, truststore to the default directory [certs](./certs) in chart with the same name before deploying the chart.
629+
630+
2. Use Helm CLI to pass your certificate, private key, truststore via `--set-file` when deploying the chart. For example (replace `$RELEASENAME` and `$NAMESPACE` with your values):
631+
632+
```bash
633+
helm upgrade -i $RELEASENAME -n $NAMESPACE docker-selenium/selenium-grid \
634+
--set tls.enabled=true \
635+
--set-file tls.secretFiles.tls\.crt=/path/to/your/tls.crt \
636+
--set-file tls.secretFiles.tls\.key=/path/to/your/tls.key \
637+
--set-file tls.secretFiles.server\.jks=/path/to/your/server.jks
625638
```
626-
For some security reasons, you may not able to put private key in your source code or your customization chart package. You can provide files with contents are encoded in Base64 format, just append `.base64` to the file name for chart able to know and decode them. For example:
639+
640+
3. Create your own TLS Secret with your certificate, private key, truststore and pass the Secret name via `tls.nameOverride` when deploying the chart. For example (replace `$RELEASENAME` and `$NAMESPACE` with your values):
641+
642+
```bash
643+
# Steps to prepare your self-signed certificate
644+
./certs/cert.sh -d /path/to/your/
645+
# Create TLS Secret with your certificate, private key, truststore
646+
kubectl create secret generic -n $NAMESPACE my-external-tls-secret \
647+
--from-file=tls.crt=/path/to/your/tls.crt \
648+
--from-file=tls.key=/path/to/your/tls.key \
649+
--from-file=server.jks=/path/to/your/server.jks
650+
# Deploy chart with your external TLS Secret
651+
helm upgrade -i $RELEASENAME -n $NAMESPACE docker-selenium/selenium-grid \
652+
--set tls.enabled=true --set tls.nameOverride=my-external-tls-secret
653+
```
654+
655+
In case your external secret contains key file names are different with default, you can instruct server to use them via following values:
627656

628657
```yaml
629658
tls:
630659
enabled: true
631-
trustStorePassword: "your_truststore_password"
632-
defaultFile:
633-
certificate: "certs/your_cert.pem.base64"
634-
privateKey: "certs/your_private_key.pkcs8.base64"
635-
trustStore: "certs/your_truststore.jks.base64"
660+
nameOverride: my-external-tls-secret
661+
certificateFile: "my-tls.crt"
662+
privateKeyFile: "my-tls.key"
663+
trustStoreFile: "my-server.jks"
664+
trustStorePassword: "mytruststorepassword"
636665
```
637666

638-
- Using Helm CLI `--set-file` to pass your own file to particular config key. For example:
667+
#### Secure Connection to Selenium Grid components
639668

640-
```bash
641-
helm upgrade -i test selenium-grid \
669+
When enabling secure communication between Selenium Grid server components, you need to set the following values:
670+
671+
```yaml
672+
tls:
673+
enabled: true
674+
```
675+
676+
In additional, if the ingress is enabled with `ingress.hostname` is set, the default server TLS secret is also used for hosts TLS secretName when `ingress.tls` is empty. Once you specify `ingress.tls`, the default server TLS secret is no longer used for hosts TLS secretName.
677+
678+
Moreover, when sub-chart `ingress-nginx` is enabled, the default server TLS secret can also be assigned via `ingress-nginx.controller.extraArgs.default-ssl-certificate`. For example (replace `$RELEASENAME` and `$NAMESPACE` with your values):
679+
680+
```bash
681+
helm upgrade -i $RELEASENAME -n $NAMESPACE docker-selenium/selenium-grid \
642682
--set tls.enabled=true \
643-
--set-file tls.certificate=/path/to/your_cert\.pem \
644-
--set-file tls.privateKey=/path/to/your_private_key\.pkcs8 \
645-
--set-file tls.trustStore=/path/to/your_truststore\.jks \
646-
--set-string tls.trustStorePassword=your_truststore_password
647-
```
683+
--set ingress-nginx.enabled=true \
684+
--set ingress-nginx.controller.extraArgs.default-ssl-certificate=$NAMESPACE/$RELEASENAME-selenium-tls-secret
685+
```
686+
687+
Below is an example of Grid UI accessible via NodePort with secure connection, and using external TLS Secret (replace `$RELEASENAME` and `$NAMESPACE` with your values):
688+
689+
```bash
690+
helm upgrade -i $RELEASENAME -n $NAMESPACE docker-selenium/selenium-grid \
691+
--set ingress.enabled=false \
692+
--set isolateComponents=true \
693+
--set components.router.serviceType=NodePort \
694+
--set tls.enabled=true \
695+
--set tls.nameOverride=my-external-tls-secret
696+
```
697+
698+
Grid UI can be accessed via HTTPS address `https://your.host.public.ip:30444`.
648699

649-
If you start NGINX ingress controller inline with Selenium Grid chart, you can configure the default certificate of NGINX ingress controller to use the same certificate as Selenium Grid. For example:
700+
#### Secure Connection to the Ingress proxy
701+
702+
When enabling secure communication via HTTPS/TLS between the client and the Ingress proxy only. The proxy will terminate the TLS connection and forward the request to the backend components via an unencrypted HTTP connection. The backend Selenium Grid components doesn't need to understand HTTPS. To enable this mode, you need to set the following values:
650703

651704
```yaml
652705
tls:
653-
enabled: true
706+
ingress:
707+
enabled: true
708+
```
654709

655-
ingress-nginx:
656-
enabled: true
657-
controller:
658-
extraArgs:
659-
default-ssl-certificate: '$(POD_NAMESPACE)/selenium-tls-secret'
710+
In additional, a self-signed certificate and private key can be generated runtime during the chart deployment for Ingress TLS by setting these values:
711+
712+
```yaml
713+
tls:
714+
ingress:
715+
generateTLS: true
716+
defaultName: "MySelfSignedCert"
717+
defaultDays: 3650
718+
defaultCN: "www.domain.com" # Common Name
719+
defaultSANList:
720+
- selenium-grid.prod.domain.com # Subject Alternative Name
721+
- selenium-grid.staging.domain.com
722+
defaultIPList:
723+
- 10.87.99.100 # Public IP of the host running K8s or LoadBalancer IP
724+
- 10.87.100.101
660725
```
661726

662-
#### Node Registration
727+
You can get the `tls.crt` and `tls.key` from the Secret after the chart is deployed. For example (replace `$RELEASENAME` and `$NAMESPACE` with your values):
728+
729+
```bash
730+
kubectl get secret $RELEASENAME-selenium-tls-secret -n $NAMESPACE -o jsonpath="{.data.tls\.crt}" | base64 -d > ./tls.crt
731+
kubectl get secret $RELEASENAME-selenium-tls-secret -n $NAMESPACE -o jsonpath="{.data.tls\.key}" | base64 -d > ./tls.key
732+
```
733+
734+
Below is an example of Grid UI accessible via secure connection to the Ingress proxy with self-signed certificate in external TLS Secret (replace `$RELEASENAME` and `$NAMESPACE` with your values):
735+
736+
```bash
737+
helm upgrade -i $RELEASENAME -n $NAMESPACE docker-selenium/selenium-grid \
738+
--set ingress.enabled=true \
739+
--set ingress.hostname="selenium-grid.prod.domain.com" \
740+
--set tls.ingress.enabled=true \
741+
--set tls.nameOverride=my-external-tls-secret \
742+
--set ingress-nginx.enabled=true \
743+
--set ingress-nginx.controller.extraArgs.default-ssl-certificate=$NAMESPACE/my-external-tls-secret
744+
```
745+
746+
Grid UI can be accessed via HTTPS address `https://selenium-grid.prod.domain.com`.
747+
748+
### Node Registration
663749

664750
To enable secure in the node registration to make sure that the node is one you control and not a rouge node, you can enable and provide a registration secret string to Distributor, Router and
665-
Node servers in config `tls.registrationSecret`. For example:
751+
Node servers in config `registrationSecret`. For example:
666752

667753
```yaml
668-
tls:
754+
registrationSecret:
669755
enabled: true
670-
registrationSecret:
671-
enabled: true
672-
value: "matchThisSecret"
756+
value: "matchThisSecret"
673757
```
674758

675759
### Configuration of tracing observability

0 commit comments

Comments
 (0)