|
| 1 | +--- |
| 2 | +hide: |
| 3 | +- navigation |
| 4 | +--- |
| 5 | + |
| 6 | +# Demo: Unity Catalog Server Authorization |
| 7 | + |
| 8 | +This demo shows how [Server Authorization](../server-authorization/index.md) works in Unity Catalog. |
| 9 | + |
| 10 | +## Enable Server Authorization |
| 11 | + |
| 12 | +Add the following to `etc/conf/server.properties`: |
| 13 | + |
| 14 | +```text |
| 15 | +server.authorization=enable |
| 16 | +``` |
| 17 | + |
| 18 | +## Enable Authorization Logging |
| 19 | + |
| 20 | +Enable `ALL` logging level for the following loggers: |
| 21 | + |
| 22 | +* [AuthDecorator](../server-authorization/AuthDecorator.md#logging) |
| 23 | +* [UnityAccessDecorator](../server-authorization/UnityAccessDecorator.md#logging) |
| 24 | + |
| 25 | +## Start UC Server |
| 26 | + |
| 27 | +Start [Unity Catalog server](../server/index.md). |
| 28 | + |
| 29 | +```bash |
| 30 | +./bin/start-uc-server |
| 31 | +``` |
| 32 | + |
| 33 | +## Unauthorized Access |
| 34 | + |
| 35 | +The UC server requires all interactions to be authenticated using a token or a cookie. |
| 36 | + |
| 37 | +This is why you face "No authorization found." error message unless either is provided. |
| 38 | + |
| 39 | +```bash |
| 40 | +./bin/uc catalog list |
| 41 | +``` |
| 42 | + |
| 43 | +```text |
| 44 | +Exception in thread "main" java.lang.RuntimeException: io.unitycatalog.client.ApiException: listCatalogs call failed with: 401 - {"error_code":"UNAUTHENTICATED","details":[{"reason":"UNAUTHENTICATED","metadata":{},"@type":"google.rpc.ErrorInfo"}],"stack_trace":null,"message":"No authorization found."} |
| 45 | + at io.unitycatalog.cli.UnityCatalogCli.main(UnityCatalogCli.java:171) |
| 46 | +Caused by: io.unitycatalog.client.ApiException: listCatalogs call failed with: 401 - {"error_code":"UNAUTHENTICATED","details":[{"reason":"UNAUTHENTICATED","metadata":{},"@type":"google.rpc.ErrorInfo"}],"stack_trace":null,"message":"No authorization found."} |
| 47 | + at io.unitycatalog.client.api.CatalogsApi.getApiException(CatalogsApi.java:77) |
| 48 | + at io.unitycatalog.client.api.CatalogsApi.listCatalogsWithHttpInfo(CatalogsApi.java:356) |
| 49 | + at io.unitycatalog.client.api.CatalogsApi.listCatalogs(CatalogsApi.java:333) |
| 50 | + at io.unitycatalog.cli.CatalogCli.listCatalogs(CatalogCli.java:78) |
| 51 | + at io.unitycatalog.cli.CatalogCli.handle(CatalogCli.java:39) |
| 52 | + at io.unitycatalog.cli.UnityCatalogCli.main(UnityCatalogCli.java:127) |
| 53 | +``` |
| 54 | + |
| 55 | +## Authorized Access |
| 56 | + |
| 57 | +Use the admin token that Unity Catalog uses internally and is conveniently stored in `etc/conf/token.txt`. |
| 58 | + |
| 59 | +```bash |
| 60 | +./bin/uc --auth_token $(cat etc/conf/token.txt) catalog list |
| 61 | +``` |
| 62 | + |
| 63 | +```text |
| 64 | +┌─────┬────────────┬──────────┬─────┬─────────────┬──────────┬──────────┬──────────┬────────────────────────────────────┐ |
| 65 | +│NAME │ COMMENT │PROPERTIES│OWNER│ CREATED_AT │CREATED_BY│UPDATED_AT│UPDATED_BY│ ID │ |
| 66 | +├─────┼────────────┼──────────┼─────┼─────────────┼──────────┼──────────┼──────────┼────────────────────────────────────┤ |
| 67 | +│unity│Main catalog│{} │null │1721234405334│null │null │null │f029b870-9468-4f10-badc-630b41e5690d│ |
| 68 | +└─────┴────────────┴──────────┴─────┴─────────────┴──────────┴──────────┴──────────┴────────────────────────────────────┘ |
| 69 | +``` |
| 70 | + |
| 71 | +You should see the following DEBUG messages in the server logs: |
| 72 | + |
| 73 | +```text |
| 74 | +DEBUG io.unitycatalog.server.service.AuthDecorator:58 - AuthDecorator checking /api/2.1/unity-catalog/catalogs?max_results=100 |
| 75 | +DEBUG io.unitycatalog.server.service.AuthDecorator:74 - Validating access-token for issuer: internal and keyId: b995bc0a527ffbbf9b43f108a1a0d825a05eb4070b2831a88dfaf34d2e879733 |
| 76 | +DEBUG io.unitycatalog.server.service.AuthDecorator:93 - Access allowed for subject: "admin" |
| 77 | +DEBUG io.unitycatalog.server.auth.decorator.UnityAccessDecorator:74 - AccessDecorator checking /api/2.1/unity-catalog/catalogs?max_results=100 |
| 78 | +DEBUG io.unitycatalog.server.auth.decorator.UnityAccessDecorator:252 - serviceName = io.unitycatalog.server.service.CatalogService, methodName = listCatalogs |
| 79 | +DEBUG io.unitycatalog.server.auth.decorator.UnityAccessDecorator:194 - authorize expression = #deny |
| 80 | +WARN io.unitycatalog.server.auth.decorator.UnityAccessDecorator:89 - No authorization resource(s) found. |
| 81 | +INFO org.casbin.jcasbin:113 - Request: [cd941442-6635-45b9-bc7a-c9b527600b3b, 3c527572-1eb3-4e5e-ba95-fa136e1b6d62, OWNER] ---> true |
| 82 | +INFO org.casbin.jcasbin:115 - Hit Policy: [cd941442-6635-45b9-bc7a-c9b527600b3b, 3c527572-1eb3-4e5e-ba95-fa136e1b6d62, OWNER] |
| 83 | +``` |
0 commit comments