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-789] Add support for grant macros #128

Closed
jtcohen6 opened this issue Jun 29, 2022 · 0 comments · Fixed by #131
Closed

[CT-789] Add support for grant macros #128

jtcohen6 opened this issue Jun 29, 2022 · 0 comments · Fixed by #131
Assignees
Labels
enhancement New feature or request

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented Jun 29, 2022

Everything in Redshift is mostly the same as in PostgreSQL, so we don't require any changes to:

  • materializations
  • get_grant_sql
  • get_revoke_sql

However, the syntax for showing grants is very different. I think something like this will work, though I'll be the first to admit that it looks & feels pretty weird:

{% macro redshift__get_show_grant_sql(relation) %}

with privileges as (

        -- valid options per https://docs.aws.amazon.com/redshift/latest/dg/r_HAS_TABLE_PRIVILEGE.html
	select 'select' as privilege
	union all
	select 'insert' as privilege
	union all
	select 'update' as privilege
	union all
	select 'delete' as privilege
	union all
	select 'references' as privilege

)

select
    u.usename as grantee,
    p.privilege
from pg_user u
cross join privileges p
where has_table_privilege(u.usename, '{{ relation }}', privilege)

{% endmacro %}

Even though that function is called has_table_privilege, it works for both tables + views. Schema-level privileges require using has_schema_privilege instead; not something we need to worry about for now.

Assuming that query is able to return columns by the same name (and we could rename them in the SQL if need be), we shouldn't need to override any other parts of the puzzle.

@jtcohen6 jtcohen6 added the enhancement New feature or request label Jun 29, 2022
@github-actions github-actions bot changed the title Add support for grant macros [CT-789] Add support for grant macros Jun 29, 2022
@McKnight-42 McKnight-42 self-assigned this Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants