You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/04/05 17:38:22 UTC

[GitHub] [nifi] thenatog opened a new pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

thenatog opened a new pull request #4972:
URL: https://github.com/apache/nifi/pull/4972


   …lter to apply the DoS filter based on path.
   
   NIFI-7912 - Working in cluster setup. Fixed tests and a log message.
   
   NIFI-7912 - Changed log levels to debug.
   
   NIFI-7912 - Added docs and default property to nifi.properties.
   
   Thank you for submitting a contribution to Apache NiFi.
   
   Please provide a short description of the PR here:
   
   #### Description of PR
   
   _Enables X functionality; fixes bug NIFI-YYYY._
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [x] Does your PR title start with **NIFI-XXXX** where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [x] Has your PR been rebased against the latest commit within the target branch (typically `main`)?
   
   - [x] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
   
   ### For code changes:
   - [x] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
   - [x] Have you written or updated unit tests to verify your changes?
   - [x] Have you verified that the full build is successful on JDK 8?
   - [ ] Have you verified that the full build is successful on JDK 11?
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] If applicable, have you updated the `LICENSE` file, including the main `LICENSE` file under `nifi-assembly`?
   - [ ] If applicable, have you updated the `NOTICE` file, including the main `NOTICE` file found under `nifi-assembly`?
   - [ ] If adding new Properties, have you added `.displayName` in addition to .name (programmatic access) for each of the new properties?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as 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.

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



[GitHub] [nifi] exceptionfactory commented on a change in pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r608067336



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/pom.xml
##########
@@ -256,5 +256,10 @@
             <version>${nifi.groovy.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-servlets</artifactId>

Review comment:
       Is this dependency addition necessary given that the most recent commit does not include a new filter class?

##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -715,20 +717,40 @@ private static int determineMaxWebRequestsPerSecond(NiFiProperties props) {
         return configuredMaxRequestsPerSecond > 0 ? configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
     }
 
+    private static long determineRequestTimeoutInMilliseconds(NiFiProperties props) {
+        long defaultRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(NiFiProperties.DEFAULT_WEB_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS));
+        long configuredRequestTimeout = 0L;
+        try {
+            configuredRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(props.getWebRequestTimeout(), TimeUnit.MILLISECONDS));
+        } catch (final NumberFormatException e) {
+            logger.warn("Exception parsing property " + NiFiProperties.WEB_REQUEST_TIMEOUT + "; using default value: " + defaultRequestTimeout);

Review comment:
       Recommend adjusting the log statement to use placeholders:
   ```suggestion
               logger.warn("Exception parsing property [{}]: using default value [{}] ", NiFiProperties.WEB_REQUEST_TIMEOUT, defaultRequestTimeout);
   ```

##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -715,20 +717,40 @@ private static int determineMaxWebRequestsPerSecond(NiFiProperties props) {
         return configuredMaxRequestsPerSecond > 0 ? configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
     }
 
+    private static long determineRequestTimeoutInMilliseconds(NiFiProperties props) {

Review comment:
       Recommend adding `final` modifier:
   ```suggestion
       private static long determineRequestTimeoutInMilliseconds(final NiFiProperties props) {
   ```

##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -715,20 +717,40 @@ private static int determineMaxWebRequestsPerSecond(NiFiProperties props) {
         return configuredMaxRequestsPerSecond > 0 ? configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
     }
 
+    private static long determineRequestTimeoutInMilliseconds(NiFiProperties props) {
+        long defaultRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(NiFiProperties.DEFAULT_WEB_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS));
+        long configuredRequestTimeout = 0L;
+        try {
+            configuredRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(props.getWebRequestTimeout(), TimeUnit.MILLISECONDS));
+        } catch (final NumberFormatException e) {
+            logger.warn("Exception parsing property " + NiFiProperties.WEB_REQUEST_TIMEOUT + "; using default value: " + defaultRequestTimeout);
+        }
+
+        return configuredRequestTimeout > 0 ? configuredRequestTimeout : defaultRequestTimeout;
+    }
+
     /**
      * Adds the {@link org.eclipse.jetty.servlets.DoSFilter} to the specified context and path. Limits incoming web requests to {@code maxWebRequestsPerSecond} per second.
      *
      * @param path the path to apply this filter
      * @param webAppContext the context to apply this filter
      * @param maxWebRequestsPerSecond the maximum number of allowed requests per second
      */
-    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond) {
+    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond, long requestTimeoutInMilliseconds, final String ipWhitelist) {
         FilterHolder holder = new FilterHolder(DoSFilter.class);
         holder.setInitParameters(new HashMap<String, String>() {{
             put("maxRequestsPerSec", String.valueOf(maxWebRequestsPerSecond));
+            put("maxRequestMs", String.valueOf(requestTimeoutInMilliseconds));
+            put("ipWhitelist", String.valueOf(ipWhitelist));
         }});
         holder.setName(DoSFilter.class.getSimpleName());
-        logger.debug("Adding DoSFilter to context at path: " + path + " with max req/sec: " + maxWebRequestsPerSecond);
+
+        String ipWhitelistLoggable = ipWhitelist;
+        if(ipWhitelist == null) {
+            ipWhitelistLoggable = "none";
+        }
+        logger.info("Adding DoSFilter to context at path: {} with max req/sec: {}, request timeout: {} ms. Whitelisted IPs not subject to filter: {}",
+                path, maxWebRequestsPerSecond, requestTimeoutInMilliseconds, ipWhitelistLoggable);

Review comment:
       The loggable representation could be handled using `StringUtils.defaultIfEmpty()`
   ```suggestion
           logger.info("Adding DoSFilter Path [{}] Max Requests per Second [{}] Timeout [{} ms] Excluded Addresses [{}]",
                   path, maxWebRequestsPerSecond, requestTimeoutInMilliseconds, StringUtils.defaultIfEmpty(ipWhitelist, "none"));
   ```

##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy
##########
@@ -540,6 +540,21 @@ class JettyServerGroovyTest extends GroovyTestCase {
         assert filterNames.contains("DoSFilter")
         assert !filterNames.contains("ContentLengthFilter")
     }
+
+    @Test
+    void testDetermineRequestTimeoutInMilliseconds() {
+        // Arrange
+        Map badProps = [
+                (NiFiProperties.WEB_REQUEST_TIMEOUT): "50 sec",
+        ]
+
+        NiFiProperties mockProps = new StandardNiFiProperties(new Properties(badProps))
+
+        // Act
+        long requestTimeout = JettyServer.determineRequestTimeoutInMilliseconds(mockProps)

Review comment:
       Recommend avoiding calls to private methods even though Groovy allows it to work.  Instead, is it possible to retrieve the configured DoSFilter and evaluate the configuration?  Otherwise, it seems acceptable to remove this test method.




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

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



[GitHub] [nifi] exceptionfactory edited a comment on pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
exceptionfactory edited a comment on pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#issuecomment-814106145


   > I agree that the IP whitelisting is more representative of how the DoS should work rather than excluding the S2S paths. Testing this out it seems like the whitelist is only applied to the request rate tracking, as the timeout method onRequestTimeout() doesn't seem to call checkWhitelist(), confirmed by docs http://archive.eclipse.org/jetty/8.0.0.M1/apidocs/org/eclipse/jetty/servlets/DoSFilter.html
   
   That's a good point about `DoSFilter.onRequestTimeout()` still enforcing the maximum value as configured using the `maxRequestMs`.  With the addition of the new property `nifi.web.request.timeout` and one more property to exclude IP addresses or subnets from rate limiting, it seems like that should provide sufficient ability to configure the filter.


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

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



[GitHub] [nifi] thenatog commented on a change in pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
thenatog commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r608086562



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy
##########
@@ -540,6 +540,21 @@ class JettyServerGroovyTest extends GroovyTestCase {
         assert filterNames.contains("DoSFilter")
         assert !filterNames.contains("ContentLengthFilter")
     }
+
+    @Test
+    void testDetermineRequestTimeoutInMilliseconds() {
+        // Arrange
+        Map badProps = [
+                (NiFiProperties.WEB_REQUEST_TIMEOUT): "50 sec",
+        ]
+
+        NiFiProperties mockProps = new StandardNiFiProperties(new Properties(badProps))
+
+        // Act
+        long requestTimeout = JettyServer.determineRequestTimeoutInMilliseconds(mockProps)

Review comment:
       Sure I can remove, used this initially to check the value was coming through correctly.




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

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



[GitHub] [nifi] exceptionfactory commented on pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#issuecomment-814106145


   > I agree that the IP whitelisting is more representative of how the DoS should work rather than excluding the S2S paths. Testing this out it seems like the whitelist is only applied to the request rate tracking, as the timeout method onRequestTimeout() doesn't seem to call checkWhitelist(), confirmed by docs http://archive.eclipse.org/jetty/8.0.0.M1/apidocs/org/eclipse/jetty/servlets/DoSFilter.html
   
   That's a good point about `DoSFilter.onRequestTimeout()` still enforcing the maximum value as configured using the `maxRequestMs`.  With the addition of the new property `nifi-web.request.timeout` and one more property to exclude IP addresses or subnets from rate limiting, it seems like that should provide sufficient ability to configure the filter.


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

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



[GitHub] [nifi] thenatog commented on a change in pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
thenatog commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r608078390



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -715,20 +717,40 @@ private static int determineMaxWebRequestsPerSecond(NiFiProperties props) {
         return configuredMaxRequestsPerSecond > 0 ? configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
     }
 
+    private static long determineRequestTimeoutInMilliseconds(NiFiProperties props) {
+        long defaultRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(NiFiProperties.DEFAULT_WEB_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS));
+        long configuredRequestTimeout = 0L;
+        try {
+            configuredRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(props.getWebRequestTimeout(), TimeUnit.MILLISECONDS));
+        } catch (final NumberFormatException e) {
+            logger.warn("Exception parsing property " + NiFiProperties.WEB_REQUEST_TIMEOUT + "; using default value: " + defaultRequestTimeout);
+        }
+
+        return configuredRequestTimeout > 0 ? configuredRequestTimeout : defaultRequestTimeout;
+    }
+
     /**
      * Adds the {@link org.eclipse.jetty.servlets.DoSFilter} to the specified context and path. Limits incoming web requests to {@code maxWebRequestsPerSecond} per second.
      *
      * @param path the path to apply this filter
      * @param webAppContext the context to apply this filter
      * @param maxWebRequestsPerSecond the maximum number of allowed requests per second
      */
-    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond) {
+    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond, long requestTimeoutInMilliseconds, final String ipWhitelist) {
         FilterHolder holder = new FilterHolder(DoSFilter.class);
         holder.setInitParameters(new HashMap<String, String>() {{
             put("maxRequestsPerSec", String.valueOf(maxWebRequestsPerSecond));
+            put("maxRequestMs", String.valueOf(requestTimeoutInMilliseconds));
+            put("ipWhitelist", String.valueOf(ipWhitelist));
         }});
         holder.setName(DoSFilter.class.getSimpleName());
-        logger.debug("Adding DoSFilter to context at path: " + path + " with max req/sec: " + maxWebRequestsPerSecond);
+
+        String ipWhitelistLoggable = ipWhitelist;
+        if(ipWhitelist == null) {
+            ipWhitelistLoggable = "none";
+        }
+        logger.info("Adding DoSFilter to context at path: {} with max req/sec: {}, request timeout: {} ms. Whitelisted IPs not subject to filter: {}",
+                path, maxWebRequestsPerSecond, requestTimeoutInMilliseconds, ipWhitelistLoggable);

Review comment:
       Ah great, I briefly looked for a way to do this. Thanks!




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

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



[GitHub] [nifi] turcsanyip commented on pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
turcsanyip commented on pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#issuecomment-814786327


   @thenatog Thanks for the review changes!
   @exceptionfactory I have no more comments, +1 from my side too.


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

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



[GitHub] [nifi] asfgit closed pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #4972:
URL: https://github.com/apache/nifi/pull/4972


   


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

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



[GitHub] [nifi] turcsanyip commented on a change in pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
turcsanyip commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r608197228



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -703,32 +705,48 @@ private static void addDenialOfServiceFilters(String path, WebAppContext webAppC
         }
     }
 
-    private static int determineMaxWebRequestsPerSecond(NiFiProperties props) {
+    private static int determineMaxWebRequestsPerSecond(final NiFiProperties props) {
         int defaultMaxRequestsPerSecond = Integer.parseInt(NiFiProperties.DEFAULT_WEB_MAX_REQUESTS_PER_SECOND);
         int configuredMaxRequestsPerSecond = 0;
         try {
             configuredMaxRequestsPerSecond = Integer.parseInt(props.getMaxWebRequestsPerSecond());
         } catch (final NumberFormatException e) {
-            logger.warn("Exception parsing property " + NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND + "; using default value: " + defaultMaxRequestsPerSecond);
+            logger.warn("Exception parsing property [{}]; using default value: [{}]", NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND, defaultMaxRequestsPerSecond);
         }
 
         return configuredMaxRequestsPerSecond > 0 ? configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
     }
 
+    private static long determineRequestTimeoutInMilliseconds(final NiFiProperties props) {
+        long defaultRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(NiFiProperties.DEFAULT_WEB_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS));
+        long configuredRequestTimeout = 0L;
+        try {
+            configuredRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(props.getWebRequestTimeout(), TimeUnit.MILLISECONDS));
+        } catch (final NumberFormatException e) {
+            logger.warn("Exception parsing property [{}]; using default value: [{}]", NiFiProperties.WEB_REQUEST_TIMEOUT, defaultRequestTimeout);
+        }
+
+        return configuredRequestTimeout > 0 ? configuredRequestTimeout : defaultRequestTimeout;
+    }
+
     /**
      * Adds the {@link org.eclipse.jetty.servlets.DoSFilter} to the specified context and path. Limits incoming web requests to {@code maxWebRequestsPerSecond} per second.
      *
      * @param path the path to apply this filter
      * @param webAppContext the context to apply this filter
      * @param maxWebRequestsPerSecond the maximum number of allowed requests per second
      */
