Sub topic 10
Controlling configuration with cluster policies
This chapter assumes you know how to create an all-purpose cluster and a job cluster, and that you understand DBUs (Databricks Units, the usage-based billing unit) and auto termination from the earlier chapters. Cluster policies apply those ideas across a whole team.
Why policies exist
Cluster settings drive cost and governance. A user who picks a large node type, sets no auto termination, or chooses a weak access mode can cause real spend or expose data. A cluster policy is a set of rules that limits which values users may choose when they create compute. Admins write the policy once, then grant users permission to use it.
Policies cover classic compute only: all-purpose clusters and job clusters. Serverless compute has no node type or worker count to restrict, so these rules do not apply to it.
What a policy contains
A policy is a JSON document. Each key is a cluster attribute path, such as node_type_id or autoscale.max_workers. Each value is a rule with a type.
| Rule type | Effect |
|---|---|
| `fixed` | Sets the value. With `hidden: true`, the user does not see it. |
| `allowlist` | The user picks from a list of values. |
| `blocklist` | Any value except those listed. |
| `range` | A number between `minValue` and `maxValue`. |
| `regex` | A string that matches a pattern. |
| `unlimited` | No restriction. You can set a default. |
Any attribute without a rule is unrestricted, unless the policy family says otherwise.
A worked policy
This policy enforces three decisions. Clusters must use standard access mode, must shut down when idle, and cannot scale beyond eight workers.
{
"data_security_mode": {
"type": "fixed",
"value": "USER_ISOLATION"
},
"autotermination_minutes": {
"type": "range",
"minValue": 10,
"maxValue": 120,
"defaultValue": 60
},
"autoscale.max_workers": {
"type": "range",
"maxValue": 8,
"defaultValue": 4
},
"node_type_id": {
"type": "allowlist",
"values": ["i3.xlarge", "i3.2xlarge"],
"defaultValue": "i3.xlarge"
},
"custom_tags.team": {
"type": "fixed",
"value": "data-platform"
}
}The node types are AWS examples. Use the equivalents on Azure or GCP. The custom_tags.team rule forces a tag onto every cluster, so cloud and billing reports can attribute cost to a team.
How policies are applied
Enforcement happens at creation and at edit time, in the UI and in the API. A user must have the Can use permission on a policy to select it. A user without the unrestricted cluster creation entitlement can create compute only through policies they can use.
Common errors
- Granting no policy access. Users who lack unrestricted creation and have no policy permission cannot create clusters at all.
- Leaving the default policy open. If users keep unrestricted creation rights, they can bypass your policies. Remove that entitlement once policies are in place.
- Forgetting existing clusters. Editing a policy does not instantly change running clusters. Clusters using it show as out of compliance and must be edited to match.
- Wrong attribute path. Nested fields use dots, such as
autoscale.max_workers. A misspelled path is not an error you will notice until the rule has no effect. - Conflicting
fixedand user input. If a job definition sets a value that afixedrule contradicts, the job's cluster creation fails.
Policies and jobs
A job cluster can reference a policy through policy_id in its new_cluster block. Setting apply_policy_default_values to true fills in policy defaults for fields you leave out. The next chapters on defining compute as code build on this.
{
"job_cluster_key": "etl_cluster",
"new_cluster": {
"policy_id": "ABC123DEF456",
"apply_policy_default_values": true,
"spark_version": "15.4.x-scala2.12",
"num_workers": 2
}
}Exercise
A policy has "autotermination_minutes": {"type": "fixed", "value": 30, "hidden": true}. A user wants a 90-minute idle timeout. What happens, and which rule type would let them choose a value up to 120?
Show answer
The user cannot change it. The field is fixed at 30 and hidden, and an API request with 90 is rejected. A range rule with maxValue 120, and optionally a defaultValue, allows the user to choose within the limits.
Exercise
Name two reasons a policy might not stop a team from creating expensive clusters.
Show answer
Users may still hold the unrestricted cluster creation entitlement and bypass policies. Also, a policy only restricts the attributes it has rules for, so an attribute with no rule, such as a large worker count with no range limit, stays open.