Skip to content

Commit 1e8a464

Browse files
craig[bot]Dedej-Bergin
andcommitted
Merge #147357
147357: sql: fix rolbypassrls column in pg_roles and pg_authid tables r=Dedej-Bergin a=Dedej-Bergin Previously, the rolbypassrls column in `pg_roles` and `pg_authid` tables was hardcoded to return false, regardless of whether a role had the BYPASSRLS option set. The fix adds a bypassRLS() method to check for the BYPASSRLS option and updates the tables to use this method instead of hardcoded values. Fixes: #146228 Epic: CRDB-48807 Release note (bug fix): Fixed a bug where the rolbypassrls column in pg_roles and pg_authid tables always returned false, even for roles with the BYPASSRLS option. Co-authored-by: Bergin Dedej <[email protected]>
2 parents 80e78d8 + e981856 commit 1e8a464

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

pkg/sql/information_schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,11 @@ func (r roleOptions) createRole() (tree.DBool, error) {
29302930
return tree.DBool(createRole), err
29312931
}
29322932

2933+
func (r roleOptions) bypassRLS() (tree.DBool, error) {
2934+
bypassRLS, err := r.Exists("BYPASSRLS")
2935+
return tree.DBool(bypassRLS), err
2936+
}
2937+
29332938
// forEachRoleAtCacheReadTS reads from system.users and related tables using a
29342939
// timestamp based on when the role membership cache was refreshed.
29352940
func forEachRoleAtCacheReadTS(

pkg/sql/logictest/testdata/logic_test/row_level_security

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5323,4 +5323,40 @@ DROP TABLE trigger_rls_table;
53235323
DROP USER alice;
53245324
DROP USER bob;
53255325

5326+
subtest bypassrls_pg_roles_pg_authid
5327+
5328+
statement ok
5329+
CREATE ROLE can_bypassrls WITH BYPASSRLS;
5330+
5331+
statement ok
5332+
CREATE ROLE cannot_bypassrls;
5333+
5334+
query B
5335+
SELECT rolbypassrls FROM pg_authid WHERE rolname = 'can_bypassrls';
5336+
----
5337+
true
5338+
5339+
query B
5340+
SELECT rolbypassrls FROM pg_authid WHERE rolname = 'cannot_bypassrls';
5341+
----
5342+
false
5343+
5344+
query B
5345+
SELECT rolbypassrls FROM pg_roles WHERE rolname = 'can_bypassrls';
5346+
----
5347+
true
5348+
5349+
5350+
query B
5351+
SELECT rolbypassrls FROM pg_roles WHERE rolname = 'cannot_bypassrls';
5352+
----
5353+
false
5354+
5355+
5356+
statement ok
5357+
DROP ROLE can_bypassrls;
5358+
5359+
statement ok
5360+
DROP ROLE cannot_bypassrls;
5361+
53265362
subtest end

pkg/sql/pg_catalog.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ https://www.postgresql.org/docs/9.5/catalog-pg-authid.html`,
637637
if err != nil {
638638
return err
639639
}
640+
bypassRLS, err := options.bypassRLS()
641+
if err != nil {
642+
return err
643+
}
640644

641645
isSuper, err := userIsSuper(ctx, p, userName)
642646
if err != nil {
@@ -652,7 +656,7 @@ https://www.postgresql.org/docs/9.5/catalog-pg-authid.html`,
652656
tree.MakeDBool(isRoot || createDB), // rolcreatedb
653657
tree.MakeDBool(roleCanLogin), // rolcanlogin.
654658
tree.DBoolFalse, // rolreplication
655-
tree.DBoolFalse, // rolbypassrls
659+
tree.MakeDBool(bypassRLS), // rolbypassrls
656660
negOneVal, // rolconnlimit
657661
passwdStarString, // rolpassword
658662
rolValidUntil, // rolvaliduntil
@@ -2986,6 +2990,10 @@ https://www.postgresql.org/docs/9.5/view-pg-roles.html`,
29862990
if err != nil {
29872991
return err
29882992
}
2993+
bypassRLS, err := options.bypassRLS()
2994+
if err != nil {
2995+
return err
2996+
}
29892997
isSuper, err := userIsSuper(ctx, p, userName)
29902998
if err != nil {
29912999
return err
@@ -3004,7 +3012,7 @@ https://www.postgresql.org/docs/9.5/view-pg-roles.html`,
30043012
negOneVal, // rolconnlimit
30053013
passwdStarString, // rolpassword
30063014
rolValidUntil, // rolvaliduntil
3007-
tree.DBoolFalse, // rolbypassrls
3015+
tree.MakeDBool(bypassRLS), // rolbypassrls
30083016
settings, // rolconfig
30093017
)
30103018
})

0 commit comments

Comments
 (0)