@@ -147,6 +147,7 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
147147 }
148148 if srv .PasswordHandler != nil {
149149 config .PasswordCallback = func (conn gossh.ConnMetadata , password []byte ) (* gossh.Permissions , error ) {
150+ resetPermissions (ctx )
150151 applyConnMetadata (ctx , conn )
151152 if ok := srv .PasswordHandler (ctx , string (password )); ! ok {
152153 return ctx .Permissions ().Permissions , fmt .Errorf ("permission denied" )
@@ -156,6 +157,7 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
156157 }
157158 if srv .PublicKeyHandler != nil {
158159 config .PublicKeyCallback = func (conn gossh.ConnMetadata , key gossh.PublicKey ) (* gossh.Permissions , error ) {
160+ resetPermissions (ctx )
159161 applyConnMetadata (ctx , conn )
160162 if ok := srv .PublicKeyHandler (ctx , key ); ! ok {
161163 return ctx .Permissions ().Permissions , fmt .Errorf ("permission denied" )
@@ -166,6 +168,7 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
166168 }
167169 if srv .KeyboardInteractiveHandler != nil {
168170 config .KeyboardInteractiveCallback = func (conn gossh.ConnMetadata , challenger gossh.KeyboardInteractiveChallenge ) (* gossh.Permissions , error ) {
171+ resetPermissions (ctx )
169172 applyConnMetadata (ctx , conn )
170173 if ok := srv .KeyboardInteractiveHandler (ctx , challenger ); ! ok {
171174 return ctx .Permissions ().Permissions , fmt .Errorf ("permission denied" )
@@ -299,6 +302,11 @@ func (srv *Server) HandleConn(newConn net.Conn) {
299302 return
300303 }
301304
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+
302310 srv .trackConn (sshConn , true )
303311 defer srv .trackConn (sshConn , false )
304312
0 commit comments