Skip to content

Make remember-me token validity configurable via system property - #26833

Merged
MarkEWaite merged 4 commits into
jenkinsci:masterfrom
annplatoworld:configurable-remember-me-token
Jul 15, 2026
Merged

Make remember-me token validity configurable via system property#26833
MarkEWaite merged 4 commits into
jenkinsci:masterfrom
annplatoworld:configurable-remember-me-token

Conversation

@annplatoworld

@annplatoworld annplatoworld commented May 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #26718

The remember-me ("Keep me signed in") cookie validity uses Spring Security's AbstractRememberMeServices default 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 the hudson.security.TokenBasedRememberMeServices2.tokenValidity system property when set. The value is parsed as Duration Unit, so admins can write 30d, 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 existing skipTooFarExpirationDateCheck system-property idiom in the same class.

Testing done

Added automated tests in TokenBasedRememberMeServices2Test:

  • tokenValidity_defaultsToSpringSecurityDefault — property unset resolves to the 14-day
    default.
  • tokenValidity_cappedAtMaximum — a 2 year value is capped to the 1 year maximum.
  • tokenValidity_nonPositiveValueFallsBackToDefault0 is ignored and a real remember-me
    login 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:

  • With 60d , the remember-me cookie Max-Age was correctly set to 60 days.
  • With 600d, the remember-me cookie Max-Age was correctly capped at the maximum allowed value of 1 year.
  • With a non-numeric value, asdf, the remember-me cookie Max-Age correctly fell back to the default value of 14 days.

Screenshots (UI changes only)

Before

After

Proposed changelog entries

  • Allow administrators to configure the remember-me ("Keep me signed in") cookie validity with the hudson.security.TokenBasedRememberMeServices2.tokenValidity system property capped 1 year.

Proposed changelog category

/label rfe

Proposed upgrade guidelines

N/A

Submitter checklist

  • The issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples). Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • UI changes do not introduce regressions when enforcing the current default rules of Content Security Policy Plugin. In particular, new or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@timja @MarkEWaite

Before the changes are marked as ready-for-merge:

Maintainer checklist

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, be a Bug or Improvement, and either the issue or pull request must be labeled as lts-candidate to be considered.

Copilot AI review requested due to automatic review settings May 25, 2026 00:13
@welcome

welcome Bot commented May 25, 2026

Copy link
Copy Markdown

Yay, your first pull request towards Jenkins core was created successfully! Thank you so much!

A contributor will provide feedback soon. Meanwhile, you can join the chats and community forums to connect with other Jenkins users, developers, and maintainers.

@comment-ops-bot comment-ops-bot Bot added rfe For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted labels May 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor