Repository navigation
[2.0] Fixes #34826: apply a removed policy rule on the next authorization decision (#34940) - #37996
Conversation
SubjectCache now loads policies and user contexts in a FreshReadScope so that a retry after an invalidation cannot read the pre-edit policy back from the thread-local request cache. On 2.0 a fresh read still read and filled that cache (under fromCache=false keys), so a load retried on the same thread could compile the old rules into the new cache generation (SubjectCacheTest.testLoadIgnoresPolicyLeftInTheThreadsRequestCache). RequestEntityCache, FreshReadScope and RequestEntityCacheTest are taken as they are on main after #34209; 2.0's copies matched main before #34089. The javadoc drops main's claim that fresh reads skip the not-found markers, which 2.0's find() still checks. #34209's EventSubscriptionScheduler change is not part of this.
…ecision (#34940) Backport of #34940 to 2.0, adapted where 2.0 differs from main: - SubjectCache's invalidator drops the policy cache on team, role and policy writes, and a user write drops that user's policy entry too. Main got that with #33632, which 2.0 does not have. Without it the post-commit invalidation this change moves to never reaches the policy cache, so a disabled policy kept granting access until the two-minute TTL ran out (PolicyEnforcementIT.aDisabledPolicyGrantsNothing). SubjectCacheTest gains main's team/role/user invalidator tests and a policy-write one, and keeps a single putUserWithPolicy helper (2.0 already had one). - invalidateAll() has no team-hierarchy cache to drop on 2.0. - McpServer: 2.0's tool callback reads no active-persona header and its prompt callback resolves the token from the transport context. Both now run inside the clean request context. McpServerRequestContextTest follows that: a persona left on the worker replaces the header test, and the prompt tests pass the token in the context. - CacheBundleTest puts back the user repository it replaced in the JVM-wide registry. Its mock answers every user name, and in 2.0's unit run it made ODCSConverterTest's owner lookups find users. - Not carried: RdfPolicyRevocationIT (2.0 has no agent SPARQL endpoint), the implementation plan and the docs/index.md entry (2.0 has no index). The ADR is carried with its guard list matched to 2.0. (cherry picked from commit 0ce7ed0)
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
| private static final Invalidatable INVALIDATOR = | ||
| (type, id, fqn) -> { | ||
| if (Entity.PERSONA.equals(type) || Entity.TEAM.equals(type)) { | ||
| if (Entity.TEAM.equals(type) || Entity.ROLE.equals(type) || Entity.POLICY.equals(type)) { | ||
| invalidateAll(); | ||
| } else if (Entity.PERSONA.equals(type)) { | ||
| invalidateAllUserContexts(); | ||
| } else if (Entity.USER.equals(type) && fqn != null) { | ||
| invalidateUserContextByFqn(fqn); | ||
| invalidateUserByFqn(fqn); | ||
| } | ||
| }; |
There was a problem hiding this comment.
⚠️ Performance: Team ref-change pub/sub now flushes every peer's policy cache
The new invalidator calls invalidateAll() for every team message, and it does not check op or fqn. On 2.0, EntityRepository.addRelationship/deleteRelationship call invalidateCacheForEntity(toEntity, toId, null). Team is a cacheable type, so that path publishes a ref-change message for the team on any relationship change that involves one. That includes making a team the owner of a table, adding a user to a team, and setting a team as domain expert. The CacheBundle pub/sub handler passes every message to all registered Invalidatables. So on every other pod, each of these ordinary writes (ingestion that assigns team owners, for example) now drops every user's compiled policies and every user context. The next requests then rebuild them from the database: user, roles, team hierarchy and policies.
This breaks the PR's assumption that these are "rare administrative writes". Under ingestion load the 2-minute policy cache stays close to empty on peers.
Fix: only call invalidateAll() for team messages that can change grants, i.e. a write to the team entity itself, which carries an fqn. Skip the fqn-less ref-change signals, or filter on op. A team-membership change already arrives as a user write and drops that user's entry.
Skip relationship-only ref-change signals (published with a null fqn) for team:
(type, id, fqn) -> {
if (Entity.ROLE.equals(type) || Entity.POLICY.equals(type)
|| (Entity.TEAM.equals(type) && fqn != null)) {
invalidateAll();
} else if (Entity.PERSONA.equals(type) || Entity.TEAM.equals(type)) {
invalidateAllUserContexts();
} else if (Entity.USER.equals(type) && fqn != null) {
invalidateUserByFqn(fqn);
}
};
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
| Deque<Scope> scopes = SCOPES.get(); | ||
| if (scopes == null) { | ||
| return; | ||
| } | ||
| scopes.remove(this); |
There was a problem hiding this comment.
New helpers break Java requirements
The added helpers violate explicit requirements in the Java guide. Here, Scope.close() adds an early return and leaves the unchanged local scopes non-final. The guide requires one trailing return and final on unchanged locals and parameters.
The new callToolWith() also exceeds the five-parameter limit, and cachePausingFirstLoad() uses a raw string in .equals() where the guide requires a constant. Bring these new helpers into line with the repository requirements before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Describe your changes:
Fixes #34826
Backport of #34940 to 2.0.
PolicyEnforcementIT.aDisabledPolicyGrantsNothingfails on every 2.0 PR, on all three engine lanes (MySQL + ES, Postgres + ES + Redis, Postgres + OpenSearch; e.g. run 44081196310 on #37962). A user keeps a grant after the policy behind it is disabled.On 2.0 the per-user policy cache (
SubjectCache, two-minute TTL) is not dropped when a policy'senabledflag changes:PolicyRepositoryinvalidated it only for rule changes, inline and before the write was stored.CacheBundle.invalidateEntity, but 2.0'sSubjectCacheinvalidator ignores policy and role writes, so the Redis lane fails too. WithcacheProvider=nonethe invalidator is not even registered.Carried from #34940 (as on main):
CacheBundleregistersSubjectCache.invalidator()for every cache provider.PolicyRepositorydrops the pre-storeSubjectCache.invalidateAll(); the post-commit path does it now.RevocableLoadingCachebacks both authorization caches. Invalidation retires the cache generation, so a load that started before an edit cannot publish the old rules.FreshReadScope.2026-10-13-authorization-caches-retire-generations-after-commit, with the guard list matched to 2.0.Needed on 2.0 in addition:
RequestEntityCachescope from Fixes #34204, #34205: stop event consumers idling after a slow batch, and give fresh reads their own cache #34209). Fixes #34826: apply a removed policy rule on the next authorization decision #34940 relies on it: on 2.0 a fresh read still used the thread's request cache, so a load retried after an invalidation could read the old policy back from it.Not carried:
RdfPolicyRevocationIT: it revokes the agent SPARQL grant, and 2.0 has no agent SPARQL endpoint.docs/index.mdentry (2.0 has no docs index).As on main since #33632, a team, role or policy write now drops every cached policy entry, and Redis pub/sub carries that to the other pods. These are administrative writes.
Type of change:
High-level design:
See the lists above. The 2.0-specific parts are the invalidator cases and the request-cache scope; everything else matches main's #34940. The ADR records the decision.
Tests:
Use cases covered
PolicyEnforcementIT).PolicyRevocationConcurrencyIT).PolicyRevocationConcurrencyIT).McpServerRequestContextTest).Unit tests
RevocableLoadingCacheTest,CacheBundleTest,McpServerRequestContextTest(adapted as above), and the twoSubjectCacheTestrace tests.RequestEntityCacheTest.SubjectCacheTestinvalidator tests for team, role and user writes (main's, from Fixes 19778: resolve the team hierarchy in batches, not one Team at a time #33632) and one for a policy write.SubjectCacheTest22,RevocableLoadingCacheTest16,RequestEntityCacheTest14,CacheBundleTest4,McpServerRequestContextTest10: 66 passed, 0 failures.SubjectCacheTest.testLoadIgnoresPolicyLeftInTheThreadsRequestCachefails (expected: <1> but was: <2>: the retried load compiled the pre-edit rules it read from the thread's request cache).openmetadata-serviceunit suite on this branch: 9534 tests, 1 failure,ODCSConverterTest.testFromODCS_WithTeam.CacheBundleTest(from Fixes #34826: apply a removed policy rule on the next authorization decision #34940) left a mock user repository that answers every name in the JVM-wide registry; running the two classes in that order reproduced it.CacheBundleTestnow puts the previous repository back, andCacheBundleTest,SubjectCacheTestandODCSConverterTestpass together (107).openmetadata-mcp: 605 passed. Full re-run after the fix:openmetadata-service9534 tests, 0 failures (1 skipped);openmetadata-mcp605, 0 failures.Backend integration tests
PolicyRevocationConcurrencyIT(from Fixes #34826: apply a removed policy rule on the next authorization decision #34940).PolicyEnforcementIT, already on 2.0, covers the disabled policy.aDisabledPolicyGrantsNothingfailed on all three engine lanes of run 44081196310 ([2.0] Fixes #28299: mask and encrypt secrets nested in a schema oneOf (#33193) #37962).none:PolicyEnforcementIT3 +PolicyRevocationConcurrencyIT7, 10 passed, 0 failures.redis(-Pmysql-elasticsearch-redis): the same 10 passed.PutKeepsTagsInSearchIT([2.0] Fixes #35879: read 2.0's response_field_names in PutKeepsTagsInSearchIT #37994),GlossaryTermApprovedTaggingITandConnectionSecretsMigrationIT. Those are separate fixes, so this PR's lanes stay red on them until those land.Ingestion integration tests
🤖 Generated with Claude Code