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

VAULT-5422: Add rate limit for TOTP passcode attempts #14864

Merged
merged 12 commits into from
Apr 14, 2022
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