Skip to content

Commit

Permalink
VAULT-5422: Add rate limit for TOTP passcode attempts (#14864)
Browse files Browse the repository at this point in the history
* VAULT-5422: Add rate limit for TOTP passcode attempts

* fixing the docs

* CL

* feedback

* Additional info in doc

* rate limit is done per entity per methodID

* refactoring a test

* rate limit OSS work for policy MFA

* adding max_validation_attempts to TOTP config

* feedback

* checking for non-nil reference
  • Loading branch information
hghaf099 authored and kitography committed Apr 24, 2022
1 parent fb5a7a5 commit 3fe56cb
Show file tree
Hide file tree
Showing 11 changed files with 434 additions and 304 deletions.
3 changes: 3 additions & 0 deletions changelog/14864.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
auth: enforce a rate limit for TOTP passcode validation attempts
```
178 changes: 95 additions & 83 deletions helper/identity/mfa/types.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions helper/identity/mfa/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ message TOTPConfig {
uint32 key_size = 6;
// @inject_tag: sentinel:"-"
int32 qr_size = 7;
// @inject_tag: sentinel:"-"
uint32 max_validation_attempts = 8;
}

// DuoConfig represents the configuration information required to perform
Expand Down
12 changes: 12 additions & 0 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ const (
// MfaAuthResponse when the value is not specified in the server config
defaultMFAAuthResponseTTL = 300 * time.Second

// defaultMaxTOTPValidateAttempts is the default value for the number
// of failed attempts to validate a request subject to TOTP MFA. If the
// number of failed totp passcode validations exceeds this max value, the
// user needs to wait until a fresh totp passcode is generated.
defaultMaxTOTPValidateAttempts = 5

// ForwardSSCTokenToActive is the value that must be set in the
// forwardToActive to trigger forwarding if a perf standby encounters
// an SSC Token that it does not have the WAL state for.
Expand Down Expand Up @@ -2264,6 +2270,9 @@ func (c *Core) postUnseal(ctx context.Context, ctxCancelFunc context.CancelFunc,
c.logger.Warn("disabling entities for local auth mounts through env var", "env", EnvVaultDisableLocalAuthMountEntities)
}
c.loginMFABackend.usedCodes = cache.New(0, 30*time.Second)
if c.systemBackend != nil && c.systemBackend.mfaBackend != nil {
c.systemBackend.mfaBackend.usedCodes = cache.New(0, 30*time.Second)
}
c.logger.Info("post-unseal setup complete")
return nil
}
Expand Down Expand Up @@ -2340,6 +2349,9 @@ func (c *Core) preSeal() error {
}

c.loginMFABackend.usedCodes = nil
if c.systemBackend != nil && c.systemBackend.mfaBackend != nil {
c.systemBackend.mfaBackend.usedCodes = nil
}
preSealPhysical(c)

c.logger.Info("pre-seal teardown complete")
Expand Down
Loading

0 comments on commit 3fe56cb

Please sign in to comment.