Make remember-me token validity configurable via system property - #26833
Merged
MarkEWaite merged 4 commits intoJul 15, 2026
Merged
Conversation
|
Yay, your first pull request towards Jenkins core was created successfully! Thank you so much! |
Fixes #26718
The remember-me ("Keep me signed in") cookie validity uses Spring Security's
AbstractRememberMeServicesdefault of 14 days, with no supported way for an administrator to change it. This PR adds a system property so the validity can be set at startup (e.g. via passing a -D property through JAVA_OPTS or an equivalent container/startup configuration in a container), which is the use case described in the issue.TokenBasedRememberMeServices2.getTokenValiditySeconds()now returns the value of thehudson.security.TokenBasedRememberMeServices2.tokenValiditysystem property when set. The value is parsed as Duration Unit, so admins can write30d,60m, or positive numbers (interpreted as seconds). The default value behaviour is unchanged when the property is absent; non-positive values are ignored (logged and falling back to the default), and values above a 1 year maximum are capped to avoid effectively non-expiring cookies. This mirrors the existingskipTooFarExpirationDateChecksystem-property idiom in the same class.Testing done
Added automated tests in
TokenBasedRememberMeServices2Test:tokenValidity_defaultsToSpringSecurityDefault— property unset resolves to the 14-daydefault.
tokenValidity_cappedAtMaximum— a 2 year value is capped to the 1 year maximum.tokenValidity_nonPositiveValueFallsBackToDefault—0is ignored and a real remember-melogin still works end-to-end.
Manual verification was performed by launching a dev instance, signing in with Keep me signed in enabled, and testing different values for
hudson.security.TokenBasedRememberMeServices2.tokenValidity:60d, theremember-mecookieMax-Agewas correctly set to 60 days.600d, theremember-mecookieMax-Agewas correctly capped at the maximum allowed value of 1 year.asdf, theremember-mecookieMax-Agecorrectly fell back to the default value of 14 days.Screenshots (UI changes only)
Before
After
Proposed changelog entries
hudson.security.TokenBasedRememberMeServices2.tokenValiditysystem property capped 1 year.Proposed changelog category
/label rfe
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives (see documentation).Desired reviewers
@timja @MarkEWaite
Before the changes are marked as
ready-for-merge:Maintainer checklist
upgrade-guide-neededlabel is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidateto be considered.