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

Add logic for using Auth.Period when handling auth login/renew requests #3677

Merged
merged 10 commits into from
Dec 15, 2017
Prev Previous commit
Next Next commit
Use switch for ttl/period check on RenewToken
  • Loading branch information
calvn committed Dec 14, 2017
commit 465506ad6c99256a38739249da89dc63ea841015
15 changes: 8 additions & 7 deletions vault/expiration.go
Original file line number Diff line number Diff line change
@@ -756,21 +756,22 @@ func (m *ExpirationManager) RenewToken(req *logical.Request, source string, toke
}

retResp := &logical.Response{}
// Cap TTL value to the sys/mount max value
if resp.Auth.TTL > sysView.MaxLeaseTTL() {
retResp.AddWarning(fmt.Sprintf("TTL of %d seconds is greater than current mount/system default of %d seconds, value will be truncated.", resp.Auth.TTL, sysView.MaxLeaseTTL()))
resp.Auth.TTL = sysView.MaxLeaseTTL()
}

switch {
// If it resp.Period is non-zero, use that as the TTL and override backend's
// call on TTL modification, such as a TTL value determined by
// framework.LeaseExtend call against the request.
if resp.Auth.Period > time.Duration(0) {
case resp.Auth.Period > time.Duration(0):
if resp.Auth.Period > sysView.MaxLeaseTTL() {
retResp.AddWarning(fmt.Sprintf("Period of %d seconds is greater than current mount/system default of %d seconds, value will be truncated.", resp.Auth.TTL, sysView.MaxLeaseTTL()))
resp.Auth.Period = sysView.MaxLeaseTTL()
}
resp.Auth.TTL = resp.Auth.Period
// Cap TTL value to the sys/mount max value
case resp.Auth.TTL > time.Duration(0):
if resp.Auth.TTL > sysView.MaxLeaseTTL() {
retResp.AddWarning(fmt.Sprintf("TTL of %d seconds is greater than current mount/system default of %d seconds, value will be truncated.", resp.Auth.TTL, sysView.MaxLeaseTTL()))
resp.Auth.TTL = sysView.MaxLeaseTTL()
}
}

// Attach the ClientToken