From f5e54c513cab09b9a047c98b73911508cbd9491e Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 22 Aug 2023 15:13:44 -0400 Subject: [PATCH 1/2] fix: add ssh commands back Unauthorized users would get an error message when using commands that need authorization --- server/ssh/middleware.go | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/server/ssh/middleware.go b/server/ssh/middleware.go index 9a387f49..300dd379 100644 --- a/server/ssh/middleware.go +++ b/server/ssh/middleware.go @@ -68,6 +68,13 @@ func CommandMiddleware(sh ssh.Handler) ssh.Handler { cmd.GitUploadArchiveCommand(), cmd.GitReceivePackCommand(), cmd.RepoCommand(), + cmd.SettingsCommand(), + cmd.UserCommand(), + cmd.InfoCommand(), + cmd.PubkeyCommand(), + cmd.SetUsernameCommand(), + cmd.JWTCommand(), + cmd.TokenCommand(), ) if cfg.LFS.Enabled { @@ -92,25 +99,6 @@ func CommandMiddleware(sh ssh.Handler) ssh.Handler { rootCmd.SetErr(s.Stderr()) rootCmd.SetContext(ctx) - user := proto.UserFromContext(ctx) - isAdmin := cmd.IsPublicKeyAdmin(cfg, s.PublicKey()) || (user != nil && user.IsAdmin()) - if user != nil || isAdmin { - if isAdmin { - rootCmd.AddCommand( - cmd.SettingsCommand(), - cmd.UserCommand(), - ) - } - - rootCmd.AddCommand( - cmd.InfoCommand(), - cmd.PubkeyCommand(), - cmd.SetUsernameCommand(), - cmd.JWTCommand(), - cmd.TokenCommand(), - ) - } - if err := rootCmd.ExecuteContext(ctx); err != nil { s.Exit(1) // nolint: errcheck return From 8a5a0ec958bec1ea73c5e05085caaa15062414c3 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 22 Aug 2023 15:50:56 -0400 Subject: [PATCH 2/2] feat: bump charmbracelet/ssh to fix race issue --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 1b4fc247..673f1b13 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/charmbracelet/git-lfs-transfer v0.1.1-0.20230725143853-5dd0632f9245 github.com/charmbracelet/keygen v0.4.3 github.com/charmbracelet/log v0.2.3 - github.com/charmbracelet/ssh v0.0.0-20230720143903-5bdd92839155 + github.com/charmbracelet/ssh v0.0.0-20230822194956-1a051f898e09 github.com/go-jose/go-jose/v3 v3.0.0 github.com/gobwas/glob v0.2.3 github.com/gogs/git-module v1.8.2 diff --git a/go.sum b/go.sum index 9a44f257..94541c2b 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ github.com/charmbracelet/log v0.2.3 h1:YVmBhJtpGL7nW/nlf5u+SEloU8XYljxozGzZpgwIv github.com/charmbracelet/log v0.2.3/go.mod h1:ZApwwzDbbETVTIRTk7724yQRJAXIktt98yGVMMaa3y8= github.com/charmbracelet/ssh v0.0.0-20230720143903-5bdd92839155 h1:vJqYhlL0doAWQPz+EX/hK5x/ZYguoua773oRz77zYKo= github.com/charmbracelet/ssh v0.0.0-20230720143903-5bdd92839155/go.mod h1:F1vgddWsb/Yr/OZilFeRZEh5sE/qU0Dt1mKkmke6Zvg= +github.com/charmbracelet/ssh v0.0.0-20230822194956-1a051f898e09 h1:ZDIQmTtohv0S/AAYE//w8mYTxCzqphhF1+4ACPDMiLU= +github.com/charmbracelet/ssh v0.0.0-20230822194956-1a051f898e09/go.mod h1:F1vgddWsb/Yr/OZilFeRZEh5sE/qU0Dt1mKkmke6Zvg= github.com/charmbracelet/wish v1.1.1 h1:KdICASKd2oh2JPvk1Z4CJtAi97cFErXF7NKienPICO4= github.com/charmbracelet/wish v1.1.1/go.mod h1:xh4KZpSULw+Xqb9bcbhw92QAinVB75CVLWrFuyY6IVs= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=