tundra-cli 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tundra_cli-0.0.0/LICENSE +7 -0
- tundra_cli-0.0.0/MANIFEST.in +9 -0
- tundra_cli-0.0.0/PKG-INFO +598 -0
- tundra_cli-0.0.0/README.md +558 -0
- tundra_cli-0.0.0/pyproject.toml +144 -0
- tundra_cli-0.0.0/setup.cfg +4 -0
- tundra_cli-0.0.0/src/tundra/__init__.py +8 -0
- tundra_cli-0.0.0/src/tundra/cli/__init__.py +10 -0
- tundra_cli-0.0.0/src/tundra/cli/__main__.py +3 -0
- tundra_cli-0.0.0/src/tundra/cli/cli.py +25 -0
- tundra_cli-0.0.0/src/tundra/cli/permissions.py +206 -0
- tundra_cli-0.0.0/src/tundra/entities.py +586 -0
- tundra_cli-0.0.0/src/tundra/error.py +4 -0
- tundra_cli-0.0.0/src/tundra/logger.py +9 -0
- tundra_cli-0.0.0/src/tundra/snowflake_connector.py +575 -0
- tundra_cli-0.0.0/src/tundra/snowflake_grants.py +2263 -0
- tundra_cli-0.0.0/src/tundra/snowflake_permission.py +46 -0
- tundra_cli-0.0.0/src/tundra/snowflake_role_grant_checker.py +121 -0
- tundra_cli-0.0.0/src/tundra/snowflake_spec_loader.py +540 -0
- tundra_cli-0.0.0/src/tundra/spec_file_loader.py +139 -0
- tundra_cli-0.0.0/src/tundra/spec_schemas/__init__.py +0 -0
- tundra_cli-0.0.0/src/tundra/spec_schemas/snowflake.py +238 -0
- tundra_cli-0.0.0/src/tundra/types.py +103 -0
- tundra_cli-0.0.0/src/tundra_cli.egg-info/PKG-INFO +598 -0
- tundra_cli-0.0.0/src/tundra_cli.egg-info/SOURCES.txt +60 -0
- tundra_cli-0.0.0/src/tundra_cli.egg-info/dependency_links.txt +1 -0
- tundra_cli-0.0.0/src/tundra_cli.egg-info/entry_points.txt +2 -0
- tundra_cli-0.0.0/src/tundra_cli.egg-info/requires.txt +23 -0
- tundra_cli-0.0.0/src/tundra_cli.egg-info/top_level.txt +1 -0
- tundra_cli-0.0.0/tests/conftest.py +52 -0
- tundra_cli-0.0.0/tests/fixtures/cli.py +14 -0
- tundra_cli-0.0.0/tests/fixtures/fs.py +47 -0
- tundra_cli-0.0.0/tests/tundra/cli/test_cli.py +22 -0
- tundra_cli-0.0.0/tests/tundra/schemas/snowflake_server_filters_grants_to_role_to_items_defined_in_config_future_grants.json +154 -0
- tundra_cli-0.0.0/tests/tundra/schemas/snowflake_server_filters_grants_to_role_to_items_defined_in_config_future_grants_expected_values.json +127 -0
- tundra_cli-0.0.0/tests/tundra/schemas/snowflake_server_filters_grants_to_role_to_items_defined_in_config_grants_to_role.json +152 -0
- tundra_cli-0.0.0/tests/tundra/schemas/snowflake_server_filters_grants_to_role_to_items_defined_in_config_grants_to_role_expected_values.json +127 -0
- tundra_cli-0.0.0/tests/tundra/specs/read_only_role.yml +31 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_server_filters_grants_to_role_to_items_defined_in_config.yml +38 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec.yml +326 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_blank.yml +1 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_edge_cases.yml +69 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_include_child.yml +62 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_include_parent.yml +38 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_include_star.yml +89 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_no_defined_refs.yml +45 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_recursive_grants.yml +35 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_reference_roles.yml +107 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_test_instance.yml +52 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_with_entity_errors.yml +43 -0
- tundra_cli-0.0.0/tests/tundra/specs/snowflake_spec_with_syntax_errors.yml +101 -0
- tundra_cli-0.0.0/tests/tundra/test_entities.py +146 -0
- tundra_cli-0.0.0/tests/tundra/test_includes.py +51 -0
- tundra_cli-0.0.0/tests/tundra/test_snowflake_connector.py +547 -0
- tundra_cli-0.0.0/tests/tundra/test_snowflake_grants.py +2817 -0
- tundra_cli-0.0.0/tests/tundra/test_snowflake_permission.py +29 -0
- tundra_cli-0.0.0/tests/tundra/test_snowflake_role_grant_checker.py +102 -0
- tundra_cli-0.0.0/tests/tundra/test_snowflake_spec_loader.py +1673 -0
- tundra_cli-0.0.0/tests/tundra/test_snowflake_user.py +350 -0
- tundra_cli-0.0.0/tests/tundra_test_utils/__init__.py +0 -0
- tundra_cli-0.0.0/tests/tundra_test_utils/snowflake_connector.py +64 -0
- tundra_cli-0.0.0/tests/tundra_test_utils/snowflake_schema_builder.py +336 -0
tundra_cli-0.0.0/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright GitLab B.V.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tundra-cli
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Snowflake permissions management tool with Apache Iceberg table support
|
|
5
|
+
Author-email: Henry Upton <henryupton@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/henryupton/tundra
|
|
8
|
+
Project-URL: Repository, https://github.com/henryupton/tundra
|
|
9
|
+
Project-URL: Issues, https://github.com/henryupton/tundra/issues
|
|
10
|
+
Keywords: snowflake,permissions,iceberg,data,warehouse,tundra,access-control
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: cerberus
|
|
18
|
+
Requires-Dist: colorama
|
|
19
|
+
Requires-Dist: coloredlogs
|
|
20
|
+
Requires-Dist: click
|
|
21
|
+
Requires-Dist: click-default-group
|
|
22
|
+
Requires-Dist: pyyaml
|
|
23
|
+
Requires-Dist: snowflake-connector-python[secure-local-storage]
|
|
24
|
+
Requires-Dist: snowflake-sqlalchemy
|
|
25
|
+
Requires-Dist: sqlalchemy
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: black; extra == "dev"
|
|
28
|
+
Requires-Dist: bumpversion; extra == "dev"
|
|
29
|
+
Requires-Dist: changelog-cli; extra == "dev"
|
|
30
|
+
Requires-Dist: coverage; extra == "dev"
|
|
31
|
+
Requires-Dist: flake8; extra == "dev"
|
|
32
|
+
Requires-Dist: isort; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy; extra == "dev"
|
|
34
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
38
|
+
Requires-Dist: types-PyYAML; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# Tundra
|
|
42
|
+
|
|
43
|
+
**Snowflake permissions management tool with Apache Iceberg table support**
|
|
44
|
+
|
|
45
|
+
Tundra is a modern fork of tundra that adds comprehensive support for Apache Iceberg tables in Snowflake, while maintaining all the original functionality for managing permissions on databases, schemas, tables, and views.
|
|
46
|
+
|
|
47
|
+
We welcome contributions! Please submit issues or pull requests on [GitHub](https://github.com/henryupton/tundra/issues).
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
Install the latest version using:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install tundra
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For development or latest features, install directly from GitHub:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install git+https://github.com/henryupton/tundra.git
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## ⭐ What's New: Iceberg Table & External Volume Support
|
|
64
|
+
|
|
65
|
+
Tundra extends the original tundra functionality with comprehensive support for **Apache Iceberg tables** and **External Volumes** in Snowflake:
|
|
66
|
+
|
|
67
|
+
### 🏔️ Iceberg Table Support
|
|
68
|
+
- 🔍 **Discovery**: Automatically discovers Iceberg tables using `SHOW ICEBERG TABLES`
|
|
69
|
+
- 📊 **Permissions**: Grants both read (`SELECT`) and write (`INSERT`, `UPDATE`, `DELETE`, etc.) privileges
|
|
70
|
+
- 🌟 **Wildcards**: Includes Iceberg tables in schema-level wildcards (`database.schema.*`)
|
|
71
|
+
- 🔄 **Revocation**: Properly revokes Iceberg table permissions when configurations change
|
|
72
|
+
|
|
73
|
+
### 📦 External Volume Support
|
|
74
|
+
- 🔗 **Storage Access**: Grants `USAGE` privileges on external volumes (S3, Azure, GCS)
|
|
75
|
+
- ⚡ **Essential for Iceberg**: External volumes are required for Iceberg table operations
|
|
76
|
+
- 🔄 **Auto-revocation**: Automatically revokes unused external volume access
|
|
77
|
+
- 🛡️ **Security**: Manages fine-grained access to external storage locations
|
|
78
|
+
|
|
79
|
+
Example configuration:
|
|
80
|
+
```yaml
|
|
81
|
+
# Define external volumes for Iceberg tables
|
|
82
|
+
external_volumes:
|
|
83
|
+
- s3_iceberg_volume:
|
|
84
|
+
storage_provider: s3
|
|
85
|
+
owner: sysadmin
|
|
86
|
+
|
|
87
|
+
roles:
|
|
88
|
+
data_engineer:
|
|
89
|
+
# Grant access to external volumes (required for Iceberg tables)
|
|
90
|
+
external_volumes:
|
|
91
|
+
- s3_iceberg_volume
|
|
92
|
+
privileges:
|
|
93
|
+
tables:
|
|
94
|
+
read:
|
|
95
|
+
- analytics.public.* # Includes Iceberg tables
|
|
96
|
+
write:
|
|
97
|
+
- analytics.public.output_* # Write access to Iceberg tables
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Usage
|
|
101
|
+
|
|
102
|
+
Use this command to check and manage the permissions of a Snowflake account.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
tundra [-v] run <spec_file> [--role] [--dry] [--diff] [--user] [--ignore-memberships]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```shell
|
|
109
|
+
#> tundra run --help
|
|
110
|
+
Usage: tundra run [OPTIONS] SPEC
|
|
111
|
+
|
|
112
|
+
Grant the permissions provided in the provided specification file for
|
|
113
|
+
specific users and roles
|
|
114
|
+
|
|
115
|
+
Options:
|
|
116
|
+
--dry Do not actually run, just check.
|
|
117
|
+
--diff Show full diff, both new and existing permissions, use with -v.
|
|
118
|
+
--role TEXT Run grants for specific roles. Usage: --role testrole --role
|
|
119
|
+
testrole2.
|
|
120
|
+
|
|
121
|
+
--user TEXT Run grants for specific users. Usage: --user testuser --user
|
|
122
|
+
testuser2.
|
|
123
|
+
|
|
124
|
+
--ignore-memberships Do not handle role membership grants/revokes
|
|
125
|
+
--help Show this message and exit.
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Use this utility command to run the SnowFlake specification loader to confirm that your `roles.yml` file is valid.
|
|
129
|
+
```bash
|
|
130
|
+
tundra [-v] spec-test <spec_file> [--role] [--user] [--ignore-memberships]
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```shell
|
|
134
|
+
#> tundra spec-test --help
|
|
135
|
+
Usage: tundra spec-test [OPTIONS] SPEC
|
|
136
|
+
|
|
137
|
+
Load SnowFlake spec based on the roles.yml provided. CLI use only for confirming specifications are valid.
|
|
138
|
+
|
|
139
|
+
Options:
|
|
140
|
+
--role TEXT Run grants for specific roles. Usage: --role testrole
|
|
141
|
+
--role testrole2.
|
|
142
|
+
|
|
143
|
+
--user TEXT Run grants for specific users. Usage: --user testuser
|
|
144
|
+
--user testuser2.
|
|
145
|
+
|
|
146
|
+
--ignore-memberships Do not handle role membership grants/revokes
|
|
147
|
+
--run-list TEXT Run grants for specific users. Usage: --user testuser
|
|
148
|
+
--user testuser2.
|
|
149
|
+
|
|
150
|
+
--help Show this message and exit.
|
|
151
|
+
```
|
|
152
|
+
Given the parameters to connect to a Snowflake account and a YAML file (a
|
|
153
|
+
"spec") representing the desired database configuration, this command makes sure
|
|
154
|
+
that the configuration of that database matches the spec. If there are
|
|
155
|
+
differences, it will return the sql grant and revoke commands required to make
|
|
156
|
+
it match the spec. If there are additional permissions set in the database this
|
|
157
|
+
command will create the necessary revoke commands with the exception of:
|
|
158
|
+
|
|
159
|
+
- Object Ownership
|
|
160
|
+
- Warehouse Privileges
|
|
161
|
+
|
|
162
|
+
Furthermore, if you are using the recommended role of `SECURITYADMIN`, `ALTER USER ...` commands will fail on users that are owned by `ACCOUNTADMIN`. In these circumstances, it is highly recommended to log into the Snowflake instance and update ownership of all users to belong to `USERADMIN` as per Snowflake recommended best practices.
|
|
163
|
+
|
|
164
|
+
Lastly, note that the default roles cannot have their role hierarchies modified. As such, any `GRANT ROLE <default role> TO ROLE <default role>;` will be excluded from the permission set generated by Tundra.
|
|
165
|
+
|
|
166
|
+
For example:
|
|
167
|
+
|
|
168
|
+
```yaml
|
|
169
|
+
...
|
|
170
|
+
roles:
|
|
171
|
+
public:
|
|
172
|
+
member_of:
|
|
173
|
+
- useradmin
|
|
174
|
+
securityadmin:
|
|
175
|
+
member_of:
|
|
176
|
+
- useradmin
|
|
177
|
+
...
|
|
178
|
+
```
|
|
179
|
+
Both of the above relationships will be skipped as this attempts to modify a default Snowflake permission structure which would generate an error on attempting to implement.
|
|
180
|
+
|
|
181
|
+
Tundra is heavily inspired by
|
|
182
|
+
[pgbedrock](https://github.com/Squarespace/pgbedrock) which can be used for
|
|
183
|
+
managing the permissions in a Postgres database.
|
|
184
|
+
|
|
185
|
+
## spec_file
|
|
186
|
+
|
|
187
|
+
The YAML specification file is used to define in a declarative way the
|
|
188
|
+
databases, roles, users and warehouses in a Snowflake account, together with the
|
|
189
|
+
permissions for databases, schemas and tables for the same account.
|
|
190
|
+
|
|
191
|
+
All permissions are abbreviated as `read` or `write` permissions, with
|
|
192
|
+
Tundra generating the proper grants for each type of object. This includes
|
|
193
|
+
shared databases which have simpler and more limited permissions than non-shared
|
|
194
|
+
databases.
|
|
195
|
+
|
|
196
|
+
According to the `read` vs. `write` permissions approach, you should be able to
|
|
197
|
+
grant granular access like `read` permissions for usage of database and schema
|
|
198
|
+
and `write` permissions to insert data into a specific table within that
|
|
199
|
+
database and schema.
|
|
200
|
+
|
|
201
|
+
Please find below the links between Tundra permissions and Snowflake grants.
|
|
202
|
+
|
|
203
|
+
| Objects | Tundra permissions | Snowflake grants |
|
|
204
|
+
|-----------|------------------------|---------------------------------------------------------------------------------------------------------------------|
|
|
205
|
+
| Databases | read | usage |
|
|
206
|
+
| | write | monitor, create schema |
|
|
207
|
+
| Schemas | read | usage |
|
|
208
|
+
| | write | monitor, create table, create view, create stage, create file format, create sequence, create function, create pipe |
|
|
209
|
+
| Table | read | select |
|
|
210
|
+
| | write | insert, update, delete, truncate, references |
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
Tables and views are listed under `tables` and handled properly behind the
|
|
214
|
+
scenes.
|
|
215
|
+
|
|
216
|
+
If `*` is provided as the parameter for tables the grant statement will use the
|
|
217
|
+
`ALL <object_type>s in SCHEMA` syntax. It will also grant to future tables and
|
|
218
|
+
views. See Snowflake documentation for [`ON
|
|
219
|
+
FUTURE`](https://docs.snowflake.net/manuals/sql-reference/sql/grant-privilege.html#optional-parameters)
|
|
220
|
+
|
|
221
|
+
If a schema name includes an asterisk (prefix or suffix), such as `snowplow_*` or `*_snowplow`, then all schemas
|
|
222
|
+
that match this pattern will be included in the grant statement _unless it is
|
|
223
|
+
for ownership_, in which case the asterisk is not supported. This can be coupled
|
|
224
|
+
with the asterisk for table grants to grant permissions on all tables in all
|
|
225
|
+
schemas that match the given pattern. This is useful for date-partitioned
|
|
226
|
+
schemas.
|
|
227
|
+
|
|
228
|
+
All entities must be explicitly referenced. For example, if a permission is
|
|
229
|
+
granted to a schema or table then the database must be explicitly referenced for
|
|
230
|
+
permissioning as well. Additionally, role membership must be explicit in the
|
|
231
|
+
config file. If a role does not have a `member_of` list, it will have all roles
|
|
232
|
+
it currently has revoked.
|
|
233
|
+
|
|
234
|
+
Roles can accept "_" as a role name either alone or nested under the `include`
|
|
235
|
+
key. There is optionally an `exclude` key that can be used if `include` is used.
|
|
236
|
+
`"_"`will grant membership to all roles defined in the spec. Any roles defined
|
|
237
|
+
in`exclude`will be removed from the list defined in`include`.
|
|
238
|
+
|
|
239
|
+
Objects like warehouses and integrations that only have one tundra permission type just
|
|
240
|
+
needs to be specified in the role (see below).
|
|
241
|
+
|
|
242
|
+
Objects can have a `meta` dictionary which may contain information that is not relevant for Tundra's
|
|
243
|
+
execution and are ignored by Tundra itself.
|
|
244
|
+
|
|
245
|
+
A specification file has the following structure:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Databases
|
|
249
|
+
databases:
|
|
250
|
+
- db_name:
|
|
251
|
+
shared: boolean
|
|
252
|
+
- db_name:
|
|
253
|
+
shared: boolean
|
|
254
|
+
owner: role_name
|
|
255
|
+
meta:
|
|
256
|
+
some_key: some_value
|
|
257
|
+
...
|
|
258
|
+
... ... ...
|
|
259
|
+
|
|
260
|
+
# Roles
|
|
261
|
+
roles:
|
|
262
|
+
- role_name:
|
|
263
|
+
warehouses:
|
|
264
|
+
- warehouse_name
|
|
265
|
+
- warehouse_name
|
|
266
|
+
...
|
|
267
|
+
|
|
268
|
+
member_of:
|
|
269
|
+
- role_name
|
|
270
|
+
- role_name
|
|
271
|
+
...
|
|
272
|
+
|
|
273
|
+
# or
|
|
274
|
+
|
|
275
|
+
member_of:
|
|
276
|
+
include:
|
|
277
|
+
- "*"
|
|
278
|
+
exclude:
|
|
279
|
+
- role_name
|
|
280
|
+
|
|
281
|
+
privileges:
|
|
282
|
+
databases:
|
|
283
|
+
read:
|
|
284
|
+
- database_name
|
|
285
|
+
- database_name
|
|
286
|
+
...
|
|
287
|
+
write:
|
|
288
|
+
- database_name
|
|
289
|
+
- database_name
|
|
290
|
+
...
|
|
291
|
+
schemas:
|
|
292
|
+
read:
|
|
293
|
+
- database_name.*
|
|
294
|
+
- database_name.schema_name
|
|
295
|
+
- database_name.schema_partial_*
|
|
296
|
+
- database_name.*_schema_partial
|
|
297
|
+
|
|
298
|
+
...
|
|
299
|
+
write:
|
|
300
|
+
- database_name.*
|
|
301
|
+
- database_name.schema_name
|
|
302
|
+
- database_name.schema_partial_*
|
|
303
|
+
- database_name.*_schema_partial
|
|
304
|
+
...
|
|
305
|
+
tables:
|
|
306
|
+
read:
|
|
307
|
+
- database_name.*.*
|
|
308
|
+
- database_name.schema_name.*
|
|
309
|
+
- database_name.schema_partial_*.*
|
|
310
|
+
- database_name.*_schema_partial.*
|
|
311
|
+
- database_name.schema_name.table_name
|
|
312
|
+
...
|
|
313
|
+
write:
|
|
314
|
+
- database_name.*.*
|
|
315
|
+
- database_name.schema_name.*
|
|
316
|
+
- database_name.schema_partial_*.*
|
|
317
|
+
- database_name.*_schema_partial.*
|
|
318
|
+
- database_name.schema_name.table_name
|
|
319
|
+
...
|
|
320
|
+
|
|
321
|
+
owns:
|
|
322
|
+
databases:
|
|
323
|
+
- database_name
|
|
324
|
+
...
|
|
325
|
+
schemas:
|
|
326
|
+
- database_name.*
|
|
327
|
+
- database_name.schema_name
|
|
328
|
+
...
|
|
329
|
+
tables:
|
|
330
|
+
- database_name.*.*
|
|
331
|
+
- database_name.schema_name.*
|
|
332
|
+
- database_name.schema_name.table_name
|
|
333
|
+
...
|
|
334
|
+
|
|
335
|
+
meta:
|
|
336
|
+
some_key: some_value
|
|
337
|
+
...
|
|
338
|
+
|
|
339
|
+
- role_name:
|
|
340
|
+
owner: role_name
|
|
341
|
+
... ... ...
|
|
342
|
+
|
|
343
|
+
# Users
|
|
344
|
+
# can_login is required the rest of the parameters are optional
|
|
345
|
+
# None of the values are validated in Snowflake, hence default_warehouse, default_namespace and default_role
|
|
346
|
+
# can contain invalid values
|
|
347
|
+
users:
|
|
348
|
+
- user_name:
|
|
349
|
+
can_login: boolean
|
|
350
|
+
member_of:
|
|
351
|
+
- role_name
|
|
352
|
+
...
|
|
353
|
+
has_password: boolean
|
|
354
|
+
display_name: string
|
|
355
|
+
first_name: string
|
|
356
|
+
middle_name: string
|
|
357
|
+
last_name: string
|
|
358
|
+
email: string
|
|
359
|
+
comment: string
|
|
360
|
+
default_warehouse: string
|
|
361
|
+
default_namespace: string
|
|
362
|
+
default_role: string
|
|
363
|
+
type: string
|
|
364
|
+
meta:
|
|
365
|
+
some_key: some_value
|
|
366
|
+
...
|
|
367
|
+
- user_name:
|
|
368
|
+
owner: role_name
|
|
369
|
+
... ... ...
|
|
370
|
+
|
|
371
|
+
# Warehouses
|
|
372
|
+
# Warehouse sizes are informative and not altered by Tundra to align with the spec file
|
|
373
|
+
warehouses:
|
|
374
|
+
- warehouse_name:
|
|
375
|
+
size: x-small
|
|
376
|
+
meta:
|
|
377
|
+
some_key: some_value
|
|
378
|
+
...
|
|
379
|
+
- warehouse_name:
|
|
380
|
+
size: x-small
|
|
381
|
+
owner: role_name
|
|
382
|
+
... ... ...
|
|
383
|
+
|
|
384
|
+
# Integrations
|
|
385
|
+
# Integration categories are informative and not altered by Tundra to align with the spec file
|
|
386
|
+
integrations:
|
|
387
|
+
- integration_name:
|
|
388
|
+
category: storage
|
|
389
|
+
meta:
|
|
390
|
+
some_key: some_value
|
|
391
|
+
...
|
|
392
|
+
- integration_name:
|
|
393
|
+
category: security
|
|
394
|
+
owner: role_name
|
|
395
|
+
... ... ...
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
# External Volumes
|
|
399
|
+
External volumes provide access to external storage locations (S3, Azure Blob Storage, Google Cloud Storage) and are essential for Apache Iceberg table operations. They are defined at the top level and referenced in roles.
|
|
400
|
+
|
|
401
|
+
```yaml
|
|
402
|
+
# External volume definitions
|
|
403
|
+
external_volumes:
|
|
404
|
+
- s3_iceberg_volume:
|
|
405
|
+
storage_provider: s3
|
|
406
|
+
owner: sysadmin
|
|
407
|
+
- azure_data_lake:
|
|
408
|
+
storage_provider: azure
|
|
409
|
+
owner: data_admin
|
|
410
|
+
- gcs_analytics:
|
|
411
|
+
storage_provider: gcs
|
|
412
|
+
owner: analytics_admin
|
|
413
|
+
|
|
414
|
+
# Role configuration with external volume access
|
|
415
|
+
roles:
|
|
416
|
+
- data_engineer:
|
|
417
|
+
external_volumes:
|
|
418
|
+
- s3_iceberg_volume
|
|
419
|
+
- azure_data_lake
|
|
420
|
+
privileges:
|
|
421
|
+
tables:
|
|
422
|
+
read:
|
|
423
|
+
- analytics.public.* # Includes Iceberg tables
|
|
424
|
+
write:
|
|
425
|
+
- analytics.staging.* # Write to Iceberg tables
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
**Important**: External volumes are required for Iceberg table operations. Roles that need to read from or write to Iceberg tables must have `USAGE` privileges on the appropriate external volumes where the Iceberg table data is stored.
|
|
429
|
+
|
|
430
|
+
For a working example with external volumes, check the [`examples/external_volumes_example.yml`](examples/external_volumes_example.yml) file.
|
|
431
|
+
|
|
432
|
+
Note: The spec file must all be in lowercase.
|
|
433
|
+
|
|
434
|
+
### Spec file inheritance/inclusion
|
|
435
|
+
|
|
436
|
+
To achieve better organization, you can include content from other YML files into your spec file using the `!include` format.
|
|
437
|
+
|
|
438
|
+
For example, the following imports the content of a `warehouses.yml` file (among others) into `snowflake_spec.yml`
|
|
439
|
+
|
|
440
|
+
```yml
|
|
441
|
+
# warehouses.yml
|
|
442
|
+
|
|
443
|
+
- wh_loading:
|
|
444
|
+
size: x-small
|
|
445
|
+
auto_suspend: 600
|
|
446
|
+
auto_resume: true
|
|
447
|
+
initially_suspended: true
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
```yml
|
|
451
|
+
# snowflake_spec.yml
|
|
452
|
+
|
|
453
|
+
# Databases
|
|
454
|
+
databases: !include databases.yml
|
|
455
|
+
|
|
456
|
+
# Warehouses
|
|
457
|
+
warehouses: !include warehouses.yml
|
|
458
|
+
|
|
459
|
+
# Roles
|
|
460
|
+
roles: !include roles.yml
|
|
461
|
+
|
|
462
|
+
# Users
|
|
463
|
+
users: !include users.yml
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### Settings
|
|
467
|
+
|
|
468
|
+
All settings are declared here with their default values and are described
|
|
469
|
+
below. These can be added to your spec.yaml file.
|
|
470
|
+
|
|
471
|
+
```yaml
|
|
472
|
+
require-owner: false
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
`require-owner`: Set to true to force having to set the `owner` property on all
|
|
476
|
+
objects defined.
|
|
477
|
+
|
|
478
|
+
## --diff
|
|
479
|
+
|
|
480
|
+
When this flag is set, a full diff with both new and already granted commands is
|
|
481
|
+
returned. Otherwise, only required commands for matching the definitions on the
|
|
482
|
+
spec are returned.
|
|
483
|
+
|
|
484
|
+
## --dry
|
|
485
|
+
|
|
486
|
+
When this flag is set, the permission queries generated are not actually sent to
|
|
487
|
+
the server and run; They are just returned to the user for examining them and
|
|
488
|
+
running them manually.
|
|
489
|
+
|
|
490
|
+
When this flag is not set, the commands will be executed on Snowflake and their
|
|
491
|
+
status will be returned and shown on the command line.
|
|
492
|
+
|
|
493
|
+
## Connection Parameters
|
|
494
|
+
|
|
495
|
+
The following environmental variables must be available to connect to Snowflake:
|
|
496
|
+
|
|
497
|
+
```bash
|
|
498
|
+
$PERMISSION_BOT_USER
|
|
499
|
+
$PERMISSION_BOT_ACCOUNT
|
|
500
|
+
$PERMISSION_BOT_WAREHOUSE
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### Username and Password
|
|
504
|
+
|
|
505
|
+
To connect using a username and password, also include the following:
|
|
506
|
+
|
|
507
|
+
```bash
|
|
508
|
+
$PERMISSION_BOT_PASSWORD
|
|
509
|
+
$PERMISSION_BOT_DATABASE
|
|
510
|
+
$PERMISSION_BOT_ROLE
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
Currently, Tundra assumes you are using the SECURITYADMIN role and will fail
|
|
514
|
+
validation if you are not.
|
|
515
|
+
|
|
516
|
+
### OAuth
|
|
517
|
+
|
|
518
|
+
To connect using an OAuth token, also include the following:
|
|
519
|
+
|
|
520
|
+
```bash
|
|
521
|
+
$PERMISSION_BOT_OAUTH_TOKEN
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### External Browser SSO Auth
|
|
525
|
+
|
|
526
|
+
To connect using an external browser with SSO Auth, also include the following:
|
|
527
|
+
|
|
528
|
+
```bash
|
|
529
|
+
$PERMISSION_BOT_AUTHENTICATOR='externalbrowser'
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### Key Pair Authentication
|
|
533
|
+
|
|
534
|
+
Rather than supplying a password or an oauth token, it's possible to connect via
|
|
535
|
+
Snowflake's Key Pair authentication by setting the following:
|
|
536
|
+
|
|
537
|
+
```bash
|
|
538
|
+
$PERMISSION_BOT_KEY_PATH
|
|
539
|
+
$PERMISSION_BOT_KEY_PASSPHRASE
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
See [Snowflake-sqlalchemy](https://github.com/snowflakedb/snowflake-sqlalchemy#key-pair-authentication-support) for more info.
|
|
543
|
+
|
|
544
|
+
## Contributing
|
|
545
|
+
|
|
546
|
+
Contributing to Tundra is easy, and most commands to do so are available
|
|
547
|
+
within the Makefile.
|
|
548
|
+
|
|
549
|
+
The easiest way to start developing is to run `make initial-setup` to install
|
|
550
|
+
all the necessary packages to develop on the project. Next run `make
|
|
551
|
+
tundra` in a second terminal, this will open a shell in a docker container
|
|
552
|
+
with the local version of Tundra installed.
|
|
553
|
+
|
|
554
|
+
You can now make changes to the files in your editor and it will be reflected in
|
|
555
|
+
the commands that you run from the docker shell.
|
|
556
|
+
|
|
557
|
+
To check code quality prior to committing changes, you can use `make local-lint`.
|
|
558
|
+
|
|
559
|
+
See the [Makefile](Makefile) for more details.
|
|
560
|
+
|
|
561
|
+
**WARNINGS**
|
|
562
|
+
|
|
563
|
+
DO NOT name git branches with forward slashes `/` as the current CI pipeline is
|
|
564
|
+
unable to manage names like this. (i.e. `username/feature/feature-name` will
|
|
565
|
+
break the CI pipeline so `username.feature.feature-name` should be used
|
|
566
|
+
instead)
|
|
567
|
+
|
|
568
|
+
This project has [pre-commit
|
|
569
|
+
hooks](https://github.com/pre-commit/pre-commit-hooks) installed to maintain
|
|
570
|
+
the existing code quality. As such, we strongly recommend you use a terminal to
|
|
571
|
+
**commit** and **push** code changes. Specifically, avoid using git
|
|
572
|
+
integrations on IDEs to make **commits** or **pushes**. **Adding** files
|
|
573
|
+
through the IDE git integrations are okay, but do not **commit** through the
|
|
574
|
+
IDE. Use the terminal to commit changes because it will show the output of each
|
|
575
|
+
of the pre-commit checks to allow you to make changes as needed.
|
|
576
|
+
|
|
577
|
+
For committing work-in-progress changes use `git commit --no-verify -m "WIP:
|
|
578
|
+
<message>"`.
|
|
579
|
+
|
|
580
|
+
For committing finalized changes, the below workflow will identify errors and allow for easier development:
|
|
581
|
+
* Make your changes and `git add <file name(s)>`
|
|
582
|
+
* `git commit` to identify/format errors in the changed files
|
|
583
|
+
* Repeat the following steps until all checks pass
|
|
584
|
+
* `git add <file name(s)>`
|
|
585
|
+
* `git commit`
|
|
586
|
+
* Add message at the prompt and save/exit the commit file
|
|
587
|
+
* When you are ready to push changes to the remote host, run `git push origin <branch name>`. This will perform additional linting/formatting checks.
|
|
588
|
+
* Repeat the following steps until all checks pass
|
|
589
|
+
* `git push origin <branch name>`
|
|
590
|
+
* `git add <file name(s)>`
|
|
591
|
+
* `git commit`
|
|
592
|
+
* Add message at the prompt and save/exit the commit file
|
|
593
|
+
* `git push origin <branch name>` until all checks pass
|
|
594
|
+
|
|
595
|
+
## Releasing
|
|
596
|
+
|
|
597
|
+
See the [issue template](https://gitlab.com/gitlab-data/tundra/-/blob/master/.gitlab/issue_templates/Releasing%20update.md)
|
|
598
|
+
for guidance on how to release a new version of this project to PyPi
|