# Upgrades & monitoring

Day-2 operations: how to upgrade to a new chart version and what to monitor once the vault is running.

## Helm upgrade flow

Every released chart version selects a tested set of service images. Keep those image coordinates
aligned with the chart. When Sodot publishes a new version, review its migration notes first, then
pull the new chart and run `helm upgrade` on each cluster. When no release-specific migration applies,
use the flow below.

### Prepare clients and approval policies

Before moving to an application release with the v0.6 API, review its [client migration notes](/releases/api#v06). Update clients for count-based vault/group responses, flat request-status responses, and signing requests that can wait for approval. Review approval thresholds and expiry windows in your policies.

Use a chart release that explicitly supports the target application version. Do not assume that overriding image tags on an older chart supplies the new release's configuration and dependencies. Review release-specific data-migration and rollback instructions before applying the upgrade.

After upgrading, [check transaction-service availability](/deploy/feature-availability) through `GET /v1/system-info`. Chart `0.1.24` deploys API release 0.7, which supports managed transfers, balances, and supported network fee sponsorship once you [enable transaction services](/deploy/feature-availability#enable-transaction-services).

### Upgrade to Crypto Vault 0.7

Crypto Vault 0.7 moves backup recipients from the Key Store to named [backup encryption-key entries](/deploy/operations/backup-dr#backup-encryption-key-entries) on the Policy Server. Its database migration runs when the new services first start. After it, existing vaults and `offchain` have **no backup assignment**, so backup exports fail until you configure entries and assign them. Signing, key creation, and other operations are unaffected. Upgrade from chart `0.1.23`; see the [chart 0.1.24 release notes](/releases/helm#0124).

1. Back up each cluster's databases. Plan any rollback from these backups: the previous release does not keep backup entries, assignments, or backup permissions scoped to specific vaults.
2. Add `policyServer.backupEncryptionKeys` to the values for **every** cluster, with the same entries on each. To keep using your current recovery keys, create one entry whose `hpke` keys are the existing `mpcKeyStores[].backupEncryptorPublicKey` values, each under its shard name (`mpc-ks-0`, `mpc-ks-1`, `mpc-ks-2`):

   ```yaml
   policyServer:
     backupEncryptionKeys:
       - entryName: primary
         keys:
           mpc-ks-0: { encryptionScheme: hpke, publicKey: "<current shard-0 backupEncryptorPublicKey>" }
           mpc-ks-1: { encryptionScheme: hpke, publicKey: "<current shard-1 backupEncryptorPublicKey>" }
           mpc-ks-2: { encryptionScheme: hpke, publicKey: "<current shard-2 backupEncryptorPublicKey>" }
   ```

   With the example Terraform, set the same entry once in `backup_encryption_keys` instead; it writes the entries into every cluster's values file:

   ```hcl
   backup_encryption_keys = [
     {
       entry_name = "primary"
       keys = {
         "mpc-ks-0" = { encryption_scheme = "hpke", public_key = "<current shard-0 backupEncryptorPublicKey>" }
         "mpc-ks-1" = { encryption_scheme = "hpke", public_key = "<current shard-1 backupEncryptorPublicKey>" }
         "mpc-ks-2" = { encryption_scheme = "hpke", public_key = "<current shard-2 backupEncryptorPublicKey>" }
       }
     },
   ]
   ```

   The Key Store no longer reads `mpcKeyStores[].backupEncryptorPublicKey` from 0.7, so you can remove it from your values and from `mpc_key_stores`.
3. Update the Terraform module or example to `0.1.24` and apply it, then upgrade every cluster to chart `0.1.24`, spokes first and hub last, as in [Within a major version](#within-a-major-version).
4. In Administrative Policy, grant **Configure Vault Backup Encryption Keys** to the group that manages backup recipients. Existing **Access Keys Backup** rules now apply to every vault; narrow them to specific vaults if needed. See [Administrative Policy actions](/guide/admin-policy/understanding).
5. Assign an entry to every vault and to `offchain` with `PUT /v1/vaults/{vault_id}/backup-encryption-keys`. See [Assign an entry to a vault](/develop/backup-export#assign-an-entry-to-a-vault).
6. Update scheduled backup jobs to export explicit scopes and to parse backup format 3, as described in the [0.7 migration notes](/releases/api#v07). Run one export and verify the archive before relying on the schedule.

### Within a major version

For a chart-only upgrade with no documented Terraform or data migration, you can upgrade directly
from any minor or patch version to any later version within the same major:

```bash
helm registry login repo.sodot.dev -u <your-username>
helm pull oci://repo.sodot.dev/sodot-helm-charts/crypto-vault --version <new-version>

# Upgrade clusters in order: spokes first, hub last
helm upgrade crypto-vault ./crypto-vault-<new-version>.tgz \
    --kubeconfig ./out/cluster-0.kubeconfig \
    --namespace crypto-vault \
    -f ./out/cluster-0.values.yaml

helm upgrade crypto-vault ./crypto-vault-<new-version>.tgz \
    --kubeconfig ./out/cluster-2.kubeconfig \
    --namespace crypto-vault \
    -f ./out/cluster-2.values.yaml

# Hub last (Orchestrator is here; upgrade it after spokes are ready)
helm upgrade crypto-vault ./crypto-vault-<new-version>.tgz \
    --kubeconfig ./out/cluster-1.kubeconfig \
    --namespace crypto-vault \
    -f ./out/cluster-1.values.yaml
```

If `chart_ha = false`, append `-f ./out/extra.values.yaml` to every command.

:::note
Upgrade spokes before the hub. The Orchestrator (on the hub) is upgraded last so that spoke Key Store and Policy Server pods are already running the new version before the Orchestrator restarts.
:::

### Upgrading the Policy Server signature quorum

This procedure requires chart and Terraform module `0.1.22` or later.

If your previous chart or saved values set `policyServer.approvalThreshold` to `1`, migrate every
cluster to the strict majority of Policy Servers. The updated chart rejects `1`. The hub derives its
threshold when the value is unset or `null`; spokes require an explicit threshold matching the hub.
For three Policy Servers, the quorum is `2`; for four or five, it is `3`.

1. Remove stale `1` overrides from your values files and Terraform inputs. If you use the example
   Terraform, update its source and regenerate the cluster handoff values. The module input is
   `bootstrap_approval_threshold`: use `null` for hub derivation and an explicit matching quorum on
   spokes. Keep an explicit quorum on every cluster during the initial setup stage, when the
   Orchestrator is disabled.
2. Upgrade spokes first, then the hub, using the corrected values. Wait for each cluster's Policy
   Server and Key Store rollout to finish before proceeding.
3. Verify the rendered and running configuration on every cluster uses the same numeric quorum
   and complete Policy Server membership; the hub's saved value may remain `null`. Older verifiers
   left at `1` may remain permissive, while others can fail startup. Treat the rollout as incomplete
   until every cluster uses the correct quorum.

`--reuse-values` can retain an old chart's default of `1`, even if you never set it explicitly.
Use `--reset-then-reuse-values` without `--reuse-values` or `--reset-values`, and override the
threshold explicitly. This preserves other saved settings while adopting the new chart defaults.
For the three-cluster example, where cluster `1` is the hub:

```bash
# Stop if a cluster upgrade fails before proceeding to the next cluster.
set -e

# Spokes: require the hub's quorum on both clusters.
for cluster in 0 2; do
  helm upgrade crypto-vault ./crypto-vault-<new-version>.tgz \
      --kubeconfig "./out/cluster-${cluster}.kubeconfig" \
      --namespace crypto-vault \
      --reset-then-reuse-values \
      -f "./out/cluster-${cluster}.values.yaml" \
      --set policyServer.approvalThreshold=2 \
      --wait
done

# Hub: derive its strict majority from the complete Policy Server topology.
helm upgrade crypto-vault ./crypto-vault-<new-version>.tgz \
    --kubeconfig ./out/cluster-1.kubeconfig \
    --namespace crypto-vault \
    --reset-then-reuse-values \
    -f ./out/cluster-1.values.yaml \
    --set policyServer.approvalThreshold=null \
    --wait
```

If `chart_ha = false`, append `-f ./out/extra.values.yaml` to each command before `--set`.
For a larger topology, replace the spoke value `2` with the hub's strict majority. You may also
set that same numeric value explicitly on the hub. Keep the corrected settings in your values
files so subsequent upgrades retain them. See the
[Helm values reference](/deploy/helm/values-reference#policy-server-signature-quorum).

### Across major versions

A routine chart upgrade uses one `helm upgrade` to roll every service to the chart-selected compatible
image set, including any explicitly qualified overrides. Keep that set aligned; there is no separate
reader/writer staging step to run by hand. Kubernetes performs a rolling update per service, and
signing stays available as long as the cross-cluster threshold holds. Release-specific infrastructure
or data migrations can require a maintenance window and take precedence over this routine flow.

Breaking format changes are confined to major versions. **Move one major at a time; you cannot skip a major version.**

Example: upgrading from `2.3.1` to `6.3.5` requires the path `2.3.1 -> 3.0.0 -> 4.0.0 -> 5.0.0 -> 6.3.5`.

The chart enforces this automatically. A preflight hook refuses any `helm upgrade` command that would skip a required major version and tells you which version to install next.

## Health and readiness checks

### Basic pod health

```bash
kubectl --kubeconfig ./out/cluster-0.kubeconfig -n crypto-vault get pods
kubectl --kubeconfig ./out/cluster-1.kubeconfig -n crypto-vault get pods
kubectl --kubeconfig ./out/cluster-2.kubeconfig -n crypto-vault get pods
```

All pods should be `Running` with all containers `Ready`. Key Store pods can take longer on first start
or after an upgrade while AWS launches the Nitro Enclave or GCP initializes the pod's Cloud KMS access.

### Orchestrator health endpoint

```bash
curl -sS https://<your-hostname>/health
```

A `200` response confirms the Orchestrator is up and has reached all six Key Store and Policy Server instances. This endpoint is also used by `helm test`:

```bash
helm test crypto-vault --kubeconfig ./out/cluster-1.kubeconfig -n crypto-vault
```

## What to monitor

Set up alerts on the following signals:

| Signal | Recommended alert |
|---|---|
| Pod not `Ready` (any cluster) | Alert immediately; Key Store and Policy Server outages reduce the signing threshold headroom |
| Orchestrator `/health` returning non-200 | Alert immediately; vault is unavailable to users |
| NATS JetStream consumer lag | Alert if consumers fall significantly behind; indicates async processing is backed up |
| RDS or Cloud SQL reachability (any cluster) | Alert immediately; database loss stops all persistence |
| KMS key usage denied | Alert immediately; KMS access loss prevents Key Store from decrypting shares |
| Key Store pod restart (any cluster) | Alert and investigate repeated restarts or readiness failures |

## Replica guidance

Default replica counts provide high availability for stateless services. The Key Store and Policy Server replicas tolerate pod disruptions within a single cluster without affecting the cross-cluster MPC threshold.

| Component | Default replicas | Notes |
|---|---|---|
| Key Store | 2 | One unified Key Store per shard. Scale the Nitro-capable node group on AWS or the Confidential node pool on GCP to fit. |
| Orchestrator | 2 | Active-active; stateless between requests. |
| Policy Server | 2 | Reader and writer are independently replicated. |
| UI | 2 | Stateless; scale freely. |

Horizontal Pod Autoscaler is available for Orchestrator, Policy Server, and UI when `autoscaling.enabled: true`. This requires the `metrics-server` addon on the hub cluster.

Pod Disruption Budgets (`maxUnavailable: 1`) are enabled by default and prevent simultaneous eviction of more than one replica per role during node drains or cluster upgrades.
