You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "sungwy (via GitHub)" <gi...@apache.org> on 2025/11/12 03:51:20 UTC

[PR] Use POJOs for OPA JSON schema construction and publish schema [polaris]

sungwy opened a new pull request, #3031:
URL: https://github.com/apache/polaris/pull/3031

   <!--
   ๐Ÿ“ Describe what changes you're proposing, especially breaking or user-facing changes. 
   ๐Ÿ“– See https://github.com/apache/polaris/blob/main/CONTRIBUTING.md for more.
   -->
   
   Follow up PR to use POJOs and publish the OPA request input schema used in `OpaPolarisAuthorizer`: https://github.com/apache/polaris/pull/2680
   
   
   ## Checklist
   - [ ] ๐Ÿ›ก๏ธ Don't disclose security issues! (contact security@apache.org)
   - [x] ๐Ÿ”— Clearly explained why the changes are needed, or linked related issues: Fixes #
   - [ ] ๐Ÿงช Added/updated tests with good coverage, or manually tested (and explained how)
   - [ ] ๐Ÿ’ก Added comments for complex logic
   - [ ] ๐Ÿงพ Updated `CHANGELOG.md` (if needed)
   - [ ] ๐Ÿ“š Updated documentation in `site/content/in-dev/unreleased` (if needed)
   


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use POJOs for OPA JSON schema construction and publish schema [polaris]

Posted by "sungwy (via GitHub)" <gi...@apache.org>.
sungwy commented on code in PR #3031:
URL: https://github.com/apache/polaris/pull/3031#discussion_r2520822771


