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-1901] [Bug] Revoke granted IAM roles fails #277

Closed
2 tasks done
mp24-git opened this issue Jan 25, 2023 · 2 comments
Closed
2 tasks done

[CT-1901] [Bug] Revoke granted IAM roles fails #277

mp24-git opened this issue Jan 25, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@mp24-git
Copy link

Is this a new bug in dbt-redshift?

  • I believe this is a new bug in dbt-redshift
  • 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:

grant select on "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:

revoke select on "mydb"."myschema"."mytable" from IAMR:AWSReservedSSO_AWSAdministratorAccess_XXXXXXXXXXX;
        
grant select on "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

  1. Create an incremental table model
  2. Set a grant to use an IAM role using the "IAMR:xxxx" syntax
  3. Run the model
  4. Run the model again (incrementally) and see the revoke fail

Relevant log output

No response

Environment

- OS: Windows 10
- Python: 3.9.1
- dbt-core: 1.3.1
- dbt-redshift: 1.3.0

Additional Context

No response

@mp24-git mp24-git added bug Something isn't working triage labels Jan 25, 2023
@github-actions github-actions bot changed the title [Bug] Revoke granted IAM roles fails [CT-1901] [Bug] Revoke granted IAM roles fails Jan 25, 2023
@mp24-git
Copy link
Author

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 %}

where the variable is defined in dbt_project.yml:

vars:
  iam_grant_role_admin: "{{ '\"IAMR:AWSReservedSSO_AWSAdministratorAccess_XXXXXXXXXXXXXX\"' if target.name == 'prod' else '\"IAMR:AWSReservedSSO_AWSAdministratorAccess_YYYYYYYYYYYYYYY\"' }}"

@jtcohen6
Copy link
Contributor

jtcohen6 commented Jan 25, 2023

Thanks for opening @mp24-git! I think this is a duplicate of dbt-labs/dbt-adapters#156.

We might want to quote grant recipients by default, except on databases where quoting leads to gnarly case sensitivity (Snowflake).

I'd encourage you to weigh in over there. I'm going to close this issue in the meantime to keep the conversation & tracking centralized.

@jtcohen6 jtcohen6 added duplicate and removed triage labels Jan 25, 2023
@jtcohen6 jtcohen6 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants