@@ -17,6 +17,7 @@ import (
17
17
"os"
18
18
"os/exec"
19
19
"path/filepath"
20
+ "reflect"
20
21
"strconv"
21
22
"strings"
22
23
"sync"
@@ -164,6 +165,10 @@ func sessionHandler(session ssh.Session) {
164
165
}
165
166
166
167
func publicKeyHandler (ctx ssh.Context , key ssh.PublicKey ) bool {
168
+ // FIXME: the "ssh.Context" is not thread-safe, so db operations should use the immutable parent "Context"
169
+ // TODO: Remove after https://github.com/gliderlabs/ssh/pull/211
170
+ parentCtx := reflect .ValueOf (ctx ).Elem ().FieldByName ("Context" ).Interface ().(context.Context )
171
+
167
172
if log .IsDebug () { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
168
173
log .Debug ("Handle Public Key: Fingerprint: %s from %s" , gossh .FingerprintSHA256 (key ), ctx .RemoteAddr ())
169
174
}
@@ -189,7 +194,7 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
189
194
// look for the exact principal
190
195
principalLoop:
191
196
for _ , principal := range cert .ValidPrincipals {
192
- pkey , err := asymkey_model .SearchPublicKeyByContentExact (ctx , principal )
197
+ pkey , err := asymkey_model .SearchPublicKeyByContentExact (parentCtx , principal )
193
198
if err != nil {
194
199
if asymkey_model .IsErrKeyNotExist (err ) {
195
200
log .Debug ("Principal Rejected: %s Unknown Principal: %s" , ctx .RemoteAddr (), principal )
@@ -246,7 +251,7 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
246
251
log .Debug ("Handle Public Key: %s Fingerprint: %s is not a certificate" , ctx .RemoteAddr (), gossh .FingerprintSHA256 (key ))
247
252
}
248
253
249
- pkey , err := asymkey_model .SearchPublicKeyByContent (ctx , strings .TrimSpace (string (gossh .MarshalAuthorizedKey (key ))))
254
+ pkey , err := asymkey_model .SearchPublicKeyByContent (parentCtx , strings .TrimSpace (string (gossh .MarshalAuthorizedKey (key ))))
250
255
if err != nil {
251
256
if asymkey_model .IsErrKeyNotExist (err ) {
252
257
log .Warn ("Unknown public key: %s from %s" , gossh .FingerprintSHA256 (key ), ctx .RemoteAddr ())
0 commit comments