Skip to content

Commit

Permalink
vault: ensure ttl expired tokens are purge
Browse files Browse the repository at this point in the history
If a token is scheduled for revocation expires before we revoke it,
ensure that it is marked as purged in raft and is only removed from
local vault state if the purge operation succeeds.

Prior to this change, we may remove the accessor from local state but
not purge it from Raft.  This causes unnecessary and churn in the next
leadership elections (and until 0.11.2 result in indefinite retries).
  • Loading branch information
Mahmood Ali committed May 21, 2020
1 parent adaeb10 commit c781608
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nomad/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,10 @@ func (v *vaultClient) revokeDaemon() {
toRevoke = maxVaultRevokeBatchSize
}
revoking := make([]*structs.VaultAccessor, 0, toRevoke)
ttlExpired := []*structs.VaultAccessor{}
for va, ttl := range v.revoking {
if now.After(ttl) {
delete(v.revoking, va)
ttlExpired = append(ttlExpired, va)
} else {
revoking = append(revoking, va)
}
Expand All @@ -1283,6 +1284,10 @@ func (v *vaultClient) revokeDaemon() {
// Unlock before a potentially expensive operation
v.revLock.Unlock()

// purge all explicitly revoked as well as ttl expired tokens
// and only remove them locally on purge success
revoking = append(revoking, ttlExpired...)

// Call the passed in token revocation function
if err := v.purgeFn(revoking); err != nil {
// Can continue since revocation is idempotent
Expand Down

0 comments on commit c781608

Please sign in to comment.