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

Add jitter to Default token expiration #260

Merged
merged 5 commits into from
Mar 4, 2025

Conversation

notSoWiseOldMan
Copy link
Contributor

@notSoWiseOldMan notSoWiseOldMan commented Feb 28, 2025

Issue #, if available:
N/A

Description of changes:
Adds a jitter to service account tokens when using the default expiration

Additionally to handle test cases where the randInt function is called I've added mocks and create a mockery config to the root of the repo to help with generating mock interfaces (mockery is recommended by http://github.com/stretchr/testify)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@notSoWiseOldMan notSoWiseOldMan requested a review from a team as a code owner February 28, 2025 19:37
pkg/constants.go Outdated
// 24hrs as that is max for EKS
MaxTokenExpiration = int64(86400)
// Default token expiration in seconds if none is defined, 22hrs
DefaultTokenExpiration = int64(79200)
Copy link
Member

Choose a reason for hiding this comment

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

The DefaultTokenExpiration is used by both IRSAv1 and IRSAv2 (Pod Identity):

  1. In IRSAv1, it has one informer cache
  2. In IRSAv2, we are only using from GetCommonConfigurations, which is being added from onboarding to IRSAv2 Add support for container credentials method #189

I believe we can add the randomization inside the GetCommonConfigurations function and not change the DefaultTokenExpiration for IRSAv1 use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I have updated GetCommonConfigurations the way you are describing in the most recent commit now. Let me know if I missed somethign

@@ -479,6 +488,26 @@ func (m *Modifier) buildPodPatchConfig(pod *corev1.Pod) *podPatchConfig {
return nil
}

func addJitter(val int64, jitterPercent int64, min int64, max int64) (int64, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be just simplified to a randomization between min and max, we don't need the val. And jitterPercentage and (min, max) is kinda similar, just to add randomization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote the function and renamed to addJitterToDefaultToken now that it is more specific

@@ -459,6 +467,7 @@ func (m *Modifier) buildPodPatchConfig(pod *corev1.Pod) *podPatchConfig {
klog.V(5).Infof("Value of roleArn after after cache retrieval for service account %s: %s", request.CacheKey(), response.RoleARN)
if response.RoleARN != "" {
tokenExpiration, containersToSkip := m.parsePodAnnotations(pod, response.TokenExpiration)
tokenExpiration = m.addJitterToDefaultToken(tokenExpiration)
Copy link
Member

Choose a reason for hiding this comment

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

We don't require this, this is IRSAv1 path

@xdu31
Copy link
Member

xdu31 commented Mar 3, 2025

/lgtm

@xdu31
Copy link
Member

xdu31 commented Mar 3, 2025

/approve

@xdu31 xdu31 self-requested a review March 4, 2025 00:07
@xdu31
Copy link
Member

xdu31 commented Mar 4, 2025

/approve

@xdu31
Copy link
Member

xdu31 commented Mar 4, 2025

/lgtm

@xdu31 xdu31 merged commit 0d3fed4 into aws:master Mar 4, 2025
1 check passed
@notSoWiseOldMan notSoWiseOldMan deleted the tokenExp_jitter branch March 4, 2025 19:44
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.

2 participants