Short-lived permission cache ignores its 60s TTL and isn't cleared on permission save or publish: a transient "deny" persists until Flush All Caches

Abierto
#38,612 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java

Línea de trabajo

Start with PermissionBitAPIImpl.doesUserHavePermission(), PermissionCacheImpl.putUserHavePermission(), and CaffineCache.put() to trace how the short-lived entry gets its TTL. Then inspect the permission-save and contentlet/Site publish paths named in the issue, along with their cluster invalidation messages. Add integration coverage for TTL expiry and invalidation after commit on all nodes; done means each acceptance criterion passes, including the existing flush behavior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

OKR : Customer Support Team : Maintenance
Problem Statement

PermissionBitAPIImpl.doesUserHavePermission() caches every yes/no permission decision in the PermissionShortLived cache group. The group is configured to keep each decision for 60 seconds:

## Cache doesUserHavePermission calls for 60 seconds
cache.permissionshortlived.seconds=60
cache.permissionshortlived.size=100000

Two defects mean a single wrong decision, including a transient "deny", is kept indefinitely on the node that computed it:

1. The 60-second TTL is never applied.

  • PermissionCacheImpl.putUserHavePermission() stores the decision with cache.put(key, hasPermission, shortLivedGroup) (PermissionCacheImpl.java:155 on main).
  • That call reaches CaffineCache.put(group, key, content), which calls put(group, key, content, Long.MAX_VALUE) (CaffineCache.java:97-98).
  • DynamicTTLCache uses the TTL stored with each entry (expireAfterCreate returns value.getTtlInMillis()). The group default built from cache.permissionshortlived.seconds is used only by DynamicTTLCache.put(key, value), which this path never calls.
  • So entries never expire. They are removed only by size eviction (100,000 entries) or by a flush of the group.

