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

[MAR-3131] Set grace to 0 on non-positive lease duration #12372

Merged
merged 3 commits into from Aug 25, 2021

Conversation

pmmukh
Copy link
Contributor

@pmmukh pmmukh commented Aug 19, 2021

@pmmukh pmmukh requested review from ncabatoff and a team August 19, 2021 18:59
@vercel vercel bot temporarily deployed to Preview – vault August 19, 2021 19:08 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook August 19, 2021 19:08 Inactive
@ncabatoff
Copy link
Contributor

I wasn't sure about this change initially because I wanted to understand if the negative remainingLeaseDuration hinted at a bug. It looks like it must occur as a result of us reaching the end of the lease's lifetime without having successfully renewed. In that case with this change we'll set grace to 0, and then we'll return nil since the lease has expired, which is what we want.

An alternative that might be a little clearer would be, on line 305, when we assign the new remainingLeaseDuration, check if it's negative, and return nil right away if so.

@pmmukh
Copy link
Contributor Author

pmmukh commented Aug 24, 2021

thanks for looking into this @ncabatoff , i really wasn't sure how exactly the negative leaseDuration was passed in, appreciate the eyes! For that L305 potential fix you mentioned, I'm going to give that a shot, see if that stops the invocation of calcGrace with negativeLeaseDuration, if so would also prefer to fix at the source there.

@pmmukh
Copy link
Contributor Author

pmmukh commented Aug 24, 2021

@ncabatoff hmm I don't think it's L305 that is causing the negative leaseDuration, at least in the context of the TestLeaseCacheRestore_expired test ( which is the one that was failing for the arm64 job ), so I added the change you suggested, added a print line Got leasedur to calculateGrace, and still seeing negative values getting passed in.
Screen Shot 2021-08-24 at 10 29 48 AM

@ncabatoff
Copy link
Contributor

Sorry, I should've cited the line rather than the number. I forgot I'd added some comments to my local checkout to make sense of what was happening. I meant this line:

				remainingLeaseDuration = initialTime.Add(time.Duration(initLeaseDuration) * time.Second).Sub(time.Now())

@pmmukh
Copy link
Contributor Author

pmmukh commented Aug 24, 2021

@ncabatoff ah yeah, so that's the line i was looking at too, i added the negative check n return nil right after it. I'm not exactly sure what the TestSendResponse object is used for, but based on this setup line in the test https://github.com/hashicorp/vault/blob/main/command/agent/cache/lease_cache_test.go#L1007, is it possible that we're creating a lease up front with a negative duration ?

@pmmukh
Copy link
Contributor Author

pmmukh commented Aug 24, 2021

To add some more context on what i've checked so far, calculateGrace is invoked in 2 places, https://github.com/hashicorp/vault/blob/main/api/lifetime_watcher.go#L260 and https://github.com/hashicorp/vault/blob/main/api/lifetime_watcher.go#L348. From some extra logs, noted that its the first call that is invoked by TestLeaseCacheRestore_expired, when passing negative values. And adding a if value < 0 return nil block there resulted in test failures, so think that might not be a valid thing to do.

@calvn
Copy link
Member

calvn commented Aug 24, 2021

Can you included a test in TestLifetimeWatcher (from renewer_test.go) that sets leaseDurationSeconds to a negative value to make sure that doRenewWithOptions performs as expected?

@vercel vercel bot temporarily deployed to Preview – vault-storybook August 24, 2021 23:38 Inactive
@vercel vercel bot temporarily deployed to Preview – vault August 24, 2021 23:38 Inactive
@pmmukh pmmukh merged commit 7f875c9 into main Aug 25, 2021
@pmmukh pmmukh deleted the mar-3131-fix-arm64-typecast-bug branch August 25, 2021 02:06
jartek pushed a commit to jartek/vault that referenced this pull request Sep 11, 2021
…2372)

* [MAR-3131] Set grace to 0 on non-positive lease duration

* [MAR-3131] Add changelog

* [VAULT-3131] Add test for negative lease duration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants