mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-01 20:56:02 +09:00
feat(postgres)!: issue user passwords through the credentials API
The chart generated every user's password at render time into <release>-credentials, which tenants could read again at any time and which Helm history kept for MaxHistory revisions, so a deployment whose policy requires a credential shown once could not run PostgreSQL here. The chart now renders a CredentialTemplate per user, and the users move under CloudNativePG's managed roles, each pointing at its account Secret, so the operator creates the role with the SCRAM verifier the Secret holds, applies a changed Secret live, and reverts a password set inside PostgreSQL. Every role is rendered as the init-script created it, because the operator reverts an attribute that differs, revokes a parent role missing from inRoles and clears a comment the spec leaves unset. The init-script stops creating, passwording and altering accounts, where it would be a second writer, and keeps the two things the operator has no field for: the marker membership and the reset of the createrole_self_grant an earlier chart set. Its marking pass waits a bounded time for CloudNativePG to create the declared roles before it marks them. users.app adopts the owner CloudNativePG bootstraps, whose password the instance manager applies again from the bootstrap secret on every pod start, so that secret is the app user's account Secret and both writers apply the one stored verifier. A users.<name>.password left in values draws an admission warning that points at a mint on the user's Credential. createRole is refused on every render path. A role a CREATEROLE user creates makes that user a member of it, CloudNativePG revokes every membership a managed role is not declared to hold, and the revoke fails on the dependent self-grant, so the user would sit in cannotReconcile on ordinary use; there is no per-role switch to leave memberships alone. The account-name checks render with the managed roles too, so a restore cannot bypass them: a user CloudNativePG or PostgreSQL reserves, a database whose derived <name>_admin or <name>_readonly role starts with pg_ or cnpg_ (which makes the CloudNativePG webhook reject the whole Cluster), and a user whose account name is no valid object name are refused. The chart's account naming is pinned to the API's on one table of names. A pre-upgrade hook refuses to let CloudNativePG adopt a role the chart did not mark, because the operator adopts a managed role within seconds of the spec reaching it, before any post-upgrade job could look. It reads the live Cluster first and connects to the database only when the upgrade adds a name CloudNativePG does not manage yet, so a database that is down does not block the resize that might fix it. For each absent declared database role it creates and marks the role as the superuser before the Cluster applies, so no tenant can plant it in the adoption window. The refusal and the create run in one psql session, keyed on a snapshot of the role's existence taken at the top, so a role planted in between collides with the CREATE and stops the hook; the statements are built with format() and \gexec, since psql does not substitute :'role' inside a DO $$ block. Verified on postgres:18: a fresh role is created NOINHERIT, commented and marked, a role planted after the snapshot fails the hook, and an existing unmarked role is refused. The hook reads the Cluster at run time with a ServiceAccount that may get only that Cluster, rather than through a template lookup, which nothing re-renders when the object changes. The flag an earlier chart set when a user held createRole is still read and never set, so such a release keeps refusing to adopt a role it did not mark. The EndpointAttachment e2e suite read testuser's password from that Secret to probe the attached addresses. It now mints one per probe and waits until the application's own Service accepts it, so the attached address is still queried exactly once. BREAKING CHANGE: PostgreSQL passwords are no longer readable from <release>-credentials. A password is issued once, by a mint on the account's Credential in core.cozystack.io, and replaced by the next mint. users.<name>.createRole is refused; a release that sets it keeps its previous chart version and passwords until it is false. Deleting a Postgres application whose release is suspended is refused. The conversion needs a platform variant with migrations enabled. Co-authored-by: IvanHunters <xorokhotnikov@gmail.com> Co-authored-by: Andrei Kvapil <kvapss@gmail.com> Assisted-by: LLM Signed-off-by: Timofei Larkin <lllamnyp@gmail.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
This commit is contained in:
1 parent
780a358083
commit
a67fa94fdb
32 files changed
+1430
-972
No files matched your search
Generated
+3
-3
@@ -65,7 +65,7 @@ type ConfigSpec struct {
|
||||
// Read-replica autoscaling configuration.
|
||||
// +kubebuilder:default:={}
|
||||
Autoscaling Autoscaling `json:"autoscaling"`
|
||||
// Users configuration map. Passwords are always auto-generated and stored in the `<release>-credentials` Secret; they cannot be set from values — read a user's password from that Secret. A `password` left over in values from before the field was removed is ignored by the render and draws an admission warning, but it is not inert on an upgraded release: the chart preserves whatever password is already in the Secret, which on the first upgrade is the value that was set before removal, so that value stays the live credential until it is rotated (dedicated rotation is tracked in cozystack/community#72). The live password lives only in the Secret.
|
||||
// Users configuration map. Each user is a PostgreSQL role the operator manages from an account Secret the platform keeps. Passwords are issued through the Cozystack credentials API: a mint on the account's `Credential` (`core.cozystack.io`) returns a new password once and stores only its SCRAM verifier, and a revoke retires the password without issuing one. A `password` key here is ignored and draws an admission warning. A password set inside PostgreSQL is reverted by the operator.
|
||||
// +kubebuilder:default:={}
|
||||
Users map[string]User `json:"users,omitempty"`
|
||||
// Databases configuration map. The PostgreSQL system databases `postgres`, `template0` and `template1` are refused.
|
||||
@@ -243,9 +243,9 @@ type TLS struct {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
// Whether the user can bypass row-level security policies (BYPASSRLS). A role can only create other roles carrying BYPASSRLS if it holds the attribute itself, so this is required alongside `createRole` to provision a privileged service role.
|
||||
// Whether the user can bypass row-level security policies (BYPASSRLS). A role can only create other roles carrying BYPASSRLS if it holds the attribute itself.
|
||||
BypassRls bool `json:"bypassRls,omitempty"`
|
||||
// Whether the user can create and manage roles (CREATEROLE). Requires PostgreSQL 16 or newer. Setting it back to `false` withdraws the attribute only: the roles the user created, and its ADMIN and SET memberships in them, stay. Once any user has held it, the chart no longer adopts an existing role it did not create, so a user or database declared later under the name of such a role fails the init job until a platform administrator drops that role.
|
||||
// Not supported while users are CloudNativePG managed roles: the chart refuses to render when it is true, and a release that sets it keeps its previous chart version until it is false. CloudNativePG revokes every membership a managed role is not declared to hold, including the one PostgreSQL gives a CREATEROLE user in each role it creates. Setting it to false withdraws CREATEROLE from a role that held it.
|
||||
CreateRole bool `json:"createRole,omitempty"`
|
||||
// Whether the user has replication privileges.
|
||||
Replication bool `json:"replication,omitempty"`
|
||||
|
||||
Reference in new issue
Block a user