Skip to content

Commit

Permalink
fix: add ssh commands back (#370)
Browse files Browse the repository at this point in the history
* fix: add ssh commands back

Unauthorized users would get an error message when using commands that
need authorization

* feat: bump charmbracelet/ssh to fix race issue
  • Loading branch information
aymanbagabas authored Aug 22, 2023
1 parent 09dedc4 commit 942d494
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
26 changes: 7 additions & 19 deletions server/ssh/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 942d494

Please sign in to comment.