Repository navigation
Fixes #39142: Stop OperationContext reuse from bypassing conditional denies - #39179
Open
detail-app[bot] wants to merge 1 commit into
Open
detail-app[bot] wants to merge 1 commit into
detail-app[bot] wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detail bug report: View on Detail
Describe your changes:
Fixes #39142
I worked on closing an authorization bypass on
GET /v1/permissions/policies?ids=becausePolicyEvaluator.hasPermissiondestructively drains the requested operations from theOperationContextas it grants them, and an empty list makes it skip the DENY pass and pass its final check vacuously. The endpoint reused oneOperationContextacross every policy id in the request, so once the first id was allowed, every later id was "authorized" without evaluating any deny rule — including the seeded!hasDomain()/!isOwner()conditional denies. Any authenticated user could read permission data derived from policies they should not be permitted to view by sending?ids=<allowedId>,<deniedId1>,<deniedId2>,....Type of change:
High-level design:
Two layers, since the root cause is the in-place drain:
OperationContextnow keeps an immutable snapshot of the originally requested operations (requestedOperations) at construction (and at lazy patch resolution) and exposes a package-privateresetOperations()that restores the working list. The liveoperationslist still drains during a single decision, so the existing grant-tracking semantics are unchanged.PolicyEvaluator.hasPermissioncallsoperationContext.resetOperations()before every evaluation, so a reused context always evaluates against the full set. This closes the footgun for every current and future caller, not just the endpoint in the report.PermissionsResource.getPermissionForPoliciesbuilds a freshOperationContextper policy id inside the loop, matching the "each decision needs its own" convention already documented inViewPermissionFilter.Tests:
Use cases covered
!isOwner()) on a second id is rejected with 403 when both ids are requested together viaGET /v1/permissions/policies?ids=<allowedId>,<deniedId>.OperationContextno longer skips the DENY pass after the first successful allow — conditional denies are evaluated on every authorization decision.OperationContextbehaves exactly as before (allow drains the list, deny throws, ungranted operations throw).Unit tests
openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/ContextReuseDenyBypassTest.java— regression guard proving a reusedOperationContextenforces the conditional deny on every id and thatresetOperations()restores the drained list. Verified the regression test fails without theresetOperations()call (with "Expected AuthorizationException to be thrown, but nothing was thrown") and passes with it.mvn jacoco:report):OperationContext.resetOperations()100% line coverage;PolicyEvaluator.hasPermission76.9% (the reset, deny pass, allow pass and success path covered; the ungranted-throw path is covered by the existingCompiledRuleTest/ContextReuseDenyBypassTestdeny cases). Class-level totals are lower because the Java IT/server suite — which the local bootstrap NPE blocked — supplies the rest of the coverage in normal CI.Backend integration tests
openmetadata-integration-tests/for new/changed API endpoints.The endpoint already exists; its multi-id admin happy path is covered by
PermissionsResourceIT.testGetPermissionsForMultiplePolicies. A non-admin multi-id IT proving the 403 on the denied id is the natural extension but could not be exercised locally (see Manual testing).Impacted plan:
→ planned unit tests
ContextReuseDenyBypassTest,PolicyEvaluatorTest; both run green:→ 11/11 pass, BUILD SUCCESS.
PermissionsResource.javais listed under "Changed classes no unit test reference" and is now covered byContextReuseDenyBypassTest.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
mvn spotless:check -pl openmetadata-service(the CI "Java checkstyle" gate) exit 0, andmvn test-compile -pl openmetadata-serviceexit 0.PermissionsResourceITvia the Testcontainers MySQL+ES stack (mvn -B verify -pl :openmetadata-integration-tests -am -Pmysql-elasticsearch -Dit.test=PermissionsResourceIT -Dtest=NoUnitTestsInThisRun). The MySQL 8.4.13 and Elasticsearch 9.3.0 containers started successfully, but the OpenMetadata application bootstrap failed inTestSuiteBootstrap.startApplicationwithjava.lang.NullPointerException: ... Entity.getEntityRelationshipRepository() is nullduring migration seeding, before HTTP was served. I verified this NPE is pre-existing and unrelated to the change by stashing the fix and reproducing the identical failure on a clean tree; no fix-touched file appears in the stack trace. The end-to-end exploit reproduction (single-id 200 vs. multi-id 403, order-independence) consequently could not be exercised locally and is pending the bootstrap fix in this environment; the unit-level engine behavior is covered byContextReuseDenyBypassTest.UI screen recording:
Not applicable — backend-only authorization fix.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.docs/decisions/(see itsREADME.md).Automatic Fixes PRs can be configured here.