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

Fixes invalid grantor field parsing in grant role propagation #7451

Merged
merged 29 commits into from
Feb 15, 2024

Conversation

gurkanindibay
Copy link
Contributor

@gurkanindibay gurkanindibay commented Jan 24, 2024

DESCRIPTION: Fixes a bug that breaks distributed GRANT statements with grantor option

In this issue 3 issues are being solved:
1.Correcting the erroneous appending of multiple granted by in the deparser.
2Adding support for grantor (granted by) in grant role propagation.
3. Implementing grantor (granted by) support during the metadata sync grant role propagation phase.

Limitations: Currently, the grantor must be created prior to the metadata sync phase. During metadata sync, both the creation of the grantor and the grants given by that role cannot be performed, as the grantor role is not detected during the dependency resolution phase.

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

Merging #7451 (6582b44) into main (c665cb8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7451   +/-   ##
=======================================
  Coverage   89.59%   89.59%           
=======================================
  Files         282      282           
  Lines       60314    60318    +4     
  Branches     7512     7513    +1     
=======================================
+ Hits        54037    54042    +5     
+ Misses       4121     4119    -2     
- Partials     2156     2157    +1     

@onurctirtir
Copy link
Member

Do we still plan to work on this PR @gurkanindibay / @halilozanakgul?

@gurkanindibay
Copy link
Contributor Author

Do we still plan to work on this PR @gurkanindibay / @halilozanakgul?

I have plans to work on it. However, I can not get answer for the errors here. There are some intentional tests here in which non-distributed role is being used. After the fix, tests fail since the non-distributed field is being used as grantor

@gurkanindibay gurkanindibay changed the title Fixes grantor on role metadata sync Fixes grantor field propagation in role propagation Feb 1, 2024
@gurkanindibay gurkanindibay changed the title Fixes grantor field propagation in role propagation Fixes invalid grantor field parsing in grant role propagation Feb 1, 2024
@gurkanindibay gurkanindibay marked this pull request as ready for review February 1, 2024 14:15
@@ -107,7 +107,7 @@ RESET ROLE;

SET citus.enable_create_role_propagation TO ON;

GRANT dist_role_3 TO non_dist_role_3;
GRANT dist_role_3 TO non_dist_role_3 granted by postgres;
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this test? Isn't the current user already postgres? And we are not looking at a propagated query or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to test_admin_role

@@ -486,7 +486,6 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt)
appendStringInfo(buf, "%s ", stmt->is_grant ? " TO " : " FROM ");
AppendRoleList(buf, stmt->grantee_roles);
AppendGrantWithAdminOption(buf, stmt);
AppendGrantedByInGrantForRoleSpec(buf, stmt->grantor, stmt->is_grant);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are multiple AppendGrantedByInGrantForRoleSpec added there which causes error

