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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cf4405b
🔒 Make kwatch secure by default
abahmed Nov 30, 2026
4137e71
🧹 Let teams set retention and lock down health endpoints
abahmed Nov 30, 2026
a2f27b8
🔑 Let the installer manifests read KwatchConfig in kwatch's namespace
abahmed Nov 30, 2026
fa79217
🕵️ Catch secrets in unusual formats before they are stored
abahmed Nov 30, 2026
19235f8
🧹 Split the entropy profile classifier to satisfy lint
abahmed Nov 30, 2026
946c4f8
🔌 Let kwatch reach in-cluster receivers and probe targets on any port
abahmed Nov 30, 2026
2eb894d
🔐 Encrypt the state file at rest with a key kept in a Secret
abahmed Nov 30, 2026
0775cf1
📝 Describe the secure-by-default release and its upgrade notes
abahmed Nov 30, 2026
0b7edca
🧹 Keep the new key Secret covered by the RBAC tests and files under t…
abahmed Nov 30, 2026
d588a89
🔧 Split the state key Role from its neighbour so the chart installs
abahmed Dec 2, 2026
8999bf6
🛡️ Pick up Alpine security fixes in the image and satisfy shellcheck
abahmed Dec 2, 2026
b19d570
Merge remote-tracking branch 'origin/main' into encryption-work
abahmed Dec 2, 2026
97097f8
🔐 Give the state file's side readers the state key
abahmed Dec 2, 2026
939ffb5
🔑 Keep the digest key when the Secret is briefly unreadable
abahmed Dec 2, 2026
9499be9
✅ Cover a metrics token read from a file with a trailing newline
abahmed Dec 2, 2026
71c92ec
📝 Document the digest key fallback and the downgrade steps
abahmed Dec 2, 2026
6c20618
📝 Note one kwatch release per namespace
abahmed Dec 2, 2026
fdf7193
📝 Explain reinstalls instead of one release per namespace, and test them
abahmed Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ jobs:
# Installer checksums: the manifests kwatch.sh fetches from
# raw.githubusercontent.com/abahmed/kwatch/<tag>/, named by that
# path and hashed from the tagged blobs (the bytes raw serves).
for f in deploy/deploy.yaml deploy/crd.yaml; do
for f in deploy/deploy.yaml deploy/deploy-no-secrets.yaml deploy/crd.yaml; do
sum=$(git show "$TAG:$f" | sha256sum | awk '{print $1}')
printf '%s %s\n' "$sum" "$f"
done > "$output/SHA256SUMS"
Expand Down Expand Up @@ -917,10 +917,10 @@ jobs:
--certificate-identity-regexp='^https://github.com/abahmed/kwatch/.github/workflows/publish.yml@' \
"$dir/SHA256SUMS"
test "$(awk '{print $2}' "$dir/SHA256SUMS" | sort | tr '\n' ' ')" = \
"deploy/crd.yaml deploy/deploy.yaml "
"deploy/crd.yaml deploy/deploy-no-secrets.yaml deploy/deploy.yaml "
base="https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$TAG"
mkdir -p "$dir/deploy"
for f in deploy/deploy.yaml deploy/crd.yaml; do
for f in deploy/deploy.yaml deploy/deploy-no-secrets.yaml deploy/crd.yaml; do
curl -fsSL --retry 5 "$base/$f" -o "$dir/$f"
done
(cd "$dir" && sha256sum -c SHA256SUMS)
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ jobs:
perl -pi -e 's/^version: .*/version: "$ENV{CHART_VER}"/' deploy/chart/Chart.yaml
perl -pi -e 's/^appVersion: .*/appVersion: "$ENV{VERSION}"/' deploy/chart/Chart.yaml
perl -pi -e 's/--version [0-9]+\.[0-9]+\.[0-9]+/--version $ENV{CHART_VER}/' deploy/chart/README.md
perl -pi -e 's#image: ghcr\.io/abahmed/kwatch:[^\n]*#image: ghcr.io/abahmed/kwatch:$ENV{VERSION}#' deploy/deploy.yaml
perl -pi -e 's#image: ghcr\.io/abahmed/kwatch:[^\n]*#image: ghcr.io/abahmed/kwatch:$ENV{VERSION}#' deploy/deploy.yaml deploy/deploy-no-secrets.yaml
fi

if [ "$COMMAND" = "stable" ]; then
Expand All @@ -470,7 +470,8 @@ jobs:

