MCPcopy Create free account
hub / github.com/tailscale/tailscale / TestLocalUnixForwarding

Function TestLocalUnixForwarding

ssh/tailssh/tailssh_integration_test.go:427–500  ·  view source on GitHub ↗

TestLocalUnixForwarding tests direct-streamlocal@openssh.com, which is what podman remote (issue #12409) and VSCode Remote (issue #5295) use to reach Unix domain sockets on the remote host through SSH. The client opens a channel to a Unix socket path on the server, and data is proxied through.

(t *testing.T)

Source from the content-addressed store, hash-verified

425// Unix domain sockets on the remote host through SSH. The client opens a
426// channel to a Unix socket path on the server, and data is proxied through.
427func TestLocalUnixForwarding(t *testing.T) {
428 debugTest.Store(true)
429 t.Cleanup(func() {
430 debugTest.Store(false)
431 })
432
433 // Create a Unix socket server in /tmp that simulates a service like
434 // podman's API socket at /run/user/<uid>/podman/podman.sock.
435 socketDir, err := os.MkdirTemp("", "tailssh-test-")
436 if err != nil {
437 t.Fatal(err)
438 }
439 t.Cleanup(func() { os.RemoveAll(socketDir) })
440 socketPath := filepath.Join(socketDir, "test-service.sock")
441
442 ul, err := net.Listen("unix", socketPath)
443 if err != nil {
444 t.Fatal(err)
445 }
446 t.Cleanup(func() { ul.Close() })
447
448 // The service echoes back whatever it receives, like an API server would.
449 go func() {
450 for {
451 conn, err := ul.Accept()
452 if err != nil {
453 return
454 }
455 go func() {
456 defer conn.Close()
457 io.Copy(conn, conn)
458 }()
459 }
460 }()
461
462 // Start Tailscale SSH server with local port forwarding enabled.
463 addr := testServerWithOpts(t, testServerOpts{
464 username: "testuser",
465 allowLocalPortForwarding: true,
466 })
467
468 // Connect to the Tailscale SSH server.
469 cl, err := ssh.Dial("tcp", addr, &ssh.ClientConfig{
470 HostKeyCallback: ssh.InsecureIgnoreHostKey(),
471 })
472 if err != nil {
473 t.Fatal(err)
474 }
475 t.Cleanup(func() { cl.Close() })
476
477 // Open a direct-streamlocal@openssh.com channel to the Unix socket,
478 // exactly as podman remote does.
479 conn, err := cl.Dial("unix", socketPath)
480 if err != nil {
481 t.Fatalf("failed to dial unix socket through SSH: %s", err)
482 }
483 defer conn.Close()
484

Callers

nothing calls this directly

Calls 12

testServerWithOptsFunction · 0.85
WriteStringMethod · 0.80
StoreMethod · 0.65
CleanupMethod · 0.65
FatalMethod · 0.65
RemoveAllMethod · 0.65
ListenMethod · 0.65
CloseMethod · 0.65
AcceptMethod · 0.65
DialMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…