Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xuluna committed Jan 2, 2024
1 parent 1c0dcc7 commit e1b6927
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ run:
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
skip-dirs:
- go/pkg
- go/src

issues:
max-issues-per-linter: 0
Expand Down
3 changes: 1 addition & 2 deletions test/ssh/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"podmon/test/ssh"
"time"
)

func main() {
Expand Down
30 changes: 29 additions & 1 deletion test/ssh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package ssh

import (
"encoding/base64"
"fmt"
"log"
"net"
"os"
"strings"
"time"
Expand Down Expand Up @@ -104,12 +107,37 @@ func NewWrapper(accessInfo *AccessInfo) *Wrapper {
ssh.Password(accessInfo.Password),
},
// Non-production only
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
// the original code is blocked by golint. this method currently set the key to empty for testing
// a warning message will be displayed with the currect key
HostKeyCallback: trustedHostKeyCallback(""),
}
wrapper := &Wrapper{SSHConfig: config}
return wrapper
}

// create human-readable SSH-key strings
func keyString(k ssh.PublicKey) string {
return k.Type() + " " + base64.StdEncoding.EncodeToString(k.Marshal())
}

func trustedHostKeyCallback(trustedKey string) ssh.HostKeyCallback {
if trustedKey == "" {
return func(_ string, _ net.Addr, k ssh.PublicKey) error {
log.Printf("WARNING: SSH-key verification is *NOT* in effect: to fix, add this trustedKey: %q", keyString(k))
return nil
}
}

return func(_ string, _ net.Addr, k ssh.PublicKey) error {
ks := keyString(k)
if trustedKey != ks {
return fmt.Errorf("SSH-key verification: expected %q but got %q", trustedKey, ks)
}

return nil
}
}

// GetSession makes underlying call to crypto ssh library to create an SSH session
func (w *Wrapper) GetSession(hostAndPort string) (SessionWrapper, error) {
client, err := ssh.Dial("tcp", hostAndPort, w.SSHConfig)
Expand Down
5 changes: 2 additions & 3 deletions test/ssh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ package ssh_test

import (
"fmt"
"podmon/test/ssh"
"podmon/test/ssh/mocks"
"strings"
"testing"
"time"

"podmon/test/ssh"
"podmon/test/ssh/mocks"

"github.com/golang/mock/gomock"
)

Expand Down

0 comments on commit e1b6927

Please sign in to comment.