mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
## What this PR does A Postgres app that declares a user named `app` loses that user's password every time its pod restarts. Clients keep the password advertised in `<release>-credentials` and start failing with `password authentication failed for user "app"`, with nothing changed on their side. `app` is the owner role CNPG bootstraps, with a generated password in `<release>-app`, and a declared `users.app` adopts that role (the init-script says so). The init-job sets the role's password from `<release>-credentials`, but CNPG's instance manager re-applies the owner's password from the bootstrap secret whenever it meets a secret version it has not applied yet (`refreshCredentialsFromSecret` → `reconcileUser` in `internal/management/controller/instance_controller.go`). Its cache is in memory, so every pod start re-applies `<release>-app` and silently undoes the init-job. Only releases whose two secrets happen to differ break, which is every release where `users.app` was declared at creation. This PR renders a `<release>-app-owner` basic-auth Secret from the same password `<release>-credentials` holds, and sets `spec.bootstrap.<method>.secret.name` to it, so both writers agree on one value. CNPG resolves the owner secret through that field before falling back to `<release>-app`, never rewrites the data of a secret it does not own, and its webhook accepts a bootstrap change on an existing Cluster. The secret goes on the method the live Cluster was bootstrapped with, read through `lookup`, because CNPG rejects two methods and a restored Cluster keeps `bootstrap.recovery` in its live spec. A release with no `users.app` renders exactly what it rendered before, and a restore in progress (`bootstrap.enabled`) is left alone, since the chart flags its credentials as pending until the init-job runs. We hit this in production: the cluster-wide pod restart of a platform upgrade broke two of the four apps that declare `users.app`; the two others survived only because their two secrets held the same value. `tests/app_owner_secret_test.yaml` covers the shared password (preserved and freshly generated), the initdb and recovery methods, a release without `users.app`, and an in-progress restore. Without the template change, 5 of its 8 tests fail. The full chart suite passes (217 tests). ### Screenshots Not a UI change. ### Downstream repositories Walked against the diff: two templates and one test file under `packages/apps/postgres`. No package is added or renamed, `values.yaml`, `values.schema.json` and `README.md` are untouched, and no output Secret or Service is renamed (a new Secret is added; the Terraform provider reads only `-credentials`, `-rw` and `-ro`). - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note fix(postgres): a user named `app` no longer loses its password when the Postgres pod restarts. CNPG re-applied its own generated password to the `app` owner role on every pod start; the chart now hands CNPG the password stored in `<release>-credentials`. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit - **New Features** - Added owner credentials when the `app` user is configured. - PostgreSQL clusters now use those credentials during initialization or recovery, while preserving compatible recovery settings for restored and actively recovering clusters. - **Bug Fixes** - Ensured generated or existing `app` passwords are reused for owner credentials. - **Tests** - Added coverage for credential reuse, password generation, omitted-user behavior, and cluster recovery scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->