> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lumenwipe.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rotate operator secrets

> Rotate the admin token, the integrator sign-in secret, the static API keys and the RPC and Horizon provider keys.

> [!NOTE]
>
> Not yet rehearsed end to end on the deployed service. The testnet rehearsal will record the time
> of each step and correct this page.

None of these secrets signs a Stellar transaction, so none can move funds. Each section lists what stops working and for whom.

**How each one is set.** Run every step in a shell started with `set -o pipefail`, so a failed command in a pipe never stores an empty version. Then check how each variable is bound:

```bash theme={null}
gcloud run services describe lumenwipe-api --region us-central1 --format='yaml(spec.template.spec.containers[0].env)'
```

An entry with `valueFrom.secretKeyRef` is bound to Secret Manager: add a version (`... | tr -d '\n' | gcloud secrets versions add <secret> --data-file=-`) and rebind it with `--update-secrets=<VAR>=<secret>:<n>`. A secret value that is a plain environment variable is readable by anyone who can describe the service: bind it to a secret as part of the rotation, the same way. Never type a secret on the command line, where it lands in shell history and the process list; pipe it, or read it into a shell variable as below. Every update creates a revision that serves within about a minute; read the binding back after it.

## Admin token

`ADMIN_API_TOKEN` gates the operator-only `/admin/api-keys` routes.

**Blast radius**: operators only. The old token stops working the moment the new revision serves. Integrators and users see nothing.

1. Generate the token into a new version, never on screen: `openssl rand -hex 32 | tr -d '\n' | gcloud secrets versions add <admin-token-secret> --data-file=-`. Expected: `Created version [<n>]`.

2. Rebind it: `gcloud run services update lumenwipe-api --region us-central1 --update-secrets=ADMIN_API_TOKEN=<admin-token-secret>:<n>`. Expected: `Done.`

3. Confirm, passing each token as a header file so it never appears on the command line:

   ```bash theme={null}
   bearer() { printf 'Authorization: Bearer %s' "$(gcloud secrets versions access "$1" --secret=<admin-token-secret>)"; }
   curl -s -o /dev/null -w '%{http_code}\n' -H @<(bearer <n>) "$API/admin/api-keys"
   curl -s -o /dev/null -w '%{http_code}\n' -H @<(bearer <previous n>) "$API/admin/api-keys"
   ```

   Expected: `400` for the new token (authorized, refused only for the missing `owner`), `401` for the old one.

4. Disable the previous version: `gcloud secrets versions disable <previous n> --secret=<admin-token-secret>`.

## Integrator sign-in secret

`INTEGRATOR_AUTH_SECRET` signs the wallet sign-in challenge and the session tokens of the self-service key page. At least 32 characters.

**Blast radius**: everyone signed in to the key page is signed out, and a challenge issued before the switch no longer verifies, so they sign in again. API keys themselves are untouched and keep working.

1. `openssl rand -hex 32 | tr -d '\n' | gcloud secrets versions add <integrator-secret> --data-file=-`, then `--update-secrets=INTEGRATOR_AUTH_SECRET=<integrator-secret>:<n>`. Expected: `Done.`

2. Confirm a new challenge is issued:

   ```bash theme={null}
   curl -s -o /dev/null -w '%{http_code}\n' -X POST "$API/v1/integrator/auth/challenge" \
     -H 'content-type: application/json' -d '{"address":"<any G address>"}'
   ```

   Expected: `200`. Sign in on the key page with a testnet wallet: the keys list loads.

3. Disable the previous version.

## Contract sign-in server account

`INTEGRATOR_WEB_AUTH_SIGNING_SEED` is the secret seed of the account that signs its own entry in every contract-account sign-in challenge. The account must exist on each network contract sign-in runs on, holding only its minimum balance; it signs nothing that can be submitted.

**Blast radius**: a challenge issued before the switch no longer verifies, so a contract account signing in at that moment signs in again. Sessions and API keys are untouched. Until the new account exists on a network, contract sign-in there answers `503 contract_sign_in_unavailable`.

1. Create a new key pair offline and fund its public key on each network: from Friendbot on testnet, and on mainnet with the base reserve, which a person sends.

2. `printf '%s' '<new S... seed>' | gcloud secrets versions add <web-auth-seed-secret> --data-file=-`, then `--update-secrets=INTEGRATOR_WEB_AUTH_SIGNING_SEED=<web-auth-seed-secret>:<n>`. Expected: `Done.`

3. Confirm a challenge is issued:

   ```bash theme={null}
   curl -s -o /dev/null -w '%{http_code}\n' -X POST "$API/v1/integrator/auth/contract/testnet/challenge" \
     -H 'content-type: application/json' -d '{"address":"<any C address>"}'
   ```

   Expected: `200`.

4. Disable the previous version. The old account's balance can be merged into the new one.

### Testnet web authentication contract

`INTEGRATOR_WEB_AUTH_CONTRACT_TESTNET` names the testnet instance of the SEP-45 web authentication contract, running the attested reference build (`SEP45_REFERENCE_WASM_HASH` in `apps/api/src/integrator/contract-auth.ts`). It is not a secret, but it is set in two places: the API's Cloud Run variable, and the GitHub repository variable of the same name that the nightly `web-auth-ttl` job in `e2e-nightly.yml` reads to extend the contract's TTL. Mainnet uses SDF's deployment and needs nothing here.

