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

SQL: Add support for SET ROLE statement #19165

Open
Tracked by #19161
jkosh44 opened this issue May 8, 2023 · 4 comments
Open
Tracked by #19161

SQL: Add support for SET ROLE statement #19165

jkosh44 opened this issue May 8, 2023 · 4 comments
Labels
A-sql Area: SQL planning C-feature Category: new feature or request

Comments

@jkosh44
Copy link
Contributor

jkosh44 commented May 8, 2023

Feature request

SET ROLE allows a user to change the active role of their current session.

See: https://www.postgresql.org/docs/15/sql-set-role.html

@jkosh44 jkosh44 added C-feature Category: new feature or request A-sql Area: SQL planning labels May 8, 2023
@jkosh44 jkosh44 self-assigned this May 8, 2023
jkosh44 added a commit to jkosh44/materialize that referenced this issue May 30, 2023
This commit updates the Session struct to separately track the current
user and the session user. Additionally, it updates the corresponding
session information functions to query the right role.

This will be useful later when we implement `SET ROLE`.

Works towards resolving MaterializeInc#19165
jkosh44 added a commit to jkosh44/materialize that referenced this issue May 30, 2023
This commit updates the Session struct to separately track the current
user and the session user. Additionally, it updates the corresponding
session information functions to query the right role.

This will be useful later when we implement `SET ROLE`.

Works towards resolving MaterializeInc#19165
jkosh44 added a commit to jkosh44/materialize that referenced this issue May 30, 2023
This commit updates the Session struct to separately track the current
user and the session user. Additionally, it updates the corresponding
session information functions to query the right role.

This will be useful later when we implement `SET ROLE`.

Works towards resolving MaterializeInc#19165
jkosh44 added a commit that referenced this issue Jun 5, 2023
This commit updates the Session struct to separately track the current
user and the session user. Additionally, it updates the corresponding
session information functions to query the right role.

This will be useful later when we implement `SET ROLE`.

Works towards resolving #19165
@jkosh44
Copy link
Contributor Author

jkosh44 commented Jun 5, 2023

Version 16 will have a couple of changes to role membership:

jkosh44 added a commit to jkosh44/materialize that referenced this issue Jul 5, 2023
Previously, the default values for session and system variables had to
be known statically at compile time. This doesn't work for variables
that have no static default, such as `role`. This commit updates the
variable framework so that default values can either be specified
statically at compile time or dynamically at run time. This will allow
us to add variables like `role` and `session authorization` in future
commits.

Works towards resolving MaterializeInc#19165
@jkosh44 jkosh44 removed their assignment Jul 12, 2023
@jkosh44
Copy link
Contributor Author

jkosh44 commented Jul 20, 2023

For a good overview on the role hierarchy in PostgreSQL take a look here: https://github.com/postgres/postgres/blob/9089287aa037fdecb5a52cec1926e5ae9569e9f9/src/backend/utils/init/miscinit.c#L461-L493

@jkosh44
Copy link
Contributor Author

jkosh44 commented Jul 20, 2023

I started updating the session variable framework to support a role session variable here: #20353

I never merged it, but it might be a good starting place.

@jkosh44
Copy link
Contributor Author

jkosh44 commented Oct 4, 2023

The SHOW ROLE semantics are a not what you may expect in PostgreSQL. SHOW ROLE shows the current role if it has been altered by SET ROLE, otherwise it shows none.

postgres=# SELECT current_role;
 current_role 
--------------
 postgres
(1 row)

postgres=# SHOW ROLE;
 role 
------
 none
(1 row)

postgres=# SET ROLE r1;
SET
postgres=> SELECT current_role;
 current_role 
--------------
 r1
(1 row)

postgres=> SHOW ROLE;
 role 
------
 r1
(1 row)

postgres=> RESET ROLE;
RESET
postgres=# SELECT current_role;
 current_role 
--------------
 postgres
(1 row)

postgres=# SHOW ROLE;
 role 
------
 none
(1 row)

This may suggest that the role GUC starts off as NULL in PostgreSQL. To model that we could make the role session variable of type Option<RoleId> with a default value of None. The current role can be derived as current_role.unwrap_or_else(|| session_role).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql Area: SQL planning C-feature Category: new feature or request
Projects
None yet
Development

No branches or pull requests

1 participant