fix: preserve domain checks for feed delete authorization#27324
fix: preserve domain checks for feed delete authorization#27324atharvasingh7007 wants to merge 2 commits intoopen-metadata:mainfrom
Conversation
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
...e/src/main/java/org/openmetadata/service/security/policyevaluator/ThreadResourceContext.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/org/openmetadata/service/security/policyevaluator/ThreadResourceContext.java
Outdated
Show resolved
Hide resolved
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
| public ThreadResourceContext(Thread thread) { | ||
| this.thread = thread; | ||
| this.owners = resolveOwners(thread); | ||
| this.aboutEntity = resolveAboutEntity(thread); | ||
| this.domains = resolveDomains(thread, aboutEntity); |
There was a problem hiding this comment.
⚠️ Edge Case: Unhandled exception in resolveOwners prevents domain resolution
The constructor eagerly calls resolveOwners() (line 29) before resolveAboutEntity() and resolveDomains(). If Entity.getEntityReferenceByName() at line 65 throws (e.g., the thread creator was deleted), the entire ThreadResourceContext construction fails and no domain context is resolved.
Previously, owner resolution was lazy — called only when getOwners() was invoked — so a failure there didn't block domain resolution. Now, a deleted user breaks domain-based authorization for the entire thread/post delete flow.
This matters because the PR's goal is to preserve domain checks: if the thread author is deleted but the thread still references a domain-scoped asset, the authorization should still evaluate domain policies.
Suggested fix:
private static List<EntityReference> resolveOwners(Thread thread) {
if (thread == null || thread.getCreatedBy() == null) {
return null;
}
try {
List<EntityReference> owners = new ArrayList<>();
owners.add(
Entity.getEntityReferenceByName(Entity.USER, thread.getCreatedBy(), Include.NON_DELETED));
return owners;
} catch (EntityNotFoundException e) {
LOG.debug("Thread creator '{}' not found", thread.getCreatedBy());
return null;
}
}
Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Gitar
|
Addressed the Gitar feedback in the latest commit (
Could a maintainer please add the |
Summary
aboutentity, with fallback to stored thread domain idshasDomain()as a list operation when there is neither a concrete entity nor any domain contextWhy
FeedResource.deleteThread()anddeletePost()previously built feed policy contexts from author names alone. Those contexts returned no entity and no domains, so domain-scoped policies could be skipped during delete authorization. In practice, thread and post deletes could be authorized without the domain checks that protect the linked asset.Validation
mvn -B -f openmetadata-service/pom.xml spotless:checkmvn -B -f openmetadata-service/pom.xml -Dtest=FeedResourceContextTest -DfailIfNoTests=false test