SonarQube 9.x: Configuring API Token Expiration for Least-Privilege Users
0 reputation · 17 Jul 2020, 17:38 UTC
0 reputation · 17 Jul 2020, 17:38 UTC
We want to enforce least‑privilege access for API tokens in SonarQube 9.x and guarantee that expired tokens are automatically rejected.
SonarQube 9.x exposes the sonar.auth.token.validity property (default 30 days), while 8.x LTS lacks this setting and relies on session‑only authentication. The permission model allows a Browse role, but it is unclear if token‑based requests honor the same role boundaries. Additionally, password resets or account deactivation invalidate all tokens, yet the timing of this invalidation relative to the token‑validity window is not documented.
sonar.auth.token.validity value per user or group, or is it strictly global?Browse role receive the same 401 response once the validity period expires, or are they exempted?35275 reputation · 17 Jul 2020, 21:45 UTC
In SonarQube 9.x, API token expiration is a global instance setting. It cannot be configured on a per-user or per-group basis. Any token issued to a user—regardless of whether they hold a high-privilege Administrator role or a restricted Browse role—is subject to the same validity window. Once a token expires, the server returns a 401 Unauthorized response; there are no exemptions for least-privilege users.
To enforce token expiration and restrict access, follow these steps:
sonar.properties file. Note that the exact property name may vary by sub-version (e.g., sonar.auth.token.maxAllowedValidity). A restart is required for this change to take effect.The ability to track token usage depends on your SonarQube edition:
logs/access.log. Failed requests using expired or revoked tokens will appear as 401 HTTP responses. For deeper debugging, logs/web.log can be set to DEBUG level to see authentication failure details.| Scenario | Behavior | Confidence |
|---|---|---|
| User Deactivation | Tokens are invalidated immediately upon user deactivation. | High |
| Password Resets | Whether a password reset invalidates existing tokens is unverified. | Low |
| Version Support | Token TTL was introduced mid-9.x; versions prior to ~9.7 may not support expiration properties. | Medium |
Required Diagnostic: Please provide your exact SonarQube version (e.g., 9.9 LTS) and Edition (Community, Developer, Enterprise), as the available audit logs and the specific property name for token validity differ across these versions.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.