Files
cozystack/hack/e2e-chainsaw/endpointattachment
a67fa94fdb 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>
2026-11-30 18:21:27 +01:00
..

EndpointAttachment E2E

chainsaw-test.yaml exercises EndpointAttachment against a live cluster in two Tests. The postgres Test is the design's contract in one sequence: an attachment that names one application and points at the tenant-facing Service of another is refused with EndpointLineageMismatch and renders nothing; a minted address publishes the read replicas of one application and is collected with its attachment; a reserved IPAddressClaim is attached to one application's primary, detached, still holds the same address, and is then attached to a different application's primary, which the same address now serves; deleting an application collects its attachment and leaves the reserved claim alone. The vminstance Test drives the two datapath modes against cozy-proxy as deployed: PortList publishes one port, WholeIP publishes every port, and a second whole-IP attachment on the same VM is refused with BackendAlreadyDelegated while the first keeps serving. The cozyplane VPC path lives in its own parked suite, hack/e2e-chainsaw/endpointattachment-vpc/, because no e2e lane installs that networking variant.

Every attachment draws its address through the address substrate (IPAddressClaim / IPAddressClass / IPAddress under local.sdn.cozystack.io, community #35), whose packages, cozystack.address-controller and cozystack.metallb-iad, are optional. The e2e install enables both (hack/e2e-platform-packages.sh), and a selected run keeps them only when this suite is selected, since it is the only suite that needs them: hack/select-install.sh maps the suite to both packages and hack/select-e2e.sh maps both back to it, so a change to either selects this suite. Whenever metallb-iad is installed, hack/e2e-post-install-prep.sh creates the default IPAddressClass sandbox on a MetalLB pool of its own that does not auto-assign, 192.168.123.190-199, announced on the sandbox bridge. The applications and cozy-proxy are the suite's runtime requirements in hack/select-install.sh, so a change to one of them does not select it.

Preconditions

  • The applications the fixtures create and their operators: Postgres (cozystack.postgres-application, with the CloudNativePG operator of cozystack.postgres-operator), and VMDisk and VMInstance (cozystack.vm-disk-application and cozystack.vm-instance-application, with KubeVirt and CDI). The engine that ships the controller, cozystack.cozystack-engine, and the tenant-test namespace as configured in hack/e2e-chainsaw/.chainsaw.yaml.
  • The cozystack.address-controller and cozystack.metallb-iad packages enabled through bundles.enabledPackages, with one IPAddressClass annotated as the default whose pool is routable from the machine running Chainsaw; the sandbox gets both as described above. The VM reachability probes dial the attached addresses from that machine; the database probes dial them from pods in the tenant namespace.
  • cozy-proxy deployed and the platform declaring it: the vminstance Test needs cozystackController.endpointAttachments.cozyProxyContractImplemented: true on the cozystack-controller, which the platform's system bundle sets wherever it emits the cozy-proxy Package: on the full variants unless disabled, and on the slim ones when opted in.
  • nc and kubectl on the machine running Chainsaw. The database probes run psql inside the application pods.

Scope note on the VM Test

The design's original VM scenario attached a second address in PortList mode to a VM whose chart Service was already external: true and expected both addresses reachable. That cannot pass against current cozy-proxy: its rule installer keeps one 1:1 slot per pod in both modes and a second delegated Service on the same pod evicts the first from both the ingress and the egress map, so the two reconcile loops flap over the slot. The Test therefore keeps the VM's chart Service internal and lets the attachment be the only delegated Service on the pod, which is also what the controller's BackendAlreadyDelegated refusal enforces from its side. Widening to several addresses per pod waits on a datapath that keeps only the egress half exclusive.

Running

chainsaw test --config hack/e2e-chainsaw/.chainsaw.yaml \
  --set-string storageClass=<class> hack/e2e-chainsaw/endpointattachment

storageClass is the StorageClass the VM disk imports into, as make test-chainsaw passes it to every suite. In CI, make test-chainsaw CHAINSAW_SUITES=endpointattachment runs it.

Cleanup

Chainsaw deletes the Postgres, VMDisk, VMInstance, IPAddressClaim and EndpointAttachment objects it applied. The rendered Services and minted claims are owned by their attachments and go with them. The sandbox class reclaims with Delete, so each address returns to the pool when its claim goes. Under the default Retain reclaim policy instead, every IPAddress the suite used is left Released once its claim is deleted: the one behind the reserved claim, and the ones behind the claims the attachments minted. Unless the IPAddressClass sets releaseDelay, each stays unusable until an admin clears its claimRef, so repeated runs drain the pool; with releaseDelay set, each returns to Available once the delay has passed.