Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (m *Server) createStreamerSSH(cfg StreamerConfig, add func(op gtrace.Operat
if err != nil {
return nil, fmt.Errorf("unable to get host params for ssh tunnel to %s:%w", cfg.params.proxyJump, err)
}
jumpHostParams.host, jumpHostParams.port = m.makeConnectArg(cfg.params.proxyJump, jumpHostParams)

opts := []ssh.SSHTunnelOption{ssh.SSHTunnelWithLogger(cfg.logger)}
if len(jumpHostParams.controlPath) > 0 {
Expand All @@ -235,7 +236,6 @@ func (m *Server) createStreamerSSH(cfg StreamerConfig, add func(op gtrace.Operat
if jumpHostParams.port > 0 {
opts = append(opts, ssh.SSHTunnelWithPort(jumpHostParams.port))
}
connHost = cfg.params.host

tun := ssh.NewSSHTunnel(jumpHostParams.host, jumpHostParams.GetCredentials(), opts...)

Expand Down
52 changes: 52 additions & 0 deletions pkg/server/server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,58 @@ Host mock-proxy
require.Contains(t, string(res.GetOut()), "Cisco IOS Software")
}

func TestDevAuthSSHConfigProxyJumpUsesInventoryIPWithoutHostName(t *testing.T) {
if testing.Short() {
t.Skip("integration test")
}

pub, priv, err := ed25519.GenerateKey(rand.Reader)
require.NoError(t, err)
sshPub, err := ssh.NewPublicKey(pub)
require.NoError(t, err)
agentSocket := startTestAgent(t, priv)

targetLn, targetPort := newSSHServerPort(t)
proxyLn, proxyPort := newSSHServerPort(t)
ctx := t.Context()

const targetUser = "target-user"
serveTestSwitch(t, ctx, targetLn, publicKeyAuthCallback(targetUser, sshPub))

const proxyUser = "proxy-user"
serveTestSwitch(t, ctx, proxyLn, publicKeyAuthCallback(proxyUser, sshPub))

cfg := serverConfigFromYAML(t, `
dev_auth:
ssh_config: true
`)
sshConfig := fmt.Sprintf(`
Host mock-sw
Port %d
User %s
IdentityAgent %s
ProxyJump localhost

Host localhost
Port %d
User %s
IdentityAgent %s
ForwardAgent yes
`, targetPort, targetUser, agentSocket, proxyPort, proxyUser, agentSocket)

client := newGnetcliTestClient(t, cfg, sshConfig, zap.NewNop())
res, err := client.Exec(ctx, &pb.CMD{
Host: "mock-sw",
Cmd: "show version",
HostParams: &pb.HostParams{
Ip: "127.0.0.1",
Device: "cisco",
},
})
require.NoError(t, err)
require.Contains(t, string(res.GetOut()), "Cisco IOS Software")
}

func publicKeyAuthCallback(user string, pubKey ssh.PublicKey) gswitch.AuthCallback {
return func(req gswitch.AuthRequest) error {
if req.Method != gswitch.AuthMethodPublicKey {
Expand Down
Loading