-    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond) {
+    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond, long requestTimeoutInMilliseconds, final String ipWhitelist) {

Review comment:
       @thenatog Thanks for extending the configuration capabilities of `DoSFilter`.
   
   Could you please update the method's javadoc as well?
   Furthermore, as this method configures not only the request rate but also the timeout now, I would consider to rename it to `addWebRequestLimitingFilter` or something similar.




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

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



[GitHub] [nifi] turcsanyip commented on a change in pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
turcsanyip commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r608197228



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -703,32 +705,48 @@ private static void addDenialOfServiceFilters(String path, WebAppContext webAppC
         }
     }
 
-    private static int determineMaxWebRequestsPerSecond(NiFiProperties props) {
+    private static int determineMaxWebRequestsPerSecond(final NiFiProperties props) {
         int defaultMaxRequestsPerSecond = Integer.parseInt(NiFiProperties.DEFAULT_WEB_MAX_REQUESTS_PER_SECOND);
         int configuredMaxRequestsPerSecond = 0;
         try {
             configuredMaxRequestsPerSecond = Integer.parseInt(props.getMaxWebRequestsPerSecond());
         } catch (final NumberFormatException e) {
-            logger.warn("Exception parsing property " + NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND + "; using default value: " + defaultMaxRequestsPerSecond);
+            logger.warn("Exception parsing property [{}]; using default value: [{}]", NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND, defaultMaxRequestsPerSecond);
         }
 
         return configuredMaxRequestsPerSecond > 0 ? configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
     }
 
+    private static long determineRequestTimeoutInMilliseconds(final NiFiProperties props) {
+        long defaultRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(NiFiProperties.DEFAULT_WEB_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS));
+        long configuredRequestTimeout = 0L;
+        try {
+            configuredRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(props.getWebRequestTimeout(), TimeUnit.MILLISECONDS));
+        } catch (final NumberFormatException e) {
+            logger.warn("Exception parsing property [{}]; using default value: [{}]", NiFiProperties.WEB_REQUEST_TIMEOUT, defaultRequestTimeout);
+        }
+
+        return configuredRequestTimeout > 0 ? configuredRequestTimeout : defaultRequestTimeout;
+    }
+
     /**
      * Adds the {@link org.eclipse.jetty.servlets.DoSFilter} to the specified context and path. Limits incoming web requests to {@code maxWebRequestsPerSecond} per second.
      *
      * @param path the path to apply this filter
      * @param webAppContext the context to apply this filter
      * @param maxWebRequestsPerSecond the maximum number of allowed requests per second
      */
