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

Make it possible to grant self created roles #298

Merged
merged 1 commit into from
Jul 27, 2023

Conversation

knizhnik
Copy link

@knizhnik knizhnik requested review from hlinnaka and MMeent July 24, 2023 15:02

AddRoleMems(stmt->role, roleid,
memberSpecs, memberIds,
BOOTSTRAP_SUPERUSERID, true);
Copy link

Choose a reason for hiding this comment

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

BOOTSTRAP_SUPERUSERID

Is that correct?

Copy link
Author

Choose a reason for hiding this comment

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

It is taken from PG 16:

	/*
	 * If the current user isn't a superuser, make them an admin of the new
	 * role so that they can administer the new object they just created.
	 * Superusers will be able to do that anyway.
	 *
	 * The grantor of record for this implicit grant is the bootstrap
	 * superuser, which means that the CREATEROLE user cannot revoke the
	 * grant. They can however grant the created role back to themselves with
	 * different options, since they enjoy ADMIN OPTION on it.
	 */
	if (!superuser())
	{
...
		AddRoleMems(BOOTSTRAP_SUPERUSERID, stmt->role, roleid,
					memberSpecs, memberIds,
					BOOTSTRAP_SUPERUSERID, &poptself);

PG 16 also also granting roles to themselves:

		/*
		 * Because of the implicit grant above, a CREATEROLE user who creates
		 * a role has the ability to grant that role back to themselves with
		 * the INHERIT or SET options, if they wish to inherit the role's
		 * privileges or be able to SET ROLE to it. The createrole_self_grant
		 * GUC can be used to make this happen automatically. This has no
		 * security implications since the same user is able to make the same
		 * grant using an explicit GRANT statement; it's just convenient.
		 */
		if (createrole_self_grant_enabled)
			AddRoleMems(currentUserId, stmt->role, roleid,
						memberSpecs, memberIds,
						currentUserId, &createrole_self_grant_options);

but I have not posted this fragment. - it requires adding createrole_self_grant_enabled GUC and more related changes.

* grant. They can however grant the created role back to themselves with
* different options, since they enjoy ADMIN OPTION on it.
*/
if (!superuser())
Copy link

Choose a reason for hiding this comment

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

Why not for roles which are superuser?

Copy link
Author

Choose a reason for hiding this comment

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

Superuser in any case has admin permission so no need to make this trick.

@knizhnik knizhnik merged commit ca3c90f into REL_15_STABLE_neon Jul 27, 2023
@knizhnik knizhnik deleted the grant_role_fix_v15 branch July 27, 2023 06:51
tristan957 pushed a commit that referenced this pull request Aug 10, 2023
tristan957 pushed a commit that referenced this pull request Nov 8, 2023
tristan957 pushed a commit that referenced this pull request Nov 8, 2023
tristan957 pushed a commit that referenced this pull request Nov 8, 2023
tristan957 pushed a commit that referenced this pull request Feb 5, 2024
tristan957 pushed a commit that referenced this pull request Feb 5, 2024
tristan957 pushed a commit that referenced this pull request Feb 6, 2024
tristan957 pushed a commit that referenced this pull request May 10, 2024
tristan957 pushed a commit that referenced this pull request May 20, 2024
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.

3 participants