Repository navigation
Fail-closed guard for PAYLOAD-source authorization - #1494
Conversation
01a7ef1 to
8b031f8
Compare
b4b76f3 to
78f1389
Compare
There was a problem hiding this comment.
LGTM. solution makes sense -- a skipped check turns into a request denied, right?
one thing that AI flagged was the "is this JSON?" check uses an exact match (equals(MediaType.JSON) see https://github.com/yili-db/unitycatalog/blob/78f138912cafdbd974869a092665dc1cac2ea80c/server/src/main/java/io/unitycatalog/server/auth/decorator/UnityAccessDecorator.java#L442), so a content-type like application/json; charset=utf-8 wouldn't match. in practice, if everyone goes through this SDK, which sends plain application/json, then it is fine.
but if they don't go through the sdk, instead, we should use Armeria's contentType.isJson()
Yes it's a defense in depth to turn any skip of auth into an error. This is one baby step forward. I will have more PRs to handle other issue including the JSON type matching, JSON completeness guessing, etc. |
| Class<?> expectedResultType, | ||
| ParameterizedType expectedParameterizedResultType) | ||
| throws Exception { | ||
| if (Boolean.TRUE.equals(ctx.attr(UnityAccessDecorator.AUTH_PENDING))) { |
There was a problem hiding this comment.
when will we set this UnityAccessDecorator.AUTH_PENDING attr in the context ?
There was a problem hiding this comment.
It is set here: https://github.com/unitycatalog/unitycatalog/pull/1494/changes#diff-9e4896b86c010ff1d4cf496f17095ee6bf98561fc8da1bceade0cb542af3a599R202 when it is sure that some auth parameters reside in the payload.
| private final RequestConverterFunction delegate; | ||
|
|
||
| public AuthorizationGateConverter(RequestConverterFunction delegate) { | ||
| this.delegate = Objects.requireNonNull(delegate, "delegate"); |
There was a problem hiding this comment.
Can you give a more clear error message if it's null ?
There was a problem hiding this comment.
This is never meant to be null at all. It's just the production version of assert.
Removing this "delegate" string. The exception NullPointerException should be self explanatory.
| * UnityAccessDecorator#AUTH_PENDING} on entry to the PAYLOAD path and clears it only after the | ||
| * authorization evaluation succeeds; if the flag is still {@code true} when a parameter is being | ||
| * bound, {@code peekData}'s callback never fired (no body, non-JSON content-type, malformed JSON, | ||
| * trailing whitespace) and the request must be denied. |
There was a problem hiding this comment.
if the flag is still {@code true} when a parameter is being
- bound, {@code peekData}'s callback never fired (no body, non-JSON content-type, malformed JSON,
- trailing whitespace) and the request must be denied.
https://github.com/unitycatalog/unitycatalog/pull/1494/changes#diff-b9504c8a386aa1943559c357fa7ce1fcc952f4e0f45df99b89b17807213699faR42-R45
In that case, we actually are throwing the PERMISSION_DENIED exception, which actually swallow the real malformed detailed. will that make it even worst to the developer to understand the response ?
There was a problem hiding this comment.
This is not the perfect error message throwing out.
The priority here is security: making sure it fails with PERMISSION_DENIED instead of going through.
In a follow up PR I will deal with this malformed/incomplete body problem and get rid of the processPeekData entirely.
UnityAccessDecorator reads body fields for authorization via Armeria's peekData callback, which only fires when a body chunk arrives AND the chunk parses as complete JSON. Body-less requests, non-JSON Content-Type, malformed JSON, and JSON with trailing whitespace all silently skip checkAuthorization while the handler still runs. This is not a live vulnerability: every endpoint using a PAYLOAD locator today also requires a POJO body, so empty/malformed requests fail at Jackson binding (400) before the handler executes. The guard is defense in depth against a future endpoint where Jackson's accident doesn't hold. Fix: - New per-request AUTH_PENDING attribute, set true on entry to the PAYLOAD path and cleared only after checkAuthorization succeeds. - New AuthorizationGateConverter wraps Jackson: if AUTH_PENDING is still true at body-binding time, deny with 403 PERMISSION_DENIED. - UnityCatalogServer wires the gate via a gatedJackson() helper so every annotated service picks it up automatically. Tested end-to-end: SdkCatalogAccessControlCRUDTest sends a body-less POST /catalogs and asserts the proper 403 response. Signed-off-by: Yi Li <[email protected]>
Signed-off-by: Yi Li <[email protected]>
78f1389 to
67db88a
Compare
🥞 Stacked PR
Use this link to review incremental changes.
PR Checklist
docsis updatedDescription of changes
Fail-closed guard for PAYLOAD-source authorization
UnityAccessDecorator authorizes body-field (PAYLOAD) locators inside Armeria's
peekDatacallback, which only fires for a request that delivers a complete JSON body. A body-less, non-JSON, or malformed request silently skips that authorization while the handler still runs. This is defense in depth: every current PAYLOAD endpoint also binds a required POJO body, so such requests already fail Jackson binding with a 400.AUTH_PENDINGattribute, set on entry to the PAYLOAD path and cleared only after the authorization evaluation runs.AuthorizationGateConverter, which denies with403 PERMISSION_DENIEDat body-binding time ifAUTH_PENDINGis still set.gatedJackson()inUnityCatalogServer.Follow-up: widening
peekData's payload-recognition heuristic (charset-qualified content types, trailing whitespace) is deferred so the gate cannot deny valid non-SDK requests; current SDK clients are unaffected.Tested:
SdkCatalogAccessControlCRUDTestasserts a body-lessPOST /catalogsreturns 403 before the handler runs.