-    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond) {
+    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond, long requestTimeoutInMilliseconds, final String ipWhitelist) {

Review comment:
       @thenatog Thanks for extending the configuration capabilities of `DoSFilter`.
   
   Could you please update the method's javadoc as well?
   Furthermore, as this method configures not only the request rate but also the timeout not, I would consider to rename it to `addWebRequestLimitingFilter` or something similar.




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

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



[GitHub] [nifi] thenatog commented on pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
thenatog commented on pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#issuecomment-813790301


   I agree that the IP whitelisting is more representative of how the DoS should work rather than excluding the S2S paths. Testing this out it seems like the whitelist is only applied to the request rate tracking, as the timeout method onRequestTimeout() doesn't seem to call checkWhitelist(), confirmed by docs http://archive.eclipse.org/jetty/8.0.0.M1/apidocs/org/eclipse/jetty/servlets/DoSFilter.html


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

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



[GitHub] [nifi] thenatog commented on a change in pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
thenatog commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r608077463



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/pom.xml
##########
@@ -256,5 +256,10 @@
             <version>${nifi.groovy.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-servlets</artifactId>

Review comment:
       Ah yes, should have been removed along with the NiFiDoSFilter. Will remove.




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

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



[GitHub] [nifi] thenatog commented on a change in pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
thenatog commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r607225636



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/requests/FilterPathUtil.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.nifi.web.security.requests;
+
+import org.apache.nifi.logging.NiFiLog;
+import javax.servlet.Filter;
+
+import org.eclipse.jetty.servlets.DoSFilter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+
+class FilterPathUtil {
+    private static final Logger logger = new NiFiLog(LoggerFactory.getLogger(FilterPathUtil.class));
+    private static final List<String> BYPASS_URI_PREFIXES = Arrays.asList("/nifi-api/data-transfer", "/nifi-api/site-to-site");
+
+    public static void bypassExcludedPaths(ServletRequest request, ServletResponse response, FilterChain chain, final String filterName) throws IOException, ServletException {

Review comment:
       This is actually unused, will remove.




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

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



[GitHub] [nifi] exceptionfactory commented on pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#issuecomment-814520389


   Thanks for making the documentation updates @thenatog!  With these changes, I am +1.  Do you have any additional feedback @turcsanyip?


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

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



[GitHub] [nifi] exceptionfactory commented on pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#issuecomment-814876578


   > @thenatog Thanks for the review changes!
   > @exceptionfactory I have no more comments, +1 from my side too.
   
   Thanks for the confirmation @turcsanyip! Merging.


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

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



[GitHub] [nifi] thenatog commented on a change in pull request #4972: NIFI-7912 - Added a Denial of Service filter wrapper called NiFiDoSFi…

Posted by GitBox <gi...@apache.org>.
thenatog commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r608255660



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -703,32 +705,48 @@ private static void addDenialOfServiceFilters(String path, WebAppContext webAppC
         }
     }
 
-    private static int determineMaxWebRequestsPerSecond(NiFiProperties props) {
+    private static int determineMaxWebRequestsPerSecond(final NiFiProperties props) {
         int defaultMaxRequestsPerSecond = Integer.parseInt(NiFiProperties.DEFAULT_WEB_MAX_REQUESTS_PER_SECOND);
         int configuredMaxRequestsPerSecond = 0;
         try {
             configuredMaxRequestsPerSecond = Integer.parseInt(props.getMaxWebRequestsPerSecond());
         } catch (final NumberFormatException e) {
-            logger.warn("Exception parsing property " + NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND + "; using default value: " + defaultMaxRequestsPerSecond);
+            logger.warn("Exception parsing property [{}]; using default value: [{}]", NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND, defaultMaxRequestsPerSecond);
         }
 
         return configuredMaxRequestsPerSecond > 0 ? configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
     }
 
+    private static long determineRequestTimeoutInMilliseconds(final NiFiProperties props) {
+        long defaultRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(NiFiProperties.DEFAULT_WEB_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS));
+        long configuredRequestTimeout = 0L;
+        try {
+            configuredRequestTimeout = Math.round(FormatUtils.getPreciseTimeDuration(props.getWebRequestTimeout(), TimeUnit.MILLISECONDS));
+        } catch (final NumberFormatException e) {
+            logger.warn("Exception parsing property [{}]; using default value: [{}]", NiFiProperties.WEB_REQUEST_TIMEOUT, defaultRequestTimeout);
+        }
+
+        return configuredRequestTimeout > 0 ? configuredRequestTimeout : defaultRequestTimeout;
+    }
+
     /**
      * Adds the {@link org.eclipse.jetty.servlets.DoSFilter} to the specified context and path. Limits incoming web requests to {@code maxWebRequestsPerSecond} per second.
      *
      * @param path the path to apply this filter
      * @param webAppContext the context to apply this filter
      * @param maxWebRequestsPerSecond the maximum number of allowed requests per second
      */
-    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond) {
+    private static void addWebRequestRateLimitingFilter(String path, WebAppContext webAppContext, int maxWebRequestsPerSecond, long requestTimeoutInMilliseconds, final String ipWhitelist) {

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.

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