mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
feat(api): serve credentials with mint and revoke, and seed accounts
The Credential view lists the account Secrets of the namespace by label and skips any no live HelmRelease owns, so no kind is served until its definition carries a credentials block. A mint replaces the stored value in one conditional write keyed on the Secret's resourceVersion and returns the plaintext once; a revoke discards it. Both record an Event on the application, which needs create on events. The application registry seeds an account Secret per declared account before it writes the HelmRelease, so the chart can reference them from the first render, prunes the Secrets of removed accounts after the write, and refuses to delete an application whose release is suspended, since Flux skips the uninstall and would leave the database running with the Secrets gone. The ApplicationDefinition reconciler computes the per-account valuesFrom entries with the function the API uses, so a release that predates the block gets them on its next reconcile. Schema defaulting moves to a package both can import. A definition declaring a format or an account source that is not built leaves its kind unserved rather than served with passwords the API cannot issue. Tenant roles gain get and list on credentials at view and create on mint and revoke at admin and for the tenant ServiceAccount. Attribution comes from the kube-apiserver audit log, so the operations docs get a policy for distributions that ship none, and monitoring-agents a value for an extra fluent-bit output so a SIEM can receive the log without dropping the VictoriaLogs outputs. Assisted-by: LLM Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
This commit is contained in:
1 parent
e0d90ab12c
commit
ae29f07a13
26 files changed
+2282
-33
No files matched your search
@@ -0,0 +1,72 @@
|
||||
# Kubernetes Audit Log
|
||||
|
||||
Cozystack attributes every issuance and revocation of a managed application password to the kube-apiserver audit log. A mint is a `create` on the `mint` subresource of a `core.cozystack.io` Credential, which kube-apiserver audits before it proxies the request to the Cozystack API, recording the caller, the time, the account in `objectRef` and the subresource that tells a mint from a revoke. kube-apiserver records neither the body nor the response of a request it proxies to an aggregated API, at any audit level, so the password shown once in the mint response cannot reach the log. The Cozystack API itself runs without audit flags, and it must stay that way or get a policy that keeps `credentials` below `RequestResponse`, because it is the one server that could write the password down.
|
||||
|
||||
The `monitoring-agents` package tails `/var/log/audit/kube/*.log` on every node and ships it to the VictoriaLogs instance in the `tenant-root` tenant, tagged `audit.*`, where it is kept for a month by default. Only `tenant-root` can read that store. Every other tenant sees the last ten operations on each of its accounts in the Credential's `status.history`, and each mint and revoke also records a Kubernetes Event on the application, with reason `CredentialIssued` or `CredentialRevoked`, naming the account and the caller.
|
||||
|
||||
## Distributions that ship no audit policy
|
||||
|
||||
Talos Linux configures kube-apiserver with an audit policy and writes the log under `/var/log/audit/kube/` out of the box, which is where the default fluent-bit input reads it. A cluster built on a distribution that gives kube-apiserver no audit policy records nothing, so attribution is lost silently. Give it the policy below, or merge these rules into the policy it has, and point the log at the directory fluent-bit tails.
|
||||
|
||||
```yaml
|
||||
apiVersion: audit.k8s.io/v1
|
||||
kind: Policy
|
||||
omitStages:
|
||||
- RequestReceived
|
||||
rules:
|
||||
# Who issued or revoked which account, and when. Metadata is all there is to
|
||||
# record for a proxied request, and all there must ever be for this resource.
|
||||
- level: Metadata
|
||||
resources:
|
||||
- group: core.cozystack.io
|
||||
resources:
|
||||
- credentials
|
||||
- credentials/mint
|
||||
- credentials/revoke
|
||||
# Account Secrets and the tenantsecrets view carry stored password forms;
|
||||
# Metadata keeps their data out of the log.
|
||||
- level: Metadata
|
||||
resources:
|
||||
- group: ""
|
||||
resources:
|
||||
- secrets
|
||||
- group: core.cozystack.io
|
||||
resources:
|
||||
- tenantsecrets
|
||||
- level: Metadata
|
||||
```
|
||||
|
||||
```
|
||||
--audit-policy-file=/etc/kubernetes/audit-policy.yaml
|
||||
--audit-log-path=/var/log/audit/kube/kube-apiserver.log
|
||||
--audit-log-maxage=30
|
||||
--audit-log-maxbackup=10
|
||||
--audit-log-maxsize=100
|
||||
```
|
||||
|
||||
The log path has to be a file under the node's `/var/log/audit/kube/` directory, because the fluent-bit DaemonSet mounts the node's `/var/log` and tails that glob. A distribution that writes the log elsewhere needs `fluent-bit.config.inputs` in the `monitoring-agents` values changed to match.
|
||||
|
||||
## Finding an issuance
|
||||
|
||||
In VictoriaLogs, the stream fields of the audit output include `verb` and `user_username`, and the record keeps the whole audit event, so a mint is found by its subresource:
|
||||
|
||||
```
|
||||
objectRef.subresource:mint AND objectRef.resource:credentials
|
||||
```
|
||||
|
||||
The matching record names the Credential in `objectRef.name`, the caller in `user.username`, the impersonated user where Kubernetes impersonation was used, the source address, the response code and the authorization decision. The user is a person only when the dashboard signs in through OIDC; without it, the dashboard acts as the tenant ServiceAccount.
|
||||
|
||||
## Shipping the log to a SIEM
|
||||
|
||||
The fluent-bit outputs of `monitoring-agents` are one string, so replacing `config.outputs` to add a destination drops the VictoriaLogs outputs with it. Add an output under `fluent-bit.extraOutputs` instead, which is appended after them. The audit records carry the tag `audit.*`:
|
||||
|
||||
```yaml
|
||||
fluent-bit:
|
||||
extraOutputs: |
|
||||
[OUTPUT]
|
||||
Name forward
|
||||
Match audit.*
|
||||
Host siem.example.org
|
||||
Port 24224
|
||||
tls on
|
||||
```
|
||||
Reference in new issue
Block a user