Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CT-808 grant adapter tests #5447

Merged
merged 18 commits into from
Jul 7, 2022
Merged

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Jul 6, 2022

resolves #5437

Description

Adapter zone grant tests.

Checklist

@gshank gshank requested a review from a team July 6, 2022 23:04
@gshank gshank requested review from a team as code owners July 6, 2022 23:04
@cla-bot cla-bot bot added the cla:yes label Jul 6, 2022
@gshank gshank marked this pull request as draft July 6, 2022 23:04
@gshank gshank changed the base branch from main to ct-660-grant-sql July 6, 2022 23:04
@gshank gshank requested review from jtcohen6 and removed request for nathaniel-may and iknox-fa July 6, 2022 23:05
@gshank
Copy link
Contributor Author

gshank commented Jul 6, 2022

Draft PR for commenting and discussion. I had to change a couple of things in ct-660 to get the basic test working, i.e. remove resource.type from the grant statement.

@gshank gshank force-pushed the ct-808-grant_adapter_tests branch from 427c131 to 8e9a4f3 Compare July 6, 2022 23:10
@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2022

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@jtcohen6 jtcohen6 mentioned this pull request Jul 7, 2022
6 tasks
Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Thanks for putting up the draft PR.

With a few small modifications (ct-808-grant_adapter_tests...jerco/grants-testing, the substance of which I've noted in comments below), I was able to get this running successfully against both Postgres + Snowflake (using slightly modified version of dbt-labs/dbt-snowflake#178).

It looks like there are two approaches to validate grant behavior:

  1. Querying the database after the model runs. I have a little bit of code that might be able to help in doing this across adapters.
  2. Checking the logs, which is trickier to match up across adapters. This does feel like a good way to validate that we're taking the "most efficient" strategy possible, following the should_revoke=True|False logic. We can count show/grant/revoke statements, and validate that we're only running them in cases where we actually need to.

test/setup_db.sh Show resolved Hide resolved
tests/adapter/dbt/tests/adapter/grants/test_models.py Outdated Show resolved Hide resolved
tests/adapter/dbt/tests/adapter/grants/test_models.py Outdated Show resolved Hide resolved
core/dbt/adapters/base/impl.py Show resolved Hide resolved
tests/adapter/dbt/tests/adapter/grants/test_models.py Outdated Show resolved Hide resolved
tests/adapter/dbt/tests/adapter/grants/test_models.py Outdated Show resolved Hide resolved
.github/workflows/main.yml Outdated Show resolved Hide resolved
@gshank gshank marked this pull request as ready for review July 7, 2022 18:22
@gshank gshank requested a review from leahwicz as a code owner July 7, 2022 18:22
@gshank gshank merged commit cefcd4f into ct-660-grant-sql Jul 7, 2022
@gshank gshank deleted the ct-808-grant_adapter_tests branch July 7, 2022 20:02
Copy link
Contributor

@McKnight-42 McKnight-42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

@gshank gshank mentioned this pull request Jul 8, 2022
6 tasks
McKnight-42 added a commit that referenced this pull request Jul 11, 2022
* init push or ct-660 work

* changes to default versions of get_show_grant_sql and get_grant_sql

* completing init default versions of all macros being called for look over and collaboration

* minor update to should_revoke

* post pairing push up (does have log statements to make sure we remove)

* minor spacing changes

* minor changes, and removal of logs so people can have clean grab of code

* minor changes to how get_revoke_sql works

* init attempt at applying apply_grants to all materialzations

* name change from recipents -> grantee

* minor changes

* working on making a context to handle the diff gathering between grant_config and curreent_grants to see what needs to be revoked, I know if we assign a role, and a model becomes dependent on it we can't drop the role now still not seeing the diff appear in log

* removing logs from most materializations to better track diff of grants generation logs

* starting to build out postgres get_show_grant_sql getting empty query errors hopefully will clear up as we add the other postgres versions of macros and isn't a psycopg2 issue as indicated by searching

* 6/27 eod update looking into diff_grants variable not getting passed into get_revoke_sql

* changes to loop cases

* changes after pairing meeting

* adding apply_grants to create_or_replace_view.sql

* models are building but testing out small issues around revoke statement never building

* postgrest must fixes from jeremy's feedback

* postgres minor change to standarize_grants_dict

* updating after pairing with dough and jeremey incorporating the new version of should revoke logic.

* adding  ref of diff_of_two_dicts to base keys ref

* change of method type for standardize_grants_dict

* minor update trying to fix unit test

* changes based on morning feedback

* change log message in default_apply_grants macro

* CT-808 grant adapter tests (#5447)

* Create initial test for grants

Co-authored-by: Jeremy Cohen <[email protected]>

* rename grant[privilege] -> grant_config[privilege]

* postgres macro rename to copy_grants

* CT-808 more grant adapter tests (#5452)

* Add tests for invalid user and invalid privilege

* Add more grant tests

* Macro touch ups

* Many more tests

* Allow easily replacing privilege names

* Keep adding tests

* Refactor macros to return lists, fix test

* Code checks

* Keep tweaking tests

* Revert cool grantees join bc Snowflake isnt happy

* Use Postgres/BQ as standard for standardize_grants_dict

* Code checks

* add missing replace

* small replace tweak,  add additional dict diffs

* All tests passing on BQ

* Add type cast to test_snapshot_grants

* Refactor for DRYer apply_grants macros

Co-authored-by: Jeremy Cohen <[email protected]>
Co-authored-by: Emily Rockman <[email protected]>

* update to main, create changelog, whitespace fixes

Co-authored-by: Gerda Shank <[email protected]>
Co-authored-by: Jeremy Cohen <[email protected]>
Co-authored-by: Emily Rockman <[email protected]>
agoblet pushed a commit to BigDataRepublic/dbt-core that referenced this pull request Sep 16, 2022
* init push or ct-660 work

* changes to default versions of get_show_grant_sql and get_grant_sql

* completing init default versions of all macros being called for look over and collaboration

* minor update to should_revoke

* post pairing push up (does have log statements to make sure we remove)

* minor spacing changes

* minor changes, and removal of logs so people can have clean grab of code

* minor changes to how get_revoke_sql works

* init attempt at applying apply_grants to all materialzations

* name change from recipents -> grantee

* minor changes

* working on making a context to handle the diff gathering between grant_config and curreent_grants to see what needs to be revoked, I know if we assign a role, and a model becomes dependent on it we can't drop the role now still not seeing the diff appear in log

* removing logs from most materializations to better track diff of grants generation logs

* starting to build out postgres get_show_grant_sql getting empty query errors hopefully will clear up as we add the other postgres versions of macros and isn't a psycopg2 issue as indicated by searching

* 6/27 eod update looking into diff_grants variable not getting passed into get_revoke_sql

* changes to loop cases

* changes after pairing meeting

* adding apply_grants to create_or_replace_view.sql

* models are building but testing out small issues around revoke statement never building

* postgrest must fixes from jeremy's feedback

* postgres minor change to standarize_grants_dict

* updating after pairing with dough and jeremey incorporating the new version of should revoke logic.

* adding  ref of diff_of_two_dicts to base keys ref

* change of method type for standardize_grants_dict

* minor update trying to fix unit test

* changes based on morning feedback

* change log message in default_apply_grants macro

* CT-808 grant adapter tests (dbt-labs#5447)

* Create initial test for grants

Co-authored-by: Jeremy Cohen <[email protected]>

* rename grant[privilege] -> grant_config[privilege]

* postgres macro rename to copy_grants

* CT-808 more grant adapter tests (dbt-labs#5452)

* Add tests for invalid user and invalid privilege

* Add more grant tests

* Macro touch ups

* Many more tests

* Allow easily replacing privilege names

* Keep adding tests

* Refactor macros to return lists, fix test

* Code checks

* Keep tweaking tests

* Revert cool grantees join bc Snowflake isnt happy

* Use Postgres/BQ as standard for standardize_grants_dict

* Code checks

* add missing replace

* small replace tweak,  add additional dict diffs

* All tests passing on BQ

* Add type cast to test_snapshot_grants

* Refactor for DRYer apply_grants macros

Co-authored-by: Jeremy Cohen <[email protected]>
Co-authored-by: Emily Rockman <[email protected]>

* update to main, create changelog, whitespace fixes

Co-authored-by: Gerda Shank <[email protected]>
Co-authored-by: Jeremy Cohen <[email protected]>
Co-authored-by: Emily Rockman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-808] Add "adapter zone" tests for grants
4 participants