-
Notifications
You must be signed in to change notification settings - Fork 493
dbt-materialize: allow setting object owners #34844
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
base: main
Are you sure you want to change the base?
Conversation
|
Thank you for your submission! We really appreciate it. Like many source-available projects, we require that you sign our Contributor License Agreement (CLA) before we can accept your contribution. I have read the Contributor License Agreement (CLA) and I hereby sign the CLA. You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
|
While I don't have a good environment for testing patches to dbt-materialize setup, I was able to test this post_hook macro and it seems to work, for reference: |
bobbyiliev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this contribution! 🙌
You can test with cd misc/dbt-materialize && ./mzcompose run default (note: it's very resource heavy as it spins up multiple containers).
| {% if owner %} | ||
| {% set alter_stmt %} | ||
| {% if relation.type == 'view' %} | ||
| alter view {{ relation }} owner to {{ owner }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth using adapter.quote() here.
| {% endmacro %} | ||
|
|
||
| -- In the dbt-adapter we extend the Relation class to include sinks and indexes | ||
| {% macro materialize__alter_owner(relation) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to help add unit tests for this if you'd like! Let me know if you prefer to add them yourself or want me to contribute that part.
Motivation
Our CI/CD pipeline uses dbt to deploy Materialize objects in a multi-tenant Materialize instance that uses RBAC heavily. The CI/CD pipeline uses the mz_system user, so the objects it creates are owned by mz_system.
However, due to Materialize's RBAC model,
we are required to do explicit grants of USAGE/SELECT to mz_system on all the objects, which feels both redundant and confusing given that mz_system is a superuser, and is not related to the role running queries against the objects.
So, we'd like dbt to be able to swap the owner of each object to the appropriate tenant's role at creation time.
Tips for reviewer
This is not yet tested, and I can't access buildkit 😅
Checklist
$T ⇔ Proto$Tmapping (possibly in a backwards-incompatible way), then it is tagged with aT-protolabel.