Telling Technology · Learning in public
All episodes
EP.120 — TWO DOORS, ONE KEY
Security in public · the default that hid a mistake

One secret opened two doors

My gateway config had a one-line convenience: if no billing secret is set, reuse the connect secret. It looked tidy and it always worked. That was the problem. The key for the low-stakes account-linking door quietly also opened the billing door, and no log, test or error would ever have told me. One commit on 2026-10-07 took the fallback out and made the gateway refuse to start when the two keys match.

A single teal key on a near-black background, its shadow falling across two keyholes side by side, one labelled connect and one labelled billing, the billing keyhole glowing coral
⌁ 1 fallback removed · 1 refuse-to-start · 2 tests · e0d1276 · 2026-10-07
first, the two doors
01 Two doors

One gateway, two ways in from the outside

The Pocket Operator is my AI assistant in Telegram: one shared bot, a separate sandbox per person. Its gateway has two inbound ingest surfaces that other services call. Connect links a person’s account to their sandbox. Billing reports payment events, the part I wired up in Billing that ships switched off. Each door is guarded by its own shared secret in gateway.env: CONNECT_INGEST_SECRET and BILLING_INGEST_SECRET. A caller that knows a secret can talk to that door. That is the whole lock. So the one rule that matters is that the two locks take different keys.

claude code — desktop
> which secrets guard the gateway's inbound surfaces, and what does each one unlock?
Two: CONNECT_INGEST_SECRET guards account linking, BILLING_INGEST_SECRET guards billing events. Both are read from gateway.env in load_settings().
Paraphrased. No secret values on this page, only the variable names.
A simple diagram: the Pocket Operator gateway as a box with two doors on its outside wall, connect on the left and billing on the right, each with its own keyhole and its own key labelled with the environment variable name
gateway.env
Two doors, and the plan was two keys.
02 The convenience

Forget the billing key, and billing works anyway

Here is the line, in gateway/pocket_gateway/config.py: billing_ingest_secret = env.get("BILLING_INGEST_SECRET") or env.get("CONNECT_INGEST_SECRET", ""). Read it as: if I forgot to set the billing secret, use the connect secret instead. There was even a test that made sure of it, named billing_secret_defaults_to_connect_secret, asserting that billing came up enabled with nothing but the connect key set. It felt helpful. One fewer thing to configure. But look at what it really says: whoever holds the key to the connect door also holds the key to the billing door. And the moment you would most want a warning, when you forgot a setting, is exactly when the default makes everything work, silently.

claude code — desktop
> git show e0d1276 -- gateway/pocket_gateway/config.py
- billing_ingest_secret=env.get("BILLING_INGEST_SECRET") or env.get("CONNECT_INGEST_SECRET", ""),
+ billing_ingest_secret=billing_secret,
The whole bug is the word or.
A dark code diff card: one red line where the billing secret falls back to the connect secret with the word or highlighted in coral, and one green line where the billing secret is only ever the billing secret
e0d1276
Before: one key, two locks. After: no key means no door.
03 Fail closed

Unset means off. Equal means don’t start.

The fix has two halves. First, no fallback: if BILLING_INGEST_SECRET is not set, the billing secret is empty and billing_enabled is False. A forgotten setting now turns the door off instead of borrowing someone else’s key. Second, the case a fallback can’t catch: what if I set both, by hand, to the same value? Then the gateway stops at boot with one plain sentence: BILLING_INGEST_SECRET must differ from CONNECT_INGEST_SECRET; refusing to start. Three lines of code, checked before the settings object even exists. A mistake there now costs me one failed start while I am at the keyboard, not a quiet open door I find out about later.

claude code — desktop
> start the gateway with BILLING_INGEST_SECRET set to the same value as CONNECT_INGEST_SECRET
BILLING_INGEST_SECRET must differ from CONNECT_INGEST_SECRET; refusing to start
exit · the settings never load, so nothing starts.
Reconstructed from the commit and its test, which asserts SystemExit.
A dark terminal: a gateway start command, then one coral line reading BILLING_INGEST_SECRET must differ from CONNECT_INGEST_SECRET, refusing to start, and the prompt returning
boot, not 3am
The cheapest place to fail is the moment you start it.
⚠️

The honest part: I wrote the test that protected the bug

The fallback was not an accident that slipped past the tests. The tests asserted it. test_billing_secret_defaults_to_connect_secret checked that the billing secret equalled the connect secret and that billing came up enabled. A green suite was guarding the exact behaviour I now think is wrong. The fix rewrote that test to say the opposite (test_billing_secret_does_not_fall_back_to_connect_secret: empty secret, billing off) and added test_billing_secret_equal_to_connect_secret_refuses_start, which expects SystemExit. I have no sign the shared key was ever used against the billing door. That is not comfort, it is the point: nothing in the old setup would have told me if it had been.

04 Receipts

Four pictures of one word: or

The tests that flipped, what each config does before and after, where a mistake gets caught, and the one-line rule I took away. Tap any image to enlarge it and read the exact prompt that drew it.

POCKET OPERATOR · FIXED 2026-10-07

A default that makes things work is a decision someone else’s attacker gets to enjoy

Convenient defaults are great for things like a port number or a timeout. For a secret they do the opposite of what you want: they turn a missing setting, the one moment you would want a loud warning, into a quiet success. The rule I took from this: a missing secret turns its door off, a reused secret stops the boot. Fail closed at start, while I am watching, not open at 3am, while I am not. If you run an agent with more than one inbound hook, grep your config for or env.get( next to the word SECRET.

A bold card on near-black: two keyholes each with its own key, and the line a missing secret turns its door off, a reused secret stops the boot
1 fallback removed · 3 lines added · 1 test rewritten · 1 test added · e0d1276
06 Steal this

A fail-closed secrets check for any agent gateway

The pattern from this episode: one secret per inbound door, no fallbacks, and a boot check that refuses to start when two doors share a key, plus the two pytest tests that pin it. Everything in this episode is free and open — clone it, run it, make it yours.

skill load_settings() pattern: unset secret = feature off cmd pytest gateway/tests/test_config.py template the refuse-to-start check: secrets must differ assets grep recipe: or env.get( next to SECRET
run it # repo soon. Python 3 + pytest: pytest gateway/tests/test_config.py -k billing_secret

No GitHub? Comment TWOKEYS on the post and the bot DMs you the link.

Next episode

My night builds now check their own homework

Next: the pipeline that writes these pages every night now registers each build as staging and runs a 13-check QA gate on it before anything is pushed. The builder grades its own output, and it is allowed to fail.

A darkened teaser image of a CI gate blocking a push
drops soon · follow so you don’t miss it