This issue also affects redshift_permissions but we have migrated to redshift_grants so haven't created a test case for that.
The code used to check grants consists of SQL functions like these:
decode(charindex('r',split_part(split_part(array_to_string(relacl, '|'),gr.groname,2 ) ,'/',1)), 0,0,1) as select,
This is imperfect and gets confused in a number of cases. It's meant to parse ACLs like these:
{"group my_reader_group=r/my_user",my_user=arwdRxtD/myuser}
These have the format of grantee=perms/grantor and grantee may be an user in the form of username or group in the form of group groupname and matches against each table in a target schema
If a group exists with the same name as an user, the code above can break the following ways:
- The code may match the grantor portion of an ACL entry and fail to pick up any permissions
- It may pick up grants to an user rather than the group, depending on the order in which the ACL entries occur.
- If a schema has 10 tables and the user has SELECT granted to only one of these, that may be interpreted by the code as having SELECT granted on all tables in the schema (I haven't verified this)
- Related to the the above, the code may pick up grants created by
redshift_default_privileges if a table was added to the schema, even if no redshift_grants resources were applied before.
- I don't understand how schema grants are verified (if at all) when there are no tables in a schema and the above query returns zero rows.
Depending on the nature of the error this may result in an one-off diff or even a permanent diff, usually when tables are created outside of Terraform, especially if the creating user had some default permissions that would apply grants to a newly created table.
This issue also affects
redshift_permissionsbut we have migrated toredshift_grantsso haven't created a test case for that.The code used to check grants consists of SQL functions like these:
This is imperfect and gets confused in a number of cases. It's meant to parse ACLs like these:
These have the format of
grantee=perms/grantorandgranteemay be an user in the form ofusernameor group in the form ofgroup groupnameand matches against each table in a target schemaIf a group exists with the same name as an user, the code above can break the following ways:
redshift_default_privilegesif a table was added to the schema, even if noredshift_grantsresources were applied before.Depending on the nature of the error this may result in an one-off diff or even a permanent diff, usually when tables are created outside of Terraform, especially if the creating user had some default permissions that would apply grants to a newly created table.