Sub topic 6
Granting the privileges models need
This chapter covers the Unity Catalog privileges that let people register, read and serve a model. It assumes you can run SQL and Python in a Databricks notebook. It also assumes you know the three-level name catalog.schema.model from the previous chapters, and that you know what a catalog, a schema and a table are in Unity Catalog.
Why models need explicit grants
A model registered in Unity Catalog is a securable object, like a table or a volume. Nobody can use it until someone grants access. Unity Catalog checks privileges at every level of the three-level name. A user needs the right to enter the catalog, the right to enter the schema, and a privilege on the model itself.
Missing one grant anywhere in that chain causes a permission error. The error often points at the catalog or schema, not at the model. That surprises people who granted access on the model and assumed they were done.
The privileges involved
Three privileges cover most model work.
| Privilege | Applies to | What it allows |
|---|---|---|
| `USE CATALOG` | Catalog | See the catalog and look inside it |
| `USE SCHEMA` | Schema | See the schema and look inside it |
| `CREATE MODEL` | Schema | Register a new model in that schema |
| `EXECUTE` | Model | Load the model, read its versions and use it, for example by serving it |
USE CATALOG and USE SCHEMA do not grant access to data or models by themselves. They only make the container reachable. Think of them as permission to walk through the doors on the way to the object.
CREATE MODEL is granted on a schema, not on a model, because the model does not exist yet when you register it. It is the privilege that registered_model_name="main.default.iris_classifier" needs the first time you run it.
EXECUTE is the privilege that matters for consumers. Loading a model with mlflow.pyfunc.load_model needs it. So does creating a serving endpoint for the model.
How the checks chain together
Every action walks the same path from the catalog down to the model. Each step must pass.
For registering a new model, the last check changes. The user needs CREATE MODEL on the schema instead of EXECUTE on a model.
Granting access to consumers
The following statements give a group everything it needs to load and serve one model. Use a group instead of individual users so access is easy to review and change.
GRANT USE CATALOG ON CATALOG main TO `data-scientists`;
GRANT USE SCHEMA ON SCHEMA main.default TO `data-scientists`;
GRANT EXECUTE ON MODEL main.default.iris_classifier TO `data-scientists`;Group names with a hyphen need backticks, as shown. You can run these in a SQL cell or the SQL editor. From a Python notebook, wrap each one in spark.sql:
statements = [
"GRANT USE CATALOG ON CATALOG main TO `data-scientists`",
"GRANT USE SCHEMA ON SCHEMA main.default TO `data-scientists`",
"GRANT EXECUTE ON MODEL main.default.iris_classifier TO `data-scientists`",
]
for statement in statements:
spark.sql(statement)The spark session is predefined in Databricks notebooks, so no import is needed.
Granting access to publishers
People who register models need more than consumers do. A typical set for a team that trains and registers models looks like this:
GRANT USE CATALOG ON CATALOG main TO `ml-engineers`;
GRANT USE SCHEMA ON SCHEMA main.default TO `ml-engineers`;
GRANT CREATE MODEL ON SCHEMA main.default TO `ml-engineers`;When a user registers a model, that user becomes its owner. The owner can grant privileges on the model to others and can change its aliases. Other ml-engineers members can register their own models in the schema. They do not automatically get access to models they did not create. This is deliberate. If a team needs shared ownership, make a group the owner or grant EXECUTE explicitly.
You can also grant a privilege on a whole schema. That covers every model in it, including models created later:
GRANT EXECUTE ON SCHEMA main.default TO `data-scientists`;This is convenient for a schema that exists only to hold production models. It is risky in a shared schema, because every new model becomes usable by the group the moment it is registered.
Checking and removing grants
To see who has what on a model, use SHOW GRANTS:
SHOW GRANTS ON MODEL main.default.iris_classifier;The output lists each principal, the privilege and the object it was granted on. Grants made at the schema or catalog level do not appear in this result, because they are stored on a different object. When a user has access you did not expect, check the schema and the catalog as well:
SHOW GRANTS ON SCHEMA main.default;
SHOW GRANTS ON CATALOG main;To remove access, revoke the same privilege from the same principal:
REVOKE EXECUTE ON MODEL main.default.iris_classifier FROM `data-scientists`;Revoking a privilege on the model does nothing if the group also holds EXECUTE on the schema. Revoke at the level where the grant was made.
Unity Catalog privileges and endpoint permissions are separate
Serving adds a second layer of access control. Unity Catalog privileges decide who can use the model. A serving endpoint has its own permission list, which decides who can view, query or manage the endpoint. The levels are Can View, Can Query and Can Manage.
| Question | Controlled by |
|---|---|
| Who can register a model in this schema? | `CREATE MODEL` on the schema |
| Who can load or serve this model? | `EXECUTE` on the model |
| Who can send requests to the endpoint? | `Can Query` on the endpoint |
| Who can update or delete the endpoint? | `Can Manage` on the endpoint |
A client that only calls the endpoint needs Can Query. It does not need EXECUTE on the model, because it never loads the model itself. A person who creates or updates an endpoint needs EXECUTE on the model, along with USE CATALOG and USE SCHEMA on the containers.
Common errors
Permission failures are the most frequent problem in this part of the workflow. These patterns cover most of them.
- Registration fails with a permission error on the schema. The user has no
CREATE MODELon the schema, or noUSE SCHEMA, or noUSE CATALOG. Check all three withSHOW GRANTS. - A model loads for you but not for a colleague. You are the owner, so you have implicit access. Your colleague has not been granted
EXECUTE. EXECUTEis granted on the model, but access still fails. The grant on the model is fine, but the user lacksUSE CATALOGorUSE SCHEMA. The container checks run first.- A group member still has no access after a grant. Group membership changes can take a moment to apply. Check that the user is in the group you granted to, and retry with a fresh session.
- The endpoint exists, but a client gets an authorization error. This is an endpoint permission problem. Grant
Can Queryon the endpoint. AddingEXECUTEon the model does not fix it.
A least-privilege layout
A workable pattern for a team uses one schema per stage of trust and one group per role:
- A development schema where
ml-engineersholdCREATE MODEL. Experimental models are registered here. - A production schema where only a CI service principal holds
CREATE MODEL. Humans getEXECUTEso they can inspect and test models but cannot overwrite them. - Consumers hold
USE CATALOG,USE SCHEMAandEXECUTEon the production schema, orCan Queryon endpoints only.
This keeps promotion to production a deliberate act. It also pairs well with aliases: the pipeline registers a new version, and the owner moves the champion alias after review.
Exercise
A data scientist in the group data-scientists has EXECUTE on main.default.iris_classifier, but mlflow.pyfunc.load_model("models:/main.default.iris_classifier@champion") fails with a permission error. SHOW GRANTS ON MODEL main.default.iris_classifier shows the group's EXECUTE grant. Name two other grants that could be missing, and write the statements that would add them.
Show answer
The group may lack USE CATALOG on main or USE SCHEMA on main.default. Unity Catalog checks the catalog and schema before the model, so a model-level grant alone is not enough. The statements are GRANT USE CATALOG ON CATALOG main TO data-scientists; and GRANT USE SCHEMA ON SCHEMA main.default TO data-scientists;. Running SHOW GRANTS ON SCHEMA main.default and SHOW GRANTS ON CATALOG main confirms which one is missing.
Exercise
A web application calls the iris-endpoint endpoint with a token and receives an authorization error. An engineer proposes granting the application's service principal EXECUTE on the model. Why is this probably the wrong fix, and what should be checked instead?
Show answer
Calling an endpoint is controlled by the endpoint's own permissions, not by Unity Catalog privileges on the model. The service principal needs Can Query on the endpoint. Check the endpoint's permission list and add Can Query for the service principal. Granting EXECUTE on the model would not change the result.