Repository navigation
Description
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
ExecuteSparqlQueryrules). - 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/rdfas the user, and the admin viewGET /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:
- Create a user with no roles (it inherits Data Consumer through the Organization team).
- As that user, call
sparql_queryover/mcponce (allowed; this is the warm-up). - As admin, fetch
DataConsumerPolicy(fields=rules), removeDataConsumerPolicy-ExecuteSparqlQuery-Rule, send the update. - Immediately, and then every 250 ms, call
sparql_queryover/mcpas 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.entitySpecificUpdateis@Transactionand callsSubjectCache.invalidateAll()insidecompareAndUpdate("rules", ...), that is before the new rules are stored and before the commit..../security/policyevaluator/SubjectCache.java:109USER_POLICIES_CACHE(expireAfterWrite(2, MINUTES)),:116USER_CONTEXT_CACHE(15 min),:156getPolicies,:275invalidateAll(also clears the user-context cache andTeamHierarchyResolver),:313loadPoliciesForUser,:390Entity.getEntity(Entity.POLICY, policyRef.getId(), "rules", NON_DELETED)..../cache/CacheBundle.java:53-57returns early when the cache provider isnone, beforeregisterInvalidatable(SubjectCache.invalidator())at:99-100. With providernone(as in the integration-test server) the post-commit invalidation hook never runs, so only the in-transaction call above exists..../jdbi3/EntityRepository.java:358CACHE_WITH_IDand:1882find(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
ExecuteSparqlQueryrules. - 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
fmcardoso commentedon Oct 7, 2026
Additional observation from manual testing of #34790 on a full local stack (
run_local_docker_rdf.sh -d postgresql, cache providernone, server at56acb6ddcf), using a real MCP client and a non-admin user with no roles, so Data Consumer is inherited through the Organization team:DataConsumerPolicy-ExecuteSparqlQuery-Rulewas removed and the user's next call came through/mcp,sparql_querystayed 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/agentandGET /v1/permissions/rdfas the same user also returned allow.RDF_QUERY_FORBIDDEN, and the next/mcpcall was denied too. With MCP-only traffic, the stale entry outlived the 2-minute expiry ofUSER_POLICIES_CACHE.notAllow. Restoring the rule took effect immediately on all three.fix(policy): retire the user's cache shard on invalidation and load p…
Fixes open-metadata#34826: apply a removed policy rule on the next au…
[2.0] Fixes #34826: apply a removed policy rule on the next authoriza…