8000 🔒 Make kwatch secure by default by abahmed · Pull Request #632 · abahmed/kwatch · GitHub
[go: up one dir, main page]

Skip to content

🔒 Make kwatch secure by default - #632

Merged
abahmed merged 18 commits into
mainfrom
secure-defaults
Dec 2, 2026
Merged

abahmed merged 18 commits into
mainfrom
secure-defaults

Conversation

@abahmed
@abahmed abahmed commented Nov 30, 2026 •
Copy link
Copy Markdown
Owner

Makes kwatch secure by default for the next release.

Changes

  1. Installer manifest least privilege. deploy/deploy.yaml no longer grants */* list/watch; its ClusterRole is the chart's rbac.mode=least-privilege list (custom resources behave as in that mode: permission_denied in /health coverage; Helm rbac.mode=full stays for CRDs). New deploy/deploy-no-secrets.yaml is the same file without Secret access (no secrets in the ClusterRole, KWATCH_WATCH_SECRETS=false); an architecture test keeps the two identical apart from that. Release/publish workflows, SHA256SUMS and check-release-consistency.sh now cover the variant.
  2. NetworkPolicy on by default in the chart (networkPolicy.enabled: true) and mirrored in both manifests. Ingress to 8060 from the release namespace only (kubelet probes need no rule: Kubernetes never blocks a pod's own node; kubeletCIDRs stays for plugins that do). Egress: DNS, API server ports, kubelet 10250, CoreDNS 9153 (kube-dns pods only) and 443 always (api.kwatch.dev, api.github.com, providers). Opt out with networkPolicy.enabled=false; new networkPolicy.extraEgress (old egress still renders).
  3. Digest key moved out of the state file into Secret kwatch-digest-key (shipped pre-created and empty by the chart and both manifests, helm.sh/resource-policy: keep). Role grants get/update on that name only, no create (RBAC cannot scope create by name; same pattern as the license instance Secret). kwatch still creates the Secret if it is missing and allowed. An existing key is migrated into the Secret on first start (digests stay stable) and then deleted from state; if the Secret cannot be used the key stays in the state file.
  4. Init container command/args are redacted with internal/redact before caching (init_wait still reads them). Env values kept for dependency checks now store only host:port (no user, password, path, query); URL userinfo is stripped from other kept values.
  5. watch.configmaps (chart value, config key, KWATCH_WATCH_CONFIGMAPS, RBAC), default true. False removes ConfigMap RBAC and the watch; coverage shows disabled_by_config and dependent checks report they cannot verify, like watch.secrets=false.
  6. upgrader.notifyProviders: [...] routes the update notice to the named providers (empty = all). Names must be configured under alert, validated.

Generated references, chart README/values/schema, docs and RELEASES.md updated.

What kwatch.sh must do (kwatch.dev/apps/web, not changed here)

  • Ask whether to allow Secret access, explaining it enables certificate expiry, missing/rotated Secret and pull-secret causes; declining keeps those checks reporting "cannot verify".
  • Allow: apply deploy/deploy.yaml. Decline: apply deploy/deploy-no-secrets.yaml. Both are fetched from the release tag and verified through SHA256SUMS, which now lists deploy/deploy-no-secrets.yaml too (publish.yml's expected-list check was updated). Releases before this one lack the file, so 8000 only offer the choice for versions that have it.
  • Switching later: apply the other manifest (it also changes the KWATCH_WATCH_SECRETS env). Stop printing "turn this off with watch.secrets"; with the variant the RBAC is actually removed.
  • Do not apply the manifest with a prune that would delete kwatch-digest-key or kwatch-license-instance.

Checks run

Targeted Go tests (config, config/crd, delivery, upgrader, inventory/kube, app, architecture), deploy/chart/test_helm.sh, manifest parity, release consistency, line-check, diff-check, docs-verify.

CI must verify

Full make ci, e2e (label e2e): kind runs with the new NetworkPolicy and manifest RBAC, and test_helm_upgrade.sh/lifecycle need a cluster. Active probes, non-443 providers and proxies need extraEgress/extraEgressPorts now.

Also in this PR

  • Configurable retention and state size: state.retention.{incidents,changes,evidence,recording}, state.maxSizeMiB (startup only).
  • Optional bearer token for /metrics (healthCheck.metricsToken / KWATCH_METRICS_TOKEN, chart metrics.tokenSecret).
  • /health no longer shows the leader pod identity or a raw leadership-loss reason.
  • Installer manifests get a namespaced Role to read KwatchConfig (the old */* rule covered it).
  • Better log redaction: entropy-based detection on by default (redact.entropy), redact.allow, redact.extraPatterns, new bare-format patterns; whole-line base64 now shows [redacted].

@abahmed abahmed added the e2e Run the real-cluster E2E suite on this pull request label Nov 30, 2026
# Conflicts:
#	Dockerfile
#	RELEASES.md
#	docs/configuration.md
Retry the Secret read, never save a new key after a failed read, and
re-read the Secret when another writer stored a key first.
@abahmed
abahmed merged commit a600f46 into main Dec 2, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e Run the real-cluster E2E suite on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0