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

allow proxy during SSH host key scan in FluxCD CLI #827

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 ssh/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ go 1.22.0
require (
github.com/onsi/gomega v1.34.2
golang.org/x/crypto v0.27.0
golang.org/x/net v0.29.0
)

require (
github.com/google/go-cmp v0.6.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
18 changes: 15 additions & 3 deletions ssh/host_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ limitations under the License.
package ssh

import (
"context"
"encoding/base64"
"fmt"
"net"
"time"

"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"
"golang.org/x/net/proxy"
)

// ScanHostKey collects the given host's preferred public key for the
Expand All @@ -45,10 +47,20 @@ func ScanHostKey(host string, timeout time.Duration, clientHostKeyAlgos []string
config.HostKeyAlgorithms = clientHostKeyAlgos
}

client, err := ssh.Dial("tcp", host, config)
if err == nil {
defer client.Close()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
// support for ALL_PROXY ENV varaible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// support for ALL_PROXY ENV varaible
// this reads the ALL_PROXY environment variable

conn, err := proxy.Dial(ctx, "tcp", host)
if err != nil {
return nil, err
}
c, chans, reqs, err := ssh.NewClientConn(conn, host, config)
if err != nil {
return nil, err
}
client := ssh.NewClient(c, chans, reqs)
defer client.Close()

if len(col.knownKeys) > 0 {
return col.knownKeys, nil
}
Expand Down