Files
cozystack/hack
Timofei Larkin 94c79925f8 feat(api): add the credentials API with mint and revoke subresources (#4921)
## What this PR does

Tenants read application passwords from Secrets today, and a leaked
password can't be taken back. This PR adds the platform side of the user
secrets API design (cozystack/community#137, ADR 0002): a password comes
out once from a mint, the next mint replaces it, and a revoke kills it.
The engines are converted in the PRs stacked on top, starting with
Postgres in #4922.

How it works:

- A kind's chart renders one `CredentialTemplate`
(`cozystack.io/v1alpha1`) per account: the username, the stored format
(`scram-sha-256`, `mysql-native`, `sha256` or `plaintext`), labels for
the account Secret, and an optional `valuesPath` for an operator that
reads no Secret.
- cozystack-controller keeps the account Secret `<template>.account`. It
seeds it on a release the API marked for seeding, adopts an unowned
Secret with the same username, leaves a foreign one alone with a
`SecretConflict` condition, and mirrors the record (origin, time, actor,
history) into the template status. For a `valuesPath` template it
maintains an optional `valuesFrom` entry on the release.
- `core.cozystack.io/v1alpha1` serves `credentials` as a read-only view
of the templates, plus `mint` and `revoke` subresources. A mint checks
the caller's `resourceVersion` precondition against the mirrored status,
builds the whole Secret and writes it in one request, or answers 409. It
never reads the Secret back. One API request writes one object; the
best-effort Event is the only extra write.
- The Application API marks a new release for seeding, keeps the account
`valuesFrom` entries when it rewrites a release, and refuses to delete a
suspended release that still has accounts, since Flux would skip its
uninstall.
- The dashboard gets a Credentials tab on the application page. It lists
accounts with origin and history; an administrator can mint or revoke,
and a viewer sees no buttons.

The application charts are untouched here: a kind starts using this only
when its chart renders templates. The `CredentialFormat` webhooks that
ADR 0002 describes are not in this PR, so `format.name` accepts only the
four built-in names for now.

### Screenshots

<img width="1440" height="900" alt="01-admin-tab"
src="https://github.com/user-attachments/assets/8c48086c-8f6c-4908-82c1-40e9078afe57"
/>

<img width="1440" height="900" alt="02-mint-dialog"
src="https://github.com/user-attachments/assets/802b2963-3f57-4c0b-ab84-f74bad28c343"
/>

<img width="1440" height="900" alt="03-mint-result"
src="https://github.com/user-attachments/assets/0e9ae3cc-7a3c-4daf-9a09-d4abf53bf70b"
/>

<img width="1440" height="900" alt="04-viewer-tab"
src="https://github.com/user-attachments/assets/10e940f2-4ceb-469d-a0f9-6c9d20a62919"
/>

### Downstream repositories

- [ ] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up: needed, cozystack/website#753 should document the
`Credential` mint/revoke flow and the dashboard tab
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up: needed later, a way to mint from Terraform; nothing breaks
in this PR alone
- [ ]
[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: none, the design is cozystack/community#137

### Release note

```release-note
feat(api): Add the credentials API. Applications that support it expose their accounts as `credentials.core.cozystack.io`; an administrator mints a password once with the `mint` subresource, and `revoke` invalidates it without issuing a new one. The dashboard shows a Credentials tab for such applications. No application uses it in this release on its own; see the per-engine changes.
```
2026-11-26 12:37:20 +03:00
..