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


##########
security-admin/src/main/java/org/apache/ranger/biz/KmsKeyMgr.java:
##########
@@ -558,26 +569,37 @@ private void throwServiceNotFoundException(String 
serviceName) {
 
     private String[] getKMSURL(String name) throws Exception {
         String[] providers;
+        String   dbKmsUrl;
 
         try {
             RangerService rangerService = svcStore.getServiceByName(name);
 
-            if (rangerService != null) {
-                String kmsUrl   = 
rangerService.getConfigs().get(KMS_URL_CONFIG);
-                String dbKmsUrl = kmsUrl;
+            if (rangerService == null) {
+                throw new Exception("Service " + name + " not found");
+            }
 
-                if (providerList.containsKey(kmsUrl)) {
-                    kmsUrl = providerList.get(kmsUrl);
-                } else {
-                    providerList.put(kmsUrl, kmsUrl);
-                }
+            dbKmsUrl = rangerService.getConfigs().get(KMS_URL_CONFIG);
+        } catch (Exception excp) {
+            logger.error("getServiceByName({}) failed", name, excp);
 
-                providers = createProvider(dbKmsUrl, kmsUrl);
+            throw new Exception("getServiceByName(" + name + ") failed", excp);
+        }
+
+        // Validate the saved provider before Ranger Admin connects to it
+        validateProviderUrl(name, dbKmsUrl);

Review Comment:
   The cost is a URI parse plus InetAddress.getByName per host, and the JVM 
caches the lookup. Successful lookups are cached by the JVM, and the KMS call 
that follows resolves the same names anyway. These are low-volume admin key 
operations, so the overhead is negligible next to the KMS round trip.
   
   I kept it at use time on purpose. A save-time-only check wouldn't cover 
providers saved before this change, configs that arrive through import or DB 
updates, or a name that later resolves to a blocked address. It also wouldn't 
cover the per-host URLs that createProvider() builds, which are what's actually 
dialed. Adding a save-time check as well, for earlier feedback, sounds 
reasonable, but it changes behaviour for existing services, so I'd prefer to do 
it in a separate JIRA.



-- 
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