A testnet reset deletes the contract. Until it is recreated, testnet contract sign-in answers `503 contract_sign_in_unavailable` and the nightly job fails with `web_auth_missing`.

1. Recreate the instance from the attested build, copying its code from mainnet by hash, and note the new `C...` address.
2. Point the API at it: `gcloud run services update lumenwipe-api --region us-central1 --update-env-vars=INTEGRATOR_WEB_AUTH_CONTRACT_TESTNET=<C...>`. Expected: `Done.`
3. Update the repository variable, or the nightly job keeps checking the old address: `gh variable set INTEGRATOR_WEB_AUTH_CONTRACT_TESTNET --repo LumenWipe/lumenwipe --body '<C...>'`.
4. Run `e2e-nightly.yml` from the Actions tab. Expected: the job `keep the testnet web authentication contract live` passes, and an open tracking issue for it closes itself.

## Static API keys

`API_KEYS` is a list of `label=key` pairs: the web app's own key, the deploy smoke key and any manually provisioned partner. Self-serve keys are rotated by their owners on the key page and are not covered here.

**Blast radius**: the holder of the rotated key only. Overlap the two keys so nobody sees a `401`.

1. **Add the new key next to the old one**, under the same label (two keys may share a label; metering counts them together). `API_KEYS` holds every static key, so it is always bound to a secret; if it is still a plain variable, bind it now. Build the new list in a shell variable, never on screen:

   ```bash theme={null}
   NEW_KEY="$(openssl rand -hex 32)"
   CURRENT="$(gcloud secrets versions access <n> --secret=<api-keys-secret>)"
   printf '%s,<label>=%s' "$CURRENT" "$NEW_KEY" | gcloud secrets versions add <api-keys-secret> --data-file=-
   gcloud run services update lumenwipe-api --region us-central1 --update-secrets=API_KEYS=<api-keys-secret>:<n+1>
   curl -s -o /dev/null -w '%{http_code}\n' -H @<(printf 'Authorization: Bearer %s' "$NEW_KEY") "$API/v1/testnet/account/<a funded testnet address>"
   ```

   Expected: `Created version [<n+1>]`, `Done.`, and `200`.

2. **Move the holder to the new key**, piped:
   * the web app: `printf %s "$NEW_KEY" | vercel env add LUMENWIPE_API_KEY production` after removing the old value with `vercel env rm LUMENWIPE_API_KEY production`, then redeploy the production build;
   * the deploy smoke test: `printf %s "$NEW_KEY" | gh secret set API_SMOKE_KEY`;
   * a partner: through the channel agreed with them.

3. **Remove the old key**: add a version with the old pair removed from the list (read it, edit it in the shell variable, pipe it in as in step 1) and rebind it. Expected: `Done.`

4. Confirm the same `curl` with the old key answers `401` and with `$NEW_KEY` `200`; for the web app, a testnet close plan loads on the site. Then `unset NEW_KEY CURRENT` and disable the superseded versions.

## RPC and Horizon provider keys

Private providers authenticate with a header: `STELLAR_RPC_HEADER_NAME_<NET>` and `STELLAR_RPC_HEADER_VALUE_<NET>` for the first RPC URL, `_2` and `_3` suffixes for the later ones, and the same scheme under `PATH_ROUTING_API_HEADER_*` for the Horizon-compatible list. `SOROSWAP_API_KEY` and `OCTOPOS_API_KEY` are the conversion quote and position detection keys.

**Blast radius**: reads through that one provider. With a provider list, a provider whose key fails is answered with `503` and the client's retry moves to the next one ([Provider outage](https://docs.lumenwipe.com/runbooks/provider-outage.md)); with a single provider, the network's reads fail until the new key is in.

1. Create the new key in the provider's console, keeping the old one active.

2. Paste the new value at a silent prompt, store it as a version and bind it:

   ```bash theme={null}
   read -rs VALUE
   printf %s "$VALUE" | gcloud secrets versions add <provider-secret> --data-file=- && unset VALUE
   gcloud run services update lumenwipe-api --region us-central1 --update-secrets=STELLAR_RPC_HEADER_VALUE_<NET>=<provider-secret>:<n>
   ```

   Expected: `Created version [<n>]` and `Done.`

3. Confirm the provider answers:

   ```bash theme={null}
   curl -s "$API/health/dependencies" | jq '.dependencies[] | select(.network=="<net>") | {upstream, state, lastErrorClass}'
   curl -s -o /dev/null -w '%{http_code}\n' "$API/health/deep"
   ```

   Expected: `"state": "up"` for `rpc` and `horizon` on that network, and `200` from `/health/deep`. Each probe result is cached for one minute (five for `paths` and `defi`), so wait that long after the switch. These routes spend provider quota; call them a few times, not in a loop.

4. Revoke the old key in the provider's console, then repeat step 3. Expected: unchanged.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.