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

[spire-agent] Added a jitter in spire agent svid renewal #4534

Merged
merged 3 commits into from
Oct 20, 2023

Conversation

stevend-uber
Copy link
Contributor

Introduces a jitter to the renewal of SVIDs in spire-agent which will allow a more uniform distribution of requests to spire-server rather than thundering herds at the same time.

#4268

Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

Thank you @stevend-uber for this contribution, it looks good to me.
I have some minor suggestions/comments.

@@ -29,6 +29,15 @@ func TestShouldRotateX509(t *testing.T) {
require.NoError(t, err)

assert.True(t, ShouldRotateX509(mockClk.Now(), badCert))


// Cert that's is already expired
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Cert that's is already expired
// Cert that's already expired


// halfLife(beginTime, expiryTime time.Time)
func TestHalfLife(t *testing.T) {
// JWT that's valid for 1hr
Copy link
Member

Choose a reason for hiding this comment

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

X509-SVID instead of JWT? The halfLife function is only used in the context of X509-SVIDs.

lifetime := expiryTime.Sub(beginTime)
return ttl <= lifetime/2
return lifetime/2
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return lifetime/2
return lifetime / 2

// The jitter is calculated as ± 10% of the half-life of the SVID.
func jitterDelta(halfLife time.Duration) time.Duration {
// ± 10% of the half-life
return time.Duration((halfLife)/10)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return time.Duration((halfLife)/10)
return time.Duration(halfLife / 10)

@@ -86,3 +95,13 @@ func TestJWTSVIDExpiresSoon(t *testing.T) {

assert.True(t, JWTSVIDExpiresSoon(expiredJWT, mockClk.Now()))
}

// halfLife(beginTime, expiryTime time.Time)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if you meant to keep this comment here?

pkg/common/rotationutil/rotationutil_test.go Show resolved Hide resolved
@@ -86,3 +95,13 @@ func TestJWTSVIDExpiresSoon(t *testing.T) {

assert.True(t, JWTSVIDExpiresSoon(expiredJWT, mockClk.Now()))
}

// halfLife(beginTime, expiryTime time.Time)
func TestHalfLife(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we really want to have this test function. Ideally, we should not need to test non-exported functions (that usually leads to fragile tests), but rather cover them through test cases of the exported function. Are there more improvements that we could do in the test ShouldRotateX509 to make sure that a proper jitter is added, within the ranges that we expect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, great point. I'll just go ahead and remove it.

@stevend-uber
Copy link
Contributor Author

Thanks @amartinezfayo all comments have been addressed :)

Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

Linter complains about the unnecessary conversion.

// The jitter is calculated as ± 10% of the half-life of the SVID.
func jitterDelta(halfLife time.Duration) time.Duration {
// ± 10% of the half-life
return time.Duration(halfLife / 10)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return time.Duration(halfLife / 10)
return halfLife / 10

@rturner3 rturner3 added this to the 1.8.3 milestone Oct 19, 2023
Signed-off-by: stevend-uber <stevend+github@uber.com>
Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

Thank you @stevend-uber!

@rturner3 rturner3 merged commit b007648 into spiffe:main Oct 20, 2023
31 checks passed
faisal-memon pushed a commit to faisal-memon/spire that referenced this pull request Dec 2, 2023
Signed-off-by: stevend-uber <stevend+github@uber.com>
Signed-off-by: Faisal Memon <fymemon@yahoo.com>
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.

3 participants