mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-16 11:26:59 +08:00
ALTER TABLE .. FORCE ROW LEVEL SECURITY
To allow users to force RLS to always be applied, even for table owners, add ALTER TABLE .. FORCE ROW LEVEL SECURITY. row_security=off overrides FORCE ROW LEVEL SECURITY, to ensure pg_dump output is complete (by default). Also add SECURITY_NOFORCE_RLS context to avoid data corruption when ALTER TABLE .. FORCE ROW SECURITY is being used. The SECURITY_NOFORCE_RLS security context is used only during referential integrity checks and is only considered in check_enable_rls() after we have already checked that the current user is the owner of the relation (which should always be the case during referential integrity checks). Back-patch to 9.5 where RLS was added.
This commit is contained in:
@ -53,6 +53,6 @@
|
||||
*/
|
||||
|
||||
/* yyyymmddN */
|
||||
#define CATALOG_VERSION_NO 201508061
|
||||
#define CATALOG_VERSION_NO 201510041
|
||||
|
||||
#endif
|
||||
|
||||
@ -66,6 +66,7 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO
|
||||
bool relhastriggers; /* has (or has had) any TRIGGERs */
|
||||
bool relhassubclass; /* has (or has had) derived classes */
|
||||
bool relrowsecurity; /* row security is enabled or not */
|
||||
bool relforcerowsecurity; /* row security forced for owners or not */
|
||||
bool relispopulated; /* matview currently holds query results */
|
||||
char relreplident; /* see REPLICA_IDENTITY_xxx constants */
|
||||
TransactionId relfrozenxid; /* all Xids < this are frozen in this rel */
|
||||
@ -95,37 +96,38 @@ typedef FormData_pg_class *Form_pg_class;
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
#define Natts_pg_class 30
|
||||
#define Anum_pg_class_relname 1
|
||||
#define Anum_pg_class_relnamespace 2
|
||||
#define Anum_pg_class_reltype 3
|
||||
#define Anum_pg_class_reloftype 4
|
||||
#define Anum_pg_class_relowner 5
|
||||
#define Anum_pg_class_relam 6
|
||||
#define Anum_pg_class_relfilenode 7
|
||||
#define Anum_pg_class_reltablespace 8
|
||||
#define Anum_pg_class_relpages 9
|
||||
#define Anum_pg_class_reltuples 10
|
||||
#define Anum_pg_class_relallvisible 11
|
||||
#define Anum_pg_class_reltoastrelid 12
|
||||
#define Anum_pg_class_relhasindex 13
|
||||
#define Anum_pg_class_relisshared 14
|
||||
#define Anum_pg_class_relpersistence 15
|
||||
#define Anum_pg_class_relkind 16
|
||||
#define Anum_pg_class_relnatts 17
|
||||
#define Anum_pg_class_relchecks 18
|
||||
#define Anum_pg_class_relhasoids 19
|
||||
#define Anum_pg_class_relhaspkey 20
|
||||
#define Anum_pg_class_relhasrules 21
|
||||
#define Anum_pg_class_relhastriggers 22
|
||||
#define Anum_pg_class_relhassubclass 23
|
||||
#define Anum_pg_class_relrowsecurity 24
|
||||
#define Anum_pg_class_relispopulated 25
|
||||
#define Anum_pg_class_relreplident 26
|
||||
#define Anum_pg_class_relfrozenxid 27
|
||||
#define Anum_pg_class_relminmxid 28
|
||||
#define Anum_pg_class_relacl 29
|
||||
#define Anum_pg_class_reloptions 30
|
||||
#define Natts_pg_class 31
|
||||
#define Anum_pg_class_relname 1
|
||||
#define Anum_pg_class_relnamespace 2
|
||||
#define Anum_pg_class_reltype 3
|
||||
#define Anum_pg_class_reloftype 4
|
||||
#define Anum_pg_class_relowner 5
|
||||
#define Anum_pg_class_relam 6
|
||||
#define Anum_pg_class_relfilenode 7
|
||||
#define Anum_pg_class_reltablespace 8
|
||||
#define Anum_pg_class_relpages 9
|
||||
#define Anum_pg_class_reltuples 10
|
||||
#define Anum_pg_class_relallvisible 11
|
||||
#define Anum_pg_class_reltoastrelid 12
|
||||
#define Anum_pg_class_relhasindex 13
|
||||
#define Anum_pg_class_relisshared 14
|
||||
#define Anum_pg_class_relpersistence 15
|
||||
#define Anum_pg_class_relkind 16
|
||||
#define Anum_pg_class_relnatts 17
|
||||
#define Anum_pg_class_relchecks 18
|
||||
#define Anum_pg_class_relhasoids 19
|
||||
#define Anum_pg_class_relhaspkey 20
|
||||
#define Anum_pg_class_relhasrules 21
|
||||
#define Anum_pg_class_relhastriggers 22
|
||||
#define Anum_pg_class_relhassubclass 23
|
||||
#define Anum_pg_class_relrowsecurity 24
|
||||
#define Anum_pg_class_relforcerowsecurity 25
|
||||
#define Anum_pg_class_relispopulated 26
|
||||
#define Anum_pg_class_relreplident 27
|
||||
#define Anum_pg_class_relfrozenxid 28
|
||||
#define Anum_pg_class_relminmxid 29
|
||||
#define Anum_pg_class_relacl 30
|
||||
#define Anum_pg_class_reloptions 31
|
||||
|
||||
/* ----------------
|
||||
* initial contents of pg_class
|
||||
@ -140,13 +142,13 @@ typedef FormData_pg_class *Form_pg_class;
|
||||
* Note: "3" in the relfrozenxid column stands for FirstNormalTransactionId;
|
||||
* similarly, "1" in relminmxid stands for FirstMultiXactId
|
||||
*/
|
||||
DATA(insert OID = 1247 ( pg_type PGNSP 71 0 PGUID 0 0 0 0 0 0 0 f f p r 30 0 t f f f f f t n 3 1 _null_ _null_ ));
|
||||
DATA(insert OID = 1247 ( pg_type PGNSP 71 0 PGUID 0 0 0 0 0 0 0 f f p r 30 0 t f f f f f f t n 3 1 _null_ _null_ ));
|
||||
DESCR("");
|
||||
DATA(insert OID = 1249 ( pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 f f p r 21 0 f f f f f f t n 3 1 _null_ _null_ ));
|
||||
DATA(insert OID = 1249 ( pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 f f p r 21 0 f f f f f f f t n 3 1 _null_ _null_ ));
|
||||
DESCR("");
|
||||
DATA(insert OID = 1255 ( pg_proc PGNSP 81 0 PGUID 0 0 0 0 0 0 0 f f p r 28 0 t f f f f f t n 3 1 _null_ _null_ ));
|
||||
DATA(insert OID = 1255 ( pg_proc PGNSP 81 0 PGUID 0 0 0 0 0 0 0 f f p r 28 0 t f f f f f f t n 3 1 _null_ _null_ ));
|
||||
DESCR("");
|
||||
DATA(insert OID = 1259 ( pg_class PGNSP 83 0 PGUID 0 0 0 0 0 0 0 f f p r 30 0 t f f f f f t n 3 1 _null_ _null_ ));
|
||||
DATA(insert OID = 1259 ( pg_class PGNSP 83 0 PGUID 0 0 0 0 0 0 0 f f p r 31 0 t f f f f f f t n 3 1 _null_ _null_ ));
|
||||
DESCR("");
|
||||
|
||||
|
||||
|
||||
@ -287,6 +287,7 @@ extern int trace_recovery(int trace_level);
|
||||
/* flags to be OR'd to form sec_context */
|
||||
#define SECURITY_LOCAL_USERID_CHANGE 0x0001
|
||||
#define SECURITY_RESTRICTED_OPERATION 0x0002
|
||||
#define SECURITY_NOFORCE_RLS 0x0004
|
||||
|
||||
extern char *DatabasePath;
|
||||
|
||||
@ -305,6 +306,7 @@ extern void GetUserIdAndSecContext(Oid *userid, int *sec_context);
|
||||
extern void SetUserIdAndSecContext(Oid userid, int sec_context);
|
||||
extern bool InLocalUserIdChange(void);
|
||||
extern bool InSecurityRestrictedOperation(void);
|
||||
extern bool InNoForceRLSOperation(void);
|
||||
extern void GetUserIdAndContext(Oid *userid, bool *sec_def_context);
|
||||
extern void SetUserIdAndContext(Oid userid, bool sec_def_context);
|
||||
extern void InitializeSessionUserId(const char *rolename, Oid useroid);
|
||||
|
||||
@ -1514,6 +1514,8 @@ typedef enum AlterTableType
|
||||
AT_ReplicaIdentity, /* REPLICA IDENTITY */
|
||||
AT_EnableRowSecurity, /* ENABLE ROW SECURITY */
|
||||
AT_DisableRowSecurity, /* DISABLE ROW SECURITY */
|
||||
AT_ForceRowSecurity, /* FORCE ROW SECURITY */
|
||||
AT_NoForceRowSecurity, /* NO FORCE ROW SECURITY */
|
||||
AT_GenericOptions /* OPTIONS (...) */
|
||||
} AlterTableType;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user