Skip to content

Commit d06babd

Browse files
committed
[BACKPORT-2025.1.3][PLAT-19739]Skip updating roleBindings if old user is being used
Summary: **Issue** After enabling RBAC, YBA does not persist role changes that it overrides for LDAP users when the role lookup fails. Refer - https://docs.yugabyte.com/stable/yugabyte-platform/administer-yugabyte-platform/ldap-authentication/#role-assignment **Fix** The fix skips the roleBinding reset in the unique case where the user’s role is not determined in the current session. Test Plan: - Configure LDAP auth -> Login with a user with no role -> (YBA defaults to readOnly) -> Login as superAdmin -> modify the role -> login again as ldap user -> role change is being persisted Reviewers: skurapati Reviewed By: skurapati Subscribers: yugaware, skurapati Differential Revision: https://phorge.dev.yugabyte.com/D50577
1 parent 0606ec0 commit d06babd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

managed/src/main/java/com/yugabyte/yw/common/LdapUtil.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ public Users authViaLDAP(String email, String password, LdapConfiguration ldapCo
629629
}
630630

631631
Users oldUser = Users.find.query().where().eq("email", email).findOne();
632+
boolean shouldUpdateRoleBindings = true;
632633

633634
if (oldUser != null) {
634635
/* If we find a valid role from LDAP then assign that to this user and disallow further
@@ -651,6 +652,10 @@ public Users authViaLDAP(String email, String password, LdapConfiguration ldapCo
651652
log.warn("No valid role could be ascertained, defaulting to {}.", roleToAssign);
652653
oldUser.setRole(roleToAssign);
653654
oldUser.setLdapSpecifiedRole(false);
655+
} else {
656+
// Preserve the existing admin-set role, no need to update role bindings
657+
log.debug("Using existing role: {}", oldUser.getRole().name());
658+
shouldUpdateRoleBindings = false;
654659
}
655660
users = oldUser;
656661
} else {
@@ -674,14 +679,15 @@ public Users authViaLDAP(String email, String password, LdapConfiguration ldapCo
674679
users.setGroupMemberships(groupMemberships);
675680
users.save();
676681

677-
if (ldapConfiguration.isUseNewRbacAuthz()) {
682+
if (ldapConfiguration.isUseNewRbacAuthz() && shouldUpdateRoleBindings) {
678683
log.debug("Using new RBAC authorization...");
684+
String roleName = users.getRole().name();
679685
List<RoleBinding> currentRoleBindings = RoleBinding.getAll(users.getUuid());
680686
currentRoleBindings.stream().forEach(rB -> rB.delete());
681687
com.yugabyte.yw.models.rbac.Role newRbacRole =
682-
com.yugabyte.yw.models.rbac.Role.get(users.getCustomerUUID(), roleToAssign.name());
688+
com.yugabyte.yw.models.rbac.Role.get(users.getCustomerUUID(), roleName);
683689
if (newRbacRole != null) {
684-
log.debug("Found role with name: {}", roleToAssign.name());
690+
log.debug("Found role with name: {}", roleName);
685691
ResourceGroup rG =
686692
ResourceGroup.getSystemDefaultResourceGroup(users.getCustomerUUID(), users);
687693
RoleBinding createdRoleBinding =
@@ -690,7 +696,7 @@ public Users authViaLDAP(String email, String password, LdapConfiguration ldapCo
690696
log.debug("Created role binding: {}", createdRoleBinding);
691697
}
692698
} else {
693-
throw new RuntimeException(String.format("No role with the name: %s found", role));
699+
throw new RuntimeException(String.format("No role with the name: %s found", roleName));
694700
}
695701
}
696702
DB.commitTransaction();

0 commit comments

Comments
 (0)