Repository navigation
[Server] Preserve resource types in authorization checks - #2076
Conversation
|
/review |
| switch (securableType) { | ||
| case TABLE, VOLUME, FUNCTION, REGISTERED_MODEL -> SCHEMA; | ||
| case SCHEMA -> CATALOG; | ||
| default -> METASTORE; |
There was a problem hiding this comment.
Should not have this fallback. This should list all types.
Maybe make this a util function to share somewhere if it can be reused later.
There was a problem hiding this comment.
Done, moved it into UnityAccessUtil and listed all types explicitly.
| case TABLE, VOLUME, FUNCTION, REGISTERED_MODEL -> SCHEMA; | ||
| case SCHEMA -> CATALOG; | ||
| default -> METASTORE; | ||
| }; |
There was a problem hiding this comment.
Maybe also compute a grandParentType = (parentType==SCHEMA) ? CATALOG : null;
There was a problem hiding this comment.
Done, using the same helper for the grandparent type too. Added tests for the ownership checks.
| authorizeAllHandle = mh.bindTo(this); | ||
| } | ||
|
|
||
| private record Resource(SecurableType type, UUID id) {} |
There was a problem hiding this comment.
[AI Assisted] nit: The Javadoc on AuthorizeExpression still describes #catalog, #schema, #table and #metastore as "the ID of the ...". With this change they are a typed Resource wrapper, not bare IDs. Can you update that doc so expression authors don't compare them against UUIDs?
There was a problem hiding this comment.
Updated the docs to explain that these contain a type and UUID, and that missing resources are null.
| return authorizer.authorize(principal, resource.type(), resource.id(), privilege); | ||
| } | ||
|
|
||
| protected boolean authorizeAny(Object... parameters) { |
There was a problem hiding this comment.
[AI Assisted] nit: authorize is now private, but authorizeAny/authorizeAll are still protected while casting to the private Resource record, so a subclass couldn't build the argument they expect. Make these private too, to match?
There was a problem hiding this comment.
Yep, made both private and updated the method lookups to match authorize.
Signed-off-by: Timothy Wang <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
e3e6619 to
2912ae4
Compare
|
/review |
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2077/files) to review incremental changes. - [stack/auth-resource-types](#2076) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2076/files)] [MERGED] - [**stack/opa-authorizer**](#2077) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2077/files)] ← _this PR_ - [stack/opa-server-config](#2078) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2078/files/263cd4d4b764f3f32f209c29a3dc9ef9adf73f85..c76911014952bde0835c20721094c002a2c2c75b)] --------- Signed-off-by: Timothy Wang <[email protected]> **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [ ] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated (not applicable to this prerequisite; documentation follows in the integration PR) **Description of changes** Add an OPA authorizer that asks about each evaluated privilege, such as `USE_CATALOG` on a catalog or `CREATE_TABLE` on a schema. UC still combines the answers through its existing expressions. Any/all checks preserve their order and short-circuit behavior. `OpaInputBuilder` reads the user's UUID, email and optional external ID, plus resource identity and parents. It supports every securable type and staging tables. No native grants, owner fields, tokens, or cloud credentials are sent. OPA replies must contain a boolean `result.allow`; unusable replies and connection failures return a generic `UNAVAILABLE` error, with no native fallback or decision cache. Missing users, resources, or parents deny the check without contacting OPA. Native grant and hierarchy methods delegate to the composed Casbin authorizer for bookkeeping. Server selection and user documentation follow in the child PR. Validation: Java formatting and all 30 backend/metadata tests passed: ```sh build/sbt javafmtAll 'server/testOnly io.unitycatalog.server.auth.OpaAuthorizerTest io.unitycatalog.server.auth.OpaInputBuilderTest' ``` --------- Signed-off-by: Timothy Wang <[email protected]>
## 🥞 Stacked PR Use this [link](https://github.com/unitycatalog/unitycatalog/pull/2078/files) to review incremental changes. - [stack/auth-resource-types](#2076) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2076/files)] [MERGED] - [stack/opa-authorizer](#2077) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2077/files)] [MERGED] - [**stack/opa-server-config**](#2078) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/2078/files)] ← _this PR_ --------- Signed-off-by: Timothy Wang <[email protected]> **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [x] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Make OPA selectable with `server.authorization.provider=opa`, a decision URL, and a response timeout for each OPA call. Casbin remains the default. Startup rejects OPA with authorization disabled or a missing/invalid decision URL. Pending OPA calls are cancelled when the UC request is cancelled or times out. OPA failures now reach callers as HTTP 503 through UC, Iceberg, and Delta error handling. UC database failures keep their UC error codes. Single authorization checks also preserve UC server error codes (HTTP 5xx) for both Casbin and OPA. Behavior change for both Casbin and OPA: unexpected errors during list authorization or resource resolution fail the whole request instead of silently omitting affected items. Permission denials and client errors (HTTP 4xx) still filter out individual items. Add configuration documentation and a runnable Rego example. Native grant/revoke/list APIs continue to manage native records; those grants do not affect OPA decisions. UC still enforces local path and staging-creator checks. Follow-up: [#2177](#2177) tracks consistent masking of internal errors in the outer list-filter catch. Validation: - `build/sbt javafmtAll`. - `server/testOnly` for `UnityCatalogServerTest`, `ServerPropertiesTest`, `IcebergRestCatalogServiceTest`, `ResultFilterTest`, `UnityAccessEvaluatorTest`, `OpaAuthorizerTest`, and `SdkOpaAccessControlTest` on `6fb1cf5d1`: 138 tests passed, none skipped. All four `SdkOpaAccessControlTest` cases ran against OPA in Docker. --------- Signed-off-by: Timothy Wang <[email protected]>
🥞 Stacked PR
Use this link to review incremental changes.
Signed-off-by: Timothy Wang [email protected]
PR Checklist
docsis updated (not applicable to this prerequisite; documentation follows in the integration PR)Description of changes
The evaluator currently drops the resource type before calling the authorizer. Preserve the resolved
SecurableTypealongside each UUID so a backend can identify the resource it must authorize.Pass that type through
authorize,authorizeAny, andauthorizeAll, including direct calls from the permission and Iceberg services. Existing SpEL expressions, null guards, and Casbin decision logic keep their behavior. There is no REST API change.Validation: Java formatting and 83 focused server tests passed:
build/sbt javafmtAll 'server/testOnly io.unitycatalog.server.auth.JCasbinAuthorizerTest io.unitycatalog.server.auth.JCasbinAuthorizerMultiInstanceTest io.unitycatalog.server.auth.decorator.UnityAccessEvaluatorTest io.unitycatalog.server.service.PermissionServiceTest io.unitycatalog.server.service.IcebergRestCatalogServiceTest io.unitycatalog.server.sdk.access.TemporaryPathCredentialAccessControlTest'