-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support event trigger for Neon users #10624
base: main
Are you sure you want to change the base?
Conversation
7425 tests run: 7072 passed, 0 failed, 353 skipped (full report)Flaky tests (2)Postgres 17
Postgres 16
Code coverage* (full report)
* collected from Rust tests only The comment gets automatically updated with the latest test results
720fe00 at 2025-02-06T20:53:26.459Z :recycle: |
} | ||
|
||
static void | ||
neon_fmgr_hook(FmgrHookEventType event, FmgrInfo *flinfo, Datum *private) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few quick thoughts:
- Placing this code in
control_plane_connector.c
seems a bit off. It follows established pattern though, so may be we need to rename file? - Some comments would be nice. Even supa source had them
- We follow Supa approach here, let's mention that as well and put a link to their PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- control_plane_connector is renamed to neon_ddl_handler
- GUC is renamed to
enable_event_triggers_for_superuser
with default valueoff
- Comments added
- Reference to Supa PR added
- Now even if event triggers are not enabled for superuser, they still can be fired if trigger procedure is owned by superuser. It allows to pass regression tests without explicit setting of this GUC and seems to be correct in general case: it should be safe to call procedure created by superuser with admin permissions.
pgxn/neon/control_plane_connector.c
Outdated
RegisterXactCallback(NeonXactCallback, NULL); | ||
RegisterSubXactCallback(NeonSubXactCallback, NULL); | ||
|
||
DefineCustomBoolVariable( | ||
"neon.disable_event_triggers_for_superuser", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a hard time doing mental negation for variables that has inverted meaning. Wouldn't it be easier with allow_event_triggers_for_superuser
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Hoo boy, this is going to be tough to get right. That's why when event triggers were introduced in the first place, they were made superuser only..
Postgres has an escape hatch for that: you can temporarily set
This trigger will fire when you log in as superuser. It runs as the user who created the function; however, it can still lay some nasty surprises for the session, like change search_path, or create temporary tables that shadow other tables.
|
We should definitely allow user to set |
Nice, thank you @hlinnaka for a prompt review. I've checked how RDS behaves in cases you've described:
Looks like no special protection there:
I've tested that setting
That one is more interesting. I've changed this trigger a bit and watched logs
some observations:
So looks like RDS has changed secdef trigger behavior.
Looks like we should fix that? Let's fix |
I have committed version which prohibit execution of any trigger procedure for superuser including ones created as security definers. As the results user will not be able to declare trigger procedures as security definers. Nit sure if it is significant limitation. It will be nice if it is possible to somehow determine the original user (before changed by security definer function invocation). Do not know how to do it, do you? Alternatively we can allow execution of user trigger procedures defined as security definers. In any case, I will be glad to hear your proposal.
I have added check for trigger return type. But I am not sure that fn_oid is always defined in FmgrInfo.
Fixed |
There are a bunch of functions in miscinit.c: GetSystemUser(), GetAuthenticatedUserId(), GetSessionUserId(), GetOuterUserId(), GetUserId(). I don't remember which is which, but perhaps one of them is what you want :-). |
To be precise, they will now be able to create such triggers, but they will not fire.
I don't really have a proposal. I can poke holes at what's proposed, but I don't have a model in mind on how it should work. Whatever the proposed model is, I'd love to see a short RFC or other doc that explains how it's supposed to work, what the threat model is, what things you can and cannot do with this, compared to having real superuser rights. Perhaps start by writing user documentation for the proposed behaviour, and work from there? |
Thank you! |
Supabase also opted in for temporary switch to superuser ( supabase/supautils#98) while skipping trigger execution. Should be safe imo |
+1, let's do that. Would be nice to discuss too:
|
42130d8
to
3782164
Compare
…tch regression test output
…ql extension test
Problem
#7570
Even triggers are supported only for superusers.
Summary of changes
Temporary switch to superuser when even trigger is created and disable execution of user's even triggers under superuser.