mneethiraj commented on code in PR #3928: URL: https://github.com/apache/polaris/pull/3928#discussion_r2932492579
########## extensions/auth/ranger/src/main/java/org/apache/polaris/extension/auth/ranger/utils/RangerUtils.java: ########## @@ -0,0 +1,255 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.polaris.extension.auth.ranger.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; +import org.apache.polaris.core.auth.PolarisAuthorizableOperation; +import org.apache.polaris.core.auth.PolarisPrincipal; +import org.apache.polaris.core.entity.PolarisEntity; +import org.apache.polaris.core.entity.PolarisEntityType; +import org.apache.polaris.core.entity.PolarisPrivilege; +import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; +import org.apache.polaris.core.persistence.ResolvedPolarisEntity; +import org.apache.polaris.extension.auth.ranger.RangerPolarisAuthorizer; +import org.apache.ranger.authz.model.RangerAccessInfo; +import org.apache.ranger.authz.model.RangerResourceInfo; +import org.apache.ranger.authz.model.RangerUserInfo; +import org.apache.ranger.authz.util.RangerResourceNameParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RangerUtils { + private static final Logger LOG = LoggerFactory.getLogger(RangerUtils.class); + + public static Properties loadProperties(String resourcePath) { + if (resourcePath == null) { + throw new IllegalStateException("invalid resource path: null"); + } + + resourcePath = resourcePath.trim(); + + if (!resourcePath.startsWith("/")) { + LOG.info("Prefixing / to resource path: {}", resourcePath); + + resourcePath = "/" + resourcePath; + } + + try (InputStream in = RangerPolarisAuthorizer.class.getResourceAsStream(resourcePath)) { + if (in != null) { + Properties prop = new Properties(); + + prop.load(in); + + return prop; + } else { + LOG.error("Unable to find {} in the classpath", resourcePath); + + throw new IllegalStateException("failed to find " + resourcePath); + } + } catch (IOException e) { + LOG.error("Unable to load {}", resourcePath, e); + + throw new IllegalStateException("failed to load " + resourcePath); + } + } + + public static String toResourceType(PolarisEntityType entityType) { + return switch (entityType) { + case ROOT -> "root"; + case PRINCIPAL -> "principal"; + case CATALOG -> "catalog"; + case NAMESPACE -> "namespace"; + case TABLE_LIKE -> "table"; + case POLICY -> "policy"; + default -> entityType.name(); // NULL_TYPE, PRINCIPAL_ROLE, CATALOG_ROLE, TASK, FILE Review Comment: 1) Ranger authorizer doesn't support entity types `PRINCIPAL_ROLE`, `CATALOG_ROLE` (and operations on them); these are specific to PolarisAuthorizerImpl, but are part of authorizer SPI. 2) Entity types `NULL_TYPE`, `TASK`, `FILE` are not referenced in any `PolarisAuthorizableOperation`. It seems these entity types are unused, hence Ranger authorizer doesn't support them. 3) In Ranger policy model, resources are named in lower case; hence the mapping for entity-types to Ranger resource names. Ref: [Ranger service-def for Polaris](https://github.com/apache/ranger/blob/master/agents-common/src/main/resources/service-defs/ranger-servicedef-polaris.json). 4) Ranger will deny authorization requests on any resource it doesn't support. So, authorizatins for entity types not explicitly mapped above will result in access to be denied. This is by design. -- 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]
