You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ranger.apache.org by Pradeep Agrawal <pr...@gmail.com> on 2022/06/24 10:12:36 UTC

Review Request 74039: RANGER-3806: Group's users mapping entry failing whenever primary key auto-increment is not set to 1 in db

-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74039/
-----------------------------------------------------------

Review request for ranger, bhavik patel, Dhaval Shah, Abhay Kulkarni, Madhan Neethiraj, Mehul Parikh, Ramesh Mani, Sailaja Polavarapu, and Velmurugan Periasamy.


Bugs: RANGER-3806
    https://issues.apache.org/jira/browse/RANGER-3806


Repository: ranger


Description
-------

**Problem Statement:** 
Ranger db table `x_group_users` has columns "added_by_id" and "upd_by_id" which should be filled with the id of logged-in user. Whenever group's-users mapping is pushed from usersync module at that time these values are considered from a config "ranger.xuser.createdByUserId" which is set to 1 in ranger-default-admin-site.xml and code as well.
If users have set ranger db table's primary key's auto-increment offset to any number other than 1 and have not updated the same accordingly in the config "ranger.xuser.createdByUserId" then request may fail due to Foreignkey constraint violation.

Example Case: if primary key's auto-increment start value has been set to 2 in db engine then first entry in table x_portal_user will have primary-key id 2. while if config  "ranger.xuser.createdByUserId" is set to 1 then due to non availablity of userID 1 when it will try to insert group-user mappinng entry in `x_group_users` table with value 1 for the column "added_by_id" and "upd_by_id" it will cause to fail the request.

**Proposed solution:** Rather directly putting the config's "ranger.xuser.createdByUserId" value in "added_by_id" and "upd_by_id" field of `x_group_users` table we can check whether user id exist in x_portal_user or not. if it does not exist then do not set the value received from config "ranger.xuser.createdByUserId" and avoid the Foreign-key Constraint Violation Exception.


Diffs
-----

  security-admin/src/main/java/org/apache/ranger/service/XGroupUserService.java 9345e8180 


Diff: https://reviews.apache.org/r/74039/diff/1/


Testing
-------

With the patch issue is not reproducing when i have set the auto_increment_increment to 3 in mysql server env.


Thanks,

Pradeep Agrawal


Re: Review Request 74039: RANGER-3806: Group's users mapping entry failing whenever primary key auto-increment is not set to 1 in db

Posted by Sailaja Polavarapu <sp...@hortonworks.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74039/#review224536
-----------------------------------------------------------


Ship it!




Ship It!

- Sailaja Polavarapu


On June 24, 2022, 10:12 a.m., Pradeep Agrawal wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/74039/
> -----------------------------------------------------------
> 
> (Updated June 24, 2022, 10:12 a.m.)
> 
> 
> Review request for ranger, bhavik patel, Dhaval Shah, Abhay Kulkarni, Madhan Neethiraj, Mehul Parikh, Ramesh Mani, Sailaja Polavarapu, and Velmurugan Periasamy.
> 
> 
> Bugs: RANGER-3806
>     https://issues.apache.org/jira/browse/RANGER-3806
> 
> 
> Repository: ranger
> 
> 
> Description
> -------
> 
> **Problem Statement:** 
> Ranger db table `x_group_users` has columns "added_by_id" and "upd_by_id" which should be filled with the id of logged-in user. Whenever group's-users mapping is pushed from usersync module at that time these values are considered from a config "ranger.xuser.createdByUserId" which is set to 1 in ranger-default-admin-site.xml and code as well.
> If users have set ranger db table's primary key's auto-increment offset to any number other than 1 and have not updated the same accordingly in the config "ranger.xuser.createdByUserId" then request may fail due to Foreignkey constraint violation.
> 
> Example Case: if primary key's auto-increment start value has been set to 2 in db engine then first entry in table x_portal_user will have primary-key id 2. while if config  "ranger.xuser.createdByUserId" is set to 1 then due to non availablity of userID 1 when it will try to insert group-user mappinng entry in `x_group_users` table with value 1 for the column "added_by_id" and "upd_by_id" it will cause to fail the request.
> 
> **Proposed solution:** Rather directly putting the config's "ranger.xuser.createdByUserId" value in "added_by_id" and "upd_by_id" field of `x_group_users` table we can check whether user id exist in x_portal_user or not. if it does not exist then do not set the value received from config "ranger.xuser.createdByUserId" and avoid the Foreign-key Constraint Violation Exception.
> 
> 
> Diffs
> -----
> 
>   security-admin/src/main/java/org/apache/ranger/service/XGroupUserService.java 9345e8180 
> 
> 
> Diff: https://reviews.apache.org/r/74039/diff/1/
> 
> 
> Testing
> -------
> 
> With the patch issue is not reproducing when i have set the auto_increment_increment to 3 in mysql server env.
> 
> 
> Thanks,
> 
> Pradeep Agrawal
> 
>