Skip to content

Policy edit that removes a rule does not reach a principal that was already authorized: the per-user policy cache keeps the old rule for 170+ s when the first request after the edit arrives via /mcp #34826

Closed

Description

@fmcardoso

Impact

Found while testing #34270 (non-admin sparql_query over MCP). The release note of #34253 tells admins to revoke ExecuteSparqlQuery by removing DataConsumerPolicy-ExecuteSparqlQuery-Rule from DataConsumerPolicy. Observed on a clean local run:

  • The rule is gone from the database and from the API immediately (policy version 0.2, 4 rules, 0 ExecuteSparqlQuery rules).
  • A principal that had made an allowed call and whose first request after the edit is an /mcp tool call stays allowed for at least 171 s (poll every 250 ms, no denial seen; upper bound unknown). During that time REST (POST /v1/rdf/sparql/agent), GET /v1/permissions/rdf as the user, and the admin view GET /v1/permissions/rdf?user=<user> also report allow.
  • If the first request after the edit goes through REST instead, the same principal gets a 403 at once, and /mcp is then denied too.
  • An explicit SubjectCache.invalidateAll() at 170 s fixes it: the next read returns the 4-rule policy and /mcp answers 403.

So a revocation is not guaranteed to take effect on a running principal. The security-relevant part is not the size of the window (the caches are meant to be short-lived) but that the stale entry outlived its documented 2-minute lifetime in this setup.

Reproduction

Local integration-test server (Postgres, search, Fuseki), cache provider none. Throwaway test McpPolicyRevocationReproIT (RDF lane), scenario a_mcpOnlyWarm_mcpFirst_150s:

  1. Create a user with no roles (it inherits Data Consumer through the Organization team).
  2. As that user, call sparql_query over /mcp once (allowed; this is the warm-up).
  3. As admin, fetch DataConsumerPolicy (fields=rules), remove DataConsumerPolicy-ExecuteSparqlQuery-Rule, send the update.
  4. Immediately, and then every 250 ms, call sparql_query over /mcp as the user.

Result: allowed on every call for 167 to 173 s (the loop ended there), twice in a row. Comparison scenarios in the same class:

Scenario First call after the edit Result
a: warm via /mcp only /mcp allowed for 167-173 s
b1: warm via /mcp only REST agent endpoint 403 at once; /mcp then 403 too
b2: warm via /mcp and REST /mcp allowed (20 s poll, never denied)
c: fresh user right after a remove and restore /mcp allowed at 28-35 ms (a restore is visible at once)
default lane, warm via the permission API, then re-read the permission API permission API notAllow within 22-76 ms
default lane, 4 threads hammering the permission API during the edit, 10 rounds permission API 0 of 10 stale

Evidence

Policy as seen through the API and as persisted (read in the same JVM through Entity.getCollectionDAO().policyDAO().findEntityByName), identical in every scenario:

Moment API Database
before the edit version 0.1, 5 rules, 1 ExecuteSparqlQuery version 0.1, 5 rules, 1
update response version 0.2, 0
right after the edit and 170 s later version 0.2, 4 rules, 0 version 0.2, 4 rules, 0

Per-user cache SubjectCache.USER_POLICIES_CACHE, read through reflection without loading it (live static field, instance identity checked):

Moment Entry for the user Stats
first allowed call after the edit (t = 34-44 ms) present, DataConsumerPolicy with 5 rules, 1 ExecuteSparqlQuery hit 3, miss 2, loadSuccess 2, eviction 0
end of the poll (t = 169-173 s) present, 5 rules, 1 ExecuteSparqlQuery hit about 1202, miss 3, loadSuccess 3, eviction 1
after SubjectCache.invalidateAll() absent (size 0)
first getPolicies after that 4 rules, 0 ExecuteSparqlQuery
/mcp call after that 403 Authorization error: ... operations [ExecuteSparqlQuery] not allowed

Other layers at the same moments: EntityRepository.CACHE_WITH_NAME has no entry for DataConsumerPolicy or role DataConsumer; CACHE_WITH_ID for the policy id was absent at the end and present at the first call in one of the two repetitions. The user's getUserContext shows roles=[], teams=[Organization], so the policy reaches the user through the Organization team's default role DataConsumer.

Reading of the counters (Guava does not count explicit invalidations as evictions): the entry was loaded once for the warm-up, once more right after the edit's invalidation (loadSuccess 2 at 34-44 ms), and once more when the 2-minute expiry hit (eviction 1, loadSuccess 3). Both reloads put the old 5-rule policy back, although the database already had the 4-rule policy. The load after the explicit invalidateAll() produced the new policy.

