From e64aa0d9c2343dc10d22fea67e9aeed82ebcb569 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 10 Aug 2023 17:04:48 +0800 Subject: [PATCH] Fix admin queue page title and fix CI failures (#26409) (#26421) Backport #26409 * Fix #26408 * Bypass the data race issue in "ssh" package (cherry picked from commit 8ad331c9d209f50ed41c92b289ea2dcf575b1bdb) --- modules/ssh/ssh.go | 9 +++++++-- routers/web/admin/queue.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 923fa51d22..a5af5c129b 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -17,6 +17,7 @@ import ( "os" "os/exec" "path/filepath" + "reflect" "strconv" "strings" "sync" @@ -164,6 +165,10 @@ func sessionHandler(session ssh.Session) { } func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool { + // FIXME: the "ssh.Context" is not thread-safe, so db operations should use the immutable parent "Context" + // TODO: Remove after https://github.com/gliderlabs/ssh/pull/211 + parentCtx := reflect.ValueOf(ctx).Elem().FieldByName("Context").Interface().(context.Context) + if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary log.Debug("Handle Public Key: Fingerprint: %s from %s", gossh.FingerprintSHA256(key), ctx.RemoteAddr()) } @@ -189,7 +194,7 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool { // look for the exact principal principalLoop: for _, principal := range cert.ValidPrincipals { - pkey, err := asymkey_model.SearchPublicKeyByContentExact(ctx, principal) + pkey, err := asymkey_model.SearchPublicKeyByContentExact(parentCtx, principal) if err != nil { if asymkey_model.IsErrKeyNotExist(err) { log.Debug("Principal Rejected: %s Unknown Principal: %s", ctx.RemoteAddr(), principal) @@ -246,7 +251,7 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool { log.Debug("Handle Public Key: %s Fingerprint: %s is not a certificate", ctx.RemoteAddr(), gossh.FingerprintSHA256(key)) } - pkey, err := asymkey_model.SearchPublicKeyByContent(ctx, strings.TrimSpace(string(gossh.MarshalAuthorizedKey(key)))) + pkey, err := asymkey_model.SearchPublicKeyByContent(parentCtx, strings.TrimSpace(string(gossh.MarshalAuthorizedKey(key)))) if err != nil { if asymkey_model.IsErrKeyNotExist(err) { log.Warn("Unknown public key: %s from %s", gossh.FingerprintSHA256(key), ctx.RemoteAddr()) diff --git a/routers/web/admin/queue.go b/routers/web/admin/queue.go index 4e01846ba8..18a8d7d3e6 100644 --- a/routers/web/admin/queue.go +++ b/routers/web/admin/queue.go @@ -16,7 +16,7 @@ func Queues(ctx *context.Context) { if !setting.IsProd { initTestQueueOnce() } - ctx.Data["Title"] = ctx.Tr("admin.monitor.queue") + ctx.Data["Title"] = ctx.Tr("admin.monitor.queues") ctx.Data["PageIsAdminMonitorQueue"] = true ctx.Data["Queues"] = queue.GetManager().ManagedQueues() ctx.HTML(http.StatusOK, tplQueue)