Skip to content

Commit

Permalink
Fix update user in the webui.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger committed Dec 12, 2023
1 parent b4f6d7d commit 2f5b5e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/mfa/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func MFAResponseFromContext(ctx context.Context) (*proto.MFAAuthenticateResponse
if !ok {
return nil, trace.BadParameter("unexpected context value type %T", val)
}
if mfaResp == nil {
return nil, trace.NotFound("mfa response not found in the context")
}
return mfaResp, nil
}
return nil, trace.NotFound("mfa response not found in the context")
Expand Down
7 changes: 6 additions & 1 deletion lib/web/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/julienschmidt/httprouter"

"github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/mfa"
"github.com/gravitational/teleport/api/types"
wantypes "github.com/gravitational/teleport/lib/auth/webauthntypes"
"github.com/gravitational/teleport/lib/httplib"
Expand Down Expand Up @@ -155,7 +156,11 @@ func updateUser(r *http.Request, m userAPIGetter, createdBy string) (*ui.User, e
return nil, trace.Wrap(err)
}

user, err := m.GetUser(r.Context(), req.Name, false)
// Remove the MFA resp from the context before getting the user.
// Otherwise, it will be consumed before the Update which actually
// requires the MFA.
getUserCtx := mfa.ContextWithMFAResponse(r.Context(), nil)
user, err := m.GetUser(getUserCtx, req.Name, false)
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down

0 comments on commit 2f5b5e8

Please sign in to comment.