Split out of #44 (item 1, topology-driven enrichment). Design only, nothing is implemented yet.
Goal
Attach Kubernetes context captured at incident-open time to incidents: owner chain (Pod → ReplicaSet/StatefulSet/DaemonSet/Job → Deployment → Service → Ingress, plus node), K8s events for the involved objects, and a pod-state snapshot (restarts, last termination reason/exit code, container status, requests/limits vs usage). The server has no Kubernetes access and one cluster hosts many teams, so a single shared in-cluster binary gathers the data for all teams. The main risk is cross-team exposure and sensitive content, so scoping and field allowlisting are first-class.
Decisions
Transport: collector dials out to the server (HTTPS, own key). No inbound port; the server holds no cluster credentials.
Trigger: on-demand snapshot at incident-open time. No continuous watch in v1 (the protocol leaves room for #44 item 2).
Intake: collector long-polls a server-side work queue.
Data v1: owner chain + pod state, K8s events, resource usage (metrics-server). No logs (#44 item 4).
Packaging: new repo terdut-collector (4th module, git.ryuvia.com/niklas/terdut-collector), own image/chart/release, deployed by terdut-operator.
Identity: new collector service-account scope, one per cluster. It can only poll its own cluster's queue, read its binding list and post results; it cannot read incidents or notes, or change config.
Redaction: typed field allowlist only.
Access model (who may see what)
Namespace binding by label. A namespace is onboarded with terdut.ryuvia.com/team=<team external_id> (e.g. kubectl label namespace payments terdut.ryuvia.com/team=payments/payments-team). Only someone able to label a namespace can expose it, and only that namespace's data is exposed. There is no TerdutTeam.spec.namespaces.
The operator is the source of bindings. It watches Namespace labels, resolves the value to a known team, and syncs the full binding set to the server (label removed = binding revoked). The collector never reports bindings, so a compromised collector cannot grant itself namespaces.
Server stores team_namespaces(team_id, cluster, namespace), unique on (cluster, namespace). Writable only by the operator's instance SA or an admin, never by team owners. A deny list (default kube-system, kube-public, kube-node-lease, terdut namespaces; configurable) refuses bindings for those names.
Confused-deputy defence in depth: (a) the server derives targets from alert labels and rejects unbound namespaces on both claim and result; (b) the collector re-checks against the server's binding list and never reads outside bound namespaces; (c) the collector key can only post results for its own cluster; (d) typed output means a forged label can yield only allowlisted fields of an object in a namespace the team owns.
Cluster identity is the existing cluster alert label (originLabel). Alerts without it are not enriched.
Snapshots are visible exactly to those who can read the incident (existing requireTeamMember, 404 for non-members).
openIncident queues a request when the alert has a cluster label and a bound namespace. Targets (namespace, pod, deployment, node, service, ...) are derived server-side and stored as plain strings.
Unbound or missing namespace: no request; a k8s_snapshot_skipped timeline event says how to onboard it.
Collector-scope endpoints: GET /api/collector/requests?wait=30s (long-poll with lease), POST /api/collector/requests/{id}/result, GET /api/collector/config (bound namespaces for its cluster). Operator-only: PUT /api/clusters/{cluster}/namespace-bindings.
Result stored as an incident_events row of type k8s_snapshot (validated JSON in detail, schema version field, ~64 KiB cap, unknown fields dropped, strings length-capped). Failures become k8s_snapshot_failed.
GET /api/incidents/{id}/context returns the parsed snapshot; "Cluster context" panel in the incident view; collector.enabled toggle.
Collector (new repo)
Static Go binary, scratch image, UID 65532; same Dockerfile/Makefile/.release.conf/Gitea workflow/chart layout as terdut-operator. Config: TERDUT_URL, TERDUT_COLLECTOR_KEY, CLUSTER_NAME.
Resolver follows only same-namespace objects (owner refs, Service selectors, Ingress/HTTPRoute backends); Node is the only cluster-scoped object. Bounded object counts, depth and timeouts.
Events via events.k8s.io for involved objects only, last ~1h, capped; messages truncated (~300 chars) and scrubbed (tokens, ://user:pass@, long base64/hex).
RBAC (read-only): get/list on pods, replicasets, deployments, statefulsets, daemonsets, jobs, services, ingresses (and httproutes if present), nodes, events, pods.metrics.k8s.io. No secrets, configmaps, pods/log, pods/exec or write verbs. Namespaced chart variant for single-namespace installs.
Operator (terdut-operator)
Namespace-label binding sync controller (RBAC already has namespaces get/list/watch); mirror the new endpoint in internal/tdclient/client.go. Unknown team value: no binding, reported as an Event.
Deploys the collector (Deployment, ServiceAccount, ClusterRole/Binding, key Secret) and mints the collector SA key, following the TerdutAlertSource secret pattern. Separate TerdutCollector CRD vs a block on TerdutServer to be decided.
Server: collector key cannot read incidents; claim/result rejected for unbound or another team's namespace; binding endpoint rejects team owners/users and deny-listed namespaces; oversized/unknown-field snapshot sanitized; non-member gets 404 on /context; unbound namespace yields k8s_snapshot_skipped.
Operator: unlabeled namespace (e.g. kube-system) gives no binding; unknown team value gives no binding; label removal revokes.
Collector: fake-clientset tests for the resolver and "label points at another namespace → refused"; golden test that Secret/env/command never appear in output.
End to end on kind: operator-deployed collector, two teams with different namespaces, crashlooping pod alert in team A's namespace produces a snapshot for A, and a forged namespace=<B's> alert through A's integration yields none.
Open items
Exact snapshot JSON schema and versioning.
Request lease/retry timings.
Whether TerdutCollector is its own CRD.
Whether an admin can write bindings through the server API on installs without the operator.
Retention: snapshots stay on the incident after a label is removed.
Version coupling: new endpoints are consumed by the collector's own client and the operator tdclient; the root CLAUDE.md coupling table needs updating when implemented.
Split out of #44 (item 1, topology-driven enrichment). **Design only, nothing is implemented yet.**
## Goal
Attach Kubernetes context captured at incident-open time to incidents: owner chain (Pod → ReplicaSet/StatefulSet/DaemonSet/Job → Deployment → Service → Ingress, plus node), K8s events for the involved objects, and a pod-state snapshot (restarts, last termination reason/exit code, container status, requests/limits vs usage). The server has no Kubernetes access and one cluster hosts many teams, so a **single shared in-cluster binary** gathers the data for all teams. The main risk is cross-team exposure and sensitive content, so scoping and field allowlisting are first-class.
## Decisions
- **Transport:** collector dials out to the server (HTTPS, own key). No inbound port; the server holds no cluster credentials.
- **Trigger:** on-demand snapshot at incident-open time. No continuous watch in v1 (the protocol leaves room for #44 item 2).
- **Intake:** collector long-polls a server-side work queue.
- **Data v1:** owner chain + pod state, K8s events, resource usage (metrics-server). **No logs** (#44 item 4).
- **Packaging:** new repo `terdut-collector` (4th module, `git.ryuvia.com/niklas/terdut-collector`), own image/chart/release, deployed by terdut-operator.
- **Identity:** new `collector` service-account scope, one per cluster. It can only poll its own cluster's queue, read its binding list and post results; it cannot read incidents or notes, or change config.
- **Redaction:** typed field allowlist only.
## Access model (who may see what)
- **Namespace binding by label.** A namespace is onboarded with `terdut.ryuvia.com/team=<team external_id>` (e.g. `kubectl label namespace payments terdut.ryuvia.com/team=payments/payments-team`). Only someone able to label a namespace can expose it, and only that namespace's data is exposed. There is no `TerdutTeam.spec.namespaces`.
- **The operator is the source of bindings.** It watches Namespace labels, resolves the value to a known team, and syncs the full binding set to the server (label removed = binding revoked). The collector never reports bindings, so a compromised collector cannot grant itself namespaces.
- **Server stores `team_namespaces(team_id, cluster, namespace)`**, unique on `(cluster, namespace)`. Writable only by the operator's instance SA or an admin, never by team owners. A deny list (default `kube-system`, `kube-public`, `kube-node-lease`, terdut namespaces; configurable) refuses bindings for those names.
- **Confused-deputy defence in depth:** (a) the server derives targets from alert labels and rejects unbound namespaces on both claim and result; (b) the collector re-checks against the server's binding list and never reads outside bound namespaces; (c) the collector key can only post results for its own cluster; (d) typed output means a forged label can yield only allowlisted fields of an object in a namespace the team owns.
- **Cluster identity** is the existing `cluster` alert label (`originLabel`). Alerts without it are not enriched.
- Snapshots are visible exactly to those who can read the incident (existing `requireTeamMember`, 404 for non-members).
## Server (terdut-server)
- Migration: `team_namespaces`, `enrichment_requests(id, incident_id, team_id, cluster, targets jsonb, status, created_at, claimed_at, done_at)`.
- `openIncident` queues a request when the alert has a `cluster` label and a bound `namespace`. Targets (`namespace`, `pod`, `deployment`, `node`, `service`, ...) are derived server-side and stored as plain strings.
- Unbound or missing namespace: no request; a `k8s_snapshot_skipped` timeline event says how to onboard it.
- Collector-scope endpoints: `GET /api/collector/requests?wait=30s` (long-poll with lease), `POST /api/collector/requests/{id}/result`, `GET /api/collector/config` (bound namespaces for its cluster). Operator-only: `PUT /api/clusters/{cluster}/namespace-bindings`.
- Result stored as an `incident_events` row of type `k8s_snapshot` (validated JSON in `detail`, schema version field, ~64 KiB cap, unknown fields dropped, strings length-capped). Failures become `k8s_snapshot_failed`.
- `GET /api/incidents/{id}/context` returns the parsed snapshot; "Cluster context" panel in the incident view; `collector.enabled` toggle.
## Collector (new repo)
- Static Go binary, `scratch` image, UID 65532; same Dockerfile/Makefile/`.release.conf`/Gitea workflow/chart layout as terdut-operator. Config: `TERDUT_URL`, `TERDUT_COLLECTOR_KEY`, `CLUSTER_NAME`.
- Resolver follows only same-namespace objects (owner refs, Service selectors, Ingress/HTTPRoute backends); Node is the only cluster-scoped object. Bounded object counts, depth and timeouts.
- Events via `events.k8s.io` for involved objects only, last ~1h, capped; messages truncated (~300 chars) and scrubbed (tokens, `://user:pass@`, long base64/hex).
- Never serialised: env vars, command/args, volume contents, annotations, non-allowlisted labels, image pull secrets, ConfigMap/Secret data.
- RBAC (read-only): get/list on pods, replicasets, deployments, statefulsets, daemonsets, jobs, services, ingresses (and httproutes if present), nodes, events, `pods.metrics.k8s.io`. **No** secrets, configmaps, pods/log, pods/exec or write verbs. Namespaced chart variant for single-namespace installs.
## Operator (terdut-operator)
- Namespace-label binding sync controller (RBAC already has namespaces get/list/watch); mirror the new endpoint in `internal/tdclient/client.go`. Unknown team value: no binding, reported as an Event.
- Deploys the collector (Deployment, ServiceAccount, ClusterRole/Binding, key Secret) and mints the `collector` SA key, following the `TerdutAlertSource` secret pattern. Separate `TerdutCollector` CRD vs a block on `TerdutServer` to be decided.
## Phasing
1. Server: migration, `collector` scope, bindings API, queue + result endpoints, validation, `/context`, docs, tests.
2. Collector repo: scaffold from the operator, resolver, snapshot structs, poll loop, chart, release pipeline.
3. Operator: label binding sync, collector deploy, tdclient.
4. TUI/web UI: render the context panel (a server without `/context` just shows no panel).
## Out of scope (v1)
Logs, Loki/Prometheus queries, continuous watch / "what changed" (#44 item 2), actions and probes (#44 item 6), Argo/Flux CRDs.
## Verification
- Server: collector key cannot read incidents; claim/result rejected for unbound or another team's namespace; binding endpoint rejects team owners/users and deny-listed namespaces; oversized/unknown-field snapshot sanitized; non-member gets 404 on `/context`; unbound namespace yields `k8s_snapshot_skipped`.
- Operator: unlabeled namespace (e.g. `kube-system`) gives no binding; unknown team value gives no binding; label removal revokes.
- Collector: fake-clientset tests for the resolver and "label points at another namespace → refused"; golden test that Secret/env/command never appear in output.
- End to end on kind: operator-deployed collector, two teams with different namespaces, crashlooping pod alert in team A's namespace produces a snapshot for A, and a forged `namespace=<B's>` alert through A's integration yields none.
## Open items
- Exact snapshot JSON schema and versioning.
- Request lease/retry timings.
- Whether `TerdutCollector` is its own CRD.
- Whether an admin can write bindings through the server API on installs without the operator.
- Retention: snapshots stay on the incident after a label is removed.
Version coupling: new endpoints are consumed by the collector's own client and the operator `tdclient`; the root `CLAUDE.md` coupling table needs updating when implemented.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Split out of #44 (item 1, topology-driven enrichment). Design only, nothing is implemented yet.
Goal
Attach Kubernetes context captured at incident-open time to incidents: owner chain (Pod → ReplicaSet/StatefulSet/DaemonSet/Job → Deployment → Service → Ingress, plus node), K8s events for the involved objects, and a pod-state snapshot (restarts, last termination reason/exit code, container status, requests/limits vs usage). The server has no Kubernetes access and one cluster hosts many teams, so a single shared in-cluster binary gathers the data for all teams. The main risk is cross-team exposure and sensitive content, so scoping and field allowlisting are first-class.
Decisions
terdut-collector(4th module,git.ryuvia.com/niklas/terdut-collector), own image/chart/release, deployed by terdut-operator.collectorservice-account scope, one per cluster. It can only poll its own cluster's queue, read its binding list and post results; it cannot read incidents or notes, or change config.Access model (who may see what)
terdut.ryuvia.com/team=<team external_id>(e.g.kubectl label namespace payments terdut.ryuvia.com/team=payments/payments-team). Only someone able to label a namespace can expose it, and only that namespace's data is exposed. There is noTerdutTeam.spec.namespaces.team_namespaces(team_id, cluster, namespace), unique on(cluster, namespace). Writable only by the operator's instance SA or an admin, never by team owners. A deny list (defaultkube-system,kube-public,kube-node-lease, terdut namespaces; configurable) refuses bindings for those names.clusteralert label (originLabel). Alerts without it are not enriched.requireTeamMember, 404 for non-members).Server (terdut-server)
team_namespaces,enrichment_requests(id, incident_id, team_id, cluster, targets jsonb, status, created_at, claimed_at, done_at).openIncidentqueues a request when the alert has aclusterlabel and a boundnamespace. Targets (namespace,pod,deployment,node,service, ...) are derived server-side and stored as plain strings.k8s_snapshot_skippedtimeline event says how to onboard it.GET /api/collector/requests?wait=30s(long-poll with lease),POST /api/collector/requests/{id}/result,GET /api/collector/config(bound namespaces for its cluster). Operator-only:PUT /api/clusters/{cluster}/namespace-bindings.incident_eventsrow of typek8s_snapshot(validated JSON indetail, schema version field, ~64 KiB cap, unknown fields dropped, strings length-capped). Failures becomek8s_snapshot_failed.GET /api/incidents/{id}/contextreturns the parsed snapshot; "Cluster context" panel in the incident view;collector.enabledtoggle.Collector (new repo)
scratchimage, UID 65532; same Dockerfile/Makefile/.release.conf/Gitea workflow/chart layout as terdut-operator. Config:TERDUT_URL,TERDUT_COLLECTOR_KEY,CLUSTER_NAME.events.k8s.iofor involved objects only, last ~1h, capped; messages truncated (~300 chars) and scrubbed (tokens,://user:pass@, long base64/hex).pods.metrics.k8s.io. No secrets, configmaps, pods/log, pods/exec or write verbs. Namespaced chart variant for single-namespace installs.Operator (terdut-operator)
internal/tdclient/client.go. Unknown team value: no binding, reported as an Event.collectorSA key, following theTerdutAlertSourcesecret pattern. SeparateTerdutCollectorCRD vs a block onTerdutServerto be decided.Phasing
collectorscope, bindings API, queue + result endpoints, validation,/context, docs, tests./contextjust shows no panel).Out of scope (v1)
Logs, Loki/Prometheus queries, continuous watch / "what changed" (#44 item 2), actions and probes (#44 item 6), Argo/Flux CRDs.
Verification
/context; unbound namespace yieldsk8s_snapshot_skipped.kube-system) gives no binding; unknown team value gives no binding; label removal revokes.namespace=<B's>alert through A's integration yields none.Open items
TerdutCollectoris its own CRD.Version coupling: new endpoints are consumed by the collector's own client and the operator
tdclient; the rootCLAUDE.mdcoupling table needs updating when implemented.