# ---- commit 1: what main carries ----
git add README.md deploy/chart/Chart.yaml deploy/chart/README.md \
deploy/deploy.yaml deploy/config-catalog.tsv \
deploy/deploy.yaml deploy/deploy-no-secrets.yaml \
deploy/config-catalog.tsv \
deploy/feature-catalog.tsv deploy/provider-catalog.tsv docs/
if git diff --cached --quiet; then
echo "nothing to bump for main"
Expand All @@ -494,8 +495,8 @@ jobs:
# install a preview build. The tag therefore sits one commit ahead of
# main, which is why the stable guard compares by reachability.
if [ "$COMMAND" = "rc" ]; then
perl -pi -e 's#image: ghcr\.io/abahmed/kwatch:[^\n]*#image: ghcr.io/abahmed/kwatch:$ENV{VERSION}#' deploy/deploy.yaml
git add deploy/deploy.yaml
perl -pi -e 's#image: ghcr\.io/abahmed/kwatch:[^\n]*#image: ghcr.io/abahmed/kwatch:$ENV{VERSION}#' deploy/deploy.yaml deploy/deploy-no-secrets.yaml
git add deploy/deploy.yaml deploy/deploy-no-secrets.yaml
if git diff --cached --quiet; then
echo "::warning::deploy/deploy.yaml already pins $VERSION; nothing to add to the tag"
else
Expand Down
75 changes: 75 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

### Highlights

- **Secure by default.** A fresh install now asks for only what kwatch needs:
- **Least-privilege installer manifests.** `deploy/deploy.yaml` grants the chart's explicit list instead of `list` and `watch` on everything. `deploy/deploy-no-secrets.yaml` is the same install with no Secret access at all.
- **NetworkPolicy on by default** in the chart and the manifest. Traffic inside the cluster works on any port (`networkPolicy.allowClusterEgress`); outside the cluster kwatch reaches DNS, the API server, kubelets and HTTPS (443). Add anything else with `networkPolicy.extraEgress` or `extraEgressPorts`, or opt out with `networkPolicy.enabled: false`.
- **The digest key is in a Secret.** The key behind the hashes of Secret and ConfigMap values moves from the state file to the Secret `kwatch-digest-key`, so a copy of the state volume holds no key. An existing key is moved on first start.
- **Less leaks into the state file.** Init container arguments and connection strings in environment variables are redacted before they are cached.
- **Less access to ask for.** `watch.configmaps: false` removes ConfigMap access, and `upgrader.notifyProviders` sends the update notice to the providers you choose.

- **Control over what is kept.** `state.retention.*` sets how long resolved incidents, changes, evidence and the flight recording stay, and `state.maxSizeMiB` sets how big the state file may grow (default 512).

- **Optional state encryption.** `state.encryption.enabled: true` encrypts the state file at rest with AES-256-GCM. The key lives in the Secret `kwatch-state-key`, never on the volume. Turn it on or off at any time: kwatch converts the file in the background. If the key is missing or wrong, kwatch stops with a clear message instead of reading nothing or writing plaintext.

- **A protected `/metrics`.** `healthCheck.metricsToken` makes `/metrics` require a bearer token, and `/health` no longer shows which replica leads.

- **Better secret redaction.** High-entropy tokens in unusual formats are caught (`redact.entropy`), `redact.allow` keeps harmless values readable, and `redact.extraPatterns` adds your own.

### Editions

### Dashboard
Expand Down Expand Up @@ -237,6 +252,15 @@

### Security

- State encryption at rest is available (`state.encryption.enabled`); the key
is in the Secret `kwatch-state-key`, read and updated by that name only.

- `/metrics` can require a bearer token (`healthCheck.metricsToken`), and
`/health` no longer includes the leader's identity.

- Redaction catches secrets in unusual formats by entropy, with
`redact.allow` and `redact.extraPatterns` for tuning.

- The image upgrades its Alpine packages at build time, so it ships
Alpine's security fixes before a rebuilt base image is published. This
fixes CVE-2026-140044 in BusyBox (`busybox` and `ssl_client` 1.37.0-r32).
Expand Down Expand Up @@ -267,6 +291,57 @@

### Upgrade notes

**Behaviour changes to check before upgrading**

- **Outbound traffic outside the cluster is limited to HTTPS.** With the new
default NetworkPolicy, kwatch reaches pods and Services inside the cluster
on any port, plus DNS, the API server, kubelets and port 443 anywhere. An
active probe, proxy, alert provider or heartbeat URL that is outside the
cluster and uses a port other than 443 (SMTP, a custom webhook port) now
needs `networkPolicy.extraEgressPorts` or `networkPolicy.extraEgress`. Set
`networkPolicy.allowClusterEgress: false` to list in-cluster peers yourself,
or `networkPolicy.enabled: false` to keep the old open egress.

- **Installer manifests no longer grant `*/*`.** `deploy/deploy.yaml` lists the
resources kwatch reads. If you added your own resource kinds to the old
ClusterRole, add them again. `deploy/deploy-no-secrets.yaml` also removes
Secret reads.

- **The digest key moves to the Secret `kwatch-digest-key`.** It is created
empty by the manifests and the chart (kept on `helm uninstall`) and filled on
first start; an existing key in the state file is moved into it and removed
from the file. The key stays in the state file only while RBAC does not let
kwatch use the Secret. If the Secret is briefly unreadable on a later start,
kwatch retries, then uses a per-process key without saving it, so Secret and
ConfigMap changes made while it was down may show once.

- **Whole-line base64 log lines now show `[redacted]`.** A log line that is
only a base64 blob is replaced in evidence and messages. Use `redact.allow`
for a value that should stay readable.

- **`/metrics` token.** If you set `healthCheck.metricsToken`, update your
scraper to send `Authorization: Bearer <token>`.

- **`/health` no longer names the leader.** Anything that read the leader
identity from it should use the Lease.

- **State encryption is off by default.** Turning it on needs the Secret
`kwatch-state-key`; the manifests and chart now ship it empty.

- **Before downgrading to v1.3.0 or earlier,** set
`state.encryption.enabled=false` and let one compaction pass finish. The
pass runs at start; it is done when the log shows `state file re-sealed`
with `encrypted=false`. An older release cannot read sealed values and
treats them as corrupt. Expect one round of Secret and ConfigMap change
notices after a downgrade: the digest key moved to the Secret
`kwatch-digest-key`, so the older release makes a new one.

- **Reinstalling with Helm under a new release name.** kwatch runs once per
cluster. The key Secrets `kwatch-digest-key` and `kwatch-state-key` are kept
on uninstall and keep their fixed names, so a reinstall under the same
release name reuses them. Helm refuses a different release name in that
namespace while they exist; add `--take-ownership` to adopt them.

## v1.3.0 (2026-11-29)

### Highlights
Expand Down
1 change: 1 addition & 0 deletions cmd/kwatch/replay_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func runReplayExport(
}
sum, err := flight.Export(flight.ExportOptions{
StatePath: *state, Since: from, Until: to, Out: *dest,
Cipher: app.SideCipher(),
})
if err != nil {
_, _ = fmt.Fprintf(errOut, "replay-export: %v\n", err)
Expand Down
21 changes: 18 additions & 3 deletions deploy/chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ helm install kwatch kwatch/kwatch \
The public chart repository contains stable releases. To test a release
candidate, use its tagged Kubernetes manifests instead.

> kwatch runs once per cluster. Its key Secrets `kwatch-digest-key` and
> `kwatch-state-key` have fixed names and are kept on uninstall, so a reinstall
> under the same release name picks up the same keys. Helm refuses a different
> release name in that namespace while the old Secrets exist; add
> `--take-ownership` to adopt them and keep the encrypted state readable.

## 🔎 Verify the install

```bash
Expand Down Expand Up @@ -206,14 +212,19 @@ Karpenter annotation with `--set-string`.
| `license.key` | The license key itself (discouraged: it lands in release history). When set and `existingSecret` is empty, the chart creates the Secret `<release>-license` | `""` |
| `license.instanceSecret` | Render the license instance Secret and its Role even though no key is set through the chart (the key reaches kwatch another way). Otherwise they are rendered only with `license.key` or `license.existingSecret` | `false` |
| `config.healthCheck.statusEndpoint` | Pro only. Serve the read-only `/status` view (open incident object names, no authentication) on the health port. Off by default; with the NetworkPolicy on it is limited like the rest of the port. Reach it with `kubectl port-forward` | `false` |
| `metrics.tokenSecret.name`, `.key` | Secret holding a bearer token. When set, `/metrics` needs `Authorization: Bearer <token>`; `/healthz` and `/readyz` stay open. Unset leaves `/metrics` open | `{}` |
| `config.state.retention.incidents` / `.changes` / `.evidence` / `.recording` | How long resolved incidents, changes, log and termination evidence, and the flight recording are kept (durations such as `168h`; ranges in the config reference). Restart to change | `168h` / `168h` / `720h` / `48h` |
| `config.state.encryption.enabled` | Encrypt the state file at rest with AES-256-GCM. The key is stored in the Secret `kwatch-state-key` in the release namespace. Enabling encrypts the existing file during the next compaction pass; disabling writes it back plain (the key must still be in the Secret). A missing or wrong key stops kwatch with a clear error. Restart to change | `false` |
| `config.state.maxSizeMiB` | Size the state file is kept under, 256 to 16384; keep it at or under a quarter of the volume. Restart to change | `512` |
| `config.healthCheck.port` | Health port: container, probe and NetworkPolicy port. The health check cannot be disabled | `8060` |
| `networkPolicy.enabled` | Render a NetworkPolicy that admits the health port (own namespace, `kubeletCIDRs` and `healthIngressFrom` only) and allows DNS, `networkPolicy.apiServerPorts` and kubelet (`networkPolicy.kubeletPort`, default 10250) egress | `false` |
| `networkPolicy.allowDefaults` | The dashboard ingress rules render whenever `networkPolicy.enabled` and `dashboard.enabled` are set, whatever this value is. With `false` you must give `ingress`/`egress`, `extraEgressPorts` or `allowProbeEgressAll`, or the render fails (an empty policy would deny all traffic and kwatch could not start). Admit the health port and open DNS, `apiServerPorts`, kubelet and DNS metrics egress. `false` only when your own rules cover the API server, kubelets and probes. With `license.key` or `license.existingSecret` set it also opens TCP 443 to any address for license activation and renewal, even if `apiServerPorts` omits 443 | `true` |
| `networkPolicy.enabled` | Render a NetworkPolicy that admits the health port (own namespace, `kubeletCIDRs` and `healthIngressFrom` only) and allows DNS, external HTTPS (443), `networkPolicy.apiServerPorts` and kubelet (`networkPolicy.kubeletPort`, default 10250) egress. On by default; `false` opts out. Kubelet probes need no rule, since Kubernetes does not let a policy block a pod's own node | `true` |
| `networkPolicy.allowDefaults` | The dashboard ingress rules render whenever `networkPolicy.enabled` and `dashboard.enabled` are set, whatever this value is. With `false` you must give `ingress`/`egress`, `extraEgressPorts` or `allowProbeEgressAll`, or the render fails (an empty policy would deny all traffic and kwatch could not start). Admit the health port and open DNS, `apiServerPorts`, kubelet and DNS metrics egress. `false` only when your own rules cover the API server, kubelets and probes. TCP 443 is always opened to any address for `api.kwatch.dev`, `api.github.com` and HTTPS providers, even if `apiServerPorts` omits 443 | `true` |
| `networkPolicy.apiServerPorts` | TCP ports open to any address for the API server and HTTPS providers; at least one is required (an empty list would open all egress) | `[443, 6443]` |
| `networkPolicy.kubeletPort` | Kubelet HTTPS port opened for node stats | `10250` |
| `networkPolicy.dnsMetricsPort` | Cluster DNS metrics port opened to the DNS pods in `kube-system` (DNS request and SERVFAIL rates); `0` omits it | `9153` |
| `networkPolicy.allowClusterEgress` | With `allowDefaults`, allow egress to pods in any namespace on any port, so in-cluster alert receivers, probe targets and Services work without extra rules. External egress stays limited to 443 and what you open. `false` to list in-cluster peers yourself in `extraEgress` | `true` |
| `networkPolicy.allowProbeEgressAll` | Allow all egress from the pod. Needed for active probes, `autoServices`, `autoDependencies`, a proxy or providers on unusual ports unless you open them one by one; `helm install` warns when these are configured with the policy on | `false` |
| `networkPolicy.ingress` / `networkPolicy.egress` | Extra full NetworkPolicy rules, for example to limit a port to one address | `[]` |
| `networkPolicy.ingress` / `networkPolicy.extraEgress` / `networkPolicy.egress` | Extra full NetworkPolicy rules appended to the defaults, for example to limit a port to one address (`egress` is the older name of `extraEgress`; both render) | `[]` |
| `networkPolicy.extraEgressPorts` | Extra TCP egress ports open to any address, for providers not on 443: SMTP (`25`, `465` or `587`) for email, or a webhook's custom port | `[]` |
| `networkPolicy.kubeletCIDRs` | Node address ranges the kubelet egress rule is limited to; empty allows any address. Also admitted to the health port, for kubelet probes on a network plugin that enforces policy on node traffic | `[]` |
| `networkPolicy.healthIngressFrom` | Extra peers (`namespaceSelector`, `podSelector` or `ipBlock`) that may reach the health port (`/health`, `/metrics`, `/status`), such as your Prometheus namespace. Without it only pods in the release namespace (and `kubeletCIDRs`) can | `[]` |
Expand All @@ -226,6 +237,9 @@ Karpenter annotation with `--set-string`.
| `dashboard.existingSecret` | Existing Secret with the keys `password` (sign-in) and `token` (API bearer token). Without it the chart ships `<release>-dashboard` empty and kwatch writes a generated password (`X FB59 XXX-XXXX-XXXX-XXXX`) and token into it once, so every renderer (`helm template`, Argo CD, Flux) sees the same manifest and the values never change. kwatch gets and updates only that Secret. Edits take effect after a restart; changing the password signs everyone out | `""` |
| `config.investigation.logs` | Pro evidence reads container logs (redacted, bounded). `false` reads none and the dashboard shows the log section as turned off | `true` |
| `config.investigation.sampleLogs` | Samples a bounded slice of the logs of Running and Ready pods for a burst of errors (redacted). `false` reads none | `true` |
| `config.redact.entropy` | Redacts tokens that look random, such as keys in formats no pattern knows. Set `false` to turn it off | `true` |
| `config.redact.allow` | Patterns (whole-token match) whose tokens the entropy rule keeps | `[]` |
| `config.redact.extraPatterns` | Your own redaction patterns (`name`, `pattern`; at most 20): every match is redacted and group 1 stays visible. A bad pattern stops startup | `[]` |
| `dashboard.networkPolicyFrom` | With `networkPolicy.enabled`: extra peers (your ingress controller, `ipBlock`s for load balancer clients) allowed to reach the dashboard port. The release namespace and `healthIngressFrom` always may | `[]` |

Sign-ins last 12 hours. A password change or a kwatch restart (upgrade,
Expand Down Expand Up @@ -258,6 +272,7 @@ pointing at Service `<release>-dashboard` (port name `dashboard`).
| `persistence.flightRecorderText` | Keep scrubbed log error lines, event and condition messages in the flight recording `kwatch replay-export` exports (names, hosts, emails, images and credentials inside them hidden); `false` drops all free text. Sets `KWATCH_FLIGHT_TEXT` | `true` |
| `persistence.emptyDirSizeLimit` | `sizeLimit` of the `emptyDir`; also passed to kwatch as `KWATCH_VOLUME_LIMIT` so the startup rewrite checks the real limit | `2Gi` |
| `watch.secrets` | Watch Secrets; `false` removes all Secret RBAC (in both `rbac.mode` values) and Secret-based checks report that they cannot verify. Secrets are watched by default, which lets the kwatch ServiceAccount list and watch Secrets cluster-wide; set `watch.secrets: false` to remove all Secret RBAC and the Secret watch. | `true` |
| `watch.configmaps` | Watch ConfigMaps; `false` removes all ConfigMap RBAC (in both `rbac.mode` values) and ConfigMap-based checks report that they cannot verify | `true` |
| `resources` | CPU and memory requests/limits; the chart sets `KWATCH_MEMORY_LIMIT` from the memory limit and kwatch sets the Go soft limit to 90% of it. Live heap is about 24 KB per pod: the default 512Mi suits about 5,000 pods comfortably and 8,000 at the edge, 10,000 pods need `768Mi` and 20,000 need `1Gi` (see docs/production-operations.md, Memory) | `100m` CPU and `128Mi` memory request (raise it to `256Mi` or more with the limit on bigger clusters), `500m` CPU and `512Mi` memory limit |
| `securityContext.runAsUser` / `securityContext.runAsGroup` | Numeric user and group of the container; they match the image's `kwatch` user | `1000` / `1000` |
| `podSecurityContext.fsGroup` | Group that owns the state volume | `1000` |
Expand Down
4 changes: 2 additions & 2 deletions deploy/chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ deploy/crd.yaml yourself. Set crd.install=false to silence this note.
{{- if and $np.enabled (not $np.allowProbeEgressAll) (or $probes.enabled $app.proxyURL) }}

WARNING: networkPolicy.enabled=true limits egress to DNS, the API server
ports, the kubelet and the DNS metrics port, but your configuration makes
kwatch dial other addresses:
ports, the kubelet, the DNS metrics port and pods in the cluster, but your
configuration may make kwatch dial other addresses outside the cluster:
{{- if $probes.enabled }}
- activeProbeMonitor targets (http, tcp, dns{{ if $probes.autoServices }}, autoServices{{ end }}{{ if $probes.autoDependencies }}, autoDependencies{{ end }}) are blocked and report as down.
{{- end }}
Expand Down
Loading
Loading
0