2. Nothing that changes the inputs to the decision clears it.
On main, flushShortTermCache() is called only from RoleFactoryImpl (L338 and L458): role grant, role revoke and role-tree moves (#35458, #38521). None of the following clear the cached decisions:

  • saving, resetting or cascading permissions on an asset (PermissionBitFactoryImpl.savePermission / assignPermissions, RoleAjax.saveRolePermission, PermissionAjax.saveAssetPermissions, PUT /api/v1/permissions/...). These evict only the primary PermissionCache entry for the asset;
  • saving, publishing or unpublishing a contentlet or Site. The anonymous READ decision depends on whether the asset is live (PermissionBitAPIImpl checks isLiveContentlet() for the CMS Anonymous role);
  • the cluster cache invalidation messages that other nodes receive for those changes.

Because respectFrontendRoles is part of the key, anonymous and front-end traffic is hit hardest: one cached false for (asset, READ, anonymous, true) denies every anonymous request for that asset on that node.

#35458 (first in v26.11.11-01) made "Flush Permission Cache" (PermissionCacheImpl.clearCache()) also flush shortLivedGroup. On older versions, including 24.12 LTS, only Flush All Caches clears these decisions.

Production impact (Freshdesk #41409, 24.12.27 LTS, 2 nodes on Kubernetes)
  1. Both nodes restarted at 05:05 UTC after a deployment.
  2. 05:06:13: a deployment step saved and published a Site record on node B.
  3. 05:06:14.984, about 1.7 s later: node A still saw the Site as not live (its cached Site and version info briefly disagreed during cross-node invalidation). It logged:
    WARN  business.PermissionBitAPIImpl - User 'anonymous' cannot verify READ permissions on Contentlet '<site-id>' because it is not live.
    ERROR business.HostAPIImpl - User 'null' does not have READ permissions on Site '<site>'
    
  4. Node A cached that false. Every anonymous request to the Site on node A was denied for the next 43 minutes, including all $webapi.getAssetPath("//<site>/application/config/...") calls in /api/vtl/* endpoints, which then returned empty responses. Node B, which had cached true, served the same requests normally, so clients saw intermittent failures.
  5. Re-saving CMS Anonymous permissions on the Site (on node A) had no effect. Only Flush All Caches resolved it.
  6. The "not live" warning is logged only when the decision is computed, not on cache hits. After the first request there was no log trail explaining the denials.

The DB grant (CMS Anonymous READ on the Site, individual permission) was present throughout. The transient "not live" window is expected to self-correct within milliseconds. It became an outage only because the decision was cached with no expiry.

Steps to Reproduce

A. Single node: the TTL is ignored and a permission save doesn't clear the decision

  1. Create a Site or folder with a file under it, and make sure CMS Anonymous does not have READ on it.
  2. As an anonymous user, request the file, or call a VTL/page that resolves it with $webapi.getAssetPath("//<site>/<path>"). The request is denied, and does not have READ permissions is logged.
  3. As an admin, grant CMS Anonymous READ on the Site or folder (Permissions tab → Save, or Roles → Permissions with cascade).
  4. Wait more than 60 seconds (longer than cache.permissionshortlived.seconds).
  5. Repeat the anonymous request.

Expected: allowed after the save, or at most 60 seconds later.
Actual: still denied indefinitely. It is fixed only by Flush All Caches (or "Flush Permission Cache" on versions that include #35458).

B. Cluster: a Site publish poisons another node

  1. Run two nodes behind a load balancer. CMS Anonymous has READ on Site X.
  2. Keep anonymous traffic going to both nodes for an endpoint that reads Site X (for example a /api/vtl/* endpoint calling $webapi.getAssetPath("//X/...")).
  3. On node B, edit and publish the Site X record (Sites → Edit → Save/Publish).
  4. Within about 2 seconds, send an anonymous request for Site X directly to node A, for example with kubectl port-forward.

Expected: at most a momentary denial that clears within 60 seconds.
Actual: if node A computes the decision while it still sees Site X as not live, it logs the cannot verify READ ... because it is not live warning once, then denies all anonymous requests for Site X until Flush All Caches. Node B is unaffected.

Note: B depends on timing and may need several attempts. A is deterministic and shows the core defect on its own.

Acceptance Criteria
  • Entries in PermissionShortLived expire after cache.permissionshortlived.seconds (default 60). A cached false stops being served within that window without any manual flush.
  • Saving, resetting or cascading permissions on an asset invalidates the cached decisions for that asset, after the transaction commits, on all cluster nodes. A request repeated immediately after the save reflects the new permissions.
  • Saving, publishing, unpublishing, archiving or deleting a contentlet or Site invalidates the cached decisions for that asset on all nodes, so a transient "not live" decision cannot outlive the publish.
  • "Flush Permission Cache" continues to clear the short-lived decisions (regression guard for #35458).
  • Integration tests cover:
    • expiry after the configured TTL;
    • invalidation on permission save, run after commit, not inside the transaction;
    • invalidation on contentlet/Site publish.
  • Optional: log at DEBUG, or rate-limited WARN, when a cached false is served for CMS Anonymous on a Site, so a stuck denial leaves a trail.
dotCMS Version

Reported on 24.12.27 LTS v15.

  • Confirmed by code review on main @ 245acad (2026-11-16): defects 1 and 2 are both still present.
Severity

High - Major functionality broken

Links

Freshdesk: #41409

  • Related: #34467 ("Cache Not Flushed After User Permission Update", open): likely the same missing clear-on-save
  • Related: #35458 (merged): clearCache() now flushes shortLivedGroup; role grant/revoke flush it after commit. Origin: private-issues#567
  • Related: #38521 (merged): flushes short-lived decisions on role-tree moves
  • Related, different path: #35680 / #35684 (merged): an empty permission list cached in the primary PermissionCache during push publishing
Lenguaje dominante
Java
Estrellas
972
Forks
493
Merge medio
2 d 12 h
PR fusionados (30 d)
228

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dotCMS/core

Todos los issues de dotCMS/core

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.