Repository navigation
Fail-closed guard for PAYLOAD-source authorization #1494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package io.unitycatalog.server.auth.decorator; | ||
|
|
||
| import com.linecorp.armeria.common.AggregatedHttpRequest; | ||
| import com.linecorp.armeria.server.ServiceRequestContext; | ||
| import com.linecorp.armeria.server.annotation.RequestConverterFunction; | ||
| import io.unitycatalog.server.exception.BaseException; | ||
| import io.unitycatalog.server.exception.ErrorCode; | ||
| import java.lang.reflect.ParameterizedType; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Fail-closed wrapper that enforces {@link UnityAccessDecorator}'s PAYLOAD-source authorization | ||
| * before delegating to an inner body converter (e.g. Jackson). The decorator sets {@link | ||
| * 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. | ||
| * | ||
| * <p>Wrapping Jackson (rather than sitting in front of it as a separate chain element) means | ||
| * services register a single converter and the gate is impossible to forget when a new annotated | ||
| * service is added. | ||
| * | ||
| * <p>Scope: gates only parameters bound via the converter chain. Endpoints with no body-bound | ||
| * parameter (pure {@code @Param}/path) don't trigger this converter, but those endpoints also don't | ||
| * use PAYLOAD locators, so the decorator never sets the flag and no gate is needed. | ||
| */ | ||
| public final class AuthorizationGateConverter implements RequestConverterFunction { | ||
|
|
||
| private final RequestConverterFunction delegate; | ||
|
|
||
| public AuthorizationGateConverter(RequestConverterFunction delegate) { | ||
| this.delegate = Objects.requireNonNull(delegate); | ||
| } | ||
|
|
||
| @Override | ||
| public Object convertRequest( | ||
| ServiceRequestContext ctx, | ||
| AggregatedHttpRequest request, | ||
| Class<?> expectedResultType, | ||
| ParameterizedType expectedParameterizedResultType) | ||
| throws Exception { | ||
| if (Boolean.TRUE.equals(ctx.attr(UnityAccessDecorator.AUTH_PENDING))) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when will we set this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| throw new BaseException( | ||
| ErrorCode.PERMISSION_DENIED, "Authorization could not be verified for this request"); | ||
| } | ||
| return delegate.convertRequest( | ||
| ctx, request, expectedResultType, expectedParameterizedResultType); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/unitycatalog/unitycatalog/pull/1494/changes#diff-b9504c8a386aa1943559c357fa7ce1fcc952f4e0f45df99b89b17807213699faR42-R45
In that case, we actually are throwing the
PERMISSION_DENIEDexception, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the perfect error message throwing out.
The priority here is security: making sure it fails with
PERMISSION_DENIEDinstead of going through.In a follow up PR I will deal with this malformed/incomplete body problem and get rid of the
processPeekDataentirely.