# Operate Kavach Enterprise

> Probes, the full metrics catalog, alerts worth setting, sizing, network requirements, what happens when something fails, and how to troubleshoot a daemon that will not start.

This page is for whoever runs `kavach-daemon` in production. It covers what the daemon exposes, what to watch, and how it behaves when its dependencies fail.

## Probes

The shadow healer and the live gateway serve three unauthenticated endpoints on `--metrics-addr`. The operator has no HTTP listener; its reference manifest probes it by running `kavach-daemon --sample-memory`.

| Endpoint | `200` when | `503` reasons |
| --- | --- | --- |
| `GET /healthz` | The process is running and not fenced. | `shutting_down`, `node_fenced` |
| `GET /readyz` | Storage has passed the startup contract probe. | `shutting_down`, `node_fenced`, `storage_not_probed`, `insufficient_live_fleet_nodes`, `fleet_lease_scan_failed: …` |
| `GET /metrics` | Always. | — |

A failing probe returns JSON with the reason, for example:

```json
{"status":"not_ready","ready":false,"reason":"storage_not_probed"}
```

Use `/healthz` for the liveness probe and `/readyz` for readiness. A **fenced** node is one that lost its lease to another node; it stops releasing effects at once, and liveness fails so Kubernetes replaces it.

## Metrics

Prometheus text format, version 0.0.4. Every metric is per daemon process, with no labels; Prometheus adds `pod` and `namespace` when it scrapes.

| Metric | Type | Meaning |
| --- | --- | --- |
| `kavach_capsules_cut_total` | counter | Incident fixtures cut from the recorder rings. |
| `kavach_shadow_scanned_total` | counter | Fixtures scanned by the shadow healer. |
| `kavach_proven_prs_total` | counter | Pull requests opened for fixes that passed every proof. |
| `kavach_steps_total` | counter | Steps processed by the live gateway. |
| `kavach_released_emits_total` | counter | Effects released after a step passed. |
| `kavach_aborted_emits_total` | counter | Effects withheld because the step failed or the node was fenced. |
| `kavach_quarantined_entities` | gauge | Entities currently in quarantine. |
| `kavach_diverted_events_total` | counter | Events for a quarantined entity, held for the drain. |
| `kavach_tracked_cells` | gauge | Entities the gateway holds in memory. |
| `kavach_evicted_cells_total` | counter | Idle healthy entities evicted from memory. |
| `kavach_active_connections` | gauge | Open gateway connections (TCP and Unix socket). |
| `kavach_rejected_connections_total` | counter | Connections refused at the connection cap. |
| `kavach_auth_rejected_total` | counter | Requests or connections refused by authentication. |
| `kavach_node_authoritative` | gauge | `1` while this daemon holds the node lease. |
| `kavach_cgroup_working_set_bytes` | gauge | The daemon's cgroup working set, or its RSS outside a cgroup. |

## Alerts worth setting

```yaml
groups:
  - name: kavach
    rules:
      - alert: KavachNotReady
        expr: kube_pod_container_status_ready{container="kavach-daemon"} == 0
        for: 5m
      - alert: KavachEntityQuarantined
        expr: kavach_quarantined_entities > 0
        for: 1m
        labels: { severity: page }
      - alert: KavachLostLease
        expr: max by (pod) (kavach_node_authoritative) == 0
        for: 2m
      - alert: KavachAuthRejections
        expr: rate(kavach_auth_rejected_total[5m]) > 0
      - alert: KavachConnectionCapReached
        expr: rate(kavach_rejected_connections_total[5m]) > 0
      - alert: KavachNearMemoryLimit
        expr: >
          kavach_cgroup_working_set_bytes
            / on (pod) kube_pod_container_resource_limits{container="kavach-daemon", resource="memory"} > 0.8
        for: 10m
```

`kavach_quarantined_entities > 0` is the one that matters most: a customer's events are being held, and they stay held until a fix ships and the entity is drained. `kavach_node_authoritative` applies to the live gateway; the shadow healer does not take a node lease. The `kube_*` series come from kube-state-metrics.

## Sizing

The reference manifests start from these values. Adjust using `kavach_cgroup_working_set_bytes` under your own traffic.

| Container | Requests | Limits |
| --- | --- | --- |
| `kavach-daemon` (sidecar) | 250m CPU, 256Mi | 1 CPU, 512Mi |
| `kavach-operator` | 100m CPU, 128Mi | 500m CPU, 512Mi |
| Shared-memory volume (`kavach-shm`) | — | 256Mi, counted against the pod's memory |

What drives each number:

