From b49a1dc3cfd2581693c32a6c3a0ead69cb33ddf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ryan4yin=20=7C=20=E4=BA=8C=E8=8A=B1?= Date: Wed, 2 Dec 2026 10:35:53 +0800 Subject: [PATCH] fix(ssh): reuse connections only for GitHub and LAN hosts (#540) Assisted-by: DeepSeek Harness (claude-opus-5-5) --- docs/security-keys.md | 5 +++++ home/base/tui/ssh.nix | 25 +++++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/docs/security-keys.md b/docs/security-keys.md index 4b45e8fd..e1c19109 100644 --- a/docs/security-keys.md +++ b/docs/security-keys.md @@ -198,6 +198,11 @@ satisfy sudo. Agent forwarding is on for `192.168.*` and the `hostsAddr` aliases ([ssh.nix](../home/base/tui/ssh.nix)); without a forwarded agent, or with the key unplugged, sudo asks for the password. +Other addresses, such as a tailnet IP, forward only with `ssh -A`. Without it, the server falls back +to its own agent, so sudo asks for the password and git fails with `agent refused operation`. The +aliases and `192.168.*` keep a `ControlMaster`, so forwarding there follows the first connection; +run `ssh -O exit ` if that master was opened without forwarding. + While a session is open, root on that server can also use the forwarded agent. Each signature still needs a touch, so an unexpected blink is the signal to refuse it. diff --git a/home/base/tui/ssh.nix b/home/base/tui/ssh.nix index bf7f6496..fbafb278 100644 --- a/home/base/tui/ssh.nix +++ b/home/base/tui/ssh.nix @@ -21,6 +21,9 @@ let ControlMaster = "auto"; ControlPersist = "30m"; ServerAliveInterval = 15; + # Servers ask the forwarded agent for sudo + # (modules/nixos/server/ssh-agent-sudo.nix). + ForwardAgent = true; }; in { @@ -53,13 +56,14 @@ in ServerAliveCountMax = 3; HashKnownHosts = false; UserKnownHostsFile = "~/.ssh/known_hosts"; - # A connection reused within 30 s needs no new touch. - ControlMaster = "auto"; ControlPath = "~/.ssh/master-%r@%n:%p"; - ControlPersist = "30s"; }; "github.com" = { + # A connection reused within 30 s needs no new touch. Not set for every + # host: a reused master keeps its own agent forwarding, ignoring `-A`. + ControlMaster = "auto"; + ControlPersist = "30s"; # WA-028: pinned to IPv4 until the mihomo v6 fake-ip pool is proven here AddressFamily = "inet"; HostName = "ssh.github.com"; @@ -68,20 +72,9 @@ in IdentitiesOnly = true; }; - "192.168.*" = { - ForwardAgent = true; - } - // lanHost; + "192.168.*" = lanHost; } - # Aliases forward the agent like their addresses do; servers ask it for sudo - # (modules/nixos/server/ssh-agent-sudo.nix). - // lib.genAttrs (builtins.attrNames myvars.networking.hostsAddr) ( - _: - { - ForwardAgent = true; - } - // lanHost - ); + // lib.genAttrs (builtins.attrNames myvars.networking.hostsAddr) (_: lanHost); }; # Keep ~/.ssh/config a real, user-owned file rather than a /nix/store symlink.