Skip to content

Commit f9f001f

Browse files
committed
managerd: Enchancing host healthcheck
1 parent 86e36b6 commit f9f001f

File tree

292 files changed

+71662
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

292 files changed

+71662
-0
lines changed

route/route.go

+28
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ package route
1212
import (
1313
"math/rand"
1414
"net"
15+
"regexp"
1516
"time"
1617

1718
"github.com/op/go-logging"
19+
20+
"golang.org/x/crypto/ssh"
1821
)
1922

2023
var log = logging.MustGetLogger("sshproxy/route")
@@ -61,6 +64,31 @@ func CanConnect(hostport string) bool {
6164
return true
6265
}
6366

67+
// MightAuthenticate tests if a connection to host:port can initiate an handshake.
68+
func MightAuthenticate(hostport string, user string) bool {
69+
ssh_config := &ssh.ClientConfig{
70+
User: user,
71+
Auth: []ssh.AuthMethod{
72+
ssh.Password("ThisIsNotIntendedToBeAValidPasswordButWeDontReallyCare"),
73+
},
74+
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
75+
}
76+
log.Debug("Dialing %s with user %s", hostport, user)
77+
client, err := ssh.Dial("tcp", hostport, ssh_config)
78+
if err != nil {
79+
re_auth_failure := regexp.MustCompile(`handshake failed: ssh: unable to authenticate`).MatchString(err.Error())
80+
if re_auth_failure {
81+
return true
82+
} else {
83+
log.Warning("Error while dialing %v", err)
84+
return false
85+
}
86+
} else {
87+
client.Close()
88+
}
89+
return true
90+
}
91+
6492
// selectDestinationOrdered selects the first reachable destination from a list
6593
// of destinations. It returns a string "host:port", an empty string (if no
6694
// destination is found) or an error.

sshproxy-managerd/sshproxy-managerd.go

+36
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"flag"
1616
"fmt"
1717
"io/ioutil"
18+
"math/rand"
1819
"net"
1920
"os"
2021
"regexp"
@@ -165,10 +166,43 @@ func (hc *hostChecker) DoCheck(hostport string) State {
165166
if route.CanConnect(hostport) {
166167
state = Up
167168
}
169+
canary_user, err := PickUser()
170+
if err == nil && canary_user != "" && state == Up {
171+
if route.MightAuthenticate(hostport, canary_user) {
172+
log.Debug("Succefully tried to authenticate to %s as %s", hostport, canary_user)
173+
} else {
174+
log.Debug("Unable to try to authenticate against %s as %s", hostport, canary_user)
175+
state = Down
176+
}
177+
} else if err != nil {
178+
log.Debugf("Unable to try to authenticate, found no user to spoof (%s)", err)
179+
}
168180
hc.Update(hostport, state, time.Now())
169181
return state
170182
}
171183

184+
func PickUser() (string, error) {
185+
chosen_user := ""
186+
if len(proxiedConnections) > 0 {
187+
chosen_item := rand.Intn(len(proxiedConnections))
188+
for k := range proxiedConnections {
189+
if chosen_item == 0 {
190+
user, err := getUserFromKey(k)
191+
if err != nil {
192+
return "", err
193+
} else {
194+
chosen_user = user
195+
break
196+
}
197+
}
198+
chosen_item--
199+
}
200+
} else {
201+
return "", errors.New("No proxied connections, unable to pick a random user...")
202+
}
203+
return chosen_user, nil
204+
}
205+
172206
// Update updates (or creates) the state of an host in the internal view.
173207
func (hc *hostChecker) Update(hostport string, state State, ts time.Time) {
174208
if s, ok := hc.States[hostport]; ok {
@@ -631,6 +665,8 @@ func main() {
631665
}
632666
defer l.Close()
633667

668+
rand.Seed(time.Now().Unix()) // initialize global pseudo random generator
669+
634670
log.Info("listening on %s\n", config.Listen)
635671

636672
queue := make(chan *request)

vendor/golang.org/x/crypto/.gitattributes

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/.gitignore

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/AUTHORS

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/CONTRIBUTING.md

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/CONTRIBUTORS

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/LICENSE

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/PATENTS

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/crypto/README.md

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)