@@ -147,6 +147,7 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
147
147
}
148
148
if srv .PasswordHandler != nil {
149
149
config .PasswordCallback = func (conn gossh.ConnMetadata , password []byte ) (* gossh.Permissions , error ) {
150
+ resetPermissions (ctx )
150
151
applyConnMetadata (ctx , conn )
151
152
if ok := srv .PasswordHandler (ctx , string (password )); ! ok {
152
153
return ctx .Permissions ().Permissions , fmt .Errorf ("permission denied" )
@@ -156,6 +157,7 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
156
157
}
157
158
if srv .PublicKeyHandler != nil {
158
159
config .PublicKeyCallback = func (conn gossh.ConnMetadata , key gossh.PublicKey ) (* gossh.Permissions , error ) {
160
+ resetPermissions (ctx )
159
161
applyConnMetadata (ctx , conn )
160
162
if ok := srv .PublicKeyHandler (ctx , key ); ! ok {
161
163
return ctx .Permissions ().Permissions , fmt .Errorf ("permission denied" )
@@ -166,6 +168,7 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
166
168
}
167
169
if srv .KeyboardInteractiveHandler != nil {
168
170
config .KeyboardInteractiveCallback = func (conn gossh.ConnMetadata , challenger gossh.KeyboardInteractiveChallenge ) (* gossh.Permissions , error ) {
171
+ resetPermissions (ctx )
169
172
applyConnMetadata (ctx , conn )
170
173
if ok := srv .KeyboardInteractiveHandler (ctx , challenger ); ! ok {
171
174
return ctx .Permissions ().Permissions , fmt .Errorf ("permission denied" )
@@ -299,6 +302,11 @@ func (srv *Server) HandleConn(newConn net.Conn) {
299
302
return
300
303
}
301
304
305
+ // Additionally, now that the connection was authed, we can take the
306
+ // permissions off of the gossh.Conn and re-attach them to the Permissions
307
+ // object stored in the Context.
308
+ ctx .Permissions ().Permissions = sshConn .Permissions
309
+
302
310
srv .trackConn (sshConn , true )
303
311
defer srv .trackConn (sshConn , false )
304
312
0 commit comments