Skip to content

Commit

Permalink
Return invalid lease on negative TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
calvn committed May 8, 2018
1 parent 8d6ab91 commit a39597e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2215,34 +2215,36 @@ func (b *SystemBackend) handleLeaseLookup(ctx context.Context, req *logical.Requ
logical.ErrInvalidRequest
}

leaseTimes, err := b.Core.expiration.FetchLeaseTimes(leaseID)
le, err := b.Core.expiration.FetchLeaseTimes(leaseID)
if err != nil {
b.Backend.Logger().Error("error retrieving lease", "lease_id", leaseID, "error", err)
return handleError(err)
}
if leaseTimes == nil {

if le == nil || le.ttl() < 0 {
return logical.ErrorResponse("invalid lease"), logical.ErrInvalidRequest
}

resp := &logical.Response{
Data: map[string]interface{}{
"id": leaseID,
"issue_time": leaseTimes.IssueTime,
"issue_time": le.IssueTime,
"expire_time": nil,
"last_renewal": nil,
"ttl": int64(0),
},
}
renewable, _ := leaseTimes.renewable()
renewable, _ := le.renewable()
resp.Data["renewable"] = renewable

if !leaseTimes.LastRenewalTime.IsZero() {
resp.Data["last_renewal"] = leaseTimes.LastRenewalTime
if !le.LastRenewalTime.IsZero() {
resp.Data["last_renewal"] = le.LastRenewalTime
}
if !leaseTimes.ExpireTime.IsZero() {
resp.Data["expire_time"] = leaseTimes.ExpireTime
resp.Data["ttl"] = leaseTimes.ttl()
if !le.ExpireTime.IsZero() {
resp.Data["expire_time"] = le.ExpireTime
resp.Data["ttl"] = le.ttl()
}

return resp, nil
}

Expand Down

0 comments on commit a39597e

Please sign in to comment.