- **CPU** is spent mostly on replay: proving a fix runs the old and new builds over the incident, its variants and the vault. It is bursty and idle between incidents.
- **Memory** in the live gateway grows with `kavach_tracked_cells`. Cap it with `--max-tracked-cells`, and evict idle healthy entities sooner with `--normal-cell-idle-ttl-ms`.
- **Memory pressure** is measured against the cgroup. By default the daemon treats 80% of `--total-memory-bytes` as high and 95% as the hard ceiling; `--max-rss-mb` sets the high mark directly. `kavach-daemon --sample-memory` prints the current reading.
- **Bucket growth** is one scrubbed archive per distinct incident, plus the audit trail. Duplicate incidents are not uploaded again.

## Network

The daemon needs only these destinations. Everything else can be denied.

| Destination | Port | Needed for |
| --- | --- | --- |
| Your object storage endpoint | 443 | Always: fixtures, vault, coordination, audit. |
| Cloud credential endpoints (EKS Pod Identity, GKE metadata server) | 80 or 443 | When you use workload identity. |
| GitHub API (`--github-api-base`, default `api.github.com`) | 443 | Only when the daemon opens pull requests. |
| Your webhook (`--webhook-url`) | 443 | Only when you configure one. |
| Kubernetes API server | 443 or 6443 | Operator only. |
| DNS | 53 | Always. |

Kavach sends nothing to Kavach Labs: there is no telemetry and no licence check that calls home. See [Data handling](https://www.thekavachlabs.com/docs/enterprise/data-handling) for exactly what goes to each destination.

## When something fails

| What fails | What the daemon does | Effect on your service |
| --- | --- | --- |
| **Storage unreachable at startup** | The contract probe is retried, then the daemon exits with code `1`. It never runs against a store it has not verified. | Shadow mode: none, the service keeps running; the pod reports the daemon container as not ready and restarting. |
| **Storage unreachable later** | The error is logged and the pass is retried on the next poll (`--poll-ms`). Fixtures already cut stay in the fixtures directory, in pod memory. | None in shadow mode. |
| **Shadow daemon crashes or is OOM-killed** | Kubernetes restarts the container. The recorder rings live in the shared volume, so incidents recorded meanwhile are still there. | None: shadow mode only reads the recordings. |
| **Service container killed** (`OOMKilled`, `SIGKILL`) | The daemon still has the tail of the recording and cuts the fixture. | — |
| **Another node takes the lease** | This node is fenced: it withholds every pending effect (`kavach_aborted_emits_total`), and `/healthz` fails. | Pending effects of the fenced node are never released twice. |
| **Ambiguous storage write** (a timeout after the store may have applied it) | Every coordination write is conditional, so a retried write cannot create a second writer. Deterministic simulation tests this case on every build. | — |
| **`SIGTERM`** | The daemon stops taking work, `/readyz` and `/healthz` report `shutting_down`, and it exits after the current pass. | — |

The live gateway sits on the path of each step's effects, so plan for it as you would any in-pod proxy: run it in the same pod as the service, and alert on readiness.

## Troubleshooting

**The daemon exits at startup with `storage contract probe failed`.** Run the probe on its own to see which step fails:

```bash
kavach-daemon --diagnose-storage s3://acme-kavach/prod --region us-east-1
```

A working bucket prints:

```text
ok bucket conditional write (create, reject-create, update, reject-stale) and range
```

| Failure | Usual cause |
| --- | --- |
| `403` on create or read of a missing key | The role lacks `s3:ListBucket` (S3) or `storage.objects.list` (GCS), so a missing key is reported as forbidden. See [Storage](https://www.thekavachlabs.com/docs/enterprise/storage). |
| `reject-create` or `reject-stale` step fails | The store does not honour conditional writes. Some S3-compatible stores do not; the daemon refuses to run on them. |
| Fails against Azure with both credentials set | Set either `AZURE_STORAGE_SAS_TOKEN` or `AZURE_STORAGE_ACCOUNT_KEY`, not both. |
| Works with `--read-only` only | The credentials can read but not write. |

**The daemon exits with code `2`.** A flag is wrong, or a secret was passed on the command line. Secrets must come from the environment or a file; see [Security](https://www.thekavachlabs.com/docs/enterprise/security#secrets).

**`/readyz` stays `storage_not_probed`.** The startup probe has not passed yet. Check the container log for the probe's error.

**No fixtures appear in the bucket.** Check that the service and the daemon mount the same shared-memory volume at the same path, that the service sets `KAVACH_SHM_DIR`, and that `kavach_capsules_cut_total` increases when the service fails. If it does but nothing is uploaded, the scrubbed fixture may no longer reproduce the failure: the daemon then refuses to upload it and records the fixture as `rejected_unverified`. Try the key-denylist-only scrubbing mode described in [Security](https://www.thekavachlabs.com/docs/enterprise/security#sensitive-data-in-fixtures).

**The operator does not create a sidecar.** Read the resource's conditions:

```bash
kubectl describe protectedservice payments -n payments
```

A rejected spec (running as root, privileged, writable root filesystem) is reported there with the reason.

Source: https://www.thekavachlabs.com/docs/enterprise/operations
