Gateway regenerates its mitmproxy CA on every restart, so re-attached bottles fail TLS #450
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
The gateway regenerates its mitmproxy CA every time the infra container is recreated. The new CA is not in any running bottle's trust store, so a bottle that correctly follows the gateway to its new address still fails TLS on every HTTPS request.
This is a third, independent strand mechanism alongside the two in #443, and it is not mentioned there. #445 fixed item 1 of #443 (name-based resolution), which makes a moved gateway addressable again — but a re-attached bottle then dies at the TLS handshake instead of at connect. Re-attach cannot work until this is fixed too.
Evidence
Observed 2026-07-21.
bot-bottle-mac-infrawas recreated at 06:05:44Z, moving192.168.128.23 -> 192.168.128.31. The gateway's CAnotBeforeis exactly the restart timestamp, which is the tell — it is minted at container start, not persisted:(mitmproxy backdates
notBeforeby two days; the time-of-day is the giveaway.)Isolating the two failures on the stranded bottle, after manually rewriting its proxy URL to the new address:
http://through the proxy -> reaches the gateway, returns a gateway-generated 403https://through the proxy ->curlexit 60, certificate verify failedSo the transport is fine and the trust anchor is not.
Why it isn't covered by the existing items
Orchestrator._tokens(item 2 of #443) is deliberately memory-only to keep secrets off disk. The CA is a different tradeoff: the private key must stay protected, but the CA certificate is public by construction — it is already distributed into every bottle's trust store. Persisting the keypair on the host and bind-mounting it into the gateway does not create a new secret-at-rest class that the design was avoiding; it gives the interception identity the same lifetime as the host rather than the lifetime of a container.Without that, every infra recreation invalidates the trust store of every running bottle, and the only recovery is relaunching the bottle — which throws away the agent session, the exact outcome #443 set out to eliminate.
Proposed fix
~/.mitmproxy(or at minimummitmproxy-ca.pem) on the host and bind-mount it into the infra container, so a recreated gateway keeps its CA identity. Protect the key with host file permissions.Incidental confirmation for the #443 caveat
#443 flagged that a long-running bottle picking up a rewritten
/etc/hostsmid-flight was never verified. Partial data point from this incident: the host-side rewrite does land on a live container — the stranded bottle's/etc/hostshad been correctly updated to the gateway's new address while the bottle was running. What remains unverified is whether a long-lived client process re-resolves rather than caching its first lookup. The bottles running during this incident predate #445 and carry a literal address in theirenviron, so they could not exercise the resolution path either way.Related