To extend a login gate across several subdomains, each site can run the same code and verify credentials with the same signing key.
It is also necessary to distinguish copying credential material from synchronizing runtime state. This article records the sharing-boundary problems encountered across three machines.
What the setup looks like
This example runs three gates with a parent-domain cookie and shared HMAC key. Cookie transmission also depends on Domain, Path, Secure, SameSite and browser policy. After signature verification, check expiry, version and user permissions.
cookie = b64u(payload) . b64u(HMAC-SHA256(payload, cookie_key))
payload = {"exp": expiry, "u": username, "v": version}
All three share the same cookie_key, so each can verify cookies issued by the other two. This worked on the first run.
Replay protection is per-site, not global
The first problem is in the design, and only became apparent after it worked.
Here each site verifies the same TOTP seed and keeps a local spent counter. Other SSO designs verify TOTP at a central identity provider while services verify login credentials; shared seeds are not required for SSO.
The consequence: a code from one 30-second window, once used on machine A, can be used again on machine B, and again on C. Replay protection became per-site rather than global.
Independent counters do not provide global single use. A central verifier or consistent shared state can, with high availability reducing single-point risk. “Two extra uses in 30 seconds” also assumes three nodes, atomic consumption, persistent counters and a specified clock-skew window.
Record replay scope, time windows and password requirements, then assess central verification against the application’s risk. The original “not a good trade” is a design choice rather than a general security result.
The key has a second copy, and the rotation script does not know
This issue was difficult to locate because the failure came from a separate verification stage.
The application on one machine needed to verify the cookie a second time itself, beyond the gate, for its own session logic — so its configuration file also held a copy of cookie_key. When the key rotated, the sync script updated all three gates and missed that second copy.
The symptom: nginx’s auth subrequest succeeded (the gate verified with the new key), the request proxied through, the application verified with the old key and returned 401. And the gate’s log showed nothing wrong — its side was entirely healthy.
Correlate gate and application status for one request. A passed gate followed by 401 points toward downstream keys, sessions or permissions; it does not uniquely establish a stale second key.
Key rotation needs a maintained list of every holder, with updates checked against that list. Relying on memory can miss a copy when a key has several consumers.
A too-narrow preservation rule in the deploy script switched login off
The same class of problem in another form.
That machine’s deploy script rewrites the application’s environment file, and to avoid clobbering runtime configuration it preserves variables matching a prefix. The original pattern was ^APP_PANEL_.
The SSO key variable added later is named APP_HB_COOKIE_KEY — which does not match. The next deploy erased it and login stopped working outright.
# before: only PANEL-prefixed vars survive, so new ones get erased
grep -E '^APP_PANEL_' "$ENV" > "$KEEP"
# after
grep -E '^APP_(PANEL|HB)_' "$ENV" > "$KEEP"
The deployment did delete this configuration. It showed that allowlist-based preservation can silently omit newly added variables: an unmatched entry disappears without necessarily producing an error.
Separate generated application configuration from operator-held secrets, merge by ownership and validate required keys. Preserve-by-default prevents omissions but can retain obsolete settings; define deletion and migration rules too.
Clearing the application’s own session is not logging out
Adopting SSO also requires updating the application’s existing logout flow.
It clears the session credential the application issued. But on the next request the gate sees a still-valid SSO cookie and passes it through as usual — a refresh puts the user right back in a logged-in state. The “sign out” button in the interface looks perfectly normal; it simply does nothing.
Expire the shared cookie with matching Domain and Path, and clear relevant application sessions. Deleting one browser’s cookie does not revoke copied self-contained tokens. Global revocation needs shared sessions, revocation state or suitable short lifetimes.
After adopting unified authentication, review the application’s identity-related legacy logic: login, logout, session expiry, and permission changes. Their identity source has changed, and old logic may continue to fail in particular scenarios.
Fix comparison inputs and digest scope
The verification method itself can also produce a false failure.
After syncing credentials you want to verify all three machines match. The intuitive approach has each generate a current code and compares them:
# produces false mismatches
for h in host-a host-b host-c; do
ssh "$h" 'gate.py now'
done
The problem is that codes are generated from a 30-second time step. Three SSH calls run in sequence with hundreds of milliseconds to seconds between them, and if that gap happens to straddle a step boundary, the later machine reports the next window’s code. It looks like the credentials disagree when they are identical.
This time-boundary difference can lead to unnecessary synchronization attempts and network investigation.
Compare required credential fields through a controlled channel using full digests. The retained command truncates to 16 hex characters, a quick fingerprint rather than complete verification. JSON formatting also changes whole-file hashes. Keep raw keys and codes out of output.
for h in host-a host-b host-c; do
printf '%-14s ' "$h"
ssh "$h" 'sudo sha256sum /etc/gate/secret.json | cut -c1-16'
done
Compare canonical configuration fields, or compare derived outputs at a fixed time step and input. Fix time, randomness and encoding, then record the source of differences.
As an aside, these three machines have no fully connected direct path — inbound from the cloud machine to the two at home does not work. So the sync script has to run from a host that can reach all three and act as the relay. That constraint does not affect correctness, but it determines which machine the script lives on, and it is worth confirming during design rather than discovering after the script is written.
Under proxy auth, exempt paths need more care than protected ones
Two of the three applications support proxy authentication. They trust an identity header from the reverse proxy and leave credential verification to it.
An exempt path can bypass authentication if it forwards client identity headers to a backend that trusts them. Clear or overwrite the header, isolate the backend and inspect other identity inputs. Test each application route.
location / {
auth_request /__auth;
auth_request_set $user $upstream_http_x_auth_user;
proxy_set_header X-Auth-User $user; # only ever from the gate's response
}
location ^~ /share/ {
proxy_set_header X-Auth-User ""; # exempt paths must blank it
}
Check each exempt path for unchanged inputs on which authentication relies. Include headers, cookies, and query parameters.
The three machines have different exemption lists — one exempts public downloads, another exempts Bearer-authenticated machine endpoints. Different lists mean correctness cannot be inherited by copying another machine’s configuration; each needs its own pass. That is what makes multi-machine deployment harder than single: the configuration looks identical and the exceptions are not.
Choose sync paths from measured reachability
The shape of the credential sync script is dictated by one physical constraint: reachability between these three machines is not symmetric.
Under the recorded reachability, home nodes can pull from the cloud; relays or established channels are alternatives. Topology determines transport choices, while authentication and integrity still need independent checks.
It is easy to write the script assuming all three can reach each other, because during local testing the machine in front of you genuinely can reach all of them. The real topology is a directed graph, not a fully connected one. Before designing any multi-machine procedure, measure the reachability matrix — every ordered pair — rather than inferring “they can reach each other” from “my laptop can reach them.”
for a in host-a host-b host-c; do
for b in host-a host-b host-c; do
[ "$a" = "$b" ] && continue
printf '%-10s -> %-10s ' "$a" "$b"
ssh -o ConnectTimeout=8 "$a" "nc -z -w 5 $b 22 && echo ok || echo unreachable"
done
done
First make every verifier accept old and new keys, then switch issuers to the new key. Remove the old key after its token lifetime and clock allowance, recording key IDs, node completion and rollback. Reachability helps schedule these protocol phases.
The cost this design already carries
Sharing a parent-domain cookie adds a trust condition that belongs in the design.
A parent-domain cookie can reach subdomains when Domain, Path, Secure and other conditions match. HttpOnly blocks direct script reads, while receiving servers can still read it. Align cookie scope with trusted services.
Shared cookies and symmetric keys enlarge joint trust. A new recipient or key holder can increase attack surface. A node holding the HMAC verification key can also mint valid credentials.
Use a separate trust domain or central login with per-site sessions and public-key verification where isolation is required. A different hostname under the same shared parent-domain cookie does not itself isolate credentials.
Single sign-on saves repeated credential entry while merging several systems’ trust boundaries. A compromised subdomain may affect the shared credential, so the risk needs assessment before integration.