Skip to content

Commit 0638d12

Browse files
authored
Update to latest Unity Catalog privileges model (#1556)
1 parent c78b127 commit 0638d12

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

catalog/resource_grants.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ var mapping = securableMapping{
188188
"CREATE_MATERIALIZED_VIEW": true,
189189
},
190190
"storage_credential": {
191-
"CREATE_TABLE": true,
192-
"READ_FILES": true,
193-
"WRITE_FILES": true,
191+
"CREATE_TABLE": true,
192+
"READ_FILES": true,
193+
"WRITE_FILES": true,
194+
"CREATE_EXTERNAL_LOCATION": true,
194195

195196
// v1.0
196197
"ALL_PRIVILEGES": true,
@@ -214,6 +215,9 @@ var mapping = securableMapping{
214215
"CREATE_RECIPIENT": true,
215216
"CREATE_PROVIDER": true,
216217
},
218+
"function": {
219+
"EXECUTE": true,
220+
},
217221
}
218222

219223
func setToStrings(set *schema.Set) (ss []string) {

docs/resources/cluster.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ Example of pushing all cluster logs to S3:
225225
```hcl
226226
cluster_log_conf {
227227
s3 {
228-
destination = "s3a://acmecorp-main/cluster-logs"
228+
destination = "s3://acmecorp-main/cluster-logs"
229229
region = "us-east-1"
230230
}
231231
}
@@ -260,7 +260,7 @@ Example of taking init script from S3:
260260
```hcl
261261
init_scripts {
262262
s3 {
263-
destination = "s3a://acmecorp-main/init-scripts/install-elk.sh"
263+
destination = "s3://acmecorp-main/init-scripts/install-elk.sh"
264264
region = "us-east-1"
265265
}
266266
}

docs/resources/grants.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,32 @@ subcategory: "Unity Catalog"
33
---
44
# databricks_grants Resource
55

6-
-> **Public Preview** This feature is in [Public Preview](https://docs.databricks.com/release-notes/release-types.html). Contact your Databricks representative to request access.
6+
-> **Public Preview** This feature is in [Public Preview](https://docs.databricks.com/release-notes/release-types.html). Contact your Databricks representative to request access.
77

88
In Unity Catalog all users initially have no access to data. Only Metastore Admins can create objects and can grant/revoke access on individual objects to users and groups. Every securable object in Unity Catalog has an owner. The owner can be any account-level user or group, called principals in general. The principal that creates an object becomes its owner. Owners receive all privileges on the securable object (e.g., `SELECT` and `MODIFY` on a table), as well as the permission to grant privileges to other principals.
99

1010
Unity Catalog supports the following privileges on securable objects:
11-
* `SELECT` - Allows the grantee to read data from the securable (applicable to tables and views).
12-
* `MODIFY` - Allows the grantee to add, update and delete data to or from the securable. (applicable to tables)
13-
* `CREATE` - Allows the grantee to create child objects within this securable.
14-
* `USAGE` - This privilege does not grant access to the securable itself, but allows the grantee to traverse the securable in order to access its child objects. For example, to select data from a table, users need to have the `SELECT` privilege on that table and `USAGE` privileges on its parent schema and parent catalog. Thus, you can use this privilege to restrict access to sections of your data namespace to specific groups.
11+
12+
- `USAGE`: Applicable object types: `CATALOG`, `SCHEMA`. This privilege does not grant access to the securable itself, but is needed for a user to interact with any object within the securable. For example, to select data from a table, users need to have the `SELECT` privilege on that table and `USAGE` privileges on its parent schema and parent catalog.
13+
14+
This is useful for allowing schema and catalog owners to be able to limit how far individual table owners can share data they produce. A table owner granting `SELECT` to another user does not allow that user read access to the table unless they also have `USAGE` on the schema and catalog.
15+
- `SELECT`: Applicable object types: `TABLE`, `VIEW`. Allows a user to select from a table or view, if the user also has `USAGE` on its parent catalog and schema.
16+
- `MODIFY`: Applicable object types: `TABLE`. Allows a user to add, update, and delete data to or from the table if the user also has `USAGE` on its parent catalog and schema.
17+
- `CREATE`: Applicable object types: `CATALOG`, `SCHEMA`. If applied to a catalog, allows a user to create a schema. The user also requires the `USAGE` permission on the catalog.
18+
19+
If applied to a schema, allows a user to create a table or view in the schema. The user also requires the `USAGE` permission on its parent catalog and the schema.
20+
- `EXECUTE`: Applicable object types: `FUNCTION`. Allows a user to invoke a user defined function, if the user also has `USAGE` on its parent catalog and schema.
21+
- `CREATE_TABLE`: Applicable object types: `EXTERNAL_LOCATION`, `STORAGE_CREDENTIAL`. Allows a user to create external tables directly in your cloud tenant using an external location or storage credential. Databricks recommends granting this privilege on an external location rather than storage credential; because the privilege is scoped to a path, it allows more control over where users can create external tables in your cloud tenant.
22+
- `READ_FILES`: Applicable object types: `EXTERNAL_LOCATION`, `STORAGE_CREDENTIAL`. Allows a user to read files directly from your cloud tenant (for example from S3 or ADLS). Databricks recommends granting this privilege on an external location rather than storage credential; because the privilege is scoped to a path it allows more control over from where users can read data.
23+
- `WRITE_FILES`: Applicable object types: `EXTERNAL_LOCATION`, `STORAGE_CREDENTIAL`. Allows a user to write files directly into your cloud tenant (for example into S3 or ADLS). We recommend granting this privilege on an external location rather than storage credential (since it is scoped to a path it allows more control over where users can write data to).
24+
- `ALL_PRIVILEGES`: Applicable object types: All object types. Allows a user to grant or revoke all privileges applicable to the securable without explicitly specifying them. This expands to all available privileges at the time of the grant.
25+
26+
In Unity Catalog, privileges are not inherited on child securable objects. For example, if you grant the `CREATE` privilege on a catalog to a user, the user does not automatically have the `CREATE` privilege on all schemas in the catalog.
1527

1628
Every `databricks_grants` resource must have exactly one securable identifier and one or more `grant` blocks with the following arguments:
1729

18-
* `principal` - User or group name.
19-
* `privileges` - One or more privileges that are specific to a securable type.
30+
- `principal` - User or group name.
31+
- `privileges` - One or more privileges that are specific to a securable type.
2032

2133
Terraform will handle any configuration drift on every `terraform apply` run, even when grants are changed outside of Terraform state.
2234

@@ -51,13 +63,13 @@ resource "databricks_grants" "sandbox" {
5163

5264
## Schema grants
5365

54-
You can grant `CREATE` and `USAGE` privileges to [*`catalog`*.*`database`*](schema.md) specified in the `schema` attribute:
66+
You can grant `CREATE` and `USAGE` privileges to [*`catalog`*.*`schema`*](schema.md) specified in the `schema` attribute:
5567

5668
```hcl
5769
resource "databricks_schema" "things" {
5870
catalog_name = databricks_catalog.sandbox.id
5971
name = "things"
60-
comment = "this database is managed by terraform"
72+
comment = "this schema is managed by terraform"
6173
properties = {
6274
kind = "various"
6375
}
@@ -74,7 +86,7 @@ resource "databricks_grants" "things" {
7486

7587
## Table grants
7688

77-
You can grant `MODIFY` and `SELECT` privileges to [*`catalog`*.*`database`*.*`table`*](table.md) specified in the `table` attribute. You can define a table through [databricks_table](table.md) resource.
89+
You can grant `MODIFY` and `SELECT` privileges to [*`catalog`*.*`schema`*.*`table`*](table.md) specified in the `table` attribute. You can define a table through [databricks_table](table.md) resource.
7890

7991
```hcl
8092
resource "databricks_grants" "customers" {
@@ -112,11 +124,11 @@ resource "databricks_grants" "things" {
112124

113125
## View grants
114126

115-
You can grant `SELECT` privileges to [*`catalog`*.*`database`*.*`view`*](table.md) specified in `view` attribute. You can define a view through [databricks_table](table.md) resource.
127+
You can grant `SELECT` privileges to [*`catalog`*.*`schema`*.*`view`*](table.md) specified in `table` attribute. You can define a view through [databricks_table](table.md) resource.
116128

117129
```hcl
118130
resource "databricks_grants" "customer360" {
119-
view = "main.reporting.customer360"
131+
table = "main.reporting.customer360"
120132
grant {
121133
principal = "Data Analysts"
122134
privileges = ["SELECT"]
@@ -135,7 +147,7 @@ data "databricks_views" "customers" {
135147
resource "databricks_grants" "customers" {
136148
for_each = data.databricks_views.customers.ids
137149
138-
view = each.value
150+
table = each.value
139151
140152
grant {
141153
principal = "sensitive"
@@ -146,7 +158,7 @@ resource "databricks_grants" "customers" {
146158

147159
## Storage credential grants
148160

149-
You can grant `CREATE_TABLE`, `READ_FILES`, and `WRITE_FILES` privileges to [databricks_storage_credential](storage_credential.md) id specified in `storage_credential` attribute:
161+
You can grant `CREATE_TABLE`, `READ_FILES`, `WRITE_FILES` and `CREATE_EXTERNAL_LOCATION` privileges to [databricks_storage_credential](storage_credential.md) id specified in `storage_credential` attribute:
150162

151163
```hcl
152164
resource "databricks_storage_credential" "external" {

0 commit comments

Comments
 (0)