# Storage

> Point Kavach Enterprise at AWS S3, Cloudflare R2, Azure Blob Storage or Google Cloud Storage, check the bucket, and give it the smallest set of permissions it needs.

Kavach Enterprise keeps fixtures, the immunity vault, fleet coordination state and the audit trail in **your** object storage. Nothing leaves your account. The daemon talks to each provider's API directly, with no cloud SDK in the image.

| Provider | Bucket URI |
| --- | --- |
| AWS S3 | `s3://bucket/prefix` |
| Cloudflare R2 and other S3-compatible stores | `s3://bucket/prefix` with an endpoint |
| Azure Blob Storage | `az://container/prefix` |
| Google Cloud Storage | `gs://bucket/prefix` |

Prefix segments may contain only `A–Z a–z 0–9 . _ -`. Never put credentials or query strings in a bucket URI.

## Check the bucket first

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

This runs the same probe every daemon runs at startup: a four-step conditional write (create-if-absent, then compare-and-swap) and a bounded range read. Kavach relies on conditional writes to guarantee a single writer per entity; a store that does not honour them fails the probe, and the daemon will not start against it. Add `--read-only` to check read access only.

## Credentials

Credentials come from the environment or from files, never from command-line flags.

### AWS S3 and R2

| Variable | Meaning |
| --- | --- |
| `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN` | Static or temporary keys. |
| `AWS_REGION` | Region; `auto` for R2. Default `us-east-1`. |
| `AWS_ENDPOINT_URL` | Required for R2 and other S3-compatible endpoints. |
| `AWS_CONTAINER_CREDENTIALS_FULL_URI`, `AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE` | EKS Pod Identity. |

Minimal IAM policy, scoped to one prefix:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:ListBucket"],
      "Resource": "arn:aws:s3:::acme-kavach",
      "Condition": { "StringLike": { "s3:prefix": ["prod", "prod/*"] } }
    },
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
      "Resource": "arn:aws:s3:::acme-kavach/prod/*"
    }
  ]
}
```

`s3:ListBucket` is needed so that reading a missing key returns `404` rather than `403`.

### Azure Blob Storage

| Variable | Meaning |
| --- | --- |
| `AZURE_STORAGE_ACCOUNT_NAME` | Storage account. |
| `AZURE_STORAGE_SAS_TOKEN` | A container-scoped SAS with `rwdl` permissions. Recommended. |
| `AZURE_STORAGE_ACCOUNT_KEY` | Shared key. Grants account-wide access; use a dedicated account. |
| `AZURE_STORAGE_ENDPOINT` | Sovereign clouds, private endpoints. |

Set either the SAS token or the account key, not both: the daemon refuses to start with both.

### Google Cloud Storage

| Variable | Meaning |
| --- | --- |
| `GOOGLE_APPLICATION_CREDENTIALS` | Service account JSON key. |
| `GCS_OAUTH_TOKEN` | A short-lived bearer token; overrides the key when set. |
| `GCE_METADATA_HOST` | GKE Workload Identity. |
| `GCS_ENDPOINT` | Custom or private endpoint. |

The service account needs only `storage.objects.create`, `delete`, `get` and `list`, bound on the one bucket. Both `create` and `delete` are required for conditional overwrites.

## What is stored

| Prefix | Contents |
| --- | --- |
| incident archives (`.kar`) | Scrubbed fixtures, with what is needed to replay them. |
| vault | Past incidents replayed against every new fix. |
| `fleet/` | Capacity samples and rolling-upgrade coordination. |
| `audit/<service>/` | The hash-chained audit trail: a head object and write-once entries. |

Old epochs are reclaimed by a garbage collector that is safe under the stores' list-after-write behaviour.

## Recommendations

- One bucket (or prefix) per environment.
- Turn on server-side encryption and block public access.
- Do not put a lifecycle expiry on the audit prefix.

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