Code path

  • openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java:259: PolicyUpdater.entitySpecificUpdate is @Transaction and calls SubjectCache.invalidateAll() inside compareAndUpdate("rules", ...), that is before the new rules are stored and before the commit.
  • .../security/policyevaluator/SubjectCache.java:109 USER_POLICIES_CACHE (expireAfterWrite(2, MINUTES)), :116 USER_CONTEXT_CACHE (15 min), :156 getPolicies, :275 invalidateAll (also clears the user-context cache and TeamHierarchyResolver), :313 loadPoliciesForUser, :390 Entity.getEntity(Entity.POLICY, policyRef.getId(), "rules", NON_DELETED).
  • .../cache/CacheBundle.java:53-57 returns early when the cache provider is none, before registerInvalidatable(SubjectCache.invalidator()) at :99-100. With provider none (as in the integration-test server) the post-commit invalidation hook never runs, so only the in-transaction call above exists.
  • .../jdbi3/EntityRepository.java:358 CACHE_WITH_ID and :1882 find(id, include, fromCache), the by-id read the loader uses.

Ruled out

  • A duplicate or restored rule in the policy: the API and the database rows both show 4 rules and 0 ExecuteSparqlQuery rules.
  • A stale test setup: the result repeats on a run with exactly one Maven JVM and fresh containers (an earlier run was invalid because two runs overlapped; it is not used here).
  • JwtFilter's 60 s cache: it maps an email to a username string and carries no roles or policies.
  • A short race window: the allowed state lasted 167 to 173 s with continuous polling, and the entry reloaded once at expiry with the old data again.
  • The permission API read path: it agrees with the stale entry and does not cause it.

Open question

Why did both reloads (right after the edit, and at the 2-minute expiry) produce the old policy while the database had the new one, and why did the reload after an explicit SubjectCache.invalidateAll() produce the new one? invalidateAll() clears three things that an expiry reload does not: USER_CONTEXT_CACHE, TeamHierarchyResolver, and the in-flight state of the loader. The data points at one of those holding input the policy loader reuses, but this was not isolated. It is also unclear why the first request's path decides the outcome (a REST-first request gets a fresh policy, an /mcp-first request does not).

Is it caused by #34270?

No evidence that it is. The code that is involved (PolicyRepository, SubjectCache, CacheBundle) is untouched by that branch, and the same stale state is returned by REST and by the permission API once it exists. It has not been shown to be MCP-wide: no pre-existing MCP tool was tested as a control, and only sparql_query and the REST agent endpoint were exercised. Whether the /mcp-first ordering matters for other tools is unknown.

Suggested direction

Invalidate after the transaction commits (a post-update hook or a commit callback), not inside it, and make the same hook run when the cache provider is none. Add a regression test that removes a rule and asserts the very next /mcp and REST calls are denied.

Related: #34270 (non-admin sparql_query over MCP, where this was found), #34253 (Data Consumer default grant whose release note relies on revocation).

Activity

  1. added
    security
    on Oct 7, 2026
  2. fmcardoso commented on Oct 7, 2026

    @fmcardoso
    MemberAuthor

    Additional observation from manual testing of #34790 on a full local stack (run_local_docker_rdf.sh -d postgresql, cache provider none, server at 56acb6ddcf), using a real MCP client and a non-admin user with no roles, so Data Consumer is inherited through the Organization team:

    • The window is longer than recorded above. After DataConsumerPolicy-ExecuteSparqlQuery-Rule was removed and the user's next call came through /mcp, sparql_query stayed allowed for at least 244 s (202 calls at 1 s intervals). The integration-test run recorded 171 s. During the window, POST /v1/rdf/sparql/agent and GET /v1/permissions/rdf as the same user also returned allow.
    • A REST request ended it. The first REST call, at about 245 s, returned 403 RDF_QUERY_FORBIDDEN, and the next /mcp call was denied too. With MCP-only traffic, the stale entry outlived the 2-minute expiry of USER_POLICIES_CACHE.
    • Control: with the same edit but REST called first, the user got a 403 about 0.4 s after the edit, then MCP gave 403 and the permission API notAllow. Restoring the rule took effect immediately on all three.
  3. moved this to In Progress 🏗️ in Roadmapon Oct 13, 2026
  4. self-assigned this
    on Oct 13, 2026
  5. added this to Shipping and removed this from Roadmapon Oct 13, 2026
  6. moved this to In Progress 🏗️ in Shippingon Oct 13, 2026
  7. moved this from In Progress 🏗️ to Done ✅ in Shippingon Oct 14, 2026
  8. added a commit that references this issue on Oct 14, 2026
    0ce7ed0
  9. added a commit that references this issue on Nov 17, 2026
    7c86957
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendsecurity

Type

No type

Projects

  • Status
    Done ✅

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions