Table of contents
- SSO Across Multiple Instances (GPG Key Export/Import)
- The problem this solves
- How it works, end to end
- What's actually protecting what
- Step-by-step: setting up a multi-instance cluster
- 1. Pick one instance as the source
- 2. Export its keystore
- 3. Distribute both files to every other instance
- 4. Make sure every instance shares the same secret
- 5. (Re)start the other instances
- 6. Verify
- Operational notes
- See also
SSO Across Multiple Instances (GPG Key Export/Import)
This page explains ProxyAuth's sync export mechanism — how it lets a token issued by one ProxyAuth instance be validated by another, and why simply sharing the same secret in config.json across instances is not enough on its own.
The problem this solves
Every token ProxyAuth issues is a blake3 hash computed by generate_token() from several inputs:
username, secret_with_timestamp, build_time, time_expire, build_rand, token_id
...concatenated in a specific order before hashing. Two things about that order and those values are not stored in config.json at all — they're baked into the compiled binary at build time:
build_timeandbuild_rand— random-ish values generated when the binary was compiled.- The shuffle order itself — which of the six fields above goes first, second, etc. before hashing.
This is deliberate: it means knowing config.json's secret alone isn't enough to forge a token — you'd also need to know the exact build-time constants and field order, which aren't stored anywhere in the running configuration.
The consequence: if you run ProxyAuth as multiple independent instances (e.g. behind a load balancer, for horizontal scaling or high availability) built from separate compilations, each one has its own random build_time/build_rand/shuffle order — even with an identical secret in config.json on every instance. A token issued by instance A will fail to validate on instance B, because the hash computed by B uses different build constants than the one A used to create it.
sync export / the keystore import mechanism exists to fix exactly this: it lets you take one instance's build constants and securely distribute them to your other instances, so they all compute tokens identically and a session can move between instances transparently — which is what makes this function as SSO across a cluster.
How it works, end to end
flowchart TD
subgraph instanceA ["Instance A — source of truth"]
A1(["proxyauth sync export"]) --> A2["Generates a one-time<br/>OpenPGP certificate"]
A2 --> A3[("key.asc<br/>certificate · private key encrypted<br/>with config.json's secret")]
A2 --> A4[("data.pgp<br/>build_time / build_rand / shuffle-order<br/>GPG-encrypted to that certificate")]
end
A3 -.->|"copy to /etc/proxyauth/import/<br/>on every other instance"| B0
A4 -.-> B0
subgraph instanceB ["Instance B, C, D... — on next startup"]
B0["Reads /etc/proxyauth/import/<br/>key.asc + data.pgp"] --> B1["Decrypts the certificate's private key<br/>using its OWN config.json secret"]
B1 --> B2{"Secret matches A's?"}
B2 -->|yes| B3["Uses the unlocked private key<br/>to decrypt data.pgp"]
B3 --> B4["Overwrites its own build_time /<br/>build_rand / shuffle-order with A's"]
B4 --> B5(["B now computes tokens identically to A —<br/>a token issued by A validates on B, and vice versa"])
end
classDef trigger fill:#eef2ff,stroke:#4f46e5,stroke-width:1px,color:#1e1b4b
classDef store fill:#fef3c7,stroke:#d97706,stroke-width:1px,color:#78350f
classDef step fill:#f8fafc,stroke:#64748b,stroke-width:1px,color:#0f172a
classDef decision fill:#fde68a,stroke:#d97706,stroke-width:1px,color:#78350f
classDef done fill:#dcfce7,stroke:#16a34a,stroke-width:1px,color:#14532d
class A1 trigger
class A3,A4 store
class A2,B0,B1,B3,B4 step
class B2 decision
class B5 done
What's actually protecting what
It's worth being precise about the security properties here, since two different secrets are involved:
- The passphrase protecting the private key in
key.ascis yourconfig.json'ssecretfield. This means the exported files are only useful to someone who already has the sharedsecret— which every legitimate instance in your cluster needs anyway (it's required for HKDF key derivation, CSRF signing, etc., independently of this mechanism). - Given that, this GPG layer isn't adding a new authentication factor — anyone who already has
secretdoesn't strictly needkey.asc/data.pgpto eventually derive matching tokens by other means. What it does provide is a safe, standard distribution mechanism:data.pgpnever reveals the build constants to anyone without the passphrase, so you can copy these two files over a channel you don't fully trust (a shared drive, a Slack upload, an unencrypted file transfer) without exposing the build constants to anyone who doesn't already holdsecret. - If an instance's
config.jsonsecretdoesn't match the one used to create the export, decryption of the private key fails, and that instance simply keeps its own independent build constants — it does not crash or block startup (see Operational notes below).
Step-by-step: setting up a multi-instance cluster
1. Pick one instance as the source
Any already-running instance works — there's nothing special about "the first one," it just needs to be the one whose build constants every other instance will adopt.
2. Export its keystore
proxyauth sync export
This must be run as root (it's gated by ensure_running_as_root()), and drops two files in the current working directory:
key.asc— the OpenPGP certificate (private key encrypted withconfig.json'ssecret)data.pgp— this instance's build constants, encrypted to that certificate
3. Distribute both files to every other instance
Copy key.asc and data.pgp to /etc/proxyauth/import/ on each of your other instances:
mkdir -p /etc/proxyauth/import
scp key.asc data.pgp other-instance:/etc/proxyauth/import/
Both files are required together — if only one is present, the import step is silently skipped (treated as "nothing to import," not an error).
4. Make sure every instance shares the same secret
This mechanism only works if config.json's secret is identical across every instance in the cluster — it's both what protects the exported private key and what's independently required for tokens to validate consistently in the first place. If you haven't already synchronized secret across instances, do that first.
5. (Re)start the other instances
On startup, each instance automatically checks /etc/proxyauth/import/ and, if both files are present and decryptable with its own secret, adopts the imported build constants before serving any traffic.
6. Verify
Log in against instance A, take the returned token/cookie, and make a request against instance B directly. If it's accepted, the sync worked. If B rejects it, double-check that secret truly matches on both sides and that both files landed in /etc/proxyauth/import/ on B.
Operational notes
- This is a one-time sync, not continuous replication. If you rebuild/redeploy instance A from source again later, it gets a new random
build_time/build_rand/shuffle order at compile time — you'll need to re-export and redistribute if you want the cluster to stay in sync after that rebuild. If you deploy the exact same compiled binary/image to every instance instead of rebuilding independently, they already share build constants and this whole mechanism becomes unnecessary — this only matters when each instance is compiled separately. - Failure is silent, not fatal. If
/etc/proxyauth/import/is missing, incomplete, or itssecretdoesn't decrypt the key, the instance just starts up with its own independently-generated build constants and logs a warning (or nothing at all, if the files are simply absent) — it does not fail to start. This means a misconfigured import can go unnoticed unless you specifically test cross-instance token validation as in step 6 above. - The private key passphrase is derived from
secretat both ends independently — it's never transmitted; each instance re-derives it locally from its ownconfig.json. There's nothing to leak in transit beyond whatkey.asc/data.pgpalready contain (which, again, are useless withoutsecret). PROXYAUTH_CONFIG_PATHcan override the config path the import step readssecretfrom (mainly intended for testing) — otherwise it defaults to/etc/proxyauth/config/config.json, same as the rest of the application.
See also
- config.json Reference — the
secretfield this entire mechanism depends on.
📖 Wiki Home · 💻 Source Code · 🐛 Report an Issue · 📜 License
Found an error or something outdated on this page? Open an issue or submit a PR against the wiki repository.