53{
57 bool relrowsecurity;
58 bool relforcerowsecurity;
59 bool amowner;
60
61 /* Nothing to do for built-in relations */
64
65 /* Fetch relation's relrowsecurity and relforcerowsecurity flags */
70
71 relrowsecurity = classform->relrowsecurity;
72 relforcerowsecurity = classform->relforcerowsecurity;
73
75
76 /* Nothing to do if the relation does not have RLS */
77 if (!relrowsecurity)
79
80 /*
81 * BYPASSRLS users always bypass RLS. Note that superusers are always
82 * considered to have BYPASSRLS.
83 *
84 * Return RLS_NONE_ENV to indicate that this decision depends on the
85 * environment (in this case, the user_id).
86 */
89
90 /*
91 * Table owners generally bypass RLS, except if the table has been set (by
92 * an owner) to FORCE ROW SECURITY, and this is not a referential
93 * integrity check.
94 *
95 * Return RLS_NONE_ENV to indicate that this decision depends on the
96 * environment (in this case, the user_id).
97 */
99 if (amowner)
100 {
101 /*
102 * If FORCE ROW LEVEL SECURITY has been set on the relation then we
103 * should return RLS_ENABLED to indicate that RLS should be applied.
104 * If not, or if we are in an InNoForceRLSOperation context, we return
105 * RLS_NONE_ENV.
106 *
107 * InNoForceRLSOperation indicates that we should not apply RLS even
108 * if the table has FORCE RLS set - IF the current user is the owner.
109 * This is specifically to ensure that referential integrity checks
110 * are able to still run correctly.
111 *
112 * This is intentionally only done after we have checked that the user
113 * is the table owner, which should always be the case for referential
114 * integrity checks.
115 */
118 }
119
120 /*
121 * We should apply RLS. However, the user may turn off the row_security
122 * GUC to get a forced error instead.
123 */
126 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
127 errmsg(
"query would be affected by row-level security policy for table \"%s\"",
129 amowner ?
errhint(
"To disable the policy for the table's owner, use ALTER TABLE NO FORCE ROW LEVEL SECURITY.") : 0));
130
131 /* RLS should be fully enabled for this relation. */
133}
bool has_bypassrls_privilege(Oid roleid)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
#define OidIsValid(objectId)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
char * get_rel_name(Oid relid)
bool InNoForceRLSOperation(void)
FormData_pg_class * Form_pg_class
static Datum ObjectIdGetDatum(Oid X)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define FirstNormalObjectId