Skip to content

[Server] Preserve resource types in authorization checks - #2076

Merged
yili-db merged 2 commits into
unitycatalog:mainfrom
timothyw553:stack/auth-resource-types
Oct 30, 2026
Merged

yili-db merged 2 commits into
unitycatalog:mainfrom
timothyw553:stack/auth-resource-types

Conversation

@timothyw553

@timothyw553 timothyw553 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


Signed-off-by: Timothy Wang [email protected]

PR Checklist

  • 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.
  • 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

The evaluator currently drops the resource type before calling the authorizer. Preserve the resolved SecurableType alongside each UUID so a backend can identify the resource it must authorize.

Pass that type through authorize, authorizeAny, and authorizeAll, 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'

@timothyw553

Copy link
Copy Markdown
Collaborator Author

/review

@timothyw553
timothyw553 marked this pull request as ready for review October 29, 2026 00:06
switch (securableType) {
case TABLE, VOLUME, FUNCTION, REGISTERED_MODEL -> SCHEMA;
case SCHEMA -> CATALOG;
default -> METASTORE;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, moved it into UnityAccessUtil and listed all types explicitly.

case TABLE, VOLUME, FUNCTION, REGISTERED_MODEL -> SCHEMA;
case SCHEMA -> CATALOG;
default -> METASTORE;
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also compute a grandParentType = (parentType==SCHEMA) ? CATALOG : null;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, made both private and updated the method lookups to match authorize.

@timothyw553
timothyw553 force-pushed the stack/auth-resource-types branch from e3e6619 to 2912ae4 Compare October 29, 2026 22:52
@yili-db

yili-db commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db
yili-db merged commit e124509 into unitycatalog:main Oct 30, 2026
20 checks passed
timothyw553 added a commit that referenced this pull request Nov 3, 2026
## 🥞 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]>
yili-db pushed a commit that referenced this pull request Nov 11, 2026
## 🥞 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants