From 0c9b569a8bfe8c704246f31fbaa5ddcf85884076 Mon Sep 17 00:00:00 2001 From: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> Date: Fri, 9 Oct 2026 18:44:49 +0200 Subject: [PATCH 1/6] feat(redis): support configurable editor storage topologies - Add standalone, Sentinel, and Cluster editor storage configuration - Validate shared Redis topology and authentication settings - Centralize Redis secret environment variables across workloads and tests - Add Redis configuration Helm tests and example values - Update documentation and deployment test coverage Assisted-by: ChatGPT 5.6 Signed-off-by: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> --- README.md | 69 ++++++++-- demo/Readme.md | 35 ++++- demo/my-values.redis-cluster.yml | 19 +++ demo/my-values.redis-data-only.yml | 7 + demo/my-values.redis-sentinel.yml | 19 +++ demo/my-values.redis-standalone.yml | 6 + demo/my-values.yml | 5 +- sources/scripts/test_ds.py | 24 ++-- sources/scripts/test_redis_config.sh | 121 ++++++++++++++++++ templates/_helpers.tpl | 80 +++++++++++- templates/configmaps/documentserver.yaml | 26 ++-- templates/deployments/converter.yaml | 13 +- templates/deployments/docservice.yaml | 13 +- .../secrets/redis-sentinel-password.yaml | 2 +- templates/statefulset/adminpanel.yaml | 13 +- templates/tests/test-ds-pod.yaml | 13 +- templates/tests/test-redis-config-cm.yaml | 13 ++ templates/tests/test-redis-config-pod.yaml | 47 +++++++ values.yaml | 35 +++-- 19 files changed, 461 insertions(+), 99 deletions(-) create mode 100644 demo/my-values.redis-cluster.yml create mode 100644 demo/my-values.redis-data-only.yml create mode 100644 demo/my-values.redis-sentinel.yml create mode 100644 demo/my-values.redis-standalone.yml create mode 100644 sources/scripts/test_redis_config.sh create mode 100644 templates/tests/test-redis-config-cm.yaml create mode 100644 templates/tests/test-redis-config-pod.yaml diff --git a/README.md b/README.md index 485a40d..9ae7a87 100644 --- a/README.md +++ b/README.md @@ -389,6 +389,53 @@ The `helm delete` command removes all the Kubernetes components associated with ### 4. Parameters +#### Editor data and statistics storage + +`docservice.editorDataStorage` and `docservice.editorStatStorage` select the +storage module for editor data and editor statistics independently. Either +setting may use `memory` while the other uses Redis: + +```yaml +docservice: + editorDataStorage: memory + editorStatStorage: standalone +``` + +The supported combinations are both settings using `memory`, one setting +using `memory` and the other using one Redis topology, or both settings using +the same Redis topology. Standalone, Sentinel, and Cluster cannot be combined +with each other because both settings share one `editorDataRedis` connection. +The chart maps each Redis-backed setting to `editorDataRedis`. + +These combinations are valid: + +```yaml +docservice: + editorDataStorage: cluster + editorStatStorage: cluster +``` + +```yaml +docservice: + editorDataStorage: sentinel + editorStatStorage: memory +``` + +This combination is invalid because it requests two different Redis +topologies from one shared connection: + +```yaml +docservice: + editorDataStorage: standalone + editorStatStorage: cluster +``` + +When `editorStatStorage` is not explicitly configured, DocumentServer uses +the editor data storage module for statistics as well. Configure only the +Redis topology required by the selected mode: `redisHost` and `redisPort` for +standalone, `redisClusterNodes` for cluster, or `redisSentinelNodes` for +Sentinel. Cluster and Sentinel cannot be configured together. + | Parameter | Description | Default | |-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| | `connections.dbType` | The database type. Possible values are `postgres`, `mariadb`, `mysql`, `oracle`, `mssql` or `dameng` | `postgres` | @@ -399,22 +446,22 @@ The `helm delete` command removes all the Kubernetes components associated with | `connections.dbPassword` | Database user password. If set to, it takes priority over the `connections.dbExistingSecret` | `""` | | `connections.dbSecretKeyName` | The name of the key that contains the Database user password | `postgres-password` | | `connections.dbExistingSecret` | Name of existing secret to use for Database passwords. Must contain the key specified in `connections.dbSecretKeyName` | `postgresql` | -| `connections.redisConnectorName` | Defines which connector to use to connect to Redis. If you need to connect to Redis Sentinel, set the value `ioredis` | `redis` | -| `connections.redistHost` | The IP address or the name of the Redis host. Not used if the values are set in `connections.redisClusterNodes` and `connections.redisSentinelNodes` | `redis-master` | -| `connections.redisPort` | The Redis server port number. Not used if the values are set in `connections.redisClusterNodes` and `connections.redisSentinelNodes` | `6379` | -| `connections.redisUser` | The Redis [user](https://redis.io/docs/management/security/acl/) name. The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file | `default` | +| `connections.redisHost` | Redis host, or the reachable startup/readiness fallback endpoint when a topology is configured | `redis-master` | +| `connections.redisPort` | Redis port used with `connections.redisHost` for the standalone/startup fallback endpoint | `6379` | +| `connections.redisUser` | Redis [user](https://redis.io/docs/management/security/acl/) name. Omitted when `connections.redisNoPass` is `true` | `default` | | `connections.redisDBNum` | Number of the redis logical database to be [selected](https://redis.io/commands/select/). The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file | `0` | | `connections.redisClusterNodes` | List of nodes in the Redis cluster. There is no need to specify every node in the cluster, 3 should be enough. You can specify multiple values. It must be specified in the `host:port` format | `[]` | | `connections.redisPassword` | The password set for the Redis account. If set to, it takes priority over the `connections.redisExistingSecret`. The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file | `""` | | `connections.redisSecretKeyName` | The name of the key that contains the Redis user password | `redis-password` | | `connections.redisExistingSecret` | Name of existing secret to use for Redis passwords. Must contain the key specified in `connections.redisSecretKeyName`. The password from this secret overrides password set in the `options` object in `local.json` | `redis` | | `connections.redisNoPass` | Defines whether to use a Redis auth without a password. If the connection to Redis server does not require a password, set the value to `true` | `false` | -| `connections.redisSentinelNodes` | List of Redis Sentinel Nodes. There is no need to specify every node, 3 should be enough. You can specify multiple values. It must be specified in the `host:port` format. Used if `connections.redisConnectorName` is set to `ioredis` | `[]` | -| `connections.redisSentinelGroupName` | Name of a group of Redis instances composed of a master and one or more slaves. Used if `connections.redisConnectorName` is set to `ioredis` | `mymaster` | -| `connections.redisSentinelExistingSecret` | Name of existing secret to use for Redis Sentinel password. Must contain the key specified in `connections.redisSentinelSecretKeyName`. The password from this secret overrides the value for the password set in the `iooptions` object in `local.json` | "" | +| `connections.redisSentinelNodes` | List of Redis Sentinel Nodes. Sentinel mode is enabled when this list is non-empty. There is no need to specify every node, 3 should be enough. It must use the `host:port` format | `[]` | +| `connections.redisSentinelGroupName` | Name of the Sentinel-monitored Redis group. | `mymaster` | +| `connections.redisSentinelUser` | Redis Sentinel ACL user name. Required together with a password when Sentinel authentication is enabled. | `""` | +| `connections.redisSentinelExistingSecret` | Name of existing secret to use for Redis Sentinel password. Must contain the key specified in `connections.redisSentinelSecretKeyName`. The password overrides `optionsSentinel` in `local.json` | `""` | | `connections.redisSentinelSecretKeyName` | The name of the key that contains the Redis Sentinel user password. If you set a password in `redisSentinelPassword`, a secret will be automatically created, the key name of which will be the value set here | `sentinel-password` | -| `connections.redisSentinelPassword` | The password set for the Redis Sentinel account. If set to, it takes priority over the `connections.redisSentinelExistingSecret`. The value in this parameter overrides the value set in the `iooptions` object in `local.json` | `""` | -| `connections.redisSentinelNoPass` | Defines whether to use a Redis Sentinel auth without a password. If the connection to Redis Sentinel does not require a password, set the value to `true` | `true` | +| `connections.redisSentinelPassword` | The password set for the Redis Sentinel account. If set, it takes priority over `connections.redisSentinelExistingSecret` and overrides the `optionsSentinel` password in `local.json` | `""` | +| `connections.redisSentinelNoPass` | If `true`, omit Sentinel ACL credentials. If `false`, both `connections.redisSentinelUser` and a Sentinel password are required. | `true` | | `connections.amqpType` | Defines the AMQP server type. Possible values are `rabbitmq` or `activemq` | `rabbitmq` | | `connections.amqpHost` | The IP address or the name of the AMQP server | `rabbitmq` | | `connections.amqpPort` | The port for the connection to AMQP server | `5672` | @@ -484,6 +531,8 @@ The `helm delete` command removes all the Kubernetes components associated with | `customPlugins.defaultPlugins.list` | Defines [which plugins](./CUSTOM_RESOURCES.md#install-selected-default-plugins-only) from the default list will be installed on the server and in the `Plugins` menu. It is executed if the `customPlugins.build` is set to `true` | `[]` | | `customPlugins.emptyPluginsDir` | Defines whether a directory with plugins in containers will [contain files](./CUSTOM_RESOURCES.md#completely-disable-plugins-directory), including service files. If set to `true`, an empty volume with the `emptyDir` type will be mapped | `false` | | `images.tag` | Global image tag for all Euro-Office Docs services and jobs | `9.3.1-1` | +| `docservice.editorDataStorage` | Editor data storage mode. Can differ from `docservice.editorStatStorage`; possible values are `memory`, `standalone`, `sentinel` or `cluster`. Redis-backed modes use the shared `editorDataRedis` connection. | `memory` | +| `docservice.editorStatStorage` | Editor statistics storage mode. If omitted, it follows `docservice.editorDataStorage`; Redis-backed modes must use the same topology as editor data. | `editorDataStorage` | | `docservice.annotations` | Defines annotations that will be additionally added to Docservice Deployment. If set to, it takes priority over the `commonAnnotations` | `{}` | | `docservice.podAnnotations` | Map of annotations to add to the Docservice deployment pods | `rollme: "{{ randAlphaNum 5 \| quote }}"` | | `docservice.replicas` | Docservice replicas quantity. If the `docservice.autoscaling.enabled` parameter is enabled, it is ignored | `2` | @@ -821,7 +870,7 @@ The `helm delete` command removes all the Kubernetes components associated with | `customResources.job.containerSecurityContext.enabled` | Enable security context for the Custom Resources container | `false` | | `customResources.job.resources.requests` | The requested resources for the job Custom Resources container | `{}` | | `customResources.job.resources.limits` | The resources limits for the job Custom Resources container | `{}` | -| `tests.enabled` | Enable the resources creation necessary for Euro-Office Docs launch testing and connected dependencies availability testing. These resources will be used when running the `helm test` command | `true` | +| `tests.enabled` | Enable launch/dependency test resources. `helm test` checks Redis, the other dependencies, the native Sentinel `NODE_CONFIG` (when Sentinel storage is selected), and the DocumentServer health endpoint; any failed check fails the test. | `true` | | `tests.annotations` | Defines annotations that will be additionally added to Test Pod. If set to, it takes priority over the `commonAnnotations` | `{}` | | `tests.customPodAntiAffinity` | Prohibiting the scheduling of Test Pod relative to other Pods containing the specified labels on the same node | `{}` | | `tests.podAffinity` | Defines [Pod affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity) rules for Test Pod scheduling by nodes relative to other Pods | `{}` | diff --git a/demo/Readme.md b/demo/Readme.md index dd724e0..70b3f4e 100644 --- a/demo/Readme.md +++ b/demo/Readme.md @@ -100,7 +100,7 @@ kubectl apply -f redis.yaml kubectl apply -f rabbitmq.yaml kubectl apply -f storage.yaml -# Wait for all four to be Running +# Wait for the three dependency pods to be Running kubectl get pods -n euro-office -w ``` @@ -110,7 +110,7 @@ Verify connectivity before installing the chart: # Postgres kubectl run pgtest --rm -it --restart=Never -n euro-office \ --image=postgres:16 -- \ - psql "postgresql://onlyoffice:onlyoffice@pg-postgresql:5432/onlyoffice" -c "SELECT 1;" + psql "postgresql://eurooffice:eurooffice@pg-postgresql:5432/eurooffice" -c "SELECT 1;" # Redis kubectl run redistest --rm -it --restart=Never -n euro-office \ @@ -135,7 +135,7 @@ Expected sequence: 3. `converter-*` → 1/1 Running 4. `docservice-*` → 2/2 Running (docservice + proxy sidecar) 5. `example-0` → 1/1 Running -5. `adminpanel-0` → 1/1 Running +6. `adminpanel-0` → 1/1 Running Press Ctrl-C once everything reads Running or Completed. @@ -211,6 +211,10 @@ sudo rm -rf /tmp/euro-office-shared - `rabbitmq.yaml` — RabbitMQ deployment, service, and secret - `storage.yaml` — `nfs` StorageClass and static PVs backed by the host-mounted shared directory - `my-values.yml` — Helm chart overrides (image references, connection URLs, JWT secret, env vars) +- `my-values.redis-standalone.yml` — enables Redis for both editor data and statistics using standalone Redis +- `my-values.redis-data-only.yml` — enables Redis for editor data while keeping statistics in memory +- `my-values.redis-sentinel.yml` — Sentinel configuration overlay for an external Redis Sentinel deployment +- `my-values.redis-cluster.yml` — Cluster configuration overlay for an external Redis Cluster deployment ## Limitations @@ -220,3 +224,28 @@ This setup is for local testing only: - The shared host volume at `/tmp/euro-office-shared` only works because k3d nodes run on a single host; in a real cluster, replace `storage.yaml` with proper NFS or another RWX provisioner - Single-replica databases with no backups - No TLS, no ingress, port-forwarding only + +## Redis editor-storage examples + +The base `my-values.yml` leaves both editor stores in their default `memory` +mode. Apply one of the overlays together with the base values file to select a +Redis topology. Only one Redis topology may be configured at a time. + +The standalone overlay works with the `redis.yaml` manifest included here: + +```bash +helm install docs .. -n euro-office \ + -f my-values.yml -f my-values.redis-standalone.yml --timeout 10m +``` + +The data-only overlay demonstrates that the two storage modules can be chosen +independently: + +```bash +helm install docs .. -n euro-office \ + -f my-values.yml -f my-values.redis-data-only.yml --timeout 10m +``` + +The Sentinel and Cluster overlays contain example node names and require an +external topology with those names, or equivalent values edited for the target +environment. They do not deploy Sentinel or Cluster resources. diff --git a/demo/my-values.redis-cluster.yml b/demo/my-values.redis-cluster.yml new file mode 100644 index 0000000..87fc104 --- /dev/null +++ b/demo/my-values.redis-cluster.yml @@ -0,0 +1,19 @@ +# Apply together with my-values.yml after providing a reachable Redis Cluster +# deployment. This file does not deploy a Redis Cluster itself. +# +# helm install docs .. -n euro-office -f my-values.yml -f my-values.redis-cluster.yml + +docservice: + editorDataStorage: cluster + editorStatStorage: cluster + +connections: + # Startup/readiness fallback endpoint. Cluster discovery uses redisClusterNodes. + redisHost: redis-cluster-0.euro-office.svc.cluster.local + redisPort: 6379 + redisClusterNodes: + - redis-cluster-0.euro-office.svc.cluster.local:6379 + - redis-cluster-1.euro-office.svc.cluster.local:6379 + - redis-cluster-2.euro-office.svc.cluster.local:6379 + # Redis Cluster does not support selecting a non-zero logical database. + redisDBNum: "0" diff --git a/demo/my-values.redis-data-only.yml b/demo/my-values.redis-data-only.yml new file mode 100644 index 0000000..b6554cf --- /dev/null +++ b/demo/my-values.redis-data-only.yml @@ -0,0 +1,7 @@ +# Editor data uses Redis; editor statistics keep the memory backend. +# Apply together with my-values.yml: +# helm install docs .. -n euro-office -f my-values.yml -f my-values.redis-data-only.yml + +docservice: + editorDataStorage: standalone + editorStatStorage: memory diff --git a/demo/my-values.redis-sentinel.yml b/demo/my-values.redis-sentinel.yml new file mode 100644 index 0000000..fff9d13 --- /dev/null +++ b/demo/my-values.redis-sentinel.yml @@ -0,0 +1,19 @@ +# Apply together with my-values.yml after providing a reachable Redis Sentinel +# deployment. This file does not deploy Sentinel itself. +# +# helm install docs .. -n euro-office -f my-values.yml -f my-values.redis-sentinel.yml + +docservice: + editorDataStorage: sentinel + editorStatStorage: sentinel + +connections: + # Fallback/startup endpoint. Sentinel discovery uses redisSentinelNodes. + redisHost: redis-sentinel.euro-office.svc.cluster.local + redisPort: 26379 + redisSentinelNodes: + - redis-sentinel-0.euro-office.svc.cluster.local:26379 + - redis-sentinel-1.euro-office.svc.cluster.local:26379 + - redis-sentinel-2.euro-office.svc.cluster.local:26379 + redisSentinelGroupName: mymaster + redisSentinelNoPass: true diff --git a/demo/my-values.redis-standalone.yml b/demo/my-values.redis-standalone.yml new file mode 100644 index 0000000..6ed5891 --- /dev/null +++ b/demo/my-values.redis-standalone.yml @@ -0,0 +1,6 @@ +# Apply together with my-values.yml: +# helm install docs .. -n euro-office -f my-values.yml -f my-values.redis-standalone.yml + +docservice: + editorDataStorage: standalone + editorStatStorage: standalone diff --git a/demo/my-values.yml b/demo/my-values.yml index d201919..25020d1 100644 --- a/demo/my-values.yml +++ b/demo/my-values.yml @@ -1,5 +1,5 @@ -# Skip the demo app +# Enable the demo app example: enabled: true dsUrl: "http://localhost:8082/" @@ -23,7 +23,6 @@ connections: dbUser: eurooffice dbPassword: eurooffice - redisConnectorName: ioredis redisHost: redis-master.euro-office.svc.cluster.local redisPort: 6379 redisPassword: redis @@ -52,4 +51,4 @@ requestFilteringAgent: log: - level: DEBUG \ No newline at end of file + level: DEBUG diff --git a/sources/scripts/test_ds.py b/sources/scripts/test_ds.py index 36439c3..745e3a9 100755 --- a/sources/scripts/test_ds.py +++ b/sources/scripts/test_ds.py @@ -4,11 +4,11 @@ import time import logging -redisConnectorName = os.environ.get('REDIS_CONNECTOR_NAME') redisHost = os.environ.get('REDIS_SERVER_HOST') redisPort = os.environ.get('REDIS_SERVER_PORT') redisUser = os.environ.get('REDIS_SERVER_USER') redisPassword = os.environ.get('REDIS_SERVER_PWD') +redisSentinelUser = os.environ.get('REDIS_SENTINEL_USER') redisSentinelPassword = os.environ.get('REDIS_SENTINEL_PWD') redisDBNum = os.environ.get('REDIS_SERVER_DB_NUM') redisConnectTimeout = 15 @@ -16,7 +16,7 @@ redisClusterNodes = list(os.environ.get('REDIS_CLUSTER_NODES').split(" ")) redisClusterNode = redisClusterNodes[0].split(":")[0] redisClusterPort = redisClusterNodes[0].split(":")[1] -if redisConnectorName == 'ioredis': +if os.environ.get('REDIS_SENTINEL_NODES'): redisSentinelGroupName = os.environ.get('REDIS_SENTINEL_GROUP_NAME') if os.environ.get('REDIS_SENTINEL_NODES'): redisSentinelNodes = list(os.environ.get('REDIS_SENTINEL_NODES').split(" ")) @@ -117,7 +117,12 @@ def get_redis_sentinel_status(): retry_strategy = Retry(ExponentialBackoff(), retries=3) global rc try: - sentinel = Sentinel([(redisSentinelNode, redisSentinelPort)], socket_timeout=redisConnectTimeout, sentinel_kwargs={'password': redisSentinelPassword}) + sentinel_kwargs = {} + if redisSentinelUser: + sentinel_kwargs['username'] = redisSentinelUser + if redisSentinelPassword: + sentinel_kwargs['password'] = redisSentinelPassword + sentinel = Sentinel([(redisSentinelNode, redisSentinelPort)], socket_timeout=redisConnectTimeout, sentinel_kwargs=sentinel_kwargs) master_host, master_port = sentinel.discover_master(redisSentinelGroupName) rc = redis.Redis( host=master_host, @@ -154,14 +159,14 @@ def check_redis_key(): def check_redis(): logger_test_ds.info('Checking Redis availability...') - if redisConnectorName == 'redis' and not os.environ.get('REDIS_CLUSTER_NODES'): - if get_redis_status() is True: + if os.environ.get('REDIS_SENTINEL_NODES'): + if get_redis_sentinel_status() is True: check_redis_key() - elif redisConnectorName == 'redis' and os.environ.get('REDIS_CLUSTER_NODES'): + elif os.environ.get('REDIS_CLUSTER_NODES'): if get_redis_cluster_status() is True: check_redis_key() - elif redisConnectorName == 'ioredis': - if get_redis_sentinel_status() is True: + else: + if get_redis_status() is True: check_redis_key() @@ -362,7 +367,7 @@ def total_status(): logger_test_ds.info('As a result of the check, the following results were obtained:') for key, value in total_result.items(): logger_test_ds.info(f'{key} = {value}') - if total_result['CheckDS'] != 'Success': + if any(value != 'Success' for value in total_result.values()): sys.exit(1) @@ -375,4 +380,3 @@ def total_status(): check_dir_access() get_ds_status() total_status() - diff --git a/sources/scripts/test_redis_config.sh b/sources/scripts/test_redis_config.sh new file mode 100644 index 0000000..4f8569b --- /dev/null +++ b/sources/scripts/test_redis_config.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +set -euo pipefail + +fail() { + echo "Redis configuration test failed: $*" >&2 + exit 1 +} + +command -v jq >/dev/null 2>&1 || fail "jq is not available in the DocumentServer image" +[[ -x /usr/local/bin/docker-entrypoint.sh ]] || fail "the native DocumentServer entrypoint is not available" + +[[ -n "${REDIS_SERVER_DB_NUM:-}" ]] || fail "REDIS_SERVER_DB_NUM is not set" + +if [[ -n "${REDIS_SENTINEL_NODES:-}" && -n "${REDIS_CLUSTER_NODES:-}" ]]; then + fail "Redis Sentinel and Cluster nodes cannot both be set" +elif [[ -n "${REDIS_SENTINEL_NODES:-}" ]]; then + topology=sentinel + [[ -n "${REDIS_SENTINEL_GROUP_NAME:-}" ]] || fail "REDIS_SENTINEL_GROUP_NAME is not set" +elif [[ -n "${REDIS_CLUSTER_NODES:-}" ]]; then + topology=cluster +else + fail "Redis Sentinel or Cluster nodes must be set" +fi + +# The orchestrated entrypoint is the component that turns Helm's environment +# into NODE_CONFIG. ENTRYPOINT_CONFIG_ONLY prevents DocService from starting; +# the regular Helm test pod separately checks that DocService starts and +# connects successfully. +render_config() { + # Explicitly remove the obsolete aliases while exercising the native names. + env -u REDIS_SERVER_PASS -u REDIS_SENTINEL_PASS -u REDIS_SERVER_DB \ + "$@" /usr/local/bin/docker-entrypoint.sh docservice +} + +check_config() { + local name="$1" + local node_config="$2" + local node_auth="$3" + local sentinel_auth="$4" + + printf '%s' "$node_config" | jq -e ' + .services.CoAuthoring.server.editorDataStorage == "editorDataRedis" and + .services.CoAuthoring.server.editorStatStorage == "editorDataRedis" and + .services.CoAuthoring.redis.name == "redis" +' >/dev/null || fail "$name: NODE_CONFIG does not select the native Redis backend" + + if [[ "$topology" == sentinel ]]; then + printf '%s' "$node_config" | jq -e --arg nodes "$REDIS_SENTINEL_NODES" --arg db "$REDIS_SERVER_DB_NUM" ' + (.services.CoAuthoring.redis.optionsSentinel | type) == "object" and + (.services.CoAuthoring.redis.optionsSentinel.sentinelRootNodes | + map("\(.host):\(.port)") == ($nodes | split(" "))) and + (.services.CoAuthoring.redis.optionsSentinel.nodeClientOptions.database == ($db | tonumber)) and + ((.services.CoAuthoring.redis.optionsCluster.rootNodes // []) | length) == 0 + ' >/dev/null || fail "$name: NODE_CONFIG does not contain the expected native Sentinel configuration" + + if [[ "$node_auth" == true ]]; then + printf '%s' "$node_config" | jq -e ' + .services.CoAuthoring.redis.optionsSentinel.nodeClientOptions | + has("username") and has("password") and has("database") + ' >/dev/null || fail "$name: authenticated Redis node options are incomplete" + else + printf '%s' "$node_config" | jq -e ' + .services.CoAuthoring.redis.optionsSentinel.nodeClientOptions | + (has("username") or has("password")) | not + ' >/dev/null || fail "$name: unauthenticated Redis node options contain credentials" + fi + + if [[ "$sentinel_auth" == true ]]; then + printf '%s' "$node_config" | jq -e ' + .services.CoAuthoring.redis.optionsSentinel.sentinelClientOptions | + has("username") and has("password") + ' >/dev/null || fail "$name: authenticated Sentinel options are incomplete" + else + printf '%s' "$node_config" | jq -e ' + .services.CoAuthoring.redis.optionsSentinel.sentinelClientOptions == {} + ' >/dev/null || fail "$name: unauthenticated Sentinel options are not empty" + fi + else + printf '%s' "$node_config" | jq -e --arg nodes "$REDIS_CLUSTER_NODES" ' + (.services.CoAuthoring.redis.optionsCluster.rootNodes | + map(.url) == ($nodes | split(" ") | map("redis://" + .))) and + ((.services.CoAuthoring.redis.optionsSentinel // {}) | length) == 0 + ' >/dev/null || fail "$name: NODE_CONFIG does not contain the expected native Cluster configuration" + + if [[ "$node_auth" == true ]]; then + printf '%s' "$node_config" | jq -e ' + .services.CoAuthoring.redis.optionsCluster.defaults | + has("username") and has("password") + ' >/dev/null || fail "$name: authenticated Cluster options are incomplete" + else + printf '%s' "$node_config" | jq -e ' + .services.CoAuthoring.redis.optionsCluster.defaults | + (has("username") or has("password")) | not + ' >/dev/null || fail "$name: unauthenticated Cluster options contain credentials" + fi + fi +} + +node_config=$(render_config) +check_config "deployed environment" "$node_config" \ + "$([[ -n "${REDIS_SERVER_PWD:-}" ]] && echo true || echo false)" \ + "$([[ -n "${REDIS_SENTINEL_PWD:-}" ]] && echo true || echo false)" + +# Exercise the supported authentication matrix using the native environment +# names. These checks only render NODE_CONFIG; the regular test-ds hook checks +# the actual Redis/Sentinel and DocService connections. +if [[ "$topology" == sentinel ]]; then + check_config "unauthenticated Redis and Sentinel" \ + "$(render_config REDIS_SERVER_USER= REDIS_SERVER_PWD= REDIS_SENTINEL_USER= REDIS_SENTINEL_PWD=)" false false + check_config "authenticated Redis and unauthenticated Sentinel" \ + "$(render_config REDIS_SERVER_USER=default REDIS_SERVER_PWD=redis-test REDIS_SENTINEL_USER= REDIS_SENTINEL_PWD=)" true false + check_config "authenticated Redis and Sentinel" \ + "$(render_config REDIS_SERVER_USER=default REDIS_SERVER_PWD=redis-test REDIS_SENTINEL_USER=sentinel-test REDIS_SENTINEL_PWD=sentinel-test)" true true +else + check_config "unauthenticated Cluster" \ + "$(render_config REDIS_SERVER_USER= REDIS_SERVER_PWD=)" false false + check_config "authenticated Cluster" \ + "$(render_config REDIS_SERVER_USER=default REDIS_SERVER_PWD=redis-test)" true false +fi + +echo "Redis native $topology configuration is valid" diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 48d6a08..e08e85c 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -11,6 +11,56 @@ Check the DB type {{- end -}} {{- end -}} +{{/* +Validate editor storage modes and their Redis topology requirements. +*/}} +{{- define "ds.editor.storage.validate" -}} +{{- $allowed := list "memory" "standalone" "sentinel" "cluster" -}} +{{- $dataStorage := default "memory" .Values.docservice.editorDataStorage -}} +{{- $statStorage := default $dataStorage .Values.docservice.editorStatStorage -}} +{{- if and .Values.connections.redisClusterNodes .Values.connections.redisSentinelNodes -}} + {{- fail "Redis Cluster and Redis Sentinel nodes cannot be configured together." -}} +{{- end -}} +{{- if and .Values.connections.redisSentinelNodes (not .Values.connections.redisSentinelNoPass) -}} + {{- if empty .Values.connections.redisSentinelUser -}} + {{- fail "Authenticated Redis Sentinel requires connections.redisSentinelUser." -}} + {{- end -}} + {{- if and (empty .Values.connections.redisSentinelPassword) (empty .Values.connections.redisSentinelExistingSecret) -}} + {{- fail "Authenticated Redis Sentinel requires connections.redisSentinelPassword or connections.redisSentinelExistingSecret." -}} + {{- end -}} +{{- end -}} +{{- if not (has $dataStorage $allowed) -}} + {{- fail (printf "Unsupported editorDataStorage %q. Possible values are memory, standalone, sentinel or cluster." $dataStorage) -}} +{{- end -}} +{{- if not (has $statStorage $allowed) -}} + {{- fail (printf "Unsupported editorStatStorage %q. Possible values are memory, standalone, sentinel or cluster." $statStorage) -}} +{{- end -}} +{{- if and (ne $dataStorage "memory") (ne $statStorage "memory") (ne $dataStorage $statStorage) -}} + {{- fail "editorDataStorage and editorStatStorage must use the same Redis topology when both are not memory." -}} +{{- end -}} +{{- $redisStorage := $dataStorage -}} +{{- if eq $redisStorage "memory" -}} + {{- $redisStorage = $statStorage -}} +{{- end -}} +{{- if eq $redisStorage "sentinel" -}} + {{- if not .Values.connections.redisSentinelNodes -}} + {{- fail "Redis Sentinel editor storage requires connections.redisSentinelNodes." -}} + {{- end -}} +{{- else if eq $redisStorage "cluster" -}} + {{- if not .Values.connections.redisClusterNodes -}} + {{- fail "Redis Cluster editor storage requires connections.redisClusterNodes." -}} + {{- end -}} +{{- else if eq $redisStorage "standalone" -}} + {{- if or .Values.connections.redisClusterNodes .Values.connections.redisSentinelNodes -}} + {{- fail "Standalone editor storage cannot be combined with Redis Cluster or Sentinel nodes." -}} + {{- end -}} +{{- end -}} +{{- if and (not .Values.connections.redisNoPass) (empty .Values.connections.redisPassword) (empty .Values.connections.redisExistingSecret) -}} + {{- fail "Authenticated Redis requires connections.redisPassword or connections.redisExistingSecret." -}} +{{- end -}} +true +{{- end -}} + {{/* Get the DB password secret */}} @@ -77,9 +127,9 @@ Return RabbitMQ password Get the Redis password secret */}} {{- define "ds.redis.secretName" -}} -{{- if or .Values.connections.redisPassword .Values.connections.redisNoPass -}} +{{- if and .Values.connections.redisPassword (not .Values.connections.redisNoPass) -}} {{- printf "%s-%s" .Release.Name (include "ds.resources.name" (list . .Values.commonNameSuffix "redis")) -}} -{{- else if .Values.connections.redisExistingSecret -}} +{{- else if and (not .Values.connections.redisNoPass) .Values.connections.redisExistingSecret -}} {{- printf "%s" (tpl .Values.connections.redisExistingSecret $) -}} {{- end -}} {{- end -}} @@ -88,7 +138,7 @@ Get the Redis password secret Return true if a secret object should be created for Redis */}} {{- define "ds.redis.createSecret" -}} -{{- if or .Values.connections.redisPassword .Values.connections.redisNoPass (not .Values.connections.redisExistingSecret) -}} +{{- if or (and .Values.connections.redisPassword (not .Values.connections.redisNoPass)) (and (not .Values.connections.redisNoPass) (not .Values.connections.redisExistingSecret)) -}} {{- true -}} {{- end -}} {{- end -}} @@ -110,9 +160,9 @@ Return Redis password Get the Redis Sentinel password secret */}} {{- define "ds.redis.sentinel.secretName" -}} -{{- if or .Values.connections.redisSentinelPassword .Values.connections.redisSentinelNoPass -}} +{{- if and .Values.connections.redisSentinelPassword (not .Values.connections.redisSentinelNoPass) -}} {{- printf "%s-%s" .Release.Name (include "ds.resources.name" (list . .Values.commonNameSuffix "redis-sentinel")) -}} -{{- else if .Values.connections.redisSentinelExistingSecret -}} +{{- else if and (not .Values.connections.redisSentinelNoPass) .Values.connections.redisSentinelExistingSecret -}} {{- printf "%s" (tpl .Values.connections.redisSentinelExistingSecret $) -}} {{- end -}} {{- end -}} @@ -121,7 +171,7 @@ Get the Redis Sentinel password secret Return true if a secret object should be created for Redis Sentinel */}} {{- define "ds.redis.sentinel.createSecret" -}} -{{- if or .Values.connections.redisSentinelPassword .Values.connections.redisSentinelNoPass (not .Values.connections.redisSentinelExistingSecret) -}} +{{- if or (and .Values.connections.redisSentinelPassword (not .Values.connections.redisSentinelNoPass)) (and (not .Values.connections.redisSentinelNoPass) (not .Values.connections.redisSentinelExistingSecret)) -}} {{- true -}} {{- end -}} {{- end -}} @@ -139,6 +189,24 @@ Return Redis Sentinel password {{- end }} {{- end -}} +{{/* Render only native Redis secret variables. Users are in the ConfigMap. */}} +{{- define "ds.redis.env" -}} +{{- if not .Values.connections.redisNoPass }} +- name: REDIS_SERVER_PWD + valueFrom: + secretKeyRef: + name: {{ template "ds.redis.secretName" . }} + key: {{ .Values.connections.redisSecretKeyName }} +{{- end }} +{{- if and .Values.connections.redisSentinelNodes (not .Values.connections.redisSentinelNoPass) }} +- name: REDIS_SENTINEL_PWD + valueFrom: + secretKeyRef: + name: {{ template "ds.redis.sentinel.secretName" . }} + key: {{ .Values.connections.redisSentinelSecretKeyName }} +{{- end }} +{{- end -}} + {{/* Get the info auth password secret */}} diff --git a/templates/configmaps/documentserver.yaml b/templates/configmaps/documentserver.yaml index b7c552e..3aaf65f 100644 --- a/templates/configmaps/documentserver.yaml +++ b/templates/configmaps/documentserver.yaml @@ -7,28 +7,38 @@ metadata: labels: {{- include "ds.labels.commonLabels" . | trim | nindent 4 }} {{- end }} - {{- if .Values.commonAnnotations }} +{{- if .Values.commonAnnotations }} annotations: {{- include "ds.annotations.commonAnnotations" ( dict "keyName" .Values.commonAnnotations "context" $ ) | nindent 4 }} - {{- end }} +{{- end }} +{{- $_ := include "ds.editor.storage.validate" . }} data: APPLICATION_NAME: {{ .Values.product.name }} + {{- if ne (default "memory" .Values.docservice.editorDataStorage) "memory" }} + EDITOR_DATA_STORAGE: editorDataRedis + {{- end }} + {{- if ne (default (default "memory" .Values.docservice.editorDataStorage) .Values.docservice.editorStatStorage) "memory" }} + EDITOR_STAT_STORAGE: editorDataRedis + {{- end }} DB_TYPE: {{ template "ds.db.type" . }} DB_USER: {{ .Values.connections.dbUser }} DB_HOST: {{ .Values.connections.dbHost }} DB_PORT: {{ .Values.connections.dbPort | quote }} DB_NAME: {{ .Values.connections.dbName }} - REDIS_CONNECTOR_NAME: {{ .Values.connections.redisConnectorName }} REDIS_SERVER_HOST: {{ .Values.connections.redisHost }} REDIS_SERVER_PORT: {{ .Values.connections.redisPort | quote }} - REDIS_SERVER_USER: {{ .Values.connections.redisUser }} + REDIS_CONNECTOR_NAME: redis + {{- if not .Values.connections.redisNoPass }} + REDIS_SERVER_USER: {{ .Values.connections.redisUser | quote }} + {{- end }} REDIS_SERVER_DB_NUM: {{ .Values.connections.redisDBNum | quote }} - {{- if.Values.connections.redisClusterNodes }} + {{- if .Values.connections.redisClusterNodes }} REDIS_CLUSTER_NODES: {{ join " " .Values.connections.redisClusterNodes }} {{- end }} - {{- if eq .Values.connections.redisConnectorName "ioredis" }} - REDIS_SENTINEL_GROUP_NAME: {{ .Values.connections.redisSentinelGroupName }} - {{- if.Values.connections.redisSentinelNodes }} + {{- if .Values.connections.redisSentinelNodes }} REDIS_SENTINEL_NODES: {{ join " " .Values.connections.redisSentinelNodes }} + REDIS_SENTINEL_GROUP_NAME: {{ .Values.connections.redisSentinelGroupName }} + {{- if not .Values.connections.redisSentinelNoPass }} + REDIS_SENTINEL_USER: {{ .Values.connections.redisSentinelUser | quote }} {{- end }} {{- end }} AMQP_TYPE: {{ .Values.connections.amqpType }} diff --git a/templates/deployments/converter.yaml b/templates/deployments/converter.yaml index 1b3a1b1..8c209fb 100644 --- a/templates/deployments/converter.yaml +++ b/templates/deployments/converter.yaml @@ -184,18 +184,7 @@ spec: secretKeyRef: name: {{ template "ds.rabbitmq.secretName" . }} key: {{ .Values.connections.amqpSecretKeyName }} - - name: REDIS_SERVER_PWD - valueFrom: - secretKeyRef: - name: {{ template "ds.redis.secretName" . }} - key: {{ .Values.connections.redisSecretKeyName }} - {{- if eq .Values.connections.redisConnectorName "ioredis" }} - - name: REDIS_SENTINEL_PWD - valueFrom: - secretKeyRef: - name: {{ template "ds.redis.sentinel.secretName" . }} - key: {{ .Values.connections.redisSentinelSecretKeyName }} - {{- end }} + {{ include "ds.redis.env" . | nindent 10 }} {{- with .Values.converter.extraEnvVars }} {{- toYaml . | nindent 10 }} {{- end }} diff --git a/templates/deployments/docservice.yaml b/templates/deployments/docservice.yaml index 73fca0f..17e212b 100644 --- a/templates/deployments/docservice.yaml +++ b/templates/deployments/docservice.yaml @@ -316,18 +316,7 @@ spec: secretKeyRef: name: {{ template "ds.rabbitmq.secretName" . }} key: {{ .Values.connections.amqpSecretKeyName }} - - name: REDIS_SERVER_PWD - valueFrom: - secretKeyRef: - name: {{ template "ds.redis.secretName" . }} - key: {{ .Values.connections.redisSecretKeyName }} - {{- if eq .Values.connections.redisConnectorName "ioredis" }} - - name: REDIS_SENTINEL_PWD - valueFrom: - secretKeyRef: - name: {{ template "ds.redis.sentinel.secretName" . }} - key: {{ .Values.connections.redisSentinelSecretKeyName }} - {{- end }} + {{ include "ds.redis.env" . | nindent 10 }} {{- with .Values.docservice.extraEnvVars }} {{- toYaml . | nindent 10 }} {{- end }} diff --git a/templates/secrets/redis-sentinel-password.yaml b/templates/secrets/redis-sentinel-password.yaml index 835d2f7..56b9153 100644 --- a/templates/secrets/redis-sentinel-password.yaml +++ b/templates/secrets/redis-sentinel-password.yaml @@ -1,4 +1,4 @@ -{{- if and (eq (include "ds.redis.sentinel.createSecret" .) "true") (eq .Values.connections.redisConnectorName "ioredis") }} +{{- if and (eq (include "ds.redis.sentinel.createSecret" .) "true") .Values.connections.redisSentinelNodes }} apiVersion: v1 kind: Secret metadata: diff --git a/templates/statefulset/adminpanel.yaml b/templates/statefulset/adminpanel.yaml index fd8ac44..151bd2c 100644 --- a/templates/statefulset/adminpanel.yaml +++ b/templates/statefulset/adminpanel.yaml @@ -94,18 +94,7 @@ spec: args: - adminpanel env: - - name: REDIS_SERVER_PWD - valueFrom: - secretKeyRef: - name: {{ template "ds.redis.secretName" . }} - key: {{ .Values.connections.redisSecretKeyName }} - {{- if eq .Values.connections.redisConnectorName "ioredis" }} - - name: REDIS_SENTINEL_PWD - valueFrom: - secretKeyRef: - name: {{ template "ds.redis.sentinel.secretName" . }} - key: {{ .Values.connections.redisSentinelSecretKeyName }} - {{- end }} + {{ include "ds.redis.env" . | nindent 8 }} {{- with .Values.adminpanel.extraEnvVars }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/templates/tests/test-ds-pod.yaml b/templates/tests/test-ds-pod.yaml index 1294331..8cd4764 100644 --- a/templates/tests/test-ds-pod.yaml +++ b/templates/tests/test-ds-pod.yaml @@ -70,18 +70,7 @@ spec: secretKeyRef: name: {{ template "ds.rabbitmq.secretName" . }} key: {{ .Values.connections.amqpSecretKeyName }} - - name: REDIS_SERVER_PWD - valueFrom: - secretKeyRef: - name: {{ template "ds.redis.secretName" . }} - key: {{ .Values.connections.redisSecretKeyName }} - {{- if eq .Values.connections.redisConnectorName "ioredis" }} - - name: REDIS_SENTINEL_PWD - valueFrom: - secretKeyRef: - name: {{ template "ds.redis.sentinel.secretName" . }} - key: {{ .Values.connections.redisSentinelSecretKeyName }} - {{- end }} + {{ include "ds.redis.env" . | nindent 4 }} - name: STORAGE_S3 value: {{ .Values.persistence.storageS3 | quote }} - name: DS_ADDRESS diff --git a/templates/tests/test-redis-config-cm.yaml b/templates/tests/test-redis-config-cm.yaml new file mode 100644 index 0000000..0e5eeb5 --- /dev/null +++ b/templates/tests/test-redis-config-cm.yaml @@ -0,0 +1,13 @@ +{{- if and .Values.tests.enabled (or (or (eq (default "memory" .Values.docservice.editorDataStorage) "sentinel") (eq (default "memory" .Values.docservice.editorStatStorage) "sentinel")) (or (eq (default "memory" .Values.docservice.editorDataStorage) "cluster") (eq (default "memory" .Values.docservice.editorStatStorage) "cluster"))) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "ds.resources.name" (list . .Values.commonNameSuffix "test-redis-config") }} + namespace: {{ include "ds.namespace" . | quote }} + {{- if .Values.commonLabels }} + labels: + {{- include "ds.labels.commonLabels" . | trim | nindent 4 }} + {{- end }} +data: +{{ (.Files.Glob "sources/scripts/test_redis_config.sh").AsConfig | indent 2 }} +{{- end }} diff --git a/templates/tests/test-redis-config-pod.yaml b/templates/tests/test-redis-config-pod.yaml new file mode 100644 index 0000000..4d3323d --- /dev/null +++ b/templates/tests/test-redis-config-pod.yaml @@ -0,0 +1,47 @@ +{{- if and .Values.tests.enabled (or (or (eq (default "memory" .Values.docservice.editorDataStorage) "sentinel") (eq (default "memory" .Values.docservice.editorStatStorage) "sentinel")) (or (eq (default "memory" .Values.docservice.editorDataStorage) "cluster") (eq (default "memory" .Values.docservice.editorStatStorage) "cluster"))) }} +apiVersion: v1 +kind: Pod +metadata: + name: {{ include "ds.resources.name" (list . .Values.commonNameSuffix "test-redis-config") }} + namespace: {{ include "ds.namespace" . | quote }} + labels: + app.kubernetes.io/component: test-redis-config + {{- if .Values.commonLabels }} + {{- include "ds.labels.commonLabels" . | trim | nindent 4 }} + {{- end }} + annotations: + "helm.sh/hook": test + "helm.sh/hook-weight": "2" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded +spec: + restartPolicy: Never + {{- if .Values.imagePullSecrets }} + imagePullSecrets: + - name: {{ .Values.imagePullSecrets }} + {{- end }} + containers: + - name: redis-config + image: {{ .Values.docservice.image.repository }}:{{ default .Values.images.tag .Values.docservice.image.tag }} + imagePullPolicy: {{ .Values.docservice.image.pullPolicy }} + command: ["bash", "/scripts/test_redis_config.sh"] + env: + - name: COMPANY_NAME + value: {{ .Values.product.name | quote }} + - name: ENTRYPOINT_CONFIG_ONLY + value: "true" + - name: JWT_ENABLED + value: "false" + {{ include "ds.redis.env" . | nindent 4 }} + envFrom: + - configMapRef: + name: {{ include "ds.resources.name" (list . .Values.commonNameSuffix "documentserver") }} + volumeMounts: + - name: test-redis-config + mountPath: /scripts/test_redis_config.sh + subPath: test_redis_config.sh + volumes: + - name: test-redis-config + configMap: + name: {{ include "ds.resources.name" (list . .Values.commonNameSuffix "test-redis-config") }} + defaultMode: 0755 +{{- end }} diff --git a/values.yaml b/values.yaml index 1bbc950..9c323a8 100644 --- a/values.yaml +++ b/values.yaml @@ -31,17 +31,16 @@ connections: ## connections.dbPassword Database user password ## If set to, it takes priority over the `connections.dbExistingSecret` dbPassword: "" - ## connections.redisConnectorName Defines which connector to use to connect to Redis - ## If you need to connect to Redis Sentinel, set the value `ioredis` - redisConnectorName: redis ## connections.redisHost The IP address or the name of the Redis host - ## Not used if the values are set in `connections.redisClusterNodes` and `connections.redisSentinelNodes` + ## Used for standalone Redis and as the startup/readiness fallback when a topology is configured. + ## In Sentinel mode, set this to a reachable fallback endpoint; Sentinel discovery uses redisSentinelNodes. redisHost: redis-master ## connections.redisPort The Redis server port number - ## Not used if the values are set in `connections.redisClusterNodes` and `connections.redisSentinelNodes` + ## Used with connections.redisHost for the standalone/startup fallback endpoint. redisPort: "6379" ## connections.redisUser The Redis user name ## ref: https://redis.io/docs/management/security/acl/ + ## Omit Redis authentication by setting connections.redisNoPass to true. ## The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file redisUser: default ## connections.redisDBNum Number of the redis logical database to be selected @@ -76,28 +75,30 @@ connections: ## There is no need to specify every node, 3 should be enough ## You can specify multiple values ## It must be specified in the `host:port` format - ## Used if `connections.redisConnectorName` is set to `ioredis` ## Example: ## redisSentinelNodes: ## - 10.244.0.79:26379 ## - 192.168.1.25:26379 redisSentinelNodes: [] ## connections.redisSentinelGroupName Name of a group of Redis instances composed of a master and one or more slaves - ## Used if `connections.redisConnectorName` is set to `ioredis` + ## Redis Sentinel is enabled when `connections.redisSentinelNodes` is not empty redisSentinelGroupName: mymaster + ## connections.redisSentinelUser The Redis Sentinel user name + ## Required together with a password when Sentinel ACL authentication is enabled. + redisSentinelUser: "" ## connections.redisSentinelExistingSecret Name of existing secret to use for Redis Sentinel password ## Must contain the key specified in `connections.redisSentinelSecretKeyName` - ## The password from this secret overrides the value for the password set in the `iooptions` object in `local.json` if you add custom configuration file + ## The password from this secret overrides the value for the password set in the `optionsSentinel` object in `local.json` if you add custom configuration file redisSentinelExistingSecret: "" ## connections.redisSentinelSecretKeyName The name of the key that contains the Redis Sentinel user password ## If you set a password in `redisSentinelPassword`, a secret will be automatically created, the key name of which will be the value set here redisSentinelSecretKeyName: sentinel-password ## connections.redisSentinelPassword The password set for the Redis Sentinel account ## If set to, it takes priority over the `connections.redisSentinelExistingSecret` - ## The value in this parameter overrides the value set in the `iooptions` object in `local.json` if you add custom configuration file + ## The value in this parameter overrides the value set in the `optionsSentinel` object in `local.json` if you add custom configuration file redisSentinelPassword: "" ## connections.redisSentinelNoPass Defines whether to use a Redis Sentinel auth without a password - ## If the connection to Redis Sentinel does not require a password, set the value to `true` + ## If Sentinel does not require ACL authentication, set the value to `true`; the Sentinel user and password are then omitted. redisSentinelNoPass: true ## connections.amqpType Defines the AMQP server type ## Possible values are `rabbitmq` or `activemq` @@ -496,6 +497,20 @@ images: ## This block defines the parameters common to all the Pods of this deployment ## docservice: + ## docservice.editorDataStorage Editor data storage mode. This setting and + ## editorStatStorage may be configured independently; one may use memory + ## while the other uses Redis. + ## `memory` keeps the application defaults. Redis-backed modes select + ## `editorDataRedis` and use the configured Redis topology. + ## Possible values are `memory`, `standalone`, `sentinel` or `cluster`. + editorDataStorage: memory + ## docservice.editorStatStorage Editor statistics storage mode. If omitted, + ## statistics use the editorDataStorage module. If both + ## settings use Redis, they must use the same topology because they share + ## the editorDataRedis connection. Different Redis topologies are not + ## supported. + ## Possible values are `memory`, `standalone`, `sentinel` or `cluster`. + editorStatStorage: "" ## docservice.annotations Defines annotations that will be additionally added to Docservice Deployment ## If set to, it takes priority over the `commonAnnotations` ## You can also use `tpl` as the value for the key From 2dd1ba075079232aefe98e3a216034489de2bd2f Mon Sep 17 00:00:00 2001 From: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> Date: Sat, 10 Oct 2026 19:38:07 +0200 Subject: [PATCH 2/6] docs(redis): improved secrets documentation Signed-off-by: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/README.md b/README.md index 9ae7a87..39f6f34 100644 --- a/README.md +++ b/README.md @@ -436,6 +436,59 @@ Redis topology required by the selected mode: `redisHost` and `redisPort` for standalone, `redisClusterNodes` for cluster, or `redisSentinelNodes` for Sentinel. Cluster and Sentinel cannot be configured together. +#### Redis authentication secrets + +When using an existing Redis Secret, set `connections.redisExistingSecret`. +The Secret must contain the key configured by +`connections.redisSecretKeyName`, which defaults to `redis-password`: + +```yaml +apiVersion: v1 +kind: Secret +metadata: + name: redis +type: Opaque +stringData: + redis-password: your-redis-password +``` + +Redis Sentinel authentication has two independent layers: Redis-node +authentication and Sentinel authentication. If both are protected, configure +both `connections.redisExistingSecret`/`connections.redisUser` and +`connections.redisSentinelExistingSecret`/`connections.redisSentinelUser`. +The Redis Secret supplies the node password, while the Sentinel Secret +supplies the Sentinel ACL password. + +For the Sentinel ACL credentials, set +`connections.redisSentinelExistingSecret` and +`connections.redisSentinelUser`. The Secret must contain the key configured by +`connections.redisSentinelSecretKeyName`, which defaults to +`sentinel-password`: + +```yaml +connections: + redisSentinelExistingSecret: redis-sentinel + redisSentinelSecretKeyName: sentinel-password + redisSentinelUser: sentinel-user + redisSentinelNoPass: false +``` + +```yaml +apiVersion: v1 +kind: Secret +metadata: + name: redis-sentinel +type: Opaque +stringData: + sentinel-password: your-sentinel-password +``` + +The Secrets must be in the namespace where the chart is installed. Set +`connections.redisNoPass: true` when Redis nodes do not require a password, or +`connections.redisSentinelNoPass: true` when Sentinel does not require ACL +credentials. Only the corresponding credentials are omitted; the other layer +can still remain authenticated. + | Parameter | Description | Default | |-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| | `connections.dbType` | The database type. Possible values are `postgres`, `mariadb`, `mysql`, `oracle`, `mssql` or `dameng` | `postgres` | From 1680fab3a052b5ab5281d7f279d678d967bf19e3 Mon Sep 17 00:00:00 2001 From: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> Date: Sat, 17 Oct 2026 12:36:54 +0200 Subject: [PATCH 3/6] feat(redis): add TLS controls and honor explicit memory statistics - Add independent TLS settings for Redis nodes and Sentinel discovery - Use TLS in connectivity checks and validate generated TLS configuration - Pass the explicit memory statistics backend to DocumentServer - Validate editor data and statistics storage independently - Document TLS settings and required image support Assisted-by: Codex:GPT-6 Signed-off-by: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> --- README.md | 29 +++++++++++++ sources/scripts/test_ds.py | 19 +++++++-- sources/scripts/test_redis_config.sh | 54 +++++++++++++++++++++--- templates/configmaps/documentserver.yaml | 4 ++ values.yaml | 9 +++- 5 files changed, 104 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 39f6f34..4b609b6 100644 --- a/README.md +++ b/README.md @@ -436,6 +436,33 @@ Redis topology required by the selected mode: `redisHost` and `redisPort` for standalone, `redisClusterNodes` for cluster, or `redisSentinelNodes` for Sentinel. Cluster and Sentinel cannot be configured together. +#### Redis TLS + +`connections.redisTLS` enables TLS for standalone Redis, Cluster connections, +and Redis nodes discovered through Sentinel. `connections.redisSentinelTLS` +enables TLS for Sentinel discovery independently. Both default to `false`: + +```yaml +connections: + redisTLS: true + redisSentinelTLS: false +``` + +These values render as the quoted `REDIS_SERVER_TLS` and +`REDIS_SENTINEL_TLS` environment variables. Use a DocumentServer image containing +the TLS changes in both the standalone and orchestrated entrypoints; older +images do not support these flags. `REDIS_SERVER_TLS=true` enables +`options.socket.tls`, `optionsSentinel.nodeClientOptions.socket.tls`, and +`optionsCluster.defaults.socket.tls`, with `rediss://` Cluster seed URLs. +`REDIS_SENTINEL_TLS=true` enables +`optionsSentinel.sentinelClientOptions.socket.tls` independently. + +The flags accept `true`/`false`; unset or empty environment values behave as +`false` without injecting TLS options. TLS does not change the configured +ports, and certificate verification stays enabled. Custom certificates and +mutual TLS are outside these values; existing mounted configuration remains +available for those settings. + #### Redis authentication secrets When using an existing Redis Secret, set `connections.redisExistingSecret`. @@ -501,6 +528,7 @@ can still remain authenticated. | `connections.dbExistingSecret` | Name of existing secret to use for Database passwords. Must contain the key specified in `connections.dbSecretKeyName` | `postgresql` | | `connections.redisHost` | Redis host, or the reachable startup/readiness fallback endpoint when a topology is configured | `redis-master` | | `connections.redisPort` | Redis port used with `connections.redisHost` for the standalone/startup fallback endpoint | `6379` | +| `connections.redisTLS` | Enable TLS for standalone Redis, Cluster, and Sentinel-discovered Redis nodes. Requires a DocumentServer image with TLS entrypoint support. | `false` | | `connections.redisUser` | Redis [user](https://redis.io/docs/management/security/acl/) name. Omitted when `connections.redisNoPass` is `true` | `default` | | `connections.redisDBNum` | Number of the redis logical database to be [selected](https://redis.io/commands/select/). The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file | `0` | | `connections.redisClusterNodes` | List of nodes in the Redis cluster. There is no need to specify every node in the cluster, 3 should be enough. You can specify multiple values. It must be specified in the `host:port` format | `[]` | @@ -510,6 +538,7 @@ can still remain authenticated. | `connections.redisNoPass` | Defines whether to use a Redis auth without a password. If the connection to Redis server does not require a password, set the value to `true` | `false` | | `connections.redisSentinelNodes` | List of Redis Sentinel Nodes. Sentinel mode is enabled when this list is non-empty. There is no need to specify every node, 3 should be enough. It must use the `host:port` format | `[]` | | `connections.redisSentinelGroupName` | Name of the Sentinel-monitored Redis group. | `mymaster` | +| `connections.redisSentinelTLS` | Enable TLS for Sentinel discovery independently of `connections.redisTLS`. Requires a DocumentServer image with TLS entrypoint support. | `false` | | `connections.redisSentinelUser` | Redis Sentinel ACL user name. Required together with a password when Sentinel authentication is enabled. | `""` | | `connections.redisSentinelExistingSecret` | Name of existing secret to use for Redis Sentinel password. Must contain the key specified in `connections.redisSentinelSecretKeyName`. The password overrides `optionsSentinel` in `local.json` | `""` | | `connections.redisSentinelSecretKeyName` | The name of the key that contains the Redis Sentinel user password. If you set a password in `redisSentinelPassword`, a secret will be automatically created, the key name of which will be the value set here | `sentinel-password` | diff --git a/sources/scripts/test_ds.py b/sources/scripts/test_ds.py index 745e3a9..e699570 100755 --- a/sources/scripts/test_ds.py +++ b/sources/scripts/test_ds.py @@ -8,6 +8,14 @@ redisPort = os.environ.get('REDIS_SERVER_PORT') redisUser = os.environ.get('REDIS_SERVER_USER') redisPassword = os.environ.get('REDIS_SERVER_PWD') +redisTLSOptions = ( + {'ssl': True, 'ssl_cert_reqs': 'required'} + if os.environ.get('REDIS_SERVER_TLS') == 'true' else {} +) +redisSentinelTLSOptions = ( + {'ssl': True, 'ssl_cert_reqs': 'required'} + if os.environ.get('REDIS_SENTINEL_TLS') == 'true' else {} +) redisSentinelUser = os.environ.get('REDIS_SENTINEL_USER') redisSentinelPassword = os.environ.get('REDIS_SENTINEL_PWD') redisDBNum = os.environ.get('REDIS_SERVER_DB_NUM') @@ -73,7 +81,8 @@ def get_redis_status(): password=redisPassword, username=redisUser, socket_connect_timeout=redisConnectTimeout, - retry=retry_strategy + retry=retry_strategy, + **redisTLSOptions ) rc.ping() except Exception as msg_redis: @@ -98,7 +107,8 @@ def get_redis_cluster_status(): username=redisUser, password=redisPassword, socket_connect_timeout=redisConnectTimeout, - retry=retry_strategy + retry=retry_strategy, + **redisTLSOptions ) rc.ping() except Exception as msg_redis: @@ -117,7 +127,7 @@ def get_redis_sentinel_status(): retry_strategy = Retry(ExponentialBackoff(), retries=3) global rc try: - sentinel_kwargs = {} + sentinel_kwargs = dict(redisSentinelTLSOptions) if redisSentinelUser: sentinel_kwargs['username'] = redisSentinelUser if redisSentinelPassword: @@ -131,7 +141,8 @@ def get_redis_sentinel_status(): password=redisPassword, username=redisUser, socket_connect_timeout=redisConnectTimeout, - retry=retry_strategy + retry=retry_strategy, + **redisTLSOptions ) rc.ping() except Exception as msg_redis: diff --git a/sources/scripts/test_redis_config.sh b/sources/scripts/test_redis_config.sh index 4f8569b..59b1c9e 100644 --- a/sources/scripts/test_redis_config.sh +++ b/sources/scripts/test_redis_config.sh @@ -37,10 +37,22 @@ check_config() { local node_config="$2" local node_auth="$3" local sentinel_auth="$4" + local node_tls="${5:-${REDIS_SERVER_TLS:-false}}" + local sentinel_tls="${6:-${REDIS_SENTINEL_TLS:-false}}" + local scheme=redis + [[ "$node_tls" != true ]] || scheme=rediss - printf '%s' "$node_config" | jq -e ' - .services.CoAuthoring.server.editorDataStorage == "editorDataRedis" and - .services.CoAuthoring.server.editorStatStorage == "editorDataRedis" and + printf '%s' "$node_config" | jq -e --argjson tls "$( [[ "$node_tls" == true ]] && echo true || echo false )" ' + .services.CoAuthoring.redis.options.socket | + (if $tls then .tls == true else has("tls") | not end) and + .rejectUnauthorized != false + ' >/dev/null || fail "$name: standalone/fallback TLS options are incorrect" + + printf '%s' "$node_config" | jq -e \ + --arg data_storage "${EDITOR_DATA_STORAGE:-editorDataMemory}" \ + --arg stat_storage "${EDITOR_STAT_STORAGE:-${EDITOR_DATA_STORAGE:-editorDataMemory}}" ' + (.services.CoAuthoring.server.editorDataStorage // "editorDataMemory") == $data_storage and + (.services.CoAuthoring.server.editorStatStorage // $data_storage) == $stat_storage and .services.CoAuthoring.redis.name == "redis" ' >/dev/null || fail "$name: NODE_CONFIG does not select the native Redis backend" @@ -53,6 +65,17 @@ check_config() { ((.services.CoAuthoring.redis.optionsCluster.rootNodes // []) | length) == 0 ' >/dev/null || fail "$name: NODE_CONFIG does not contain the expected native Sentinel configuration" + printf '%s' "$node_config" | jq -e \ + --argjson node_tls "$( [[ "$node_tls" == true ]] && echo true || echo false )" \ + --argjson sentinel_tls "$( [[ "$sentinel_tls" == true ]] && echo true || echo false )" ' + def check_tls($enabled): + .socket | (if $enabled then .tls == true else has("tls") | not end) and + .rejectUnauthorized != false; + .services.CoAuthoring.redis.optionsSentinel | + (.nodeClientOptions | check_tls($node_tls)) and + (.sentinelClientOptions | check_tls($sentinel_tls)) + ' >/dev/null || fail "$name: Redis node and Sentinel TLS options are incorrect" + if [[ "$node_auth" == true ]]; then printf '%s' "$node_config" | jq -e ' .services.CoAuthoring.redis.optionsSentinel.nodeClientOptions | @@ -72,16 +95,22 @@ check_config() { ' >/dev/null || fail "$name: authenticated Sentinel options are incomplete" else printf '%s' "$node_config" | jq -e ' - .services.CoAuthoring.redis.optionsSentinel.sentinelClientOptions == {} + (.services.CoAuthoring.redis.optionsSentinel.sentinelClientOptions | del(.socket)) == {} ' >/dev/null || fail "$name: unauthenticated Sentinel options are not empty" fi else - printf '%s' "$node_config" | jq -e --arg nodes "$REDIS_CLUSTER_NODES" ' + printf '%s' "$node_config" | jq -e --arg nodes "$REDIS_CLUSTER_NODES" --arg scheme "$scheme" ' (.services.CoAuthoring.redis.optionsCluster.rootNodes | - map(.url) == ($nodes | split(" ") | map("redis://" + .))) and + map(.url) == ($nodes | split(" ") | map($scheme + "://" + .))) and ((.services.CoAuthoring.redis.optionsSentinel // {}) | length) == 0 ' >/dev/null || fail "$name: NODE_CONFIG does not contain the expected native Cluster configuration" + printf '%s' "$node_config" | jq -e --argjson tls "$( [[ "$node_tls" == true ]] && echo true || echo false )" ' + .services.CoAuthoring.redis.optionsCluster.defaults.socket | + (if $tls then .tls == true else has("tls") | not end) and + .rejectUnauthorized != false + ' >/dev/null || fail "$name: Cluster TLS options are incorrect" + if [[ "$node_auth" == true ]]; then printf '%s' "$node_config" | jq -e ' .services.CoAuthoring.redis.optionsCluster.defaults | @@ -118,4 +147,17 @@ else "$(render_config REDIS_SERVER_USER=default REDIS_SERVER_PWD=redis-test)" true false fi +# Exercise TLS independently, including the entrypoint's empty/unset defaults. +# Authentication is omitted here so TLS-only Sentinel options are also checked. +for node_tls in true false empty unset; do + for sentinel_tls in true false empty unset; do + tls_env=(-u REDIS_SERVER_TLS -u REDIS_SENTINEL_TLS) + [[ "$node_tls" == unset ]] || tls_env+=("REDIS_SERVER_TLS=${node_tls/empty/}") + [[ "$sentinel_tls" == unset ]] || tls_env+=("REDIS_SENTINEL_TLS=${sentinel_tls/empty/}") + check_config "Redis TLS=$node_tls, Sentinel TLS=$sentinel_tls" \ + "$(render_config "${tls_env[@]}" REDIS_SERVER_USER= REDIS_SERVER_PWD= REDIS_SENTINEL_USER= REDIS_SENTINEL_PWD=)" \ + false false "$node_tls" "$sentinel_tls" + done +done + echo "Redis native $topology configuration is valid" diff --git a/templates/configmaps/documentserver.yaml b/templates/configmaps/documentserver.yaml index 3aaf65f..4d339dd 100644 --- a/templates/configmaps/documentserver.yaml +++ b/templates/configmaps/documentserver.yaml @@ -18,6 +18,8 @@ data: {{- end }} {{- if ne (default (default "memory" .Values.docservice.editorDataStorage) .Values.docservice.editorStatStorage) "memory" }} EDITOR_STAT_STORAGE: editorDataRedis + {{- else if eq .Values.docservice.editorStatStorage "memory" }} + EDITOR_STAT_STORAGE: editorDataMemory {{- end }} DB_TYPE: {{ template "ds.db.type" . }} DB_USER: {{ .Values.connections.dbUser }} @@ -26,6 +28,8 @@ data: DB_NAME: {{ .Values.connections.dbName }} REDIS_SERVER_HOST: {{ .Values.connections.redisHost }} REDIS_SERVER_PORT: {{ .Values.connections.redisPort | quote }} + REDIS_SERVER_TLS: {{ .Values.connections.redisTLS | quote }} + REDIS_SENTINEL_TLS: {{ .Values.connections.redisSentinelTLS | quote }} REDIS_CONNECTOR_NAME: redis {{- if not .Values.connections.redisNoPass }} REDIS_SERVER_USER: {{ .Values.connections.redisUser | quote }} diff --git a/values.yaml b/values.yaml index 9c323a8..b1487db 100644 --- a/values.yaml +++ b/values.yaml @@ -38,6 +38,9 @@ connections: ## connections.redisPort The Redis server port number ## Used with connections.redisHost for the standalone/startup fallback endpoint. redisPort: "6379" + ## connections.redisTLS Enable TLS for standalone Redis, Cluster, and Sentinel-discovered Redis nodes + ## Requires a DocumentServer image supporting REDIS_SERVER_TLS. Ports remain unchanged. + redisTLS: false ## connections.redisUser The Redis user name ## ref: https://redis.io/docs/management/security/acl/ ## Omit Redis authentication by setting connections.redisNoPass to true. @@ -83,6 +86,9 @@ connections: ## connections.redisSentinelGroupName Name of a group of Redis instances composed of a master and one or more slaves ## Redis Sentinel is enabled when `connections.redisSentinelNodes` is not empty redisSentinelGroupName: mymaster + ## connections.redisSentinelTLS Enable TLS for Sentinel discovery independently of connections.redisTLS + ## Requires a DocumentServer image supporting REDIS_SENTINEL_TLS. Ports remain unchanged. + redisSentinelTLS: false ## connections.redisSentinelUser The Redis Sentinel user name ## Required together with a password when Sentinel ACL authentication is enabled. redisSentinelUser: "" @@ -505,7 +511,8 @@ docservice: ## Possible values are `memory`, `standalone`, `sentinel` or `cluster`. editorDataStorage: memory ## docservice.editorStatStorage Editor statistics storage mode. If omitted, - ## statistics use the editorDataStorage module. If both + ## statistics use the editorDataStorage module. Set explicitly to `memory` + ## to keep statistics in memory when editor data uses Redis. If both ## settings use Redis, they must use the same topology because they share ## the editorDataRedis connection. Different Redis topologies are not ## supported. From cb480bb370162485f861abc4fc32bcd68549790e Mon Sep 17 00:00:00 2001 From: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> Date: Sat, 17 Oct 2026 12:46:45 +0200 Subject: [PATCH 4/6] fix(helm): honor test settings in Redis configuration pod - Apply the configured service account and security contexts - Respect test scheduling settings and global fallbacks - Include test annotations, resource limits, and init containers Assisted-by: Codex:GPT-6 Signed-off-by: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> --- templates/tests/test-redis-config-pod.yaml | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/templates/tests/test-redis-config-pod.yaml b/templates/tests/test-redis-config-pod.yaml index 4d3323d..09036ce 100644 --- a/templates/tests/test-redis-config-pod.yaml +++ b/templates/tests/test-redis-config-pod.yaml @@ -13,16 +13,53 @@ metadata: "helm.sh/hook": test "helm.sh/hook-weight": "2" "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded + {{- if or .Values.commonAnnotations .Values.tests.annotations }} + {{- $dictValue := default .Values.commonAnnotations .Values.tests.annotations }} + {{- include "ds.annotations.commonAnnotations" ( dict "keyName" $dictValue "context" $ ) | nindent 4 }} + {{- end }} spec: + serviceAccountName: {{ include "ds.serviceAccountName" . }} + {{- if .Values.podSecurityContext.enabled }} + securityContext: {{- toYaml .Values.podSecurityContext.tests | nindent 4 }} + {{- end }} restartPolicy: Never + {{- if or .Values.tests.customPodAntiAffinity .Values.tests.podAffinity .Values.tests.nodeAffinity }} + affinity: + {{- with .Values.tests.customPodAntiAffinity }} + podAntiAffinity: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- with .Values.tests.podAffinity }} + podAffinity: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- with .Values.tests.nodeAffinity }} + nodeAffinity: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- end }} + {{- if or .Values.nodeSelector .Values.tests.nodeSelector }} + nodeSelector: {{ toYaml (default .Values.nodeSelector .Values.tests.nodeSelector) | nindent 4 }} + {{- end }} + {{- if or .Values.tolerations .Values.tests.tolerations }} + tolerations: {{ toYaml (default .Values.tolerations .Values.tests.tolerations) | nindent 4 }} + {{- end }} {{- if .Values.imagePullSecrets }} imagePullSecrets: - name: {{ .Values.imagePullSecrets }} {{- end }} + {{- with .Values.tests.initContainers }} + initContainers: + {{- toYaml . | nindent 4 }} + {{- end }} containers: - name: redis-config image: {{ .Values.docservice.image.repository }}:{{ default .Values.images.tag .Values.docservice.image.tag }} imagePullPolicy: {{ .Values.docservice.image.pullPolicy }} + {{- if .Values.tests.containerSecurityContext.enabled }} + securityContext: {{- omit .Values.tests.containerSecurityContext "enabled" | toYaml | nindent 6 }} + {{- end }} + resources: {{ toYaml .Values.tests.resources | nindent 6 }} command: ["bash", "/scripts/test_redis_config.sh"] env: - name: COMPANY_NAME From a1ad6e33a0d62d7e44802852ed20a6aad0f7f41c Mon Sep 17 00:00:00 2001 From: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> Date: Sun, 18 Oct 2026 12:32:14 +0200 Subject: [PATCH 5/6] fix(redis): support password-only Redis and Sentinel authentication Allow optional usernames while preserving existing defaults and independent NoPass behavior. Expand authentication coverage across standalone, Sentinel, and Cluster, and document password-only authentication. Assisted-by: Codex:GPT-6 Signed-off-by: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> --- README.md | 33 +++-- sources/scripts/test_redis_config.sh | 106 ++++++++------- sources/scripts/test_redis_rendering.py | 150 +++++++++++++++++++++ templates/_helpers.tpl | 3 - templates/configmaps/documentserver.yaml | 4 +- templates/tests/test-redis-config-cm.yaml | 3 +- templates/tests/test-redis-config-pod.yaml | 3 +- values.yaml | 12 +- 8 files changed, 243 insertions(+), 71 deletions(-) create mode 100644 sources/scripts/test_redis_rendering.py diff --git a/README.md b/README.md index 4b609b6..f1fc177 100644 --- a/README.md +++ b/README.md @@ -465,6 +465,13 @@ available for those settings. #### Redis authentication secrets +Redis/Valkey supports password-only authentication and named ACL users for +standalone, Sentinel-discovered nodes, and Cluster. An omitted username authenticates as the `default` user. The chart keeps +`connections.redisUser: default` and `connections.redisSentinelUser: ""` as +its defaults. Set `connections.redisUser: ""` to omit the Redis-node protocol +username for password-only authentication, or supply a username for a named +ACL user. The username is emitted only when nonempty and that authentication is enabled. + When using an existing Redis Secret, set `connections.redisExistingSecret`. The Secret must contain the key configured by `connections.redisSecretKeyName`, which defaults to `redis-password`: @@ -481,14 +488,16 @@ stringData: Redis Sentinel authentication has two independent layers: Redis-node authentication and Sentinel authentication. If both are protected, configure -both `connections.redisExistingSecret`/`connections.redisUser` and -`connections.redisSentinelExistingSecret`/`connections.redisSentinelUser`. +both `connections.redisExistingSecret` and +`connections.redisSentinelExistingSecret`, or supply the passwords directly +with `connections.redisPassword` and `connections.redisSentinelPassword`. The Redis Secret supplies the node password, while the Sentinel Secret -supplies the Sentinel ACL password. +supplies the Sentinel password. Each authenticated layer requires a password +or an existing password Secret; usernames are optional. -For the Sentinel ACL credentials, set -`connections.redisSentinelExistingSecret` and -`connections.redisSentinelUser`. The Secret must contain the key configured by +For password-only Sentinel authentication, leave +`connections.redisSentinelUser: ""`. Set it to a named ACL user when needed, +as in the example below. The Secret must contain the key configured by `connections.redisSentinelSecretKeyName`, which defaults to `sentinel-password`: @@ -512,7 +521,7 @@ stringData: The Secrets must be in the namespace where the chart is installed. Set `connections.redisNoPass: true` when Redis nodes do not require a password, or -`connections.redisSentinelNoPass: true` when Sentinel does not require ACL +`connections.redisSentinelNoPass: true` when Sentinel does not require credentials. Only the corresponding credentials are omitted; the other layer can still remain authenticated. @@ -529,21 +538,21 @@ can still remain authenticated. | `connections.redisHost` | Redis host, or the reachable startup/readiness fallback endpoint when a topology is configured | `redis-master` | | `connections.redisPort` | Redis port used with `connections.redisHost` for the standalone/startup fallback endpoint | `6379` | | `connections.redisTLS` | Enable TLS for standalone Redis, Cluster, and Sentinel-discovered Redis nodes. Requires a DocumentServer image with TLS entrypoint support. | `false` | -| `connections.redisUser` | Redis [user](https://redis.io/docs/management/security/acl/) name. Omitted when `connections.redisNoPass` is `true` | `default` | +| `connections.redisUser` | Redis [user](https://redis.io/docs/management/security/acl/) name. Set to `""` for password-only authentication as `default`. Omitted when empty or `connections.redisNoPass` is `true` | `default` | | `connections.redisDBNum` | Number of the redis logical database to be [selected](https://redis.io/commands/select/). The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file | `0` | | `connections.redisClusterNodes` | List of nodes in the Redis cluster. There is no need to specify every node in the cluster, 3 should be enough. You can specify multiple values. It must be specified in the `host:port` format | `[]` | | `connections.redisPassword` | The password set for the Redis account. If set to, it takes priority over the `connections.redisExistingSecret`. The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file | `""` | | `connections.redisSecretKeyName` | The name of the key that contains the Redis user password | `redis-password` | | `connections.redisExistingSecret` | Name of existing secret to use for Redis passwords. Must contain the key specified in `connections.redisSecretKeyName`. The password from this secret overrides password set in the `options` object in `local.json` | `redis` | -| `connections.redisNoPass` | Defines whether to use a Redis auth without a password. If the connection to Redis server does not require a password, set the value to `true` | `false` | +| `connections.redisNoPass` | If `true`, omit Redis-node credentials independently of Sentinel authentication. If `false`, a node password or existing password Secret is required; the username is optional. | `false` | | `connections.redisSentinelNodes` | List of Redis Sentinel Nodes. Sentinel mode is enabled when this list is non-empty. There is no need to specify every node, 3 should be enough. It must use the `host:port` format | `[]` | | `connections.redisSentinelGroupName` | Name of the Sentinel-monitored Redis group. | `mymaster` | | `connections.redisSentinelTLS` | Enable TLS for Sentinel discovery independently of `connections.redisTLS`. Requires a DocumentServer image with TLS entrypoint support. | `false` | -| `connections.redisSentinelUser` | Redis Sentinel ACL user name. Required together with a password when Sentinel authentication is enabled. | `""` | +| `connections.redisSentinelUser` | Optional Redis Sentinel ACL user name. Empty omits the protocol username for password-only authentication as `default`. Omitted when `connections.redisSentinelNoPass` is `true`. | `""` | | `connections.redisSentinelExistingSecret` | Name of existing secret to use for Redis Sentinel password. Must contain the key specified in `connections.redisSentinelSecretKeyName`. The password overrides `optionsSentinel` in `local.json` | `""` | | `connections.redisSentinelSecretKeyName` | The name of the key that contains the Redis Sentinel user password. If you set a password in `redisSentinelPassword`, a secret will be automatically created, the key name of which will be the value set here | `sentinel-password` | | `connections.redisSentinelPassword` | The password set for the Redis Sentinel account. If set, it takes priority over `connections.redisSentinelExistingSecret` and overrides the `optionsSentinel` password in `local.json` | `""` | -| `connections.redisSentinelNoPass` | If `true`, omit Sentinel ACL credentials. If `false`, both `connections.redisSentinelUser` and a Sentinel password are required. | `true` | +| `connections.redisSentinelNoPass` | If `true`, omit Sentinel credentials independently of Redis-node authentication. If `false`, a Sentinel password or existing password Secret is required; the username is optional. | `true` | | `connections.amqpType` | Defines the AMQP server type. Possible values are `rabbitmq` or `activemq` | `rabbitmq` | | `connections.amqpHost` | The IP address or the name of the AMQP server | `rabbitmq` | | `connections.amqpPort` | The port for the connection to AMQP server | `5672` | @@ -952,7 +961,7 @@ can still remain authenticated. | `customResources.job.containerSecurityContext.enabled` | Enable security context for the Custom Resources container | `false` | | `customResources.job.resources.requests` | The requested resources for the job Custom Resources container | `{}` | | `customResources.job.resources.limits` | The resources limits for the job Custom Resources container | `{}` | -| `tests.enabled` | Enable launch/dependency test resources. `helm test` checks Redis, the other dependencies, the native Sentinel `NODE_CONFIG` (when Sentinel storage is selected), and the DocumentServer health endpoint; any failed check fails the test. | `true` | +| `tests.enabled` | Enable launch/dependency test resources. `helm test` checks Redis, the other dependencies, the native Redis `NODE_CONFIG` (when standalone, Sentinel, or Cluster storage is selected), and the DocumentServer health endpoint; any failed check fails the test. | `true` | | `tests.annotations` | Defines annotations that will be additionally added to Test Pod. If set to, it takes priority over the `commonAnnotations` | `{}` | | `tests.customPodAntiAffinity` | Prohibiting the scheduling of Test Pod relative to other Pods containing the specified labels on the same node | `{}` | | `tests.podAffinity` | Defines [Pod affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity) rules for Test Pod scheduling by nodes relative to other Pods | `{}` | diff --git a/sources/scripts/test_redis_config.sh b/sources/scripts/test_redis_config.sh index 59b1c9e..6116e87 100644 --- a/sources/scripts/test_redis_config.sh +++ b/sources/scripts/test_redis_config.sh @@ -19,7 +19,7 @@ elif [[ -n "${REDIS_SENTINEL_NODES:-}" ]]; then elif [[ -n "${REDIS_CLUSTER_NODES:-}" ]]; then topology=cluster else - fail "Redis Sentinel or Cluster nodes must be set" + topology=standalone fi # The orchestrated entrypoint is the component that turns Helm's environment @@ -32,13 +32,30 @@ render_config() { "$@" /usr/local/bin/docker-entrypoint.sh docservice } +# Validate the username for this case, which may override the deployed one. +# An omitted username selects the default account through password-only AUTH. +check_auth() { + local name="$1" options="$2" authenticated="$3" username="$4" user_key="${5:-username}" + printf '%s' "$options" | jq -e \ + --argjson authenticated "$authenticated" --arg username "$username" --arg user_key "$user_key" ' + if $authenticated then + (.password | type == "string" and length > 0) and + (if $username != "" then .[$user_key] == $username else has($user_key) | not end) + else + (has($user_key) or has("password")) | not + end + ' >/dev/null || fail "$name: credentials do not match the expected authentication" +} + check_config() { local name="$1" local node_config="$2" local node_auth="$3" local sentinel_auth="$4" - local node_tls="${5:-${REDIS_SERVER_TLS:-false}}" - local sentinel_tls="${6:-${REDIS_SENTINEL_TLS:-false}}" + local node_user="${5-${REDIS_SERVER_USER:-}}" + local sentinel_user="${6-${REDIS_SENTINEL_USER:-}}" + local node_tls="${7:-${REDIS_SERVER_TLS:-false}}" + local sentinel_tls="${8:-${REDIS_SENTINEL_TLS:-false}}" local scheme=redis [[ "$node_tls" != true ]] || scheme=rediss @@ -56,6 +73,14 @@ check_config() { .services.CoAuthoring.redis.name == "redis" ' >/dev/null || fail "$name: NODE_CONFIG does not select the native Redis backend" + # The orchestrated entrypoint uses user/db for standalone options, and + # username/database for Sentinel and Cluster node-redis options. + check_auth "$name: standalone/fallback" \ + "$(printf '%s' "$node_config" | jq '.services.CoAuthoring.redis.options')" "$node_auth" "$node_user" user + printf '%s' "$node_config" | jq -e --arg db "$REDIS_SERVER_DB_NUM" ' + .services.CoAuthoring.redis.options.db == $db + ' >/dev/null || fail "$name: standalone/fallback database is incorrect" + if [[ "$topology" == sentinel ]]; then printf '%s' "$node_config" | jq -e --arg nodes "$REDIS_SENTINEL_NODES" --arg db "$REDIS_SERVER_DB_NUM" ' (.services.CoAuthoring.redis.optionsSentinel | type) == "object" and @@ -76,29 +101,16 @@ check_config() { (.sentinelClientOptions | check_tls($sentinel_tls)) ' >/dev/null || fail "$name: Redis node and Sentinel TLS options are incorrect" - if [[ "$node_auth" == true ]]; then - printf '%s' "$node_config" | jq -e ' - .services.CoAuthoring.redis.optionsSentinel.nodeClientOptions | - has("username") and has("password") and has("database") - ' >/dev/null || fail "$name: authenticated Redis node options are incomplete" - else - printf '%s' "$node_config" | jq -e ' - .services.CoAuthoring.redis.optionsSentinel.nodeClientOptions | - (has("username") or has("password")) | not - ' >/dev/null || fail "$name: unauthenticated Redis node options contain credentials" - fi - - if [[ "$sentinel_auth" == true ]]; then - printf '%s' "$node_config" | jq -e ' - .services.CoAuthoring.redis.optionsSentinel.sentinelClientOptions | - has("username") and has("password") - ' >/dev/null || fail "$name: authenticated Sentinel options are incomplete" - else + check_auth "$name: Redis nodes" \ + "$(printf '%s' "$node_config" | jq '.services.CoAuthoring.redis.optionsSentinel.nodeClientOptions')" "$node_auth" "$node_user" + check_auth "$name: Sentinel" \ + "$(printf '%s' "$node_config" | jq '.services.CoAuthoring.redis.optionsSentinel.sentinelClientOptions')" "$sentinel_auth" "$sentinel_user" + if [[ "$sentinel_auth" != true ]]; then printf '%s' "$node_config" | jq -e ' (.services.CoAuthoring.redis.optionsSentinel.sentinelClientOptions | del(.socket)) == {} ' >/dev/null || fail "$name: unauthenticated Sentinel options are not empty" fi - else + elif [[ "$topology" == cluster ]]; then printf '%s' "$node_config" | jq -e --arg nodes "$REDIS_CLUSTER_NODES" --arg scheme "$scheme" ' (.services.CoAuthoring.redis.optionsCluster.rootNodes | map(.url) == ($nodes | split(" ") | map($scheme + "://" + .))) and @@ -111,17 +123,13 @@ check_config() { .rejectUnauthorized != false ' >/dev/null || fail "$name: Cluster TLS options are incorrect" - if [[ "$node_auth" == true ]]; then - printf '%s' "$node_config" | jq -e ' - .services.CoAuthoring.redis.optionsCluster.defaults | - has("username") and has("password") - ' >/dev/null || fail "$name: authenticated Cluster options are incomplete" - else - printf '%s' "$node_config" | jq -e ' - .services.CoAuthoring.redis.optionsCluster.defaults | - (has("username") or has("password")) | not - ' >/dev/null || fail "$name: unauthenticated Cluster options contain credentials" - fi + check_auth "$name: Cluster" \ + "$(printf '%s' "$node_config" | jq '.services.CoAuthoring.redis.optionsCluster.defaults')" "$node_auth" "$node_user" + else + printf '%s' "$node_config" | jq -e ' + ((.services.CoAuthoring.redis.optionsSentinel // {}) | length) == 0 and + ((.services.CoAuthoring.redis.optionsCluster // {}) | length) == 0 + ' >/dev/null || fail "$name: standalone configuration contains a topology" fi } @@ -133,19 +141,23 @@ check_config "deployed environment" "$node_config" \ # Exercise the supported authentication matrix using the native environment # names. These checks only render NODE_CONFIG; the regular test-ds hook checks # the actual Redis/Sentinel and DocService connections. -if [[ "$topology" == sentinel ]]; then - check_config "unauthenticated Redis and Sentinel" \ - "$(render_config REDIS_SERVER_USER= REDIS_SERVER_PWD= REDIS_SENTINEL_USER= REDIS_SENTINEL_PWD=)" false false - check_config "authenticated Redis and unauthenticated Sentinel" \ - "$(render_config REDIS_SERVER_USER=default REDIS_SERVER_PWD=redis-test REDIS_SENTINEL_USER= REDIS_SENTINEL_PWD=)" true false - check_config "authenticated Redis and Sentinel" \ - "$(render_config REDIS_SERVER_USER=default REDIS_SERVER_PWD=redis-test REDIS_SENTINEL_USER=sentinel-test REDIS_SENTINEL_PWD=sentinel-test)" true true -else - check_config "unauthenticated Cluster" \ - "$(render_config REDIS_SERVER_USER= REDIS_SERVER_PWD=)" false false - check_config "authenticated Cluster" \ - "$(render_config REDIS_SERVER_USER=default REDIS_SERVER_PWD=redis-test)" true false -fi +for node_auth in none password acl; do + node_user='' node_password='' + [[ "$node_auth" == none ]] || node_password=redis-test + [[ "$node_auth" != acl ]] || node_user=redis-test-user + sentinel_cases=(none) + [[ "$topology" != sentinel ]] || sentinel_cases+=(password acl) + for sentinel_auth in "${sentinel_cases[@]}"; do + sentinel_user='' sentinel_password='' + [[ "$sentinel_auth" == none ]] || sentinel_password=sentinel-test + [[ "$sentinel_auth" != acl ]] || sentinel_user=sentinel-test-user + check_config "Redis auth=$node_auth, Sentinel auth=$sentinel_auth" \ + "$(render_config "REDIS_SERVER_USER=$node_user" "REDIS_SERVER_PWD=$node_password" \ + "REDIS_SENTINEL_USER=$sentinel_user" "REDIS_SENTINEL_PWD=$sentinel_password")" \ + "$([[ "$node_auth" != none ]] && echo true || echo false)" \ + "$([[ "$sentinel_auth" != none ]] && echo true || echo false)" "$node_user" "$sentinel_user" + done +done # Exercise TLS independently, including the entrypoint's empty/unset defaults. # Authentication is omitted here so TLS-only Sentinel options are also checked. @@ -156,7 +168,7 @@ for node_tls in true false empty unset; do [[ "$sentinel_tls" == unset ]] || tls_env+=("REDIS_SENTINEL_TLS=${sentinel_tls/empty/}") check_config "Redis TLS=$node_tls, Sentinel TLS=$sentinel_tls" \ "$(render_config "${tls_env[@]}" REDIS_SERVER_USER= REDIS_SERVER_PWD= REDIS_SENTINEL_USER= REDIS_SENTINEL_PWD=)" \ - false false "$node_tls" "$sentinel_tls" + false false "" "" "$node_tls" "$sentinel_tls" done done diff --git a/sources/scripts/test_redis_rendering.py b/sources/scripts/test_redis_rendering.py new file mode 100644 index 0000000..1ebc520 --- /dev/null +++ b/sources/scripts/test_redis_rendering.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +"""Redis authentication regression tests. Run with Python 3, PyYAML and Helm: + + python3 sources/scripts/test_redis_rendering.py +""" + +import itertools +import json +from pathlib import Path +import subprocess +import tempfile +import unittest + +import yaml + + +CHART = Path(__file__).resolve().parents[2] +AUTH_MODES = {"none": "ignored-user", "password": "", "acl": "app-user"} + + +def render(values): + with tempfile.NamedTemporaryFile(mode="w", suffix=".json") as overrides: + json.dump(values, overrides) + overrides.flush() + return subprocess.run( + ["helm", "template", "redis-auth-test", str(CHART), "-f", overrides.name], + text=True, capture_output=True, check=False, + ) + + +def environment_lists(value): + if isinstance(value, dict): + if "env" in value: + yield value["env"] + for child in value.values(): + yield from environment_lists(child) + elif isinstance(value, list): + for child in value: + yield from environment_lists(child) + + +class RedisAuthenticationRendering(unittest.TestCase): + def documents(self, values): + result = render(values) + self.assertEqual(result.returncode, 0, result.stderr) + return [doc for doc in yaml.safe_load_all(result.stdout) if doc] + + def test_username_defaults(self): + defaults = yaml.safe_load((CHART / "values.yaml").read_text())["connections"] + self.assertEqual(defaults["redisUser"], "default") + self.assertEqual(defaults["redisSentinelUser"], "") + documents = self.documents({}) + config = next(doc["data"] for doc in documents if doc["metadata"]["name"] == "documentserver") + self.assertEqual(config["REDIS_SERVER_USER"], "default") + self.assertNotIn("REDIS_SENTINEL_USER", config) + + def test_authentication_matrix(self): + for topology, node_mode, source in itertools.product( + ("standalone", "sentinel", "cluster"), AUTH_MODES, ("inline", "existing") + ): + sentinel_modes = AUTH_MODES if topology == "sentinel" else ("none",) + for sentinel_mode in sentinel_modes: + with self.subTest(topology=topology, node=node_mode, sentinel=sentinel_mode, source=source): + connections = {} + for prefix, mode, password in ( + ("redis", node_mode, "node-password"), + ("redisSentinel", sentinel_mode, "sentinel-password"), + ): + connections.update({ + prefix + "User": AUTH_MODES[mode], + prefix + "NoPass": mode == "none", + prefix + "Password": password if source == "inline" else "", + prefix + "ExistingSecret": "external-" + prefix, + }) + if topology == "sentinel": + connections["redisSentinelNodes"] = ["sentinel-a:26379", "sentinel-b:26379"] + elif topology == "cluster": + connections["redisClusterNodes"] = ["redis-a:6379", "redis-b:6379"] + documents = self.documents({ + "connections": connections, + "docservice": {"editorDataStorage": topology}, + }) + config = next(doc["data"] for doc in documents if doc["metadata"]["name"] == "documentserver") + secrets = {doc["metadata"]["name"]: doc for doc in documents if doc["kind"] == "Secret"} + for env_prefix, prefix, mode, password in ( + ("REDIS_SERVER", "redis", node_mode, "node-password"), + ("REDIS_SENTINEL", "redisSentinel", sentinel_mode, "sentinel-password"), + ): + enabled = mode != "none" and (prefix == "redis" or topology == "sentinel") + if enabled and AUTH_MODES[mode]: + self.assertEqual(config[env_prefix + "_USER"], AUTH_MODES[mode]) + else: + self.assertNotIn(env_prefix + "_USER", config) + refs = [entry["valueFrom"]["secretKeyRef"] + for env in environment_lists(documents) + for entry in env if entry["name"] == env_prefix + "_PWD"] + self.assertEqual(bool(refs), enabled) + created_name = "redis-auth-test-" + ("redis" if prefix == "redis" else "redis-sentinel") + self.assertEqual(created_name in secrets, enabled and source == "inline") + for ref in refs: + if source == "existing": + self.assertEqual(ref["name"], "external-" + prefix) + else: + self.assertEqual(ref["name"], created_name) + self.assertEqual(secrets[ref["name"]]["stringData"][ref["key"]], password) + for kind in ("Pod", "ConfigMap"): + self.assertTrue(any(doc["kind"] == kind and doc["metadata"]["name"] == "test-redis-config" + for doc in documents)) + + def test_missing_required_passwords(self): + for topology, username in itertools.product(("standalone", "sentinel", "cluster"), ("", "app-user")): + connections = {"redisUser": username, "redisExistingSecret": "", "redisPassword": ""} + if topology == "sentinel": + connections["redisSentinelNodes"] = ["sentinel:26379"] + elif topology == "cluster": + connections["redisClusterNodes"] = ["redis:6379"] + with self.subTest(topology=topology, username=username): + result = render({"connections": connections, "docservice": {"editorDataStorage": topology}}) + self.assertNotEqual(result.returncode, 0) + self.assertRegex(result.stderr, "Authenticated Redis requires connections.redisPassword or connections.redisExistingSecret|A Redis Password is required!") + for node_no_pass, username in itertools.product((True, False), ("", "sentinel-user")): + with self.subTest(node_no_pass=node_no_pass, sentinel_username=username): + result = render({"connections": { + "redisNoPass": node_no_pass, + "redisSentinelNodes": ["sentinel:26379"], + "redisSentinelUser": username, + "redisSentinelNoPass": False, + "redisSentinelPassword": "", + "redisSentinelExistingSecret": "", + }}) + self.assertNotEqual(result.returncode, 0) + self.assertRegex(result.stderr, "Authenticated Redis Sentinel requires connections.redisSentinelPassword or connections.redisSentinelExistingSecret|A Redis Sentinel Password is required!") + + def test_no_pass_without_passwords(self): + self.documents({"connections": { + "redisNoPass": True, "redisPassword": "", "redisExistingSecret": "", + "redisSentinelNodes": ["sentinel:26379"], + "redisSentinelNoPass": True, "redisSentinelPassword": "", "redisSentinelExistingSecret": "", + }}) + + def test_configuration_hook_selection(self): + for storage, enabled in (("memory", True), ("standalone", False)): + documents = self.documents({"docservice": {"editorDataStorage": storage}, "tests": {"enabled": enabled}}) + self.assertFalse(any(doc["metadata"]["name"] == "test-redis-config" for doc in documents)) + documents = self.documents({"docservice": {"editorStatStorage": "standalone"}}) + self.assertTrue(any(doc["kind"] == "Pod" and doc["metadata"]["name"] == "test-redis-config" for doc in documents)) + + +if __name__ == "__main__": + unittest.main() diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index e08e85c..cbf4bb7 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -22,9 +22,6 @@ Validate editor storage modes and their Redis topology requirements. {{- fail "Redis Cluster and Redis Sentinel nodes cannot be configured together." -}} {{- end -}} {{- if and .Values.connections.redisSentinelNodes (not .Values.connections.redisSentinelNoPass) -}} - {{- if empty .Values.connections.redisSentinelUser -}} - {{- fail "Authenticated Redis Sentinel requires connections.redisSentinelUser." -}} - {{- end -}} {{- if and (empty .Values.connections.redisSentinelPassword) (empty .Values.connections.redisSentinelExistingSecret) -}} {{- fail "Authenticated Redis Sentinel requires connections.redisSentinelPassword or connections.redisSentinelExistingSecret." -}} {{- end -}} diff --git a/templates/configmaps/documentserver.yaml b/templates/configmaps/documentserver.yaml index 4d339dd..a418580 100644 --- a/templates/configmaps/documentserver.yaml +++ b/templates/configmaps/documentserver.yaml @@ -31,7 +31,7 @@ data: REDIS_SERVER_TLS: {{ .Values.connections.redisTLS | quote }} REDIS_SENTINEL_TLS: {{ .Values.connections.redisSentinelTLS | quote }} REDIS_CONNECTOR_NAME: redis - {{- if not .Values.connections.redisNoPass }} + {{- if and (not .Values.connections.redisNoPass) .Values.connections.redisUser }} REDIS_SERVER_USER: {{ .Values.connections.redisUser | quote }} {{- end }} REDIS_SERVER_DB_NUM: {{ .Values.connections.redisDBNum | quote }} @@ -41,7 +41,7 @@ data: {{- if .Values.connections.redisSentinelNodes }} REDIS_SENTINEL_NODES: {{ join " " .Values.connections.redisSentinelNodes }} REDIS_SENTINEL_GROUP_NAME: {{ .Values.connections.redisSentinelGroupName }} - {{- if not .Values.connections.redisSentinelNoPass }} + {{- if and (not .Values.connections.redisSentinelNoPass) .Values.connections.redisSentinelUser }} REDIS_SENTINEL_USER: {{ .Values.connections.redisSentinelUser | quote }} {{- end }} {{- end }} diff --git a/templates/tests/test-redis-config-cm.yaml b/templates/tests/test-redis-config-cm.yaml index 0e5eeb5..69300e2 100644 --- a/templates/tests/test-redis-config-cm.yaml +++ b/templates/tests/test-redis-config-cm.yaml @@ -1,4 +1,5 @@ -{{- if and .Values.tests.enabled (or (or (eq (default "memory" .Values.docservice.editorDataStorage) "sentinel") (eq (default "memory" .Values.docservice.editorStatStorage) "sentinel")) (or (eq (default "memory" .Values.docservice.editorDataStorage) "cluster") (eq (default "memory" .Values.docservice.editorStatStorage) "cluster"))) }} +{{- $redisModes := list "standalone" "sentinel" "cluster" -}} +{{- if and .Values.tests.enabled (or (has (default "memory" .Values.docservice.editorDataStorage) $redisModes) (has (default "memory" .Values.docservice.editorStatStorage) $redisModes)) }} apiVersion: v1 kind: ConfigMap metadata: diff --git a/templates/tests/test-redis-config-pod.yaml b/templates/tests/test-redis-config-pod.yaml index 09036ce..dd5aa1b 100644 --- a/templates/tests/test-redis-config-pod.yaml +++ b/templates/tests/test-redis-config-pod.yaml @@ -1,4 +1,5 @@ -{{- if and .Values.tests.enabled (or (or (eq (default "memory" .Values.docservice.editorDataStorage) "sentinel") (eq (default "memory" .Values.docservice.editorStatStorage) "sentinel")) (or (eq (default "memory" .Values.docservice.editorDataStorage) "cluster") (eq (default "memory" .Values.docservice.editorStatStorage) "cluster"))) }} +{{- $redisModes := list "standalone" "sentinel" "cluster" -}} +{{- if and .Values.tests.enabled (or (has (default "memory" .Values.docservice.editorDataStorage) $redisModes) (has (default "memory" .Values.docservice.editorStatStorage) $redisModes)) }} apiVersion: v1 kind: Pod metadata: diff --git a/values.yaml b/values.yaml index b1487db..b27b58b 100644 --- a/values.yaml +++ b/values.yaml @@ -43,6 +43,7 @@ connections: redisTLS: false ## connections.redisUser The Redis user name ## ref: https://redis.io/docs/management/security/acl/ + ## Defaults to `default`; set to "" for password-only authentication (no protocol username, authenticates as default). ## Omit Redis authentication by setting connections.redisNoPass to true. ## The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file redisUser: default @@ -71,8 +72,8 @@ connections: ## If set to, it takes priority over the `connections.redisExistingSecret` ## The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file redisPassword: "" - ## connections.redisNoPass Defines whether to use a Redis auth without a password - ## If the connection to Redis server does not require a password, set the value to `true` + ## connections.redisNoPass Omit Redis-node credentials when true, independently of Sentinel authentication. + ## When false, a password or existing password secret is required; the username is optional. redisNoPass: false ## connections.redisSentinelNodes: List of Redis Sentinel Nodes ## There is no need to specify every node, 3 should be enough @@ -90,7 +91,8 @@ connections: ## Requires a DocumentServer image supporting REDIS_SENTINEL_TLS. Ports remain unchanged. redisSentinelTLS: false ## connections.redisSentinelUser The Redis Sentinel user name - ## Required together with a password when Sentinel ACL authentication is enabled. + ## Defaults to "" for password-only authentication (no protocol username, authenticates as default). + ## Set a username for a named ACL user; authentication still requires a password or existing password secret. redisSentinelUser: "" ## connections.redisSentinelExistingSecret Name of existing secret to use for Redis Sentinel password ## Must contain the key specified in `connections.redisSentinelSecretKeyName` @@ -103,8 +105,8 @@ connections: ## If set to, it takes priority over the `connections.redisSentinelExistingSecret` ## The value in this parameter overrides the value set in the `optionsSentinel` object in `local.json` if you add custom configuration file redisSentinelPassword: "" - ## connections.redisSentinelNoPass Defines whether to use a Redis Sentinel auth without a password - ## If Sentinel does not require ACL authentication, set the value to `true`; the Sentinel user and password are then omitted. + ## connections.redisSentinelNoPass Omit Sentinel credentials when true, independently of Redis-node authentication. + ## When false, a password or existing password secret is required; the username is optional. redisSentinelNoPass: true ## connections.amqpType Defines the AMQP server type ## Possible values are `rabbitmq` or `activemq` From d1f96de93253bb9a884a392ea3060b63eefa4375 Mon Sep 17 00:00:00 2001 From: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:59:44 +0200 Subject: [PATCH 6/6] fix(helm): share Redis CA trust with application and test pods Add a shared CA Secret setting for Redis and Sentinel TLS. Mount the bundle and configure trust in application and connectivity test containers, avoiding duplicate configuration. Document shared trust settings and add regression tests. Assisted-by: Codex:gpt-6 Signed-off-by: Nico Van Laerebeke <1520618+nvanlaerebeke@users.noreply.github.com> --- README.md | 46 +++++++++++- sources/scripts/test_ds.py | 40 +++++----- sources/scripts/test_ds_tls.py | 78 ++++++++++++++++++++ sources/scripts/test_redis_rendering.py | 98 ++++++++++++++++++++++++- templates/_helpers.tpl | 55 ++++++++++++++ templates/deployments/converter.yaml | 3 + templates/deployments/docservice.yaml | 3 + templates/statefulset/adminpanel.yaml | 3 + templates/tests/test-ds-pod.yaml | 12 +++ values.yaml | 16 ++++ 10 files changed, 333 insertions(+), 21 deletions(-) create mode 100644 sources/scripts/test_ds_tls.py diff --git a/README.md b/README.md index f1fc177..da4521d 100644 --- a/README.md +++ b/README.md @@ -459,9 +459,44 @@ images do not support these flags. `REDIS_SERVER_TLS=true` enables The flags accept `true`/`false`; unset or empty environment values behave as `false` without injecting TLS options. TLS does not change the configured -ports, and certificate verification stays enabled. Custom certificates and -mutual TLS are outside these values; existing mounted configuration remains -available for those settings. +ports, and certificate verification stays enabled. Client certificates for +mutual TLS still use the existing mounted application configuration. + +For private CAs, configure one shared Secret containing a PEM CA bundle: + +```yaml +connections: + redisTLS: true + redisSentinelTLS: true # Enable only if Sentinel also uses TLS. + redisCAExistingSecret: redis-ca + redisCASecretKeyName: ca.crt +``` + +Create `redis-ca` in the release namespace, for example: + +```sh +kubectl create secret generic redis-ca --from-file=ca.crt=./ca-bundle.pem --namespace +``` + +The chart mounts this same bundle read-only into Docservice, Converter, +Adminpanel (when enabled), and the dependency connectivity test pod. No extra +volume or environment configuration is needed. If Redis and Sentinel use +different CAs, include both issuers in the bundle. The shared configuration is +active when either TLS flag is enabled; without it, the existing trust defaults +are retained. Certificate verification remains required. + +Application containers use `NODE_EXTRA_CA_CERTS`, which extends Node.js trust +for outbound TLS connections. An explicit `socket.ca` in custom application +configuration takes precedence, as does an existing `NODE_EXTRA_CA_CERTS` in a +component's `extraEnvVars`. Restart application pods after updating the CA +bundle so Node.js reloads it. + +For test-specific trust, `tests.extraEnvVars` can override +`REDIS_SERVER_CA_CERTS` (standalone, Cluster, or Sentinel-discovered Redis) and +`REDIS_SENTINEL_CA_CERTS` (Sentinel discovery). Use `tests.extraVolumes` and +`tests.extraVolumeMounts` to mount any additional bundles. Each path is used +only when its corresponding TLS flag is enabled. The test pod does not inherit +unrelated application mounts or `local.json` settings. #### Redis authentication secrets @@ -538,6 +573,8 @@ can still remain authenticated. | `connections.redisHost` | Redis host, or the reachable startup/readiness fallback endpoint when a topology is configured | `redis-master` | | `connections.redisPort` | Redis port used with `connections.redisHost` for the standalone/startup fallback endpoint | `6379` | | `connections.redisTLS` | Enable TLS for standalone Redis, Cluster, and Sentinel-discovered Redis nodes. Requires a DocumentServer image with TLS entrypoint support. | `false` | +| `connections.redisCAExistingSecret` | Existing Secret containing a PEM CA bundle, shared by application containers and the connectivity test when Redis or Sentinel TLS is enabled | `""` | +| `connections.redisCASecretKeyName` | Key containing the PEM CA bundle in `connections.redisCAExistingSecret` | `ca.crt` | | `connections.redisUser` | Redis [user](https://redis.io/docs/management/security/acl/) name. Set to `""` for password-only authentication as `default`. Omitted when empty or `connections.redisNoPass` is `true` | `default` | | `connections.redisDBNum` | Number of the redis logical database to be [selected](https://redis.io/commands/select/). The value in this parameter overrides the value set in the `options` object in `local.json` if you add custom configuration file | `0` | | `connections.redisClusterNodes` | List of nodes in the Redis cluster. There is no need to specify every node in the cluster, 3 should be enough. You can specify multiple values. It must be specified in the `host:port` format | `[]` | @@ -969,6 +1006,9 @@ can still remain authenticated. | `tests.nodeSelector` | Node labels for Test Pod assignment. If set to, it takes priority over the `nodeSelector` | `{}` | | `tests.tolerations` | Tolerations for Test Pod assignment. If set to, it takes priority over the `tolerations` | `[]` | | `tests.initContainers` | Defines containers that run before Test container in the Pod | `[]` | +| `tests.extraEnvVars` | Extra environment variables for the dependency connectivity test container, including `REDIS_SERVER_CA_CERTS` and `REDIS_SENTINEL_CA_CERTS` PEM bundle paths | `[]` | +| `tests.extraVolumes` | Extra volumes for the dependency connectivity test Pod, such as CA certificate Secrets | `[]` | +| `tests.extraVolumeMounts` | Extra volume mounts for the dependency connectivity test container | `[]` | | `tests.image.repository` | Test container image name | `ghcr.io/euro-office/cluster-utils` | | `tests.image.tag` | Test container image tag. If set to, it takes priority over the `images.tag` | `""` | | `tests.image.pullPolicy` | Test container image pull policy | `IfNotPresent` | diff --git a/sources/scripts/test_ds.py b/sources/scripts/test_ds.py index e699570..e056309 100755 --- a/sources/scripts/test_ds.py +++ b/sources/scripts/test_ds.py @@ -4,18 +4,23 @@ import time import logging + +def redis_tls_options(prefix): + if os.environ.get(f'{prefix}_TLS') != 'true': + return {} + options = {'ssl': True, 'ssl_cert_reqs': 'required'} + ca_certs = os.environ.get(f'{prefix}_CA_CERTS') + if ca_certs: + options['ssl_ca_certs'] = ca_certs + return options + + redisHost = os.environ.get('REDIS_SERVER_HOST') redisPort = os.environ.get('REDIS_SERVER_PORT') redisUser = os.environ.get('REDIS_SERVER_USER') redisPassword = os.environ.get('REDIS_SERVER_PWD') -redisTLSOptions = ( - {'ssl': True, 'ssl_cert_reqs': 'required'} - if os.environ.get('REDIS_SERVER_TLS') == 'true' else {} -) -redisSentinelTLSOptions = ( - {'ssl': True, 'ssl_cert_reqs': 'required'} - if os.environ.get('REDIS_SENTINEL_TLS') == 'true' else {} -) +redisTLSOptions = redis_tls_options('REDIS_SERVER') +redisSentinelTLSOptions = redis_tls_options('REDIS_SENTINEL') redisSentinelUser = os.environ.get('REDIS_SENTINEL_USER') redisSentinelPassword = os.environ.get('REDIS_SENTINEL_PWD') redisDBNum = os.environ.get('REDIS_SERVER_DB_NUM') @@ -382,12 +387,13 @@ def total_status(): sys.exit(1) -init_logger('test') -logger_test_ds = logging.getLogger('test.ds') -check_redis() -check_db() -check_mq() -if storageS3 == 'false': - check_dir_access() -get_ds_status() -total_status() +if __name__ == '__main__': + init_logger('test') + logger_test_ds = logging.getLogger('test.ds') + check_redis() + check_db() + check_mq() + if storageS3 == 'false': + check_dir_access() + get_ds_status() + total_status() diff --git a/sources/scripts/test_ds_tls.py b/sources/scripts/test_ds_tls.py new file mode 100644 index 0000000..51b0586 --- /dev/null +++ b/sources/scripts/test_ds_tls.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +"""Connectivity hook TLS regression tests. Run with Python 3 and redis-py: + + python3 sources/scripts/test_ds_tls.py +""" + +import importlib.util +import itertools +import os +from pathlib import Path +import unittest +from unittest.mock import Mock, patch + +import redis +import redis.cluster + + +SCRIPT = Path(__file__).with_name("test_ds.py") + + +class RedisTLSConnectivity(unittest.TestCase): + def test_tls_and_ca_settings_reach_each_client(self): + for topology, node_tls, sentinel_tls, node_ca, sentinel_ca in itertools.product( + ("standalone", "cluster", "sentinel"), (False, True), (False, True), + ("", "/ca/nodes.pem"), ("", "/ca/sentinels.pem"), + ): + with self.subTest(topology=topology, node_tls=node_tls, sentinel_tls=sentinel_tls, + node_ca=node_ca, sentinel_ca=sentinel_ca): + env = { + "DB_PORT": "5432", + "REDIS_SERVER_HOST": "redis", "REDIS_SERVER_PORT": "6379", + "REDIS_SERVER_TLS": str(node_tls).lower(), + "REDIS_SENTINEL_TLS": str(sentinel_tls).lower(), + "REDIS_SERVER_CA_CERTS": node_ca, + "REDIS_SENTINEL_CA_CERTS": sentinel_ca, + } + if topology == "cluster": + env["REDIS_CLUSTER_NODES"] = "redis:6379" + elif topology == "sentinel": + env.update({"REDIS_SENTINEL_NODES": "sentinel:26379", + "REDIS_SENTINEL_GROUP_NAME": "mymaster"}) + spec = importlib.util.spec_from_file_location("connectivity_hook", SCRIPT) + hook = importlib.util.module_from_spec(spec) + with patch.dict(os.environ, env, clear=True): + spec.loader.exec_module(hook) + hook.logger_test_ds = Mock() + with patch.object(redis, "Redis") as standalone, \ + patch.object(redis.cluster, "RedisCluster") as cluster, \ + patch.object(redis, "Sentinel") as sentinel: + sentinel.return_value.discover_master.return_value = ("master", 6379) + client = cluster if topology == "cluster" else standalone + client.return_value.ping.return_value = True + check = {"standalone": hook.get_redis_status, + "cluster": hook.get_redis_cluster_status, + "sentinel": hook.get_redis_sentinel_status}[topology] + self.assertIs(check(), True) + self.assert_tls_options(client.call_args.kwargs, node_tls, node_ca) + if topology == "sentinel": + self.assert_tls_options(sentinel.call_args.kwargs["sentinel_kwargs"], + sentinel_tls, sentinel_ca) + self.assertEqual(client.call_args.kwargs["host"], "master") + + def assert_tls_options(self, options, enabled, ca): + if enabled: + self.assertIs(options["ssl"], True) + self.assertEqual(options["ssl_cert_reqs"], "required") + if ca: + self.assertEqual(options["ssl_ca_certs"], ca) + else: + self.assertNotIn("ssl_ca_certs", options) + else: + self.assertNotIn("ssl", options) + self.assertNotIn("ssl_cert_reqs", options) + self.assertNotIn("ssl_ca_certs", options) + + +if __name__ == "__main__": + unittest.main() diff --git a/sources/scripts/test_redis_rendering.py b/sources/scripts/test_redis_rendering.py index 1ebc520..45cf7fd 100644 --- a/sources/scripts/test_redis_rendering.py +++ b/sources/scripts/test_redis_rendering.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Redis authentication regression tests. Run with Python 3, PyYAML and Helm: +"""Redis authentication and TLS chart regression tests. Run with Python 3, PyYAML and Helm: python3 sources/scripts/test_redis_rendering.py """ @@ -145,6 +145,102 @@ def test_configuration_hook_selection(self): documents = self.documents({"docservice": {"editorStatStorage": "standalone"}}) self.assertTrue(any(doc["kind"] == "Pod" and doc["metadata"]["name"] == "test-redis-config" for doc in documents)) + def test_connectivity_hook_ca_mounts(self): + extras = { + "extraEnvVars": [ + {"name": "REDIS_SERVER_CA_CERTS", "value": "/etc/redis-ca/node.crt"}, + {"name": "REDIS_SENTINEL_CA_CERTS", "value": "/etc/redis-ca/sentinel.crt"}, + ], + "extraVolumes": [{"name": "redis-ca", "secret": {"secretName": "private-redis-ca"}}], + "extraVolumeMounts": [{"name": "redis-ca", "mountPath": "/etc/redis-ca", "readOnly": True}], + } + for storage_s3 in (False, True): + with self.subTest(storage_s3=storage_s3): + documents = self.documents({ + "tests": extras, "persistence": {"storageS3": storage_s3}, + "docservice": {"editorDataStorage": "sentinel"}, + "connections": {"redisSentinelNodes": ["sentinel:26379"], + "redisTLS": True, "redisSentinelTLS": True, + "redisCAExistingSecret": "shared-ca"}, + }) + pod = next(doc for doc in documents if doc["kind"] == "Pod" + and doc["metadata"]["name"] == "test-ds") + container = pod["spec"]["containers"][0] + for entry in extras["extraEnvVars"]: + self.assertIn(entry, container["env"]) + self.assertEqual(sum(e["name"] == entry["name"] for e in container["env"]), 1) + self.assertIn(extras["extraVolumes"][0], pod["spec"]["volumes"]) + self.assertIn(extras["extraVolumeMounts"][0], container["volumeMounts"]) + self.assertIn("test-ds", [v["name"] for v in pod["spec"]["volumes"]]) + self.assertEqual("ds-files" in [v["name"] for v in pod["spec"]["volumes"]], not storage_s3) + + def test_shared_ca_for_applications_and_connectivity_hook(self): + ca_path = "/etc/redis-ca-certificates/ca.crt" + for topology, node_tls, sentinel_tls, secret in itertools.product( + ("standalone", "sentinel", "cluster"), (False, True), (False, True), + ("", "{{ .Release.Name }}-ca"), + ): + with self.subTest(topology=topology, node_tls=node_tls, sentinel_tls=sentinel_tls, secret=secret): + connections = {"redisTLS": node_tls, "redisSentinelTLS": sentinel_tls, + "redisCAExistingSecret": secret} + if topology == "sentinel": + connections["redisSentinelNodes"] = ["sentinel:26379"] + elif topology == "cluster": + connections["redisClusterNodes"] = ["redis:6379"] + documents = self.documents({ + "connections": connections, + "docservice": {"editorDataStorage": topology}, + "adminpanel": {"enabled": True}, + }) + enabled = bool(secret and (node_tls or sentinel_tls)) + found = set() + for doc in documents: + spec = doc.get("spec", {}) + spec = spec.get("template", {}).get("spec", spec) + for container in spec.get("containers", []): + component = container["name"] + if component not in ("docservice", "converter", "adminpanel", "test-ds"): + continue + found.add(component) + env = {e["name"]: e for e in container.get("env", [])} + volumes = [v for v in spec["volumes"] if v["name"] == "redis-ca-certificates"] + mounts = [v for v in container["volumeMounts"] if v["name"] == "redis-ca-certificates"] + self.assertEqual(bool(volumes), enabled) + self.assertEqual(bool(mounts), enabled) + if enabled: + self.assertEqual(volumes[0]["secret"], { + "secretName": "redis-auth-test-ca", "items": [{"key": "ca.crt", "path": "ca.crt"}], + }) + self.assertEqual(mounts[0]["mountPath"], str(Path(ca_path).parent)) + self.assertIs(mounts[0]["readOnly"], True) + expected_env = ({"REDIS_SERVER_CA_CERTS": enabled and node_tls, + "REDIS_SENTINEL_CA_CERTS": enabled and sentinel_tls} + if component == "test-ds" else {"NODE_EXTRA_CA_CERTS": enabled}) + for key, present in expected_env.items(): + self.assertEqual(key in env, present) + if present: + self.assertEqual(env[key]["value"], ca_path) + self.assertEqual(found, {"docservice", "converter", "adminpanel", "test-ds"}) + + def test_shared_ca_respects_application_overrides(self): + override = {"name": "NODE_EXTRA_CA_CERTS", "value": "/existing/ca.pem"} + documents = self.documents({ + "connections": {"redisTLS": True, "redisCAExistingSecret": "redis-ca", + "redisCASecretKeyName": "trust.pem"}, + "adminpanel": {"enabled": True, "extraEnvVars": [override]}, + "docservice": {"extraEnvVars": [override]}, + "converter": {"extraEnvVars": [override]}, + }) + for doc in documents: + if doc["kind"] not in ("Deployment", "StatefulSet"): + continue + spec = doc["spec"]["template"]["spec"] + for container in spec["containers"]: + if container["name"] in ("docservice", "converter", "adminpanel"): + self.assertEqual([e for e in container["env"] if e["name"] == override["name"]], [override]) + volume = next(v for v in spec["volumes"] if v["name"] == "redis-ca-certificates") + self.assertEqual(volume["secret"]["items"], [{"key": "trust.pem", "path": "ca.crt"}]) + if __name__ == "__main__": unittest.main() diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index cbf4bb7..d530e70 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -204,6 +204,61 @@ Return Redis Sentinel password {{- end }} {{- end -}} +{{/* Share Redis CA trust between the application containers and the connectivity hook. */}} +{{- define "ds.redis.ca.enabled" -}} +{{- $tls := or .Values.connections.redisTLS .Values.connections.redisSentinelTLS -}} +{{- if and .Values.connections.redisCAExistingSecret $tls -}} +true +{{- end -}} +{{- end -}} + +{{- define "ds.redis.ca.volume" -}} +{{- if include "ds.redis.ca.enabled" . }} +- name: redis-ca-certificates + secret: + secretName: {{ tpl .Values.connections.redisCAExistingSecret . | quote }} + items: + - key: {{ .Values.connections.redisCASecretKeyName | quote }} + path: ca.crt +{{- end }} +{{- end -}} + +{{- define "ds.redis.ca.mount" -}} +{{- if include "ds.redis.ca.enabled" . }} +- name: redis-ca-certificates + mountPath: /etc/redis-ca-certificates + readOnly: true +{{- end }} +{{- end -}} + +{{- define "ds.redis.ca.env" -}} +{{- $overrides := dict }} +{{- range .extraEnvVars }} +{{- $_ := set $overrides .name true }} +{{- end }} +{{- if and (include "ds.redis.ca.enabled" .context) (not (hasKey $overrides "NODE_EXTRA_CA_CERTS")) }} +- name: NODE_EXTRA_CA_CERTS + value: /etc/redis-ca-certificates/ca.crt +{{- end }} +{{- end -}} + +{{- define "ds.redis.ca.testEnv" -}} +{{- if include "ds.redis.ca.enabled" . }} +{{- $overrides := dict }} +{{- range .Values.tests.extraEnvVars }} +{{- $_ := set $overrides .name true }} +{{- end }} +{{- if and .Values.connections.redisTLS (not (hasKey $overrides "REDIS_SERVER_CA_CERTS")) }} +- name: REDIS_SERVER_CA_CERTS + value: /etc/redis-ca-certificates/ca.crt +{{- end }} +{{- if and .Values.connections.redisSentinelTLS (not (hasKey $overrides "REDIS_SENTINEL_CA_CERTS")) }} +- name: REDIS_SENTINEL_CA_CERTS + value: /etc/redis-ca-certificates/ca.crt +{{- end }} +{{- end }} +{{- end -}} + {{/* Get the info auth password secret */}} diff --git a/templates/deployments/converter.yaml b/templates/deployments/converter.yaml index 8c209fb..fcc53a1 100644 --- a/templates/deployments/converter.yaml +++ b/templates/deployments/converter.yaml @@ -142,6 +142,7 @@ spec: {{- with .Values.converter.extraVolumes }} {{- toYaml . | nindent 8 }} {{- end }} + {{ include "ds.redis.ca.volume" . | nindent 8 }} terminationGracePeriodSeconds: {{ .Values.converter.terminationGracePeriodSeconds }} {{- if .Values.converter.hostAliases }} hostAliases: {{- toYaml .Values.converter.hostAliases | nindent 8 }} @@ -185,6 +186,7 @@ spec: name: {{ template "ds.rabbitmq.secretName" . }} key: {{ .Values.connections.amqpSecretKeyName }} {{ include "ds.redis.env" . | nindent 10 }} + {{ include "ds.redis.ca.env" (dict "context" . "extraEnvVars" .Values.converter.extraEnvVars) | nindent 10 }} {{- with .Values.converter.extraEnvVars }} {{- toYaml . | nindent 10 }} {{- end }} @@ -261,3 +263,4 @@ spec: {{- with .Values.converter.extraVolumeMounts }} {{- toYaml . | nindent 10 }} {{- end }} + {{ include "ds.redis.ca.mount" . | nindent 10 }} diff --git a/templates/deployments/docservice.yaml b/templates/deployments/docservice.yaml index 17e212b..577ac04 100644 --- a/templates/deployments/docservice.yaml +++ b/templates/deployments/docservice.yaml @@ -154,6 +154,7 @@ spec: {{- with .Values.docservice.extraVolumes }} {{- toYaml . | nindent 8 }} {{- end }} + {{ include "ds.redis.ca.volume" . | nindent 8 }} terminationGracePeriodSeconds: {{ .Values.docservice.terminationGracePeriodSeconds }} {{- if .Values.docservice.hostAliases }} hostAliases: {{- toYaml .Values.docservice.hostAliases | nindent 8 }} @@ -317,6 +318,7 @@ spec: name: {{ template "ds.rabbitmq.secretName" . }} key: {{ .Values.connections.amqpSecretKeyName }} {{ include "ds.redis.env" . | nindent 10 }} + {{ include "ds.redis.ca.env" (dict "context" . "extraEnvVars" .Values.docservice.extraEnvVars) | nindent 10 }} {{- with .Values.docservice.extraEnvVars }} {{- toYaml . | nindent 10 }} {{- end }} @@ -383,3 +385,4 @@ spec: {{- with .Values.docservice.extraVolumeMounts }} {{- toYaml . | nindent 10 }} {{- end }} + {{ include "ds.redis.ca.mount" . | nindent 10 }} diff --git a/templates/statefulset/adminpanel.yaml b/templates/statefulset/adminpanel.yaml index 151bd2c..3397ba5 100644 --- a/templates/statefulset/adminpanel.yaml +++ b/templates/statefulset/adminpanel.yaml @@ -95,6 +95,7 @@ spec: - adminpanel env: {{ include "ds.redis.env" . | nindent 8 }} + {{ include "ds.redis.ca.env" (dict "context" . "extraEnvVars" .Values.adminpanel.extraEnvVars) | nindent 8 }} {{- with .Values.adminpanel.extraEnvVars }} {{- toYaml . | nindent 8 }} {{- end }} @@ -143,6 +144,7 @@ spec: {{- with .Values.adminpanel.extraVolumeMounts }} {{- toYaml . | nindent 10 }} {{- end }} + {{ include "ds.redis.ca.mount" . | nindent 10 }} volumes: {{- if not .Values.persistence.storageS3 }} - name: ds-files @@ -170,4 +172,5 @@ spec: {{- with .Values.adminpanel.extraVolumes }} {{- toYaml . | nindent 8 }} {{- end }} + {{ include "ds.redis.ca.volume" . | nindent 8 }} {{- end }} diff --git a/templates/tests/test-ds-pod.yaml b/templates/tests/test-ds-pod.yaml index 8cd4764..6cdbd9e 100644 --- a/templates/tests/test-ds-pod.yaml +++ b/templates/tests/test-ds-pod.yaml @@ -75,6 +75,10 @@ spec: value: {{ .Values.persistence.storageS3 | quote }} - name: DS_ADDRESS value: {{ include "ds.resources.name" (list . .Values.commonNameSuffix "docservice") }} + {{ include "ds.redis.ca.testEnv" . | nindent 4 }} + {{- with .Values.tests.extraEnvVars }} + {{- toYaml . | nindent 4 }} + {{- end }} envFrom: - configMapRef: name: {{ include "ds.resources.name" (list . .Values.commonNameSuffix "documentserver") }} @@ -86,6 +90,10 @@ spec: - name: test-ds mountPath: /scripts/test_ds.py subPath: test_ds.py + {{ include "ds.redis.ca.mount" . | nindent 4 }} + {{- with .Values.tests.extraVolumeMounts }} + {{- toYaml . | nindent 4 }} + {{- end }} command: ['python', '/scripts/test_ds.py'] volumes: {{- if not .Values.persistence.storageS3 }} @@ -97,5 +105,9 @@ spec: configMap: name: {{ include "ds.resources.name" (list . .Values.commonNameSuffix "test-ds") }} defaultMode: 0755 + {{ include "ds.redis.ca.volume" . | nindent 2 }} + {{- with .Values.tests.extraVolumes }} + {{- toYaml . | nindent 2 }} + {{- end }} restartPolicy: Never {{- end }} diff --git a/values.yaml b/values.yaml index b27b58b..1c6cb50 100644 --- a/values.yaml +++ b/values.yaml @@ -41,6 +41,13 @@ connections: ## connections.redisTLS Enable TLS for standalone Redis, Cluster, and Sentinel-discovered Redis nodes ## Requires a DocumentServer image supporting REDIS_SERVER_TLS. Ports remain unchanged. redisTLS: false + ## connections.redisCAExistingSecret Existing Secret containing a PEM CA bundle for Redis and Sentinel TLS. + ## Shared by Docservice, Converter, Adminpanel and the dependency connectivity test; no manual mounts are needed. + ## Include both issuers in the bundle if Redis and Sentinel use different CAs. + ## Used when connections.redisTLS or connections.redisSentinelTLS is true. + redisCAExistingSecret: "" + ## connections.redisCASecretKeyName Key containing the PEM CA bundle in connections.redisCAExistingSecret. + redisCASecretKeyName: ca.crt ## connections.redisUser The Redis user name ## ref: https://redis.io/docs/management/security/acl/ ## Defaults to `default`; set to "" for password-only authentication (no protocol username, authenticates as default). @@ -2405,6 +2412,15 @@ tests: ## test.initContainers Containers that run before Test container in a Pod ## ref:https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ initContainers: [] + ## tests.extraEnvVars Extra environment variables for the dependency connectivity test container. + ## connections.redisCAExistingSecret configures private-CA trust for application and test Pods together. + ## Optionally override REDIS_SERVER_CA_CERTS and REDIS_SENTINEL_CA_CERTS with test-specific PEM bundle paths. + ## Each path is used only when its corresponding connections.redisTLS or connections.redisSentinelTLS is true. + extraEnvVars: [] + ## tests.extraVolumes Extra volumes for the dependency connectivity test Pod (e.g. CA certificate Secrets). + extraVolumes: [] + ## tests.extraVolumeMounts Extra mounts for the dependency connectivity test container. + extraVolumeMounts: [] ## Test container image parameters image: ## tests.image.repository test container image name