@@ -240,10 +242,11 @@ SELECT roleid::regrole::text AS role, member::regrole::text, (grantor::regrole::
role | member | grantor | admin_option
---------------------------------------------------------------------
dist_role_1 | dist_role_2 | t | f
dist_role_3 | non_dist_role_3 | t | f
Copy link
Member

Choose a reason for hiding this comment

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

Should we change the query into this so that we can verify whether we set grantor properly?

SELECT roleid::regrole::text AS role, member::regrole::text, grantor::regrole::text, admin_option FROM pg_auth_members WHERE roleid::regrole::text LIKE '%dist\_%' ORDER BY 1, 2;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can not since grantor for pg 14 and pg 15 is different from pg16. I think that's why they put such check

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference?
There is probably some valid reason for this change but it kind of makes the test useless, since the grantor will almost always be postgres in our tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now added test_admin_role into viable grantor list to make grantor t for the list.

@@ -240,10 +242,11 @@ SELECT roleid::regrole::text AS role, member::regrole::text, (grantor::regrole::
role | member | grantor | admin_option
---------------------------------------------------------------------
dist_role_1 | dist_role_2 | t | f
dist_role_3 | non_dist_role_3 | t | f
dist_role_3 | non_dist_role_3 | f | f
Copy link
Member

Choose a reason for hiding this comment

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

Can we also add another test to make sure that we properly set grantor on other nodes too, maybe by using:

SELECT result FROM run_command_on_all_nodes(
  $$
  SELECT json_agg(q.* ORDER BY member) FROM (
    SELECT member::regrole::text, grantor::regrole::text, admin_option
    FROM pg_auth_members WHERE roleid::regrole::text = 'dist_role_3'
  ) q;
  $$
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added run_all_nodes into the query

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the test to see the grantor for the new statement.

Copy link
Member

@onurctirtir onurctirtir left a comment

Choose a reason for hiding this comment

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

LGTM except that one last test

@@ -228,22 +228,41 @@ SET ROLE non_dist_role_1;
GRANT dist_role_1 TO dist_role_2;
RESET ROLE;
SET citus.enable_create_role_propagation TO ON;
GRANT dist_role_3 TO non_dist_role_3;
create role test_admin_role;
grant dist_role_3 to test_admin_role with admin option;
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this into this so that we can actually test whether we propagate grantor. The latter grant stmt doesn't test this because of the none distributed role.

Suggested change
grant dist_role_3 to test_admin_role with admin option;
grant dist_role_3 to test_admin_role granted by ... with admin option;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

suggested change is the same as the current code. Do I miss sth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added test_admin_role just for granted by. I added a distributed role grant on next step. Is it sufficient?

Copy link
Member

Choose a reason for hiding this comment

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

Regarding this GRANT stmt:

GRANT dist_role_3 TO dist_role_4 granted by test_admin_role;

We get different outputs on different nodes:

"member":"dist_role_4","role":"dist_role_3","grantor":"test_admin_role","admin_option":false}
...
"member":"dist_role_4","role":"dist_role_3","grantor":"postgres","admin_option":false}
...
"member":"dist_role_4","role":"dist_role_3","grantor":"postgres","admin_option":false}

So I got confused a bit, is this really expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bug related to metadata_sync wrong grantor issue. I will fix it in another PR as we have talked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right . grantor was being set to NULL. Fixed it.

@onurctirtir
Copy link
Member

DESCRIPTION: grantor field defined multiple times in role parsing which causes parsing error when using DeparseTreeNode This PR fixes granted by statement parsing for grant role propagation

Description format seems incorrect, could you improve this based on our usual format?

@onurctirtir
Copy link
Member

DESCRIPTION: This PR fixes granted by statement parsing for grant role propagation

Can we follow our usual description format, as in:

DESCRIPTION: Fixes a bug that breaks distributed GRANT statements with grantor option

Comment on lines -1244 to -1248
/*
* Postgres don't seem to use the grantor. Even dropping the grantor doesn't
* seem to affect the membership. If this changes, we might need to add grantors
* to the dependency resolution too. For now we just don't propagate it.
*/
Copy link
Member

Choose a reason for hiding this comment

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

LGTM now except what this comment states ..

As I mentioned earlier, could you please talk to @halilozanakgul to decide:
a) How hard it is to accomplish what this comment states, or,
b) If we're taking the risk of " role does not exist" errors coming from workers when the grantor is not a distributed role given that we expect such conditions to be rare.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

nvm this, but let's fix metadata syncing issue in this PR too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the grantor propagation other than missing grantor before metadata sync phase. In dependency resolution phase, if grantor has admin rolesi then it can not be propagated. I think it is not a must for our tasks. I can open an issue and continue working on that task with suitable priority

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@onurctirtir we discussed the issue in the meeting on 02/12/2024. Now grantor is not being taken from dependency resolution when it has an admin option on it.
I need to investigate further. Right now, since we have blocked issues. We decided to keep this issue as it is and after unblock all issues.
In parallel, I will start investigating the issue with the issue #7488
Thanks.

@onurctirtir onurctirtir linked an issue Feb 8, 2024 that may be closed by this pull request
src/backend/distributed/commands/role.c Outdated Show resolved Hide resolved
Co-authored-by: Onur Tirtir <onurcantirtir@gmail.com>
@gurkanindibay gurkanindibay enabled auto-merge (squash) February 15, 2024 07:49
@gurkanindibay gurkanindibay merged commit 59da063 into main Feb 15, 2024
157 checks passed
@gurkanindibay gurkanindibay deleted the missing_grantor_sync branch February 15, 2024 08:27
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.

Grantor propagation support
3 participants