-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: prevent arbitrary writes to system.comments
Previously, the GRANT, UPDATE, DELETE and INSERT privileges were granted to `public`, i.e. everyone, on `system.comments`. This was unintended - only users with permissions on an object should be able to modify that object's comments. This patch fixes it. Release note (security update): Any user could previously modify any database/table/view/index comment via direct SQL updates to `system.comments`. This was unintended and a form of privilege escalation, and is now prevented. The privileges required for the COMMENT statement and `pg_description`, `col_description()`, `obj_description()` and `shobj_description()` are operating as in PostgreSQL and unaffected by this change: all users can *view* any comments on any object (bypassing other privileges), but modifying comments require write privilege on the target object.
- Loading branch information
Showing
12 changed files
with
152 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Disable automatic stats to avoid flakiness. | ||
statement ok | ||
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false | ||
|
||
subtest regression45707 | ||
|
||
user root | ||
|
||
statement ok | ||
CREATE DATABASE d45707; CREATE TABLE d45707.t45707(x INT); | ||
GRANT SELECT ON DATABASE d45707 TO testuser; | ||
GRANT SELECT ON d45707.t45707 TO testuser | ||
|
||
statement ok | ||
COMMENT ON DATABASE d45707 IS 'd45707'; | ||
COMMENT ON TABLE d45707.t45707 IS 't45707'; | ||
COMMENT ON COLUMN d45707.t45707.x IS 'x45707'; | ||
COMMENT ON INDEX d45707.t45707@primary IS 'p45707' | ||
|
||
user testuser | ||
|
||
statement ok | ||
SET DATABASE = d45707 | ||
|
||
# Verify the user cannot modify the comments | ||
|
||
statement error user testuser does not have CREATE privilege on database d45707 | ||
COMMENT ON DATABASE d45707 IS 'd45707' | ||
|
||
statement error user testuser does not have CREATE privilege on relation t45707 | ||
COMMENT ON TABLE d45707.t45707 IS 't45707' | ||
|
||
statement error user testuser does not have CREATE privilege on relation t45707 | ||
COMMENT ON COLUMN d45707.t45707.x IS 'x45707' | ||
|
||
statement error user testuser does not have CREATE privilege on relation t45707 | ||
COMMENT ON INDEX d45707.t45707@primary IS 'p45707' | ||
|
||
# Verify that the user can view the comments | ||
|
||
query T | ||
SELECT shobj_description(oid, 'pg_database') | ||
FROM pg_database | ||
WHERE datname = 'd45707' | ||
---- | ||
d45707 | ||
|
||
query T | ||
SELECT col_description(attrelid, attnum) | ||
FROM pg_attribute | ||
WHERE attrelid = 't45707'::regclass AND attname = 'x' | ||
---- | ||
x45707 | ||
|
||
query T | ||
SELECT obj_description('t45707'::REGCLASS) | ||
---- | ||
t45707 | ||
|
||
query T | ||
SELECT obj_description(indexrelid) | ||
FROM pg_index | ||
WHERE indrelid = 't45707'::REGCLASS | ||
AND indisprimary | ||
---- | ||
p45707 | ||
|
||
# Verify that the user can modify the comments. | ||
|
||
user root | ||
|
||
statement ok | ||
GRANT ALL ON DATABASE d45707 TO testuser; | ||
GRANT ALL ON TABLE d45707.t45707 TO testuser | ||
|
||
user testuser | ||
|
||
statement ok | ||
COMMENT ON DATABASE d45707 IS 'd45707_2'; | ||
COMMENT ON TABLE d45707.t45707 IS 't45707_2'; | ||
COMMENT ON COLUMN d45707.t45707.x IS 'x45707_2'; | ||
COMMENT ON INDEX d45707.t45707@primary IS 'p45707_2' |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.