Skip to content

Commit

Permalink
Grant schema OWNERSHIP privilege to DATABASE OWNER role
Browse files Browse the repository at this point in the history
  • Loading branch information
littleK0i committed May 8, 2024
1 parent 8508cb6 commit 864e023
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.27.1] - 2024-05-08

- Grant schema OWNERSHIP privilege to DATABASE OWNER role. Unfortunately, it seems to be the only way to allow external tools to DROP schemas.

## [0.27.0] - 2024-05-06

This is a major update to permissions and SnowDDL internals, which introduces some breaking changes. [Read more about it](https://docs.snowddl.com/breaking-changes-log/0.27.0-may-2024).
Expand Down
5 changes: 5 additions & 0 deletions snowddl/_config/sample02_01/business_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fivetran:
database_owner:
- fivetran_db
warehouse_usage:
- fivetran_wh
1 change: 1 addition & 0 deletions snowddl/_config/sample02_01/fivetran_db/params.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
is_sandbox: true
permission_model: fivetran
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# nothing
3 changes: 3 additions & 0 deletions snowddl/_config/sample02_01/user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ext_script_fivetran:
business_roles:
- fivetran
4 changes: 4 additions & 0 deletions snowddl/_config/sample02_01/warehouse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ dynamic_table_wh:
size: XSMALL
auto_suspend: 60

fivetran_wh:
size: XSMALL
auto_suspend: 60

task_wh:
size: XSMALL
auto_suspend: 60
Expand Down
9 changes: 0 additions & 9 deletions snowddl/resolver/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ def create_object(self, bp: DatabaseBlueprint):
# Drop schema PUBLIC which is created automatically
self.engine.execute_safe_ddl("DROP SCHEMA {database:i}.{schema:i}", {"database": bp.full_name, "schema": "PUBLIC"})

# Add a special FUTURE GRANT to ensure schemas are owned by SnowDDL admin role regardless of creation mechanism
self.engine.execute_safe_ddl(
"GRANT OWNERSHIP ON FUTURE SCHEMAS IN DATABASE {full_name:i} TO ROLE {current_role:i}",
{
"full_name": bp.full_name,
"current_role": self.engine.context.current_role,
},
)

return ResolveResult.CREATE

def compare_object(self, bp: DatabaseBlueprint, row: dict):
Expand Down
11 changes: 1 addition & 10 deletions snowddl/resolver/database_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,7 @@ def get_blueprint_owner_role(self, database_bp: DatabaseBlueprint):

future_grants.append(
FutureGrant(
privilege="USAGE",
on_future=ObjectType.SCHEMA,
in_parent=ObjectType.DATABASE,
name=database_bp.full_name,
)
)

future_grants.append(
FutureGrant(
privilege="MODIFY",
privilege="OWNERSHIP",
on_future=ObjectType.SCHEMA,
in_parent=ObjectType.DATABASE,
name=database_bp.full_name,
Expand Down
2 changes: 1 addition & 1 deletion snowddl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.27.0"
__version__ = "0.27.1"

0 comments on commit 864e023

Please sign in to comment.