Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete method id if not used in an MFA enforcement config #14063

Merged
merged 2 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions vault/login_mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,18 @@ func (b *LoginMFABackend) deleteMFAConfigByMethodID(ctx context.Context, configI
b.mfaLock.Lock()
defer b.mfaLock.Unlock()

eConfigIter, err := b.MemDBMFALoginEnforcementConfigIterator()
if err != nil {
return err
}

for eConfigRaw := eConfigIter.Next(); eConfigRaw != nil; eConfigRaw = eConfigIter.Next() {
eConfig := eConfigRaw.(*mfa.MFAEnforcementConfig)
if strutil.StrListContains(eConfig.MFAMethodIDs, configID) {
return fmt.Errorf("methodID is still used by an enforcement configuration with ID: %s", eConfig.ID)
}
}

// Delete the config from storage
entryIndex := prefix + configID
err = b.Core.systemBarrierView.Delete(ctx, entryIndex)
Expand Down
4 changes: 2 additions & 2 deletions vault/request_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ func (c *Core) handleRequest(ctx context.Context, req *logical.Request) (retResp
// Only the token store is allowed to return an auth block, for any
// other request this is an internal error.
if resp != nil && resp.Auth != nil {
if !strings.HasPrefix(req.Path, "auth/token/") && req.Path != "sys/mfa/validate" {
if !strings.HasPrefix(req.Path, "auth/token/") {
c.logger.Error("unexpected Auth response for non-token backend", "request_path", req.Path)
retErr = multierror.Append(retErr, ErrInternalError)
return nil, auth, retErr
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func (c *Core) handleLoginRequest(ctx context.Context, req *logical.Request) (re
return
}
// If the response generated an authentication, then generate the token
if resp != nil && resp.Auth != nil {
if resp != nil && resp.Auth != nil && req.Path != "sys/mfa/validate" {
leaseGenerated := false

// by placing this after the authorization check, we don't leak
Expand Down