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

オープン
#38,612 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
backend, databases

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Java
スター
972
フォーク
493
平均マージ
2日 12時間
マージ済み PR(30日)
228

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dotCMS/core のほかの issue

dotCMS/core の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。