You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the existing issues, and I could not find an existing issue for this bug
Current Behavior
I am using the new grants setting to grant select permissions on all DBT-generated tables to the AWS Administrator Access IAM role, so that anyone who can access our AWS account can also query the Redshift database, e.g. using Redshift Query Editor.
In Redshift SQL, the grant works like this:
grantselecton"mydb"."myschema"."mytable to "IAMR:AWSReservedSSO_AWSAdministratorAccess_XXXXXXXXXXX"
To achieve this, I have added the following in my dbt_project.yml:
models:
myschema:
+grants:
+select:
# variables are not supported in dbt_project.yml (https://github.com/dbt-labs/dbt-core/discussions/6170)
- "{{ '\"IAMR:AWSReservedSSO_AWSAdministratorAccess_XXXXXXXXXXXXXX\"' if target.name == 'prod' else '\"IAMR:AWSReservedSSO_AWSAdministratorAccess_YYYYYYYYYYYYYYY\"' }}"
Note the additional quotation marks in the grant statement and the role name. Those are required by Redshift for IAM users/roles.
This works for any table model which is built as table, but not for incremental models. For incremental models, DBT generates a revoke statement first. This however does not contain the quotation marks:
revokeselecton"mydb"."myschema"."mytable"from IAMR:AWSReservedSSO_AWSAdministratorAccess_XXXXXXXXXXX;
grantselecton"mydb"."myschema"."mytable" to "IAMR:AWSReservedSSO_AWSAdministratorAccess_XXXXXXXXXXX";
The revoke fails with Redshift error message user "IAMR:awsreservedsso_awsadministratoraccess_xxxxxxxxxxx" does not exist.
Expected Behavior
The revoke statement should be valid for IAM users/roles and contain the required quotation marks.
Steps To Reproduce
Create an incremental table model
Set a grant to use an IAM role using the "IAMR:xxxx" syntax
Run the model
Run the model again (incrementally) and see the revoke fail
As a workaround, I run the following macro in the on-run-end hook:
{% macro create_schema_grants() %}
{% for schema in schemas %}
grant usage on schema {{ schema }} to {{ var("iam_grant_role_admin") }};
grant select on all tables in schema {{ schema }} to {{ var("iam_grant_role_admin") }};
{% endfor %}
{% endmacro %}
Is this a new bug in dbt-redshift?
Current Behavior
I am using the new
grants
setting to grant select permissions on all DBT-generated tables to the AWS Administrator Access IAM role, so that anyone who can access our AWS account can also query the Redshift database, e.g. using Redshift Query Editor.In Redshift SQL, the grant works like this:
To achieve this, I have added the following in my
dbt_project.yml
:Note the additional quotation marks in the
grant
statement and the role name. Those are required by Redshift for IAM users/roles.This works for any table model which is built as table, but not for incremental models. For incremental models, DBT generates a
revoke
statement first. This however does not contain the quotation marks:The
revoke
fails with Redshift error messageuser "IAMR:awsreservedsso_awsadministratoraccess_xxxxxxxxxxx" does not exist
.Expected Behavior
The
revoke
statement should be valid for IAM users/roles and contain the required quotation marks.Steps To Reproduce
Relevant log output
No response
Environment
Additional Context
No response
The text was updated successfully, but these errors were encountered: