|
| 1 | +--- |
| 2 | +title: "Lakeformation" |
| 3 | +id: lakeformation |
| 4 | +--- |
| 5 | + |
| 6 | +## Tags |
| 7 | +The adapter implements AWS Lakeformation tags management in the following way: |
| 8 | +- you can enable or disable lf-tags management via [config](./table-configuration) (disabled by default). |
| 9 | +Here are config examples: |
| 10 | + |
| 11 | +`model_config.sql`: |
| 12 | +```sql |
| 13 | +{{ |
| 14 | + config( |
| 15 | + materialized='incremental', |
| 16 | + incremental_strategy='append', |
| 17 | + on_schema_change='append_new_columns', |
| 18 | + table_type='iceberg', |
| 19 | + schema='test_schema', |
| 20 | + lf_tags_config={ |
| 21 | + 'enabled': true, |
| 22 | + 'tags': { |
| 23 | + 'tag1': 'value1', |
| 24 | + 'tag2': 'value2' |
| 25 | + }, |
| 26 | + 'tags_columns': { |
| 27 | + 'tag1': { |
| 28 | + 'value1': ['column1', 'column2'], |
| 29 | + 'value2': ['column3', 'column4'] |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + ) |
| 34 | +}} |
| 35 | +``` |
| 36 | + |
| 37 | +`dbt_project.yml`: |
| 38 | +```yaml |
| 39 | + +lf_tags_config: |
| 40 | + enabled: true |
| 41 | + tags: |
| 42 | + tag1: value1 |
| 43 | + tag2: value2 |
| 44 | + tags_columns: |
| 45 | + tag1: |
| 46 | + value1: [ column1, column2 ] |
| 47 | +``` |
| 48 | +
|
| 49 | +- once you enable the feature, lf-tags will be updated on every dbt run |
| 50 | +- first, all lf-tags for **columns** are removed to avoid inheritance issues |
| 51 | +- then all redundant lf-tags are removed from **table** and actual tags from config are applied |
| 52 | +- finally, lf-tags for **columns** are applied |
| 53 | +
|
| 54 | +:::info |
| 55 | +
|
| 56 | +It's important to understand the following points: |
| 57 | +- dbt does not manage lf-tags for database |
| 58 | +- dbt does not manage lakeformation permissions |
| 59 | +
|
| 60 | +That's why you should handle this by yourself manually or using some automation tools like terraform, AWS CDK etc. |
| 61 | +You may find the following links useful to manage that: |
| 62 | +- [terraform aws_lakeformation_permissions](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lakeformation_permissions) |
| 63 | +- [terraform aws_lakeformation_resource_lf_tags](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lakeformation_resource_lf_tags) |
| 64 | +
|
| 65 | +::: |
| 66 | +
|
| 67 | +## Data Cell Filters |
| 68 | +The adapter implements AWS Lakeformation Data Cell Filters management in the following way. |
| 69 | +`model_config.sql`: |
| 70 | +```sql |
| 71 | +{{ |
| 72 | + config( |
| 73 | + materialized='incremental', |
| 74 | + incremental_strategy='append', |
| 75 | + on_schema_change='append_new_columns', |
| 76 | + table_type='iceberg', |
| 77 | + schema='test_schema', |
| 78 | + lf_grants={ |
| 79 | + 'data_cell_filters': { |
| 80 | + 'enabled': True | False, |
| 81 | + 'filters': { |
| 82 | + 'filter_name': { |
| 83 | + 'row_filter': '<filter_condition>', |
| 84 | + 'principals': ['principal_arn1', 'principal_arn2'] |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | +}} |
| 90 | +``` |
| 91 | + |
| 92 | +or more advanced example for `dbt_project.yml` |
| 93 | +```yaml |
| 94 | +models: |
| 95 | + directory: |
| 96 | + +schema: your_schema |
| 97 | + +materialized: incremental |
| 98 | + +on_schema_change: sync_all_columns |
| 99 | + model1: |
| 100 | + +lf_grants: &default_rls |
| 101 | + data_cell_filters: |
| 102 | + enabled: true |
| 103 | + filters: |
| 104 | + name1: |
| 105 | + row_filter: "field1 = 'value1'" |
| 106 | + principals: |
| 107 | + - "role1_arn" |
| 108 | + - "role2_arn" |
| 109 | + name2: |
| 110 | + row_filter: "field1 = 'value2'" |
| 111 | + principals: |
| 112 | + - "role3_arn" |
| 113 | + - "role4_arn" |
| 114 | + model2: |
| 115 | + +lf_grants: *default_rls # reuse previously defined config |
| 116 | +``` |
| 117 | + |
| 118 | +- Data cell filters management can't be automated outside dbt because the filter can't be attached to the table |
| 119 | +which doesn't exist. |
| 120 | +- Once you `enable` this config, dbt will set all filters and their permissions during every dbt run. |
| 121 | +- Such approach keeps the actual state of row level security configuration actual after every dbt run and |
| 122 | +applies changes if they occur: drop, create, update filters and their permissions. |
| 123 | + |
| 124 | +:::caution |
| 125 | + |
| 126 | +It's important to understand that LF permissions work like `union`. |
| 127 | +Let's imagine this scenario: |
| 128 | +- Table X has tag `domain=foo` |
| 129 | +- Role A has `select` permission for tables with `domain=foo` |
| 130 | +- We add a data cell filter for a column in table X and then grant permissions to role A |
| 131 | + |
| 132 | +In this case, tag permissions are the ones considered, and cell-level permissions are totally ignored. |
| 133 | +This means that this data cell filters management feature implies that you should use permissions for specific tables |
| 134 | +which don't have already tag-level permissions in that specific database or table. |
| 135 | + |
| 136 | +::: |
0 commit comments