Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

At least pass correct ipv6 notation if required #169

Merged
merged 1 commit into from
Oct 20, 2022
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
23 changes: 17 additions & 6 deletions cmd/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/netip"
"os"
"strings"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
dockerclient "github.com/docker/docker/client"
Expand All @@ -18,10 +24,6 @@ import (
"github.com/metal-stack/metalctl/cmd/sorters"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"io"
"os"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -247,6 +249,7 @@ func (c *firewallCmd) firewallPureSSH(fwAllocation *models.V1MachineAllocation)

func (c *firewallCmd) firewallSSHViaVPN(firewall *models.V1FirewallResponse) (err error) {
projectID := firewall.Allocation.Project
socksProxyPort := viper.GetInt("proxy-port")

authKeyResp, err := c.client.VPN().GetVPNAuthKey(vpn.NewGetVPNAuthKeyParams().WithBody(&models.V1VPNRequest{
Pid: projectID,
Expand All @@ -269,7 +272,7 @@ func (c *firewallCmd) firewallSSHViaVPN(firewall *models.V1FirewallResponse) (er

containerConfig := &container.Config{
Image: tailscaleImage,
Cmd: []string{"tailscaled", "--tun=userspace-networking", "--no-logs-no-support", fmt.Sprintf("--socks5-server=:%d", viper.GetInt("proxy-port"))},
Cmd: []string{"tailscaled", "--tun=userspace-networking", "--no-logs-no-support", fmt.Sprintf("--socks5-server=:%d", socksProxyPort)},
}
hostConfig := &container.HostConfig{
NetworkMode: container.NetworkMode("host"),
Expand Down Expand Up @@ -311,8 +314,16 @@ func (c *firewallCmd) firewallSSHViaVPN(firewall *models.V1FirewallResponse) (er
if err != nil {
return fmt.Errorf("failed to get Firewall VPN address: %w", err)
}
ip, err := netip.ParseAddr(firewallVPNAddr)
if err != nil {
return fmt.Errorf("unable to parse firewall vpn address %w", err)
}
addr := ip.String()
if ip.Is6() {
addr = fmt.Sprintf("[%s]", ip)
}

err = SSHClientOverSOCKS5("metal", viper.GetString("identity"), firewallVPNAddr, 22, fmt.Sprintf(":%d", viper.GetInt("proxy-port")))
err = SSHClientOverSOCKS5("metal", viper.GetString("identity"), addr, 22, fmt.Sprintf(":%d", socksProxyPort))
if err != nil {
return fmt.Errorf("machine console error:%w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"fmt"
"golang.org/x/net/proxy"
"net"
"os"
"time"

"golang.org/x/net/proxy"

"golang.org/x/crypto/ssh"
"golang.org/x/term"
)
Expand Down