ControlMaster considered harmful
How an innocent performance optimization turns an authenticated SSH connection into a reusable local security capability.
It starts with a performance problem
Anyone who automates infrastructure over SSH eventually encounters the same problem: opening connections is expensive. Running a single remote command may take less time than establishing the connection required to execute it. Multiply that overhead by hundreds of commands, dozens of hosts, repeated file transfers or an entire deployment pipeline, and the temptation to optimize becomes obvious.
Every new SSH connection normally requires a TCP connection, SSH protocol negotiation, cryptographic key exchange, server identity verification and user authentication. On a high-latency network, the round trips alone can be significant. Add a hardware-backed key or an interactive second factor and the cost is no longer merely computational. It becomes operational.
OpenSSH offers a rather elegant solution: ControlMaster. Authenticate once, keep the connection open and reuse it for subsequent invocations of ssh, scp or sftp where supported.
It works remarkably well. And that is precisely why it deserves closer scrutiny. ... continue