-
Notifications
You must be signed in to change notification settings - Fork 92
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
Restrict DROP USER/ROLE from non-dbo user #2859
Restrict DROP USER/ROLE from non-dbo user #2859
Conversation
Signed-off-by: ANJU BHARTI <[email protected]>
Pull Request Test Coverage Report for Build 10453221297Details
💛 - Coveralls |
if (!has_privs_of_role(GetUserId(),get_role_oid(db_owner_name, false))) | ||
ereport(ERROR, | ||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), | ||
errmsg("User does not have permission to perform this action."))); |
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.
Is this aligning with ideal T-SQL behaviour? Error msg is matching?
|
||
/* must be database owner to drop user/role*/ | ||
db_owner_name = get_db_owner_name(get_cur_db_name()); | ||
if (!has_privs_of_role(GetUserId(),get_role_oid(db_owner_name, false))) |
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.
nit: ...(GetUserId(),<WHITESPACE> get_role_oid...
|
||
/* must be database owner to drop user/role*/ | ||
db_owner_name = get_db_owner_name(get_cur_db_name()); | ||
if (!has_privs_of_role(GetUserId(),get_role_oid(db_owner_name, false))) |
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.
Why has_privs_of_role
, not is_member_of_role
?
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.
Because this is what we are checking when creating the role/user.
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.
Overall changes looks good.
ba94f77
to
1734382
Compare
Signed-off-by: ANJU BHARTI <[email protected]>
1734382
to
ec5d2b5
Compare
Signed-off-by: ANJU BHARTI <[email protected]>
63ee771
to
7c1b926
Compare
Signed-off-by: ANJU BHARTI <[email protected]>
7c1b926
to
675f72e
Compare
if ((drop_user && strncmp(logical_role_name, "dbo", rolename_len) == 0) || | ||
(drop_role && strncmp(logical_role_name, "db_owner", rolename_len) == 0)) |
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.
What if this check is run against user name d
or db_o
or db_ow
etc.? We need to have the length comparison before using strncmp().
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.
Please add such testcases.
const char *db_owner_name; | ||
int role_oid; | ||
int rolename_len; | ||
char *logical_role_name = NULL; |
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.
logical_role_name is not needed IMO. Let's use rolespec->rolename only.
Signed-off-by: ANJU BHARTI <[email protected]>
@@ -3285,15 +3285,44 @@ bbf_ProcessUtility(PlannedStmt *pstmt, | |||
{ | |||
RoleSpec *rolspec = lfirst(item); | |||
char *user_name; | |||
char *db_principal; |
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.
We should pfree db_principal
. db_owner_name
is a const char*, it can't be freed.
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.
We should not pfree db_principal as it is pointing to string literal.
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.
it is it pointing to string literal then make it const char * here itself.
const char * db_principal = drop_user ? "user" : "role"
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.
Why do we need separate test files? Let's reuse some existing test files. IIRC we should avoid creating new test files wherever possible.
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.
We don’t have any such testfile for this usecase hence created one for this usecase testing.
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 meant wherever we have tests for restricting create login/user, we can use that file.
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.
please add some tests which involves if exists
, for example, drop user if exists username
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.
LGTM!
|
||
user_name = get_physical_user_name(db_name, rolspec->rolename, false); | ||
db_owner_name = get_db_owner_name(get_cur_db_name()); |
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.
Nit: simply use db_name
instead of get_cur_db_name
|
||
user_name = get_physical_user_name(db_name, rolspec->rolename, false); | ||
db_owner_name = get_db_owner_name(get_cur_db_name()); | ||
role_oid = get_role_oid(user_name, true); |
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.
why missing_ok = true?
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.
For if exist case which is already present in some testfiles
@@ -3285,15 +3285,44 @@ bbf_ProcessUtility(PlannedStmt *pstmt, | |||
{ | |||
RoleSpec *rolspec = lfirst(item); | |||
char *user_name; | |||
char *db_principal; |
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.
it is it pointing to string literal then make it const char * here itself.
const char * db_principal = drop_user ? "user" : "role"
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.
please add some tests which involves if exists
, for example, drop user if exists username
Signed-off-by: Harsh Lunagariya <[email protected]>
|
||
user_name = get_physical_user_name(db_name, rolspec->rolename, false); | ||
db_owner_name = get_db_owner_name(db_name); |
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.
we should check whether user_name is valid T-SQL role or login.
Signed-off-by: Harsh Lunagariya <[email protected]>
|
a66de39
into
babelfish-for-postgresql:BABEL_4_X_DEV
) Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]> Co-authored-by: Harsh Lunagariya <[email protected]> Signed-off-by: Harsh Lunagariya <[email protected]>
) Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]> Co-authored-by: Harsh Lunagariya <[email protected]> Signed-off-by: Harsh Lunagariya <[email protected]>
Earlier, a user was able to drop user/role that belonged to another database. With this commit, a user can only drop the role/user that belongs to the same database with sufficient privileges. Issues Resolved Task: BABEL-5173 Signed-off-by: Shalini Lohia [email protected]
Earlier, a user was able to drop user/role that belonged to another database. With this commit, a user can only drop the role/user that belongs to the same database with sufficient privileges. Issues Resolved Task: BABEL-5173 Signed-off-by: Shalini Lohia [email protected]
) Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]> Co-authored-by: Harsh Lunagariya <[email protected]> Signed-off-by: Harsh Lunagariya <[email protected]>
) Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]> Co-authored-by: Harsh Lunagariya <[email protected]> Signed-off-by: Harsh Lunagariya <[email protected]>
) Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]> Co-authored-by: Harsh Lunagariya <[email protected]> Signed-off-by: Harsh Lunagariya <[email protected]>
) Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]> Co-authored-by: Harsh Lunagariya <[email protected]> Signed-off-by: Harsh Lunagariya <[email protected]>
) (babelfish-for-postgresql#2864) Earlier, a user was able to drop user/role that belonged to another database. With this commit, a user can only drop the role/user that belongs to the same database with sufficient privileges. Issues Resolved Task: BABEL-5173 Signed-off-by: Shalini Lohia [email protected]
) (babelfish-for-postgresql#2864) Earlier, a user was able to drop user/role that belonged to another database. With this commit, a user can only drop the role/user that belongs to the same database with sufficient privileges. Issues Resolved Task: BABEL-5173 Signed-off-by: Shalini Lohia [email protected]
) (babelfish-for-postgresql#2865) Earlier, a user was able to drop user/role that belonged to another database. With this commit, a user can only drop the role/user that belongs to the same database with sufficient privileges. Issues Resolved Task: BABEL-5173 Signed-off-by: Shalini Lohia [email protected]
) (babelfish-for-postgresql#2865) Earlier, a user was able to drop user/role that belonged to another database. With this commit, a user can only drop the role/user that belongs to the same database with sufficient privileges. Issues Resolved Task: BABEL-5173 Signed-off-by: Shalini Lohia [email protected]
Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]>
Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]>
Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not. With this commit, Only dbo and members of db_owner will have the permission to drop user/role. Additionally, this restricts dropping internal database principal such as dbo and db_owner, it restricts dropping non-Babelfish roles from TDS endpoint. Task: BABEL-5173 Authored-by: ANJU BHARTI <[email protected]>
Earlier, a user was able to drop user/role that belonged to another database. With this commit, a user can only drop the role/user that belongs to the same database with sufficient privileges. Issues Resolved Task: BABEL-5173 Signed-off-by: Shalini Lohia [email protected]
) (babelfish-for-postgresql#2864) Earlier, a user was able to drop user/role that belonged to another database. With this commit, a user can only drop the role/user that belongs to the same database with sufficient privileges. Issues Resolved Task: BABEL-5173 Signed-off-by: Shalini Lohia [email protected]
Description
Earlier, any user was able to drop user/role, irrespective of whether that user has required privileges or not.
With this commit, only dbo should have the permission to drop user/role.
Issues Resolved
BABEL-5173
Test Scenarios Covered
Use case based -
Boundary conditions -
Arbitrary inputs -
Negative test cases -
Minor version upgrade tests -
Major version upgrade tests -
Performance tests -
Tooling impact -
Client tests -
Check List
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.