Skip to content
Draft
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 cmd/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (c *firewallCmd) firewallPureSSH(fwAllocation *models.V1MachineAllocation)
}
for _, ip := range nw.Ips {
if portOpen(ip, "22", time.Second) {
err = sshClient("metal", viper.GetString("identity"), ip, 22, nil, false)
err = sshClient("metal", viper.GetString("identity"), ip, 22, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ func (c *machineCmd) machineConsole(args []string) error {
token = authContext.IDToken
}

err = sshClient(id, viper.GetString("sshidentity"), parsedurl.Host, bmcConsolePort, &token, viper.GetBool("admin"))
err = sshClient(id, viper.GetString("sshidentity"), parsedurl.Host, bmcConsolePort, &token)
if err != nil {
return fmt.Errorf("machine console error:%w", err)
}
Expand Down
34 changes: 16 additions & 18 deletions cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,33 @@ func (c *firewallCmd) firewallSSHViaVPN(firewall *models.V1FirewallResponse) (er
}

// sshClient opens an interactive ssh session to the host on port with user, authenticated by the key.
func sshClient(user, keyfile, host string, port int, idToken *string, passwordAuth bool) error {
func sshClient(user, keyfile, host string, port int, idToken *string) error {

var opts []metalssh.ConnectOpt
if passwordAuth {
opts = append(opts, metalssh.ConnectOptOutputPassword(*idToken))
} else {
if keyfile == "" {
var err error
keyfile, err = searchSSHKey()
if err != nil {
return err
}
}

privateKey, err := os.ReadFile(keyfile)
if keyfile == "" {
var err error
keyfile, err = searchSSHKey()
if err != nil {
return err
}
}

opts = append(opts, metalssh.ConnectOptOutputPrivateKey(privateKey))
privateKey, err := os.ReadFile(keyfile)
if err != nil {
return err
}

opts = append(opts, metalssh.ConnectOptOutputPrivateKey(privateKey))

s, err := metalssh.NewClient(user, host, port, opts...)
if err != nil {
return err
}
var env *metalssh.Env
if idToken != nil {
env = &metalssh.Env{"LC_METAL_STACK_OIDC_TOKEN": *idToken}

env := map[string]string{
"LC_METAL_STACK_OIDC_TOKEN": pointer.SafeDeref(idToken),
}
return s.Connect(env)
sshEnv := metalssh.Env(env)

return s.Connect(&sshEnv)
}