Files
cozystack/packages/core/platform
Andrei Kvapil 1791336e04 feat(mongodb)!: mint tenant passwords through the credentials API (#5380)
## What this PR does

MongoDB passwords are no longer readable from the per-user
`<release>-user-<name>` Secrets, and tenants lose the `databaseAdmin`
login from `<release>-credentials`. Every tenant tier can read both
today. An administrator mints a password on the user's `Credential` and
sees it once, the operator applies it live, and the next mint or a
revoke kills it. MongoDB computes SCRAM itself, so the account Secret
keeps the plaintext, readable only by the platform. A user removed from
`users` is now also dropped from the database. This is the MongoDB part
of the user secrets API design (cozystack/community#137).

Stacked on #5379. Review only the top three commits:

- `credentials-migrate` gets `--source-key` and `--source-per-account`,
to read one source Secret per user.
- The chart renders a `plaintext` CredentialTemplate per user, points
`passwordSecretRef` at its account Secret and hides
`<release>-credentials` from tenants. Every declared user holds an empty
marker role, and a post-upgrade hook drops users that hold it but are no
longer declared, since the Percona operator never drops a user removed
from `spec.users`.
- Migration 67 seeds the account Secrets from the per-user Secrets
before the chart switches. Its finish Job deletes the per-user Secrets
Helm left behind.

Tested on a three-node cluster, fresh install: a minted password logs in
after 3 s, the old one fails 3 s after the next mint, revoke works, no
pod restarts. That run showed a removed user staying in the database,
which the last commit fixes. Full upgrade from 1.7.1 on the same
cluster, all engines at once with a client loop each: migrations 64-71
ran in order and every account was adopted with its old password. The
MongoDB loop had one server-selection timeout during the platform roll
and no authentication error. After the upgrade, a removed user is gone
from `admin.system.users`.

Breaking for users: tenants lose `databaseAdmin`, their only admin login
today. Passwords can't be read any more. A user name that collides with
a system user, maps to an invalid account name (such as `_backup`), is
longer than 63 characters, or maps to the same account as another name
(`a.b` and `a-b`) now fails the render. A user removed from `users` is
dropped on the next upgrade.

Open questions:

1. Should the conversion rotate `databaseAdmin`? Tenants could read it.
2. Without `databaseAdmin`, no tenant user can manage users or the
cluster. Add a per-database admin role, or leave it like that?
3. The drop hook fails the upgrade if there's no writable primary within
5 minutes, on purpose. Is that the right trade?

### Screenshots

No UI change.

### Downstream repositories

- [ ] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up: needed, a MongoDB note for the credentials API docs
(cozystack/website#753) and an upgrade note that tenants lose
`databaseAdmin`
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up: needed, `cozystack_mongodb` still sends
`users.<name>.password`
- [ ]
[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: needed, the MongoDB row in the design, and the
`databaseAdmin` row once question 1 is decided

### Release note

```release-note
feat(mongodb)!: MongoDB passwords are issued through the credentials API. The per-user `<release>-user-<name>` Secrets are removed, `users.<name>.password` is ignored, and tenants can no longer read `databaseAdmin`. An administrator mints a password on the user's Credential; it is shown once and applies within seconds without a restart. A user removed from `users` is now dropped from MongoDB. Existing passwords keep working through the upgrade. Clients that log in as `databaseAdmin` must move to a declared user, and user names that collide with a system user must be renamed before upgrading.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* MongoDB user passwords are now managed through platform account
credentials, with one-time issuance and revocation. Password values in
app configuration are ignored, and reserved MongoDB system-user names
are rejected.
  * Obsolete chart-managed MongoDB users are removed during upgrades.
* Migration support transfers existing MongoDB passwords to
platform-managed account credentials.

* **Bug Fixes**
* MongoDB credential Secrets are excluded from tenant access and
enumeration.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-12-02 11:45:53 -05:00
..