-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Machine ID: Warn when returned cert TTL is less than expected #52833
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,6 +396,47 @@ func generateIdentity( | |
return newIdentity, nil | ||
} | ||
|
||
// warnOnEarlyExpiration logs a warning if the given identity is likely to | ||
// expire problematically early. This can happen if either the configured TTL is | ||
// less than the renewal interval, or if the server returns certs valid for a | ||
// shorter-than-expected period of time. | ||
// This assumes the identity was just renewed, for the purposes of calculating | ||
// TTLs. | ||
func warnOnEarlyExpiration( | ||
ctx context.Context, | ||
log *slog.Logger, | ||
ident *identity.Identity, | ||
lifetime config.CredentialLifetime, | ||
) { | ||
// Calculate a rough TTL, assuming this was called shortly after the | ||
// identity was returned. We'll add a minute buffer to compensate and avoid | ||
// superfluous warning messages. | ||
effectiveTTL := ident.TLSIdentity.Expires.Sub(time.Now()) + time.Minute | ||
|
||
if effectiveTTL < lifetime.TTL { | ||
l := log.With( | ||
"requested_ttl", lifetime.TTL, | ||
"renewal_interval", lifetime.RenewalInterval, | ||
"effective_ttl", effectiveTTL, | ||
"expires", ident.TLSIdentity.Expires, | ||
"roles", ident.TLSIdentity.Groups, | ||
) | ||
|
||
if effectiveTTL < lifetime.RenewalInterval { | ||
l.WarnContext(ctx, "The server returned an identity shorter than "+ | ||
"expected and below the configured renewal interval, probably "+ | ||
"due to a `max_session_ttl` configured on a server-side role. "+ | ||
"Unless corrected, the credentials will be invalid for some "+ | ||
"period until renewal.") | ||
} else { | ||
l.WarnContext(ctx, "The server returned an identity shorter than "+ | ||
"the requested TTL, probably due to a `max_session_ttl` "+ | ||
"configured on a server-side role. It may not remain valid as "+ | ||
"long as expected.") | ||
Comment on lines
+432
to
+435
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some experimenting and found that bots can always fetch their own roles, so technically we could make some queries and log exactly which role caused the shortened TTL. Any thoughts on whether or not that would be worth the effort? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That'd be a really nice touch, but I think it depends on how many roles bots have in the common case. My hunch is that it's low enough that it wouldn't take users long to figure out which is the problematic role. |
||
} | ||
} | ||
} | ||
|
||
// fetchDefaultRoles requests the bot's own role from the auth server and | ||
// extracts its full list of allowed roles. | ||
func fetchDefaultRoles(ctx context.Context, roleGetter services.RoleGetter, identity *identity.Identity) ([]string, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit janky and may have some minor false negatives due to the 1m buffer. Hopefully sane enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think this is fine. We presumably need to adjust for clock skew between the client and server anyway?