##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/Resource.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents the resource(s) being accessed in an authorization request.
+ *
+ * <p>Contains primary target entities and optional secondary entities.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableResource.class)
+@JsonDeserialize(as = ImmutableResource.class)
+public interface Resource {
+  /** The primary target entities being accessed. */
+  @JsonProperty("targets")
+  List<ResourceEntity> targets();
+
+  /** Secondary entities involved in the operation (e.g., source table in RENAME). */
+  @JsonProperty("secondaries")
+  List<ResourceEntity> secondaries();

Review Comment:
   Thanks @snazy - that's a good suggestion. Now that I look at it, `targets` is also Nullable according to the `authorizeOrThrow` Authorizer interface method. I'll adopt a similar suggestion there



-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use POJOs for OPA JSON schema construction and publish schema [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #3031:
URL: https://github.com/apache/polaris/pull/3031#discussion_r2517334010


##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/Resource.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents the resource(s) being accessed in an authorization request.
+ *
+ * <p>Contains primary target entities and optional secondary entities.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableResource.class)
+@JsonDeserialize(as = ImmutableResource.class)
+public interface Resource {
+  /** The primary target entities being accessed. */
+  @JsonProperty("targets")
+  List<ResourceEntity> targets();
+
+  /** Secondary entities involved in the operation (e.g., source table in RENAME). */
+  @JsonProperty("secondaries")
+  List<ResourceEntity> secondaries();

Review Comment:
   If the whole property is optional, maybe add
   ```
   @JsonInclude(JsonInclude.Include.NON_EMPTY)
   ```
   But I'm not sure whether the JSON schema generator respects this.



##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/Context.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Additional context information for the authorization request.
+ *
+ * <p>Used for tracking and correlation purposes.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableContext.class)
+@JsonDeserialize(as = ImmutableContext.class)
+public interface Context {
+  /** A unique identifier for correlating this request with OPA server logs. */
+  @JsonProperty("request_id")

Review Comment:
   Hint:
   you can use
   ```java
   @JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)
   ```
   on a type and IIRC also at the package level.



##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/Actor.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents the actor (principal) making an authorization request.
+ *
+ * <p>Contains the principal identifier and associated roles.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableActor.class)
+@JsonDeserialize(as = ImmutableActor.class)
+public interface Actor {
+  /** The principal name or identifier. */
+  @JsonProperty("principal")

Review Comment:
   Nit: no need to specify this, if the property name's the same.



##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/ResourceEntity.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import jakarta.annotation.Nullable;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents a single resource entity in the authorization context.
+ *
+ * <p>Contains the entity type, name, and hierarchical parent path.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableResourceEntity.class)
+@JsonDeserialize(as = ImmutableResourceEntity.class)
+public interface ResourceEntity {
+  /** The type of the resource (e.g., "CATALOG", "NAMESPACE", "TABLE"). */
+  @JsonProperty("type")
+  String type();
+
+  /** The name of the resource. */
+  @JsonProperty("name")
+  String name();
+
+  /**
+   * The hierarchical path of parent entities.
+   *
+   * <p>For example, a table might have parents: [catalog, namespace].
+   */
+  @Nullable
+  @JsonProperty("parents")
+  List<ResourceEntity> parents();

Review Comment:
   ```suggestion
     @JsonInclude(JsonInclude.Include.NON_NULL)
     List<ResourceEntity> parents();
   ```
   (same as above)



##########
extensions/auth/opa/impl/build.gradle.kts:
##########
@@ -58,3 +59,64 @@ dependencies {
   testImplementation(project(":polaris-async-java"))
   testImplementation(project(":polaris-idgen-mocks"))
 }
+
+// Task to generate JSON Schema from model classes

Review Comment:
   Couple of Gradle improvements could be applied.
   I've created PR against your branch, as it's a bit more: sungwy#3
   
   The idea to have separate generation and validation steps is good IMO, as it makes it obvious that such changes affect the expected OPA contract.
   
   Summary:
   * Make both tasks cacheable
   * Adjust logging output (keep output brief)
   * Moved schema generator class to a separate source-set/configurations, because it's not prod code, but more importantly to not let the json-schema-generator dependency leak into the production runtime classpath



##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/ResourceEntity.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import jakarta.annotation.Nullable;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents a single resource entity in the authorization context.
+ *
+ * <p>Contains the entity type, name, and hierarchical parent path.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableResourceEntity.class)
+@JsonDeserialize(as = ImmutableResourceEntity.class)
+public interface ResourceEntity {
+  /** The type of the resource (e.g., "CATALOG", "NAMESPACE", "TABLE"). */
+  @JsonProperty("type")
+  String type();
+
+  /** The name of the resource. */
+  @JsonProperty("name")
+  String name();
+
+  /**
+   * The hierarchical path of parent entities.
+   *
+   * <p>For example, a table might have parents: [catalog, namespace].
+   */
+  @Nullable

Review Comment:
   I suspect this is for the JSON schema generator?



##########
extensions/auth/opa/impl/SCHEMA.md:
##########
@@ -0,0 +1,106 @@
+# OPA Input Schema Management

Review Comment:
   Will need a license header to pass CI.



-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use POJOs for OPA JSON schema construction and publish schema [polaris]

Posted by "sungwy (via GitHub)" <gi...@apache.org>.
sungwy commented on PR #3031:
URL: https://github.com/apache/polaris/pull/3031#issuecomment-3524868239

   Thank you for the reviews @snazy ๐Ÿ˜„ 
   
   I'd like to add a link to the generated schema file in the new OPA documentation page, either in this PR or https://github.com/apache/polaris/pull/3030
   
   So feel free to approve and merge one, but not the other so I can add that link once we get one of these in!


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use POJOs for OPA JSON schema construction and publish schema [polaris]

Posted by "sungwy (via GitHub)" <gi...@apache.org>.
sungwy commented on code in PR #3031:
URL: https://github.com/apache/polaris/pull/3031#discussion_r2520636209


##########
extensions/auth/opa/impl/build.gradle.kts:
##########
@@ -58,3 +59,64 @@ dependencies {
   testImplementation(project(":polaris-async-java"))
   testImplementation(project(":polaris-idgen-mocks"))
 }
+
+// Task to generate JSON Schema from model classes

Review Comment:
   yeah that's definitely a good idea to split out the json-schema-generator dependency into a separate path. Thank you again for being so kind with your help in the review @snazy ๐Ÿ˜„ 



-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use POJOs for OPA JSON schema construction and publish schema [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy merged PR #3031:
URL: https://github.com/apache/polaris/pull/3031


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use POJOs for OPA JSON schema construction and publish schema [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #3031:
URL: https://github.com/apache/polaris/pull/3031#discussion_r2522897003


##########
extensions/auth/opa/impl/build.gradle.kts:
##########
@@ -17,22 +17,34 @@
  * under the License.
  */
 
+import java.io.OutputStream
+
 plugins {
   id("polaris-server")
   id("org.kordamp.gradle.jandex")
 }
 
+val jsonSchemaGenerator = sourceSets.create("jsonSchemaGenerator")
+
 dependencies {
   implementation(project(":polaris-core"))
   implementation(libs.apache.httpclient5)
   implementation(platform(libs.jackson.bom))
   implementation("com.fasterxml.jackson.core:jackson-core")
   implementation("com.fasterxml.jackson.core:jackson-databind")
+  implementation("com.fasterxml.jackson.module:jackson-module-jsonSchema")

Review Comment:
   Let's remove this dependency - don't need it.
   
   ```suggestion
   ```



##########
extensions/auth/opa/impl/SCHEMA.md:
##########
@@ -0,0 +1,126 @@
+

Review Comment:
   Nit:
   
   ```suggestion
   ```



-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use POJOs for OPA JSON schema construction and publish schema [polaris]

Posted by "sungwy (via GitHub)" <gi...@apache.org>.
sungwy commented on code in PR #3031:
URL: https://github.com/apache/polaris/pull/3031#discussion_r2520690106


##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/Context.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Additional context information for the authorization request.
+ *
+ * <p>Used for tracking and correlation purposes.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableContext.class)
+@JsonDeserialize(as = ImmutableContext.class)
+public interface Context {
+  /** A unique identifier for correlating this request with OPA server logs. */
+  @JsonProperty("request_id")

Review Comment:
   neat ๐Ÿ˜„ 
   



-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org