sungwy commented on code in PR #2680: URL: https://github.com/apache/polaris/pull/2680#discussion_r2395874717
########## polaris-core/src/main/java/org/apache/polaris/core/auth/OpaPolarisAuthorizer.java: ########## @@ -0,0 +1,303 @@ +/* + * 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.core.auth; + +// Removed Quarkus/MicroProfile annotations for portability +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import java.io.IOException; +import java.util.List; +import java.util.Set; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import org.apache.iceberg.exceptions.ForbiddenException; +import org.apache.polaris.core.entity.PolarisBaseEntity; +import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; + +/** + * OPA-based implementation of {@link PolarisAuthorizer}. + * + * <p>This authorizer delegates authorization decisions to an Open Policy Agent (OPA) server using a + * configurable REST API endpoint and policy path. The input to OPA is constructed from the + * principal, entities, operation, and resource context. + */ +public class OpaPolarisAuthorizer implements PolarisAuthorizer { + private final String opaServerUrl; + private final String opaPolicyPath; + private final OkHttpClient httpClient; + private final ObjectMapper objectMapper; + + /** Private constructor for factory method and advanced wiring. */ + private OpaPolarisAuthorizer( + String opaServerUrl, + String opaPolicyPath, + OkHttpClient httpClient, + ObjectMapper objectMapper) { + this.opaServerUrl = opaServerUrl; + this.opaPolicyPath = opaPolicyPath; + this.httpClient = httpClient; + this.objectMapper = objectMapper; + } + + /** + * Static factory for runtime configuration and CDI producer compatibility. + * + * @param opaServerUrl OPA server URL + * @param opaPolicyPath OPA policy path + * @param timeoutMs HTTP call timeout in milliseconds + * @param client OkHttpClient (optional, can be null) + * @param mapper ObjectMapper (optional, can be null) + * @return OpaPolarisAuthorizer instance + */ + public static OpaPolarisAuthorizer create( Review Comment: Noted - I've made changes to the code to make use of `OpaPolarisAuthorizerFactory` and `DefaultPolarisAuthorizerFactory` to use the `@Identifier` annotation instead. Please let me know if this is what you meant! ########## runtime/defaults/src/main/resources/application.properties: ########## @@ -193,6 +193,15 @@ polaris.oidc.principal-roles-mapper.type=default # polaris.storage.gcp.token=token # polaris.storage.gcp.lifespan=PT1H +# Polaris authorization implementation settings +# Which authorizer to use: "default" (PolarisAuthorizerImpl) or "opa" (OpaPolarisAuthorizer) +polaris.authorization.implementation=default Review Comment: done ! -- 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]
