-
Notifications
You must be signed in to change notification settings - Fork 8
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
add config ssh jump server #1522
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ type sshSuite struct { | |
jumpSSHServer ssh.Server | ||
jumpServerPort int | ||
privateKey gossh.Signer | ||
hostKey gossh.Signer | ||
testInDestinationServerF func(fm ssh.ForwardMessage) | ||
received chan bool | ||
} | ||
|
@@ -71,13 +72,29 @@ func (s *sshSuite) Init(c *qt.C) { | |
port, err = jimmtest.GetFreePort() | ||
c.Assert(err, qt.IsNil) | ||
s.jumpServerPort = port | ||
s.jumpSSHServer, err = ssh.NewJumpSSHServer(context.Background(), port, resolver{}) | ||
k, err := rsa.GenerateKey(rand.Reader, 2048) | ||
c.Assert(err, qt.IsNil) | ||
hostKey := pem.EncodeToMemory( | ||
&pem.Block{ | ||
Type: "RSA PRIVATE KEY", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no constant for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i've looked around and it's always a string, no types. even in the godoc of this field: |
||
Bytes: x509.MarshalPKCS1PrivateKey(k), | ||
}, | ||
) | ||
s.hostKey, err = gossh.ParsePrivateKey(hostKey) | ||
c.Assert(err, qt.IsNil) | ||
|
||
s.jumpSSHServer, err = ssh.NewJumpServer(context.Background(), | ||
ssh.Config{ | ||
Port: fmt.Sprint(port), | ||
HostKey: hostKey}, | ||
resolver{}, | ||
) | ||
c.Assert(err, qt.IsNil) | ||
go func() { | ||
_ = s.jumpSSHServer.ListenAndServe() | ||
}() | ||
|
||
k, err := rsa.GenerateKey(rand.Reader, 2048) | ||
k, err = rsa.GenerateKey(rand.Reader, 2048) | ||
c.Assert(err, qt.IsNil) | ||
keyPEM := pem.EncodeToMemory( | ||
&pem.Block{ | ||
|
@@ -98,8 +115,7 @@ func (s *sshSuite) Init(c *qt.C) { | |
|
||
func (s *sshSuite) TestSSHJump(c *qt.C) { | ||
client, err := gossh.Dial("tcp", fmt.Sprintf(":%d", s.jumpServerPort), &gossh.ClientConfig{ | ||
//nolint:gosec // this will be removed once we handle hostkeys | ||
HostKeyCallback: gossh.InsecureIgnoreHostKey(), | ||
HostKeyCallback: gossh.FixedHostKey(s.hostKey.PublicKey()), | ||
Auth: []gossh.AuthMethod{ | ||
gossh.PublicKeys(s.privateKey), | ||
}, | ||
|
@@ -130,8 +146,7 @@ func (s *sshSuite) TestSSHJump(c *qt.C) { | |
|
||
func (s *sshSuite) TestSSHJumpDialFail(c *qt.C) { | ||
_, err := gossh.Dial("tcp", fmt.Sprintf(":%d", 1), &gossh.ClientConfig{ | ||
//nolint:gosec // this will be removed once we handle hostkeys | ||
HostKeyCallback: gossh.InsecureIgnoreHostKey(), | ||
HostKeyCallback: gossh.FixedHostKey(s.hostKey.PublicKey()), | ||
Auth: []gossh.AuthMethod{ | ||
gossh.PublicKeys(s.privateKey), | ||
}, | ||
|
@@ -142,8 +157,7 @@ func (s *sshSuite) TestSSHJumpDialFail(c *qt.C) { | |
func (s *sshSuite) TestSSHFinalDestinationDialFail(c *qt.C) { | ||
|
||
client, err := gossh.Dial("tcp", fmt.Sprintf(":%d", s.jumpServerPort), &gossh.ClientConfig{ | ||
//nolint:gosec // this will be removed once we handle hostkeys | ||
HostKeyCallback: gossh.InsecureIgnoreHostKey(), | ||
HostKeyCallback: gossh.FixedHostKey(s.hostKey.PublicKey()), | ||
Auth: []gossh.AuthMethod{ | ||
gossh.PublicKeys(s.privateKey), | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why isn't the resolver field on the Config struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the resolver is not a config but a service needed to operate the ssh server. I would leave it as a separate argument.
Don't you agree?