Skip to content

Commit e841688

Browse files
fix(postgres): accept integer values for postgresql.parameters in schema (#2687)
## What this PR does PostgreSQL server parameters like `max_connections` are natural integers, but the chart's schema declared them as `{type: string}` only. When users supply bare integers (e.g. `max_connections: 100`) — either directly in Application CR specs or via the UI — Helm rejects the values at schema validation time before template rendering, causing HelmRelease failures. The Helm template already handles both types via `{{ $value | toString | quote }}`, so the fix is to teach the schema to accept both. ### Approach The schema files (`values.schema.json` and the embedded `openAPISchema` in `postgres-rd/cozyrds/postgres.yaml`) are generated from `values.yaml` annotations via `cozyvalues-gen`. Hand-editing them does not survive `make generate` — same regeneration trap that caught #2466 (issue #2597). `cozyvalues-gen` v1.4.0 (cozystack/cozyvalues-gen#25) adds an `intOrString` type alias for map values that emits `additionalProperties.anyOf: [integer, string]` plus the Kubernetes `x-kubernetes-int-or-string: true` marker. ### Changes - `packages/apps/postgres/values.yaml`: annotation flipped from `@field {map[string]string}` to `@field {map[string]intOrString}`, description updated to note integer values are accepted. - Regenerated artifacts: `values.schema.json`, embedded `openAPISchema` in `packages/system/postgres-rd/cozyrds/postgres.yaml`, `packages/apps/postgres/README.md`, and `api/apps/v1alpha1/postgresql/types.go` (Parameters is now `map[string]intstr.IntOrString`). - `packages/apps/postgres/templates/db.yaml`: `$dangerousParams` list extended with `archive_cleanup_command` and `recovery_end_command` (same RCE surface as `archive_command` / `restore_command`). ### Verification - `helm template` with `max_connections: 200` (int) and `max_connections: "200"` (string) produce identical render output. - Dangerous-param block list rejects `archive_cleanup_command` and `recovery_end_command` with the expected `SECURITY:` error. - `make test` in `packages/apps/postgres/`: 13/13 pass. - `make generate` is idempotent — schema files don't drift on regen. ### Release note ```release-note fix(postgres): accept integer values for postgresql.parameters to prevent HelmRelease failures when parameters are supplied as unquoted integers; also block archive_cleanup_command and recovery_end_command (RCE surface). ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * PostgreSQL parameters now accept integer or string values; integers are automatically coerced to strings. * **Security** * Enhanced parameter filtering blocks additional dangerous settings: archive_cleanup_command and recovery_end_command. * **Documentation** * Updated docs and charts to describe int-or-string parameter support and revised blocked-parameter guidance. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/cozystack/cozystack/pull/2687?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents e002f10 + 26db323 commit e841688

8 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎.github/workflows/pre-commit.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
4848
- name: Install generate
4949
run: |
50-
curl -sSL https://github.com/cozystack/cozyvalues-gen/releases/download/v1.3.0/cozyvalues-gen-linux-amd64.tar.gz | tar -xzvf- -C /usr/local/bin/ cozyvalues-gen
50+
curl -sSL https://github.com/cozystack/cozyvalues-gen/releases/download/v1.4.0/cozyvalues-gen-linux-amd64.tar.gz | tar -xzvf- -C /usr/local/bin/ cozyvalues-gen
5151
5252
- name: Run pre-commit hooks
5353
run: |

‎api/apps/v1alpha1/postgresql/types.go‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/postgresql/zz_generated.deepcopy.go‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/apps/postgres/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ See:
177177

178178
### Application-specific parameters
179179

180-
| Name | Description | Type | Value |
181-
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----- |
182-
| `postgresql` | PostgreSQL server configuration. | `object` | `{}` |
183-
| `postgresql.parameters` | PostgreSQL server parameters. All values must be strings (quote numbers: "100"). BLOCKED (enable arbitrary code execution): archive_command, restore_command, ssl_passphrase_command, dynamic_library_path, local_preload_libraries, session_preload_libraries, shared_preload_libraries. Do NOT override CloudNativePG-managed parameters: archive_mode, primary_conninfo, wal_level, max_replication_slots. | `map[string]string` | `{}` |
180+
| Name | Description | Type | Value |
181+
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | ----- |
182+
| `postgresql` | PostgreSQL server configuration. | `object` | `{}` |
183+
| `postgresql.parameters` | PostgreSQL server parameters. Values may be strings or integers; integers are coerced to strings by the template (e.g. both `max_connections: 100` and `max_connections: "100"` are accepted). BLOCKED (enable arbitrary code execution): archive_command, restore_command, ssl_passphrase_command, archive_cleanup_command, recovery_end_command, dynamic_library_path, local_preload_libraries, session_preload_libraries, shared_preload_libraries. Do NOT override CloudNativePG-managed parameters: archive_mode, primary_conninfo, wal_level, max_replication_slots. | `map[string]intOrString` | `{}` |
184184

185185

186186
### Quorum-based synchronous replication

‎packages/apps/postgres/templates/db.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ spec:
108108
{{- $defaults := dict "max_wal_senders" "30" }}
109109
{{- $params := merge (dict) .Values.postgresql.parameters $defaults }}
110110
{{- /* Security: Block parameters that enable arbitrary code execution (shell commands or .so loading) */ -}}
111-
{{- $dangerousParams := list "archive_command" "restore_command" "ssl_passphrase_command" "dynamic_library_path" "local_preload_libraries" "session_preload_libraries" "shared_preload_libraries" }}
111+
{{- $dangerousParams := list "archive_command" "restore_command" "ssl_passphrase_command" "archive_cleanup_command" "recovery_end_command" "dynamic_library_path" "local_preload_libraries" "session_preload_libraries" "shared_preload_libraries" }}
112112
{{- range $key, $value := $params }}
113113
{{- $normalizedKey := lower $key }}
114114
{{- if has $normalizedKey $dangerousParams }}

‎packages/apps/postgres/values.schema.json‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,21 @@
137137
"default": {},
138138
"properties": {
139139
"parameters": {
140-
"description": "PostgreSQL server parameters. All values must be strings (quote numbers: \"100\"). BLOCKED (enable arbitrary code execution): archive_command, restore_command, ssl_passphrase_command, dynamic_library_path, local_preload_libraries, session_preload_libraries, shared_preload_libraries. Do NOT override CloudNativePG-managed parameters: archive_mode, primary_conninfo, wal_level, max_replication_slots.",
140+
"description": "PostgreSQL server parameters. Values may be strings or integers; integers are coerced to strings by the template (e.g. both `max_connections: 100` and `max_connections: \"100\"` are accepted). BLOCKED (enable arbitrary code execution): archive_command, restore_command, ssl_passphrase_command, archive_cleanup_command, recovery_end_command, dynamic_library_path, local_preload_libraries, session_preload_libraries, shared_preload_libraries. Do NOT override CloudNativePG-managed parameters: archive_mode, primary_conninfo, wal_level, max_replication_slots.",
141141
"type": "object",
142142
"default": {
143143
"max_connections": "100"
144144
},
145145
"additionalProperties": {
146-
"type": "string"
146+
"anyOf": [
147+
{
148+
"type": "integer"
149+
},
150+
{
151+
"type": "string"
152+
}
153+
],
154+
"x-kubernetes-int-or-string": true
147155
}
148156
}
149157
}

‎packages/apps/postgres/values.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ version: v18
8989
##
9090

9191
## @typedef {struct} PostgreSQL - PostgreSQL server configuration.
92-
## @field {map[string]string} [parameters] - PostgreSQL server parameters. All values must be strings (quote numbers: "100"). BLOCKED (enable arbitrary code execution): archive_command, restore_command, ssl_passphrase_command, dynamic_library_path, local_preload_libraries, session_preload_libraries, shared_preload_libraries. Do NOT override CloudNativePG-managed parameters: archive_mode, primary_conninfo, wal_level, max_replication_slots.
92+
## @field {map[string]intOrString} [parameters] - PostgreSQL server parameters. Values may be strings or integers; integers are coerced to strings by the template (e.g. both `max_connections: 100` and `max_connections: "100"` are accepted). BLOCKED (enable arbitrary code execution): archive_command, restore_command, ssl_passphrase_command, archive_cleanup_command, recovery_end_command, dynamic_library_path, local_preload_libraries, session_preload_libraries, shared_preload_libraries. Do NOT override CloudNativePG-managed parameters: archive_mode, primary_conninfo, wal_level, max_replication_slots.
9393

9494
## @param {PostgreSQL} postgresql - PostgreSQL server configuration.
9595
postgresql:
@@ -104,7 +104,7 @@ postgresql:
104104
## work_mem: "256MB"
105105
##
106106
## SECURITY: The following parameters are BLOCKED (enable arbitrary code execution):
107-
## archive_command, restore_command, ssl_passphrase_command (shell commands),
107+
## archive_command, restore_command, ssl_passphrase_command, archive_cleanup_command, recovery_end_command (shell commands),
108108
## dynamic_library_path, local_preload_libraries, session_preload_libraries,
109109
## shared_preload_libraries (arbitrary .so loading)
110110
##

0 commit comments

Comments
 (0)