Repository navigation
Sign tokens with a versioned server key so V1 can be retired - #15198
Conversation
One key version now signs tokens and encrypts data (_APP_OPENSSL_KEY_CURRENT). Verification accepts every configured version from _APP_OPENSSL_KEY_OLDEST up, and stored data is still decrypted by the version it records. With the defaults nothing changes, so this can ship before V2 exists. Raising OLDEST to 2 refuses V1-signed account JWTs, ephemeral keys and other tokens. Adds the `encryption` task, which re-encrypts stored values with the current version. It is a dry run unless --commit=true and resumes with --after. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟡 1 medium 📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Boot and doctor audits skip non-current accepted keys · EncryptionKey.php:98–113 · // src/Appwrite/Auth/EncryptionKey.php
98 public static function assertProduction(string $env, ?string $key): void
99 {
100 if ($env !== 'production') {
101 return;
102 }
103
104 $name = '_APP_OPENSSL_KEY_V' . self::version();
105
106 if ($key === null || $key === '') {
107 throw new \RuntimeException($name . ' is missing. Set a unique secret before running in production.');
108 }
109
🧹 Nitpicks (4) — 🟢 4 low
The change replaces single-key
Reviewed commit: 0ca63b7 |
🟢 Tier S · Ready to merge
This pull request adds versioned server-key configuration and uses the selected current key for token signing while accepting configured older keys for verification. It also updates encryption to use versioned keys, adds a task to re-encrypt existing data, and updates startup checks, deployment configuration, and rotation tests. The latest change revises the V2 key description to omit the re-encryption task from its signing-key rotation steps. Latest changes: The new commit removes the re-encryption-task instruction from the V2 key description, leaving steps to make the key current and then raise the oldest accepted version.
📂 Walkthrough · 5
Reviewed the commits since |
This PR now only moves signing off V1. The encrypt filter, storage file encryption and the re-encrypt task follow in a stacked PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Security rulesWARNING (2 new) — review signal only; does not fail the job.
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What
_APP_OPENSSL_KEY_V1no longer has to sign everything. One version of the server key signs tokens. Verification accepts every configured version from an "oldest" bound up. Once V1 is no longer accepted, nothing signed with it authenticates.This PR only covers signing. Encrypting stored data with the new version, plus a task that re-encrypts existing data, follows in a stacked PR (#15199). That one is not needed to retire V1 as a signing key.
Config (new, all optional)
_APP_OPENSSL_KEY_V2_APP_OPENSSL_KEY_CURRENT1_APP_OPENSSL_KEY_OLDEST12turns V1 acceptance offVerification accepts the current key plus every configured
_APP_OPENSSL_KEY_V{n}fromOLDESTup to the first unset version. This means V2 is accepted as soon as it is configured, even while V1 is still current. During a rolling deploy, pods still on V1 accept tokens from pods already on V2. With the defaults nothing changes, so this can be deployed before V2 exists.Changes
Appwrite\Auth\EncryptionKeygainsversion(),get(),current(),accepted()anddecode(), which tries a JWT against each accepted key and stops at the first non-signature error. Startup checks (http,worker,realtime,mqtt,doctor) now check the current key, soCURRENT=2withoutV2refuses to start.ephemeral_key mint site: preview proxy, deployments, executions, screenshots, project and organization ephemeral key endpoints, the functions worker and the migrations workerx-appwrite-jwtfor console and project, inrequest.php, realtime and MQTTephemeral_/dynamic_keys (Auth/Key.php)Vcs\State::verify()andAlert\Unsubscribenow take several keys.encryptfilter and storage uploads keep using V1, and decryption still picks the key by the stored version.Cutover runbook (ops)
Never paste key values into tickets, logs or chat. Generate V2 inside the secret store.
_APP_OPENSSL_KEY_V2on every Appwrite deployment in every region (API, realtime, MQTT, workers, schedulers, tasks). Deploy. Nothing changes yet, but every pod now accepts V2._APP_OPENSSL_KEY_CURRENT=2everywhere and deploy. New JWTs, ephemeral keys and tokens are signed with V2. V1 tokens still verify.ephemeral_keys with its own copy of the key, so edge has to be configured with the new key and deployed. Cloud code that reads_APP_OPENSSL_KEY_V1directly must move to the current key too. Do not go on to step 4 until nothing signs with V1, or every key edge mints will be refused._APP_OPENSSL_KEY_OLDEST=2everywhere and deploy. From then on these are refused when signed with V1: JWTs, ephemeral keys, resource and file tokens, push and export links, unsubscribe links, and in-flight OAuth and VCS state. Expected fallout:/v1/tokens, valid up to 10 years) and data-export links issued before step 2 stop working and must be reissued._APP_OPENSSL_KEY_V1stays configured. Encrypt stored data with the current key version and add a re-encrypt task #15199 moves encryption to the current version and adds the re-encrypt task.What to watch after each step:
USER_JWT_INVALIDandUSER_UNAUTHORIZEDrates on API and realtime_APP_OPENSSL_KEY_V2 is missingmeans step 1 was skipped on that podTests
tests/unit/Auth/EncryptionKeyTest.phpcovers:OLDEST=2, which is the decode path everyx-appwrite-jwtcheck uses, for console and project aliketests/unit/Auth/KeyTest.php: a V1-signedephemeral_key is accepted during the grace window and refused (USER_UNAUTHORIZED) once V1 is retired. This test fails against the original code, which still accepts it._APP_OPENSSL_KEY_OLDESTon a running server, because it needs a server config change mid-suite.🤖 Generated with Claude Code