feat(ssh): support ssh known hosts file (#6263)
This commit is contained in:
1 parent
6533c8bdb3
commit
4bae4f23f5
7 files changed
+281
-2
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
serverpb "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
// Option - how Options are passed as arguments.
|
||||
@@ -30,6 +31,7 @@ type Options struct {
|
||||
WithTestKdcAddress string
|
||||
WithTestKerberosServerHostname string
|
||||
WithLogger hclog.Logger
|
||||
WithSshHostKeyCallback ssh.HostKeyCallback
|
||||
}
|
||||
|
||||
func getDefaultOptions() Options {
|
||||
@@ -87,3 +89,11 @@ func WithLogger(l hclog.Logger) Option {
|
||||
o.WithLogger = l
|
||||
}
|
||||
}
|
||||
|
||||
// WithSshHostKeyCallback allows specifying a ssh.HostKeyCallback function
|
||||
// to be used for host key verification.
|
||||
func WithSshHostKeyCallback(with ssh.HostKeyCallback) Option {
|
||||
return func(o *Options) {
|
||||
o.WithSshHostKeyCallback = with
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"net"
|
||||
"reflect"
|
||||
"runtime"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
|
||||
serverpb "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func Test_GetOpts(t *testing.T) {
|
||||
@@ -63,4 +65,15 @@ func Test_GetOpts(t *testing.T) {
|
||||
testOpts.WithTestKerberosServerHostname = testKerberosServerHostname
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithSshHostKeyCallback", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getDefaultOptions()
|
||||
assert.Nil(opts.WithSshHostKeyCallback)
|
||||
|
||||
signer, err := ssh.NewSignerFromKey(ed25519.NewKeyFromSeed([]byte("foobfoobfoobfoobfoobfoobfoobfoob")))
|
||||
assert.NoError(err)
|
||||
|
||||
opts = GetOpts(WithSshHostKeyCallback(ssh.FixedHostKey(signer.PublicKey())))
|
||||
assert.NotNil(opts.WithSshHostKeyCallback)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user