Skip to content
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

fix: allow members of source table to create vectorizer #254

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

JamesGuthrie
Copy link
Member

@JamesGuthrie JamesGuthrie commented Nov 26, 2024

In f68e73a we added support for cascading the source/target table drop to the queue and other dependent objects. In adding this, we added a security definer function which asserts that the owner of the source table is calling the security definer function.

Due to how security definer functions work with current_user, the ownership check opted to use session_user to check ownership. This is problematic because in connections which use SET ROLE, the session_user may not be the same as current_user.

This commit relaxes the ownership check to check whether the current
user is a member of the role that owns the source table.

@JamesGuthrie JamesGuthrie requested a review from a team as a code owner November 26, 2024 10:19
@JamesGuthrie JamesGuthrie force-pushed the jg/fix-non-owner-create-vectorizer branch from b9d68d3 to b8ead49 Compare November 26, 2024 10:22
-- don't let anyone but the owner of the source table call this
select k.relowner operator(pg_catalog.=) pg_catalog.session_user()::pg_catalog.regrole
-- don't let anyone but the owner (or members of the owner's role) of the source table call this
select pg_catalog.pg_has_role(_vectorizer_create_dependencies.caller, k.relowner, 'MEMBER')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird attribute qualification (_vectorizer_create_dependencies.caller instead of just caller), why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

drop function if exists ai._vectorizer_create_dependencies(integer);

-- https://stackoverflow.com/a/42011279
create domain whoami as name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we want to schema qualify it as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, done

Copy link
Member

@alexeyklyukin alexeyklyukin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good (a few nits)

@JamesGuthrie JamesGuthrie force-pushed the jg/fix-non-owner-create-vectorizer branch 2 times, most recently from 1b1c839 to bdc11b5 Compare November 26, 2024 14:37
@JamesGuthrie JamesGuthrie force-pushed the jg/fix-non-owner-create-vectorizer branch from bdc11b5 to 12082d3 Compare November 26, 2024 15:42
@@ -0,0 +1 @@
drop function if exists ai._vectorizer_create_dependencies(integer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait why do we need this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doh - we don't. It was a stray leftover from before I removed some other bits.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

In f68e73a we added support for cascading the source/target table drop
to the queue and other dependent objects. In adding this, we added a
security definer function which asserts that the owner of the source
table is calling the security definer function.

Due to how security definer functions work with `current_user`, the
ownership check opted to use `session_user` to check ownership. This is
problematic because in connections which use `SET ROLE`, the
`session_user` may not be the same as `current_user`.

This commit relaxes the ownership check to check whether the current
user is a member of the role that owns the source table.
@JamesGuthrie JamesGuthrie force-pushed the jg/fix-non-owner-create-vectorizer branch from 12082d3 to a0fa061 Compare November 26, 2024 15:47
@JamesGuthrie JamesGuthrie merged commit 3953779 into main Nov 26, 2024
5 checks passed
@JamesGuthrie JamesGuthrie deleted the jg/fix-non-owner-create-vectorizer branch November 26, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants