You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by "andrew4699 (via GitHub)" <gi...@apache.org> on 2024/09/09 20:37:09 UTC

[PR] Add a config option to limit request body size [polaris]

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

   # Description
   
   Adds a config option to limit the request body size. This is useful to prevent DoS-style attacks before the request moves further through the request handlers.
   
   ## Type of change
   
   - [X] New feature (non-breaking change which adds functionality)
   
   # How Has This Been Tested?
   
   Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
   
   - [X] Added an integration test
   - [X] Existing tests work
   - [X] Ran Polaris with no limit, a small limit, and a high limit, and verified that the behavior was as expected
   
   # Checklist:
   
   Please delete options that are not relevant.
   
   - [X] I have performed a self-review of my code
   - [X] I have commented my code, particularly in hard-to-understand areas
   - [ ] I have made corresponding changes to the documentation
   - [X] My changes generate no new warnings
   - [ ] If adding new functionality, I have discussed my implementation with the community using the linked GitHub issue
   


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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +147,15 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxDocumentBytes")
+  public void setMaxDocumentBytes(long maxDocumentBytes) {
+    this.maxDocumentBytes = maxDocumentBytes;
+  }
+
+  public long getMaxDocumentBytes() {
+    return maxDocumentBytes;
+  }

Review Comment:
   Ok I updated it to default to -1, explained what -1 is, and restricted 0 with an exception/useful comment.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1762044468


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -151,12 +151,13 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
 
   @JsonProperty("maxRequestBodyBytes")
   public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
-    if (maxRequestBodyBytes == 0) {
-      // The underlying library that we use to implement the limit treats -1 and 0 as the same, so
-      // we block 0 to prevent ambiguity.
+    if (maxRequestBodyBytes <= 0 && maxRequestBodyBytes != -1) {
+      // The underlying library that we use to implement the limit treats all values <= 0 as the
+      // same, so
+      // we block all but -1 to prevent ambiguity.

Review Comment:
   nit: This formatting looks a bit odd. Can it be 2 lines?



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   Please see my new comment below on why 0 may make more sense in this specific instance.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/throttling/RequestThrottlingErrorResponse.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.service.throttling;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Response object for errors caused by DoS-prevention throttling mechanisms, such as request size
+ * limits
+ */
+public class RequestThrottlingErrorResponse {
+  public enum Error {

Review Comment:
   `Error` is a name from `java.lang` - can you choose something different here?



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/throttling/RequestThrottlingErrorResponse.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.service.throttling;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Response object for errors caused by DoS-prevention throttling mechanisms, such as request size
+ * limits
+ */
+public class RequestThrottlingErrorResponse {
+  public enum Error {

Review Comment:
   Updated



##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +149,23 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxRequestBodyBytes")
+  public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
+    if (maxRequestBodyBytes == 0) {

Review Comment:
   Updated to restrict all but -1



##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +149,23 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxRequestBodyBytes")
+  public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
+    if (maxRequestBodyBytes == 0) {

Review Comment:
   Updated to restrict all but -1



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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

   Thanks @andrew4699 for working on this. Thanks @snazy @eric-maynard  for the review.


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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +149,23 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxRequestBodyBytes")
+  public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
+    if (maxRequestBodyBytes <= 0 && maxRequestBodyBytes != -1) {
+      // The underlying library that we use to implement the limit treats all values <= 0 as the
+      // same, so we block all but -1 to prevent ambiguity.
+      throw new IllegalArgumentException(
+          String.format(
+              "maxRequestBodyBytes must be a positive integer or %d to specify no limit.",
+              REQUEST_BODY_BYTES_NO_LIMIT));
+    }

Review Comment:
   minor suggestion: 
   ```
   Preconditions.checkArgument(condition, message);
   ```



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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

   Just updated a couple of things:
   - Renamed `maxDocumentBytes` to `maxRequestBodyBytes`
   - Changed the default to -1 and made it throw an exception if you try to use 0, since the underlying implementation treats 0 and -1 as the same and we don't want to trick the user into thinking 0 actually does something different
   - Improved comments in the config
   - Added an additional test validating that there's already an existing limit on total header size


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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   Renamed to maxRequestBodyBytes and updated/moved the comment.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1752906441


##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   1. This comment would ideally not be inline
   2. Do we really want to call this `maxDocumentBytes`? What is a "Document" in the context of a Polaris instance?
   3. Whatever we call it, we might put a small comment explaining what this is



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   From a DoS perspective I would expect all entity types to be about the same order of magnitude of size, so at least from that perspective I think just having a single global limit makes the most sense.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1757712756


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +149,23 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxRequestBodyBytes")
+  public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
+    if (maxRequestBodyBytes == 0) {
+      // The underlying library that we use to implement the limit treats -1 and 0 as the same, so
+      // we block 0 to prevent ambiguity.
+      throw new IllegalArgumentException(
+          String.format(
+              "maxRequestBodyBytes may not be 0. Use %d to specify no limit.",

Review Comment:
   nit: "maxRequestBodyBytes must be a positive integer or `%d` to specify no limit."



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "sfc-gh-aixu (via GitHub)" <gi...@apache.org>.
sfc-gh-aixu commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1757301506


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +147,15 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxDocumentBytes")
+  public void setMaxDocumentBytes(long maxDocumentBytes) {
+    this.maxDocumentBytes = maxDocumentBytes;
+  }
+
+  public long getMaxDocumentBytes() {
+    return maxDocumentBytes;
+  }

Review Comment:
   From the code from StreamReadConstraints, that means both 0 and -1 are considered no limits. But I think it does make sense to have -1 for unlimited and disallow 0.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1751151419


##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   If there's any situation where we might want to set this on a per-entity (catalog, namespace, table) level in the future I think this could be a PolarisConfiguration, otherwise I think this is good as-is



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "collado-mike (via GitHub)" <gi...@apache.org>.
collado-mike commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1751070956


##########
polaris-service/src/main/java/org/apache/polaris/service/throttling/RequestThrottlingErrorResponse.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.service.throttling;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class RequestThrottlingErrorResponse {

Review Comment:
   Class-level docs



##########
polaris-service/src/main/java/org/apache/polaris/service/throttling/StreamReadConstraintsExceptionMapper.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.service.throttling;
+
+import com.fasterxml.jackson.core.exc.StreamConstraintsException;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.ext.ExceptionMapper;
+
+public class StreamReadConstraintsExceptionMapper

Review Comment:
   Class-level docs



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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

   I'm fine with either -1 or 0. My main concern with using 0 is that there is a chance that it might be misunderstood as a valid limit rather than indicating "no limit." In contrast, -1 is less ambiguous in this context. Additionally, I recommend defining a constant for clarity:
   ```
   private static final long DOCUMENT_BYTES_NO_LIMIT = -1;
   ``` 


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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +147,15 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxDocumentBytes")
+  public void setMaxDocumentBytes(long maxDocumentBytes) {
+    this.maxDocumentBytes = maxDocumentBytes;
+  }
+
+  public long getMaxDocumentBytes() {
+    return maxDocumentBytes;
+  }

Review Comment:
   I think it should have a default value.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +147,15 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxDocumentBytes")
+  public void setMaxDocumentBytes(long maxDocumentBytes) {
+    this.maxDocumentBytes = maxDocumentBytes;
+  }
+
+  public long getMaxDocumentBytes() {
+    return maxDocumentBytes;
+  }

Review Comment:
   Checking a bit more about class `StreamReadConstraints`.  `-1` is the right default value, which means no limit.
   ```
           public Builder maxDocumentLength(long maxDocLen) {
               if (maxDocLen <= 0L) {
                   maxDocLen = -1L;
               }
   
               this.maxDocLen = maxDocLen;
               return this;
           }
   ```



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1757712911


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +149,23 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxRequestBodyBytes")
+  public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
+    if (maxRequestBodyBytes == 0) {

Review Comment:
   nit: Maybe we should constrain this to a positive integer or -1 while we're at it



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -151,12 +151,13 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
 
   @JsonProperty("maxRequestBodyBytes")
   public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
-    if (maxRequestBodyBytes == 0) {
-      // The underlying library that we use to implement the limit treats -1 and 0 as the same, so
-      // we block 0 to prevent ambiguity.
+    if (maxRequestBodyBytes <= 0 && maxRequestBodyBytes != -1) {
+      // The underlying library that we use to implement the limit treats all values <= 0 as the
+      // same, so
+      // we block all but -1 to prevent ambiguity.

Review Comment:
   Updated.
   
   I've just been letting spotless take the wheel with these, but I guess it's ok with either style? We should probably update it to prefer a single format if possible.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   Maybe use -1 to indicate no limit since 0 can be used to disallow anything?



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   From a DoS perspective I would expect all entity types to be about the same order of magnitude of size, so at least from that perspective I think just having a single global limit makes the most sense. But that doesn't stop us from pursuing per-entity-type limits in the future.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   We may also explain what is the default value. 



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1752911429


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +147,15 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxDocumentBytes")
+  public void setMaxDocumentBytes(long maxDocumentBytes) {
+    this.maxDocumentBytes = maxDocumentBytes;
+  }
+
+  public long getMaxDocumentBytes() {
+    return maxDocumentBytes;
+  }

Review Comment:
   I also find 0-as-unlimited a little confusing. I agree that if we make the default -1 it might imply that 0 is different from -1, but I also think a default of 0 is going to raise some questions.
   
   Maybe we should just disallow 0, since `StreamReadConstraints` doesn't support what 0 would intuitively mean ("reject all requests")



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +147,15 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxDocumentBytes")
+  public void setMaxDocumentBytes(long maxDocumentBytes) {
+    this.maxDocumentBytes = maxDocumentBytes;
+  }
+
+  public long getMaxDocumentBytes() {
+    return maxDocumentBytes;
+  }

Review Comment:
   Thank you for pulling this up, this actually makes me more strongly interested in 0. Please see my new comment below.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +147,15 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxDocumentBytes")
+  public void setMaxDocumentBytes(long maxDocumentBytes) {
+    this.maxDocumentBytes = maxDocumentBytes;
+  }
+
+  public long getMaxDocumentBytes() {
+    return maxDocumentBytes;
+  }

Review Comment:
   Ok I updated it to default to -1, explained what -1 is, and restricted 0 with an exception/useful comment. I agree that -1 is a better indicator of "no limit" and restricting 0 solves some ambiguity.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +149,23 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxRequestBodyBytes")
+  public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
+    if (maxRequestBodyBytes == 0) {

Review Comment:
   Should we consider throwing an exception when the configured value for maxRequestBodyBytes is less than -1 (e.g., -2, -100)? While the underlying library can technically handle these values, I believe we should restrict any negative number except for -1, which is already treated as "unlimited." This is consistent with our approach of throwing an exception for a value of 0.



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1757712911


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +149,23 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxRequestBodyBytes")
+  public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
+    if (maxRequestBodyBytes == 0) {

Review Comment:
   nit: Maybe we should clamp to positive integer or -1 while we're at it



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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


##########
polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java:
##########
@@ -146,6 +149,23 @@ public void setFeatureConfiguration(Map<String, Object> featureConfiguration) {
     this.configurationStore = new DefaultConfigurationStore(featureConfiguration);
   }
 
+  @JsonProperty("maxRequestBodyBytes")
+  public void setMaxRequestBodyBytes(long maxRequestBodyBytes) {
+    if (maxRequestBodyBytes == 0) {
+      // The underlying library that we use to implement the limit treats -1 and 0 as the same, so
+      // we block 0 to prevent ambiguity.
+      throw new IllegalArgumentException(
+          String.format(
+              "maxRequestBodyBytes may not be 0. Use %d to specify no limit.",

Review Comment:
   Updated



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

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


Re: [PR] Add a config option to limit request body size [polaris]

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

   I agree with the reasons for wanting to make -1 the default value, but I'd like to offer a counterargument for why it may make sense to keep it at 0 in this case:
   - As [this](https://github.com/apache/polaris/pull/276#discussion_r1752430980) comment shows, both 0 and -1 disable the limit. Listing -1 may falsely lead the user to believe that 0 is different.
   - Default value compatibility across JSON serializers. With the default set to 0, you don't have to worry about whether your serialization library respects your default value nor what it does with unspecified fields.


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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1751150793


##########
polaris-service/src/test/resources/polaris-server-integrationtest.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/iceberg-rest-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 1000000

Review Comment:
   nit: missing EOL newline



##########
polaris-server.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/polaris-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 0 # Don't set a limit

Review Comment:
   ditto



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

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


Re: [PR] Add a config option to limit request body size [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #276:
URL: https://github.com/apache/polaris/pull/276#discussion_r1751150793


##########
polaris-service/src/test/resources/polaris-server-integrationtest.yml:
##########
@@ -167,3 +167,5 @@ logging:
       archivedLogFilenamePattern: ./logs/iceberg-rest-%d.log.gz
       # The maximum number of log files to archive.
       archivedFileCount: 14
+
+maxDocumentBytes: 1000000

Review Comment:
   nit: missing EOF newline



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

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