Commit 663ab4a
committed
fix(sshConn): evaluate Match exec blocks and honour ProxyJump=none
pretty resolves ssh_config entries for every target and every jump
host, but the sshconfig.Context passed to the resolver left
Context.Exec unset. The ssh_config library silently evaluates every
'Match host X exec "..."' block as non-matching when Exec is nil, so
directives that pick a reachable jump host dynamically - common in
corporate configs, e.g.
Match host jump-alias exec "nc -zG 1 primary.example.net 22"
HostName primary.example.net
Match host jump-alias exec "nc -zG 1 secondary.example.net 22"
HostName secondary.example.net
never applied. Their HostName override was skipped, the alias stayed
literal, and the connection failed at DNS resolution with 'no such
host'.
Fix: wire an Exec callback through the resolver.
- Introduce shellMatchExec: runs the already-token-expanded command
via /bin/sh -c (cmd.exe /C on Windows), with stdin/stdout/stderr
detached and a 10s timeout cap so a misbehaving probe can't hang
the CLI.
- Expose it via a package-level matchExecFunc var so tests can stub
exec evaluation deterministically without shelling out. This
matches the existing stubbing pattern used for connectionFunc /
sessionFunc.
- Pass matchExecFunc as Context.Exec from SSHConfigResolver.resolve
so every host and jump-host resolution benefits without any caller
changes in cmd/.
Follow-on correctness fix surfaced by the above: once Match exec
starts actually firing, 'Match originalhost "jump-*" ProxyJump none'
patterns produce ProxyJump="none". OpenSSH treats that as an explicit
opt-out that cancels inherited ProxyJump rules, but pretty was parsing
it as a literal jump host named "none" and trying to dial it.
ResolveHost now drops 'none' before calling ParseProxyJump, and
ParseProxyJump also collapses to an empty slice whenever any component
equals "none" (case insensitive), guaranteeing no caller ever sees
the sentinel.
Tests:
- TestResolveHostMatchExecApplies: first matching exec probe wins
and its HostName is returned.
- TestResolveHostMatchExecAllFailKeepsAlias: when every probe fails
the alias is left unchanged.
- TestShellMatchExecSucceedsForTrue / FailsForFalse / EmptyCmd: pin
the default shell callback's semantics on POSIX.
- TestParseProxyJumpNoneDisablesJumps: covers 'none', 'None', 'NONE',
and surrounding whitespace.
- TestResolveHostProxyJumpNoneClearsJumps: end-to-end sanity check
that a specific-block ProxyJump=none beats a wildcard block and
results in zero jumps.
No changes required in ncode/ssh_config: it already parses Match exec
and expands %-tokens correctly; it just needs the caller to provide a
runtime Exec callback, which is this change.1 parent 45b9942 commit 663ab4a
2 files changed
Lines changed: 213 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
16 | 62 | | |
17 | 63 | | |
18 | 64 | | |
| |||
134 | 180 | | |
135 | 181 | | |
136 | 182 | | |
137 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
138 | 187 | | |
139 | 188 | | |
140 | 189 | | |
| |||
200 | 249 | | |
201 | 250 | | |
202 | 251 | | |
203 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
204 | 264 | | |
205 | 265 | | |
206 | 266 | | |
| |||
231 | 291 | | |
232 | 292 | | |
233 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
234 | 298 | | |
235 | 299 | | |
236 | 300 | | |
237 | 301 | | |
238 | 302 | | |
239 | | - | |
240 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
241 | 308 | | |
| 309 | + | |
242 | 310 | | |
243 | 311 | | |
244 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
184 | 291 | | |
185 | 292 | | |
186 | 293 | | |
| |||
206 | 313 | | |
207 | 314 | | |
208 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
209 | 350 | | |
210 | 351 | | |
211 | 352 | | |
| |||
0 commit comments