mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-12-03 13:33:57 +01:00
fix(ssh): reuse connections only for GitHub and LAN hosts (#540)
Assisted-by: DeepSeek Harness (claude-opus-5-5)
This commit is contained in:
1 parent
fa6cded1da
commit
b49a1dc3cf
2 files changed
+14
-16
No files matched your search
@@ -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 <host>` 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.
|
||||
|
||||
|
||||
+9
-16
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user