-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Features | ||
body: Support security grants | ||
time: 2022-10-05T13:46:13.789545+02:00 | ||
custom: | ||
Author: mdesmet | ||
Issue: "" | ||
PR: "130" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{% macro trino__get_show_grant_sql(relation) -%} | ||
select | ||
grantee, | ||
lower(privilege_type) as privilege_type | ||
from information_schema.table_privileges | ||
where table_catalog = '{{ relation.database }}' | ||
and table_schema = '{{ relation.schema }}' | ||
and table_name = '{{ relation.identifier }}' | ||
{%- endmacro %} | ||
|
||
{% macro trino__copy_grants() %} | ||
{# | ||
-- This macro should return true or false depending on the answer to | ||
-- following question: | ||
-- when an object is fully replaced on your database, do grants copy over? | ||
-- e.g. on Postgres this is never true, | ||
-- on Spark this is different for views vs. non-Delta tables vs. Delta tables, | ||
-- on Snowflake it depends on the user-supplied copy_grants configuration. | ||
-- true by default, which means “play it safe”: grants MIGHT have copied over, | ||
-- so dbt will run an extra query to check them + calculate diffs. | ||
#} | ||
{{ return(False) }} | ||
{% endmacro %} | ||
|
||
{%- macro trino__get_grant_sql(relation, privilege, grantees) -%} | ||
grant {{ privilege }} on {{ relation }} to {{ adapter.quote(grantees[0]) }} | ||
{%- endmacro %} | ||
|
||
{%- macro trino__support_multiple_grantees_per_dcl_statement() -%} | ||
{# | ||
-- This macro should return true or false depending on the answer to | ||
-- following question: | ||
-- does this database support grant {privilege} to user_a, user_b, ...? | ||
-- or do user_a + user_b need their own separate grant statements? | ||
#} | ||
{{ return(False) }} | ||
{%- endmacro -%} | ||
|
||
{% macro trino__call_dcl_statements(dcl_statement_list) %} | ||
{% for dcl_statement in dcl_statement_list %} | ||
{% call statement('grant_or_revoke') %} | ||
{{ dcl_statement }} | ||
{% endcall %} | ||
{% endfor %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
from dbt.context.base import BaseContext # diff_of_two_dicts only | ||
from dbt.tests.adapter.grants.test_model_grants import BaseModelGrants | ||
|
||
|
||
@pytest.mark.hive | ||
# TODO: setup Galaxy and Starbust tests | ||
# See https://github.com/starburstdata/dbt-trino/issues/147 | ||
# and also https://github.com/starburstdata/dbt-trino/issues/146 | ||
@pytest.mark.skip_profile("starburst_galaxy") | ||
# To run this test locally add following env vars: | ||
# DBT_TEST_USER_1=user1 | ||
# DBT_TEST_USER_2=user2 | ||
# DBT_TEST_USER_3=user3 | ||
class TestModelGrants(BaseModelGrants): | ||
def assert_expected_grants_match_actual(self, project, relation_name, expected_grants): | ||
actual_grants = self.get_grants_on_relation(project, relation_name) | ||
# Remove the creation user | ||
try: | ||
for privilege in ["delete", "update", "insert", "select"]: | ||
if privilege in actual_grants: | ||
actual_grants[privilege].remove("admin") | ||
if len(actual_grants[privilege]) == 0: | ||
del actual_grants[privilege] | ||
except ValueError: | ||
pass | ||
|
||
# need a case-insensitive comparison | ||
# so just a simple "assert expected == actual_grants" won't work | ||
diff_a = BaseContext.diff_of_two_dicts(actual_grants, expected_grants) | ||
diff_b = BaseContext.diff_of_two_dicts(expected_grants, actual_grants) | ||
assert diff_a == diff_b == {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters