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

Stop Vault token renew on task exit #2495

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ func (f *tokenFuture) Get() string {
// allows setting the initial Vault token. This is useful when the Vault token
// is recovered off disk.
func (r *TaskRunner) vaultManager(token string) {
// Always stop renewing the token. If token is empty or untracked, it is a
// no-op so this is always safe.
defer r.vaultClient.StopRenewToken(r.vaultFuture.Get())

// updatedToken lets us store state between loops. If true, a new token
// has been retrieved and we need to apply the Vault change mode
var updatedToken bool
Expand Down
8 changes: 1 addition & 7 deletions client/vaultclient/vaultclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,8 @@ func (c *vaultClient) renew(req *vaultClientRenewalRequest) error {
// item is tracked by the renewal loop, stop renewing
// it by removing the corresponding heap entry.
if err := c.heap.Remove(req.id); err != nil {
return fmt.Errorf("failed to remove heap entry. err: %v", err)
return fmt.Errorf("failed to remove heap entry: %v", err)
}
delete(c.heap.heapMap, req.id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers sake, there are so many things called heap. The c.heap.Remove method has this definition:

func (h *vaultClientHeap) Remove(id string) error {
	if entry, ok := h.heapMap[id]; ok {
		heap.Remove(&h.heap, entry.index)
		delete(h.heapMap, id)
		return nil
	}

	return fmt.Errorf("heap doesn't contain entry for %v", id)
}

Thus the delete(c.heap.heapMap, req.id) is not necessary


// Report the fatal error to the client
req.errCh <- renewalErr
Expand Down Expand Up @@ -578,15 +577,10 @@ func (c *vaultClient) stopRenew(id string) error {
return nil
}

// Remove the identifier from the heap
if err := c.heap.Remove(id); err != nil {
return fmt.Errorf("failed to remove heap entry: %v", err)
}

// Delete the identifier from the map only after the it is removed from
// the heap. Heap's remove method relies on the heap map.
delete(c.heap.heapMap, id)

// Signal an update to the renewal loop.
if c.running {
select {
Expand Down