Repository navigation
feat: add column_grant_overridden_by_table_grant lint (0033) - #200
Open
mattmuller wants to merge 1 commit into
Open
mattmuller wants to merge 1 commit into
mattmuller wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
New WARN-level lint
0033_column_grant_overridden_by_table_grant.What is the current behavior?
Nothing flags a column-level privilege that is made pointless by a table-level privilege. Postgres allows an operation if the role holds the privilege on the table or on the column. A table-level
SELECTcovers every column, soGRANT SELECT (a, b) ON t TO anondoes not restrictanontoaandbifanonalso holdsSELECTont. The author thinks a column is hidden, and it is not.On Supabase the table-level grant often comes from the default grants on
publictables, or fromPUBLIC.What is the new behavior?
The lint reports (table, role, privilege) where the role is
anonorauthenticated, has an entry for the privilege inpg_attribute.attacl(SELECT,INSERT,UPDATE,REFERENCES), andhas_table_privilege(role, table, privilege)is true. The latter includesPUBLICand role inheritance. Tables must be in an exposed schema (pgrst.db_schemas, defaultpublic). Extension-owned tables are skipped.What the catalogue can and cannot show. A plain
REVOKE SELECT (col) ON t FROM roleagainst a table-level grant stores nothing, because there is nothing to remove, so that case cannot be detected and is not attempted. The lint only reports the detectable footprint: a column entry that exists alongside the table grant. Docs state this limitation.Minimal repro:
Remediation (documented): revoke the table-level privilege, then grant the columns again, since a table-level revoke also clears the role's column entries of that kind.
Additional context
Related but different: #196 / #197 cover a policy whose role lacks a table privilege. #197 also claims number
0031, so numbers in this series may need adjusting at merge.How it was tested
test/sql/0033_column_grant_overridden_by_table_grant.sql. The fixtures grantSELECTon newpublictables toPUBLIC, so the test revokes everything first.SELECTwith no table-level grant; table-levelSELECTwith no column entries; table-levelSELECTwith column-levelUPDATE(different privileges).SELECTon the same role; table-levelSELECTinherited fromPUBLICwith a column grant toanon.Full suite passes on
supabase/postgres15.14.1.169 and 17.6.1.169, including thesplinter.sqlvalidity check.bin/check_lints.pypasses.False-positive risk. Low to moderate. The column grant is always redundant when it fires. It may be a leftover from an earlier setup where the table grant is intentional.