vyommani commented on code in PR #1229:
URL: https://github.com/apache/ranger/pull/1229#discussion_r4011547441


##########
security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java:
##########
@@ -695,20 +697,60 @@ private void blockAdminFromKMSService(RangerSecurityZone 
securityZone) {
 
             if (serviceMap != null) {
                 for (String serviceName : serviceMap.keySet()) {
-                    XXService xService = 
daoManager.getXXService().findByName(serviceName);
-
-                    if (xService != null) {
-                        XXServiceDef xServiceDef = 
daoManager.getXXServiceDef().getById(xService.getType());
+                    String serviceType = 
daoManager.getXXServiceDef().findServiceDefTypeByServiceName(serviceName);
 
-                        if 
(EmbeddedServiceDefsUtil.KMS_IMPL_CLASS_NAME.equals(xServiceDef.getImplclassname()))
 {
-                            throw restErrorUtil.createRESTException("KMS 
Services/Service-Defs are not accessible for Zone operations", 
MessageEnums.OPER_NOT_ALLOWED_FOR_ENTITY);
-                        }
+                    if 
(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME.equals(serviceType)) {
+                        throw restErrorUtil.createRESTException("KMS 
Services/Service-Defs are not accessible for Zone operations", 
MessageEnums.OPER_NOT_ALLOWED_FOR_ENTITY);
                     }
                 }
             }
         }
     }
 
+    private void blockAdminFromKMSServiceOnUpdate(RangerSecurityZone 
submittedZone, Long zoneId) {
+        if (bizUtil.isAdmin()) {
+            blockAdminFromKMSService(submittedZone);
+
+            if (zoneId != null) {

Review Comment:
   The existing-zone check here blocks the only way to fix a zone that already 
contains a KMS service (e.g. one created on an older build before this check 
existed). Delete is blocked below, and ROLE_KEY_ADMIN can't operate on zones, 
so an admin who submits this zone with the KMS service removed is still 
rejected — the zone can't be edited or deleted through the API.
   
   The check also adds nothing: if the submitted zone still contains the KMS 
service, blockAdminFromKMSService(submittedZone) catches it; if it doesn't, 
that's the removal we want to allow. Suggest checking only the submitted zone 
on update, dropping the securityZoneStore.getSecurityZone(zoneId) read, and 
adding a test that an admin can remove a KMS service from an existing zone (PUT 
without KMS → DELETE should then succeed).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to