grim/hgkeeper

Parents da30c41b6cf3
Children 75c2fc8feb73
Read all ssh keys from a file only logging errors. Also output how many keys we loaded for each user
--- a/access/users.go Tue Sep 17 22:09:41 2019 -0500
+++ b/access/users.go Tue Sep 17 22:50:27 2019 -0500
@@ -5,6 +5,7 @@
"io/ioutil"
"os"
"path/filepath"
+ "strings"
"sync"
log "github.com/sirupsen/logrus"
@@ -57,19 +58,26 @@
return
}
+ counter := 0
+
// iterate through the file reading one ssh public key at a time
for len(buffer) > 0 {
var pubkey ssh.PublicKey
pubkey, _, _, buffer, err = ssh.ParseAuthorizedKey(buffer)
if err != nil {
- log.Warnf("failed to parse key file for user %s: %v", username, err)
- return
+ if !strings.HasSuffix(err.Error(), "ssh: no key found") {
+ log.Warnf("failed to parse key file for user %s: %v", username, err)
+ }
+
+ continue
}
fingerprint := ssh.FingerprintSHA256(pubkey)
keys[fingerprint] = username
+ counter++
}
+ log.Infof("loaded %d keys for user %q", counter, username)
}
// UsernameFromFingerprint looks up a username from an SSH key's fingerprint