# Rotate and revoke secrets without restarting containers or leaking snapshots

Gregale · Updated 2026-11-26

Every secret mutation on Gregale invalidates memory snapshots so restored VMs never serve stale keys, `--restart` performs a draining rolling replacement, and images with `com.gregale.secret-reload-signal` hot-reload in-process with verifiable acknowledgements.

**Rotate or revoke application secrets on Gregale without stale memory snapshots surviving or blindly dropping live connections.** Every secret update immediately invalidates existing memory snapshots so restored microVMs never serve revoked credentials, `--restart` runs a draining rolling replacement, and opted-in containers can hot-reload secrets in-process with verifiable application acknowledgements and durable revocation records.

## Why secret rotation breaks on traditional PaaS platforms

On many PaaS providers, rotating a database password or third-party token forces a cold restart of running containers—or worse, snapshot-based scale-to-zero platforms risk waking paused containers with yesterday's environment values. Security teams also lack proof after an incident: deleting an env var in a dashboard does not verify whether every running process actually stopped using the old key.

## Safe defaults: snapshot invalidation and draining restarts

By default on Gregale, secrets are write-only to the API, sealed at rest, and delivered into the guest only at wake:

```bash
gregale env set --app my-api STRIPE_SECRET_KEY="$STRIPE_SECRET_KEY"
gregale env rotate --app my-api DATABASE_URL="$NEW_DATABASE_URL" --restart
gregale env list --app my-api
gregale env unset --app my-api STRIPE_SECRET_KEY
```

Three platform guarantees prevent stale secrets even without application code changes:

- **Automatic snapshot invalidation:** Whenever a secret changes, existing memory snapshots are invalidated immediately. The next cold wake boots fresh with the updated environment before capturing a new snapshot, and `--restart` prevents live processes carrying the old environment from ever being snapshotted.
- **Draining rolling replacement (`--restart`):** Gregale cold-boots replacement instances with the new values, routes traffic to them, waits for gateway convergence and in-flight requests to drain, and then tears down the old instances.
- **Version-fenced delivery states:** `gregale env list` tracks each key as `pending`, `delivered`, or `failed` tied to exact wake and instance IDs, so racing observations from an older wake can never mark a newer version delivered.

For multi-service apps, project environment secrets (`gregale environment secrets set shop production`) share credentials across every service in the environment (up to `Free 8`, `Hobby 25`, `Pro 50`, `Scale 100` per environment) without repeating per-app edits.

## Zero-restart hot reload and startup readiness

Applications that can swap database pools or API clients inside a live process can opt in with an OCI image label:

```dockerfile
LABEL com.gregale.secret-reload-signal="SIGHUP"
LABEL com.gregale.secret-reload-readiness="required"
```

1. On start, after registering its signal handler (`SIGHUP`, `SIGUSR1`, or `SIGUSR2`, distinct from `STOPSIGNAL`), the app writes `ready\n` to `FAAS_SECRETS_RELOAD_READY_FILE` so signals never arrive before handlers are installed.
2. When a secret changes, guest-init (polling every 10 seconds) writes an atomic mode-`0400` snapshot `{revision,secrets}` on `/tmp` tmpfs (`FAAS_SECRETS_SNAPSHOT_FILE`) and signals the workload.
3. After updating its internal pools/clients, the app can POST its self-attestation (`revision`, `status: "applied"`, and `FAAS_SECRETS_RELOAD_GENERATION`) to `FAAS_SECRETS_RELOAD_ACK_ENDPOINT`.

Process generations isolate restarts inside the VM so an exiting process's late acknowledgement can never overwrite a new process's status.

## Verify rotation and revocation from CI or incident scripts

```bash
gregale env rotate --app my-api DATABASE_URL="$NEW_DATABASE_URL" --wait-for-ack
gregale env unset --app my-api COMPROMISED_KEY --wait-for-ack --timeout 2m
```

- `secrets rotate --wait-for-ack` polls the complete roster of authorized active runtimes until every reload-enabled target acknowledges the current revision, failing fast with a non-zero exit if any target lacks reload support or reports failure.
- `gregale env unset --wait-for-ack --timeout 2m` records a durable, value-free revocation record (queryable at `GET /v1/apps/{slug}/secret-revocations/{id}`) containing the exact target roster, status codes, and timestamps—and exits non-zero if any runtime times out or cannot live-reload.

## What to expect and when to use `--restart`

- **Self-attestation vs memory inspection:** Application acknowledgements reflect trusted app self-reporting; removing a key from the projected file cannot purge credentials your app forgot to drop from heap variables.
- **No handler? Use `--restart`:** Images without `com.gregale.secret-reload-signal` cannot live-reload and fail `--wait-for-ack` intentionally rather than silently succeeding; use `--restart` for apps that read `process.env` only once at boot.

See [Manage secrets](https://gregale.dev/docs/secrets.md), [Set environment variables](https://gregale.dev/docs/env.md), [How scaling to zero works](https://gregale.dev/docs/scale-to-zero.md), and [Security](https://gregale.dev/docs/security.md).

## Questions

### Can a restored scale-to-zero snapshot serve an old secret after rotation?

No. Rotating or deleting a secret immediately invalidates existing memory snapshots, forcing the next wake to cold-boot with the current secret versions before taking a fresh snapshot.

### How does zero-restart secret reload verify my app updated its pools?

Images with `com.gregale.secret-reload-signal` receive an atomic mode-`0400` snapshot file and process signal, and POST a generation-scoped self-attestation to `FAAS_SECRETS_RELOAD_ACK_ENDPOINT` checked by `--wait-for-ack`.

### What happens if my image does not handle reload signals?

Use `gregale env rotate --restart` for a draining rolling replacement. Commands with `--wait-for-ack` intentionally fail non-zero rather than pretending a non-reloading container rotated.

Canonical URL: https://gregale.dev/articles/zero-restart-secret-rotation

