added log statement for source of check hook

This commit is contained in:
Suhas Thalanki
2025-05-28 12:15:03 -04:00
parent 315c80a08d
commit e14854d6fb

View File

@@ -1,8 +1,8 @@
diff --git a/sql/anon.sql b/sql/anon.sql
index 0cdc769..f6cc950 100644
index 0cdc769..85a58a6 100644
--- a/sql/anon.sql
+++ b/sql/anon.sql
@@ -1141,3 +1141,8 @@ $$
@@ -1141,3 +1141,9 @@ $$
-- TODO : https://en.wikipedia.org/wiki/L-diversity
-- TODO : https://en.wikipedia.org/wiki/T-closeness
@@ -11,6 +11,7 @@ index 0cdc769..f6cc950 100644
+
+GRANT ALL ON SCHEMA anon to neon_superuser;
+GRANT ALL ON ALL TABLES IN SCHEMA anon TO neon_superuser;
+-- GRANT SET ON PARAMETER anon.transparent_dynamic_masking TO neon_superuser;
diff --git a/sql/init.sql b/sql/init.sql
index 7da6553..7961984 100644
--- a/sql/init.sql
@@ -151,7 +152,7 @@ index 7da6553..7961984 100644
+
+SECURITY LABEL FOR anon ON FUNCTION anon.toggle_transparent_dynamic_masking IS 'UNTRUSTED';
diff --git a/src/guc.rs b/src/guc.rs
index 74d3822..848c902 100644
index 74d3822..696a505 100644
--- a/src/guc.rs
+++ b/src/guc.rs
@@ -3,7 +3,7 @@
@@ -163,7 +164,7 @@ index 74d3822..848c902 100644
pub static ANON_DUMMY_LOCALE: GucSetting<Option<&'static CStr>> =
GucSetting::<Option<&'static CStr>>::new(Some(unsafe {
@@ -51,6 +51,43 @@ static ANON_MASK_SCHEMA: GucSetting<Option<&'static CStr>> =
@@ -51,6 +51,45 @@ static ANON_MASK_SCHEMA: GucSetting<Option<&'static CStr>> =
CStr::from_bytes_with_nul_unchecked(b"mask\0")
}));
@@ -171,12 +172,13 @@ index 74d3822..848c902 100644
+unsafe extern "C-unwind" fn check_bool_guc_hook(
+ _newval: *mut bool,
+ _extra: *mut *mut c_void,
+ _source: u32
+ source: u32
+) -> bool {
+ unsafe {
+ let oid = pg_sys::GetUserId();
+ let user_name = CStr::from_ptr(pg_sys::GetUserNameFromId(oid, true));
+ let user_str = user_name.to_str().unwrap();
+ pg_sys::info!("Source: {}", source);
+ pg_sys::info!("user: {} trying to change boolean guc", user_str);
+ if pg_sys::superuser() || user_str == "neon_superuser" || user_str == "neondb_owner" {
+ return true;
@@ -189,12 +191,13 @@ index 74d3822..848c902 100644
+unsafe extern "C-unwind" fn check_string_guc_hook(
+_newval: *mut *mut libc::c_char,
+_extra: *mut *mut c_void,
+_source: u32
+source: u32
+) -> bool {
+ unsafe {
+ let oid = pg_sys::GetUserId();
+ let user_name = CStr::from_ptr(pg_sys::GetUserNameFromId(oid, true));
+ let user_str = user_name.to_str().unwrap();
+ pg_sys::info!("Source: {}", source);
+ pg_sys::info!("user: {} trying to change string guc", user_str);
+ if pg_sys::superuser() || user_str == "neon_superuser" || user_str == "neondb_owner" {
+ return true;
@@ -207,7 +210,7 @@ index 74d3822..848c902 100644
// Register the GUC parameters for the extension
//
pub fn register_gucs() {
@@ -61,6 +98,9 @@ pub fn register_gucs() {
@@ -61,6 +100,9 @@ pub fn register_gucs() {
&ANON_DUMMY_LOCALE,
GucContext::Suset,
GucFlags::SUPERUSER_ONLY,
@@ -217,7 +220,7 @@ index 74d3822..848c902 100644
);
GucRegistry::define_string_guc(
@@ -70,6 +110,9 @@ pub fn register_gucs() {
@@ -70,6 +112,9 @@ pub fn register_gucs() {
&ANON_K_ANONYMITY_PROVIDER,
GucContext::Suset,
GucFlags::SUPERUSER_ONLY,
@@ -227,7 +230,7 @@ index 74d3822..848c902 100644
);
//
@@ -87,6 +130,9 @@ pub fn register_gucs() {
@@ -87,6 +132,9 @@ pub fn register_gucs() {
&ANON_MASKING_POLICIES,
GucContext::Suset,
GucFlags::SUPERUSER_ONLY, /* | GucFlags::LIST_INPUT */
@@ -237,7 +240,7 @@ index 74d3822..848c902 100644
);
GucRegistry::define_bool_guc(
@@ -94,16 +140,22 @@ pub fn register_gucs() {
@@ -94,16 +142,22 @@ pub fn register_gucs() {
"Mask all columns with NULL (or the default value for NOT NULL columns)",
"",
&ANON_PRIVACY_BY_DEFAULT,
@@ -262,7 +265,7 @@ index 74d3822..848c902 100644
);
GucRegistry::define_bool_guc(
@@ -113,6 +165,9 @@ pub fn register_gucs() {
@@ -113,6 +167,9 @@ pub fn register_gucs() {
&ANON_RESTRICT_TO_TRUSTED_SCHEMAS,
GucContext::Suset,
GucFlags::SUPERUSER_ONLY,
@@ -272,7 +275,7 @@ index 74d3822..848c902 100644
);
GucRegistry::define_bool_guc(
@@ -120,8 +175,11 @@ pub fn register_gucs() {
@@ -120,8 +177,11 @@ pub fn register_gucs() {
"A masking rule cannot change a column data type, unless you disable this",
"Disabling the mode is not recommended",
&ANON_STRICT_MODE,
@@ -285,7 +288,7 @@ index 74d3822..848c902 100644
);
// The GUC vars below are not used in the Rust code
@@ -134,6 +192,9 @@ pub fn register_gucs() {
@@ -134,6 +194,9 @@ pub fn register_gucs() {
&ANON_ALGORITHM,
GucContext::Suset,
GucFlags::SUPERUSER_ONLY,
@@ -295,7 +298,7 @@ index 74d3822..848c902 100644
);
GucRegistry::define_string_guc(
@@ -141,8 +202,11 @@ pub fn register_gucs() {
@@ -141,8 +204,11 @@ pub fn register_gucs() {
"The schema where the dynamic masking views are stored",
"",
&ANON_MASK_SCHEMA,
@@ -308,7 +311,7 @@ index 74d3822..848c902 100644
);
GucRegistry::define_string_guc(
@@ -152,6 +216,9 @@ pub fn register_gucs() {
@@ -152,6 +218,9 @@ pub fn register_gucs() {
&ANON_SALT,
GucContext::Suset,
GucFlags::SUPERUSER_ONLY,
@@ -318,7 +321,7 @@ index 74d3822..848c902 100644
);
GucRegistry::define_string_guc(
@@ -159,7 +226,10 @@ pub fn register_gucs() {
@@ -159,7 +228,10 @@ pub fn register_gucs() {
"The schema where the table are masked by the dynamic masking engine",
"",
&ANON_SOURCE_SCHEMA,