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/06 11:06:23 UTC

[GitHub] [nifi] gresockj opened a new pull request #4976: NIFI-3862: Added Issuer DN support to ListenHTTP

gresockj opened a new pull request #4976:
URL: https://github.com/apache/nifi/pull/4976


   #### Description of PR
   
   Beyond just adding the restlistener.remote.issuer.dn attribute to flow files coming out of the ListenHTTP processor, this patch adds an optional "Authorized Issuer DN Pattern" property to ListenHTTP, which will allow finer-grained authorization of users.
   
   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?
   - [X] 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:
   - [X] 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] gresockj commented on a change in pull request #4976: NIFI-3862: Added Issuer DN support to ListenHTTP

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



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/ListenHTTPServlet.java
##########
@@ -335,8 +348,9 @@ public void process(final OutputStream rawOut) throws IOException {
             }
 
             flowFile = session.putAllAttributes(flowFile, attributes);
-            flowFile = saveRequestDetailsAsAttributes(request, session, foundSubject, flowFile);
-            session.getProvenanceReporter().receive(flowFile, request.getRequestURL().toString(), sourceSystemFlowFileIdentifier, "Remote DN=" + foundSubject, transferMillis);
+            flowFile = saveRequestDetailsAsAttributes(request, session, foundSubject, foundIssuer, flowFile);
+            final String details = String.format("Remote DN=%s, Issuer DN=%s", foundSubject, foundIssuer);
+            session.getProvenanceReporter().receive(flowFile, request.getRequestURL().toString(), sourceSystemFlowFileIdentifier, details + foundIssuer, transferMillis);

Review comment:
       Yep, certainly a typo.




-- 
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 #4976: NIFI-3862: Added Issuer DN support to ListenHTTP

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


   


-- 
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 #4976: NIFI-3862: Added Issuer DN support to ListenHTTP

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



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/ListenHTTPServlet.java
##########
@@ -180,14 +184,22 @@ protected void doPost(final HttpServletRequest request, final HttpServletRespons
 
             final X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
             foundSubject = DEFAULT_FOUND_SUBJECT;
+            foundIssuer = DEFAULT_FOUND_ISSUER;
             if (certs != null && certs.length > 0) {
                 for (final X509Certificate cert : certs) {
                     foundSubject = cert.getSubjectDN().getName();
+                    foundIssuer = cert.getIssuerDN().getName();
                     if (authorizedPattern.matcher(foundSubject).matches()) {
-                        break;
+                        if (authorizedIssuerPattern.matcher(foundIssuer).matches()) {
+                            break;
+                        } else {
+                            logger.warn("Rejecting transfer attempt from " + foundSubject + ", Issuer " + foundIssuer + " because the Issuer is not authorized, host=" + request.getRemoteHost());

Review comment:
       Recommend adjusting the log message to use placeholders and indicating the host first:
   ```suggestion
                               logger.warn("Access Forbidden [Issuer not authorized] Host [{}] Subject [{}] Issuer [{}]", request.getRemoteHost(), foundSubject, foundIssuer);
   ```

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/ListenHTTPServlet.java
##########
@@ -335,8 +348,9 @@ public void process(final OutputStream rawOut) throws IOException {
             }
 
             flowFile = session.putAllAttributes(flowFile, attributes);
-            flowFile = saveRequestDetailsAsAttributes(request, session, foundSubject, flowFile);
-            session.getProvenanceReporter().receive(flowFile, request.getRequestURL().toString(), sourceSystemFlowFileIdentifier, "Remote DN=" + foundSubject, transferMillis);
+            flowFile = saveRequestDetailsAsAttributes(request, session, foundSubject, foundIssuer, flowFile);
+            final String details = String.format("Remote DN=%s, Issuer DN=%s", foundSubject, foundIssuer);
+            session.getProvenanceReporter().receive(flowFile, request.getRequestURL().toString(), sourceSystemFlowFileIdentifier, details + foundIssuer, transferMillis);

Review comment:
       It looks like the concatenation of `details` and `foundIssuer` should be changed to just `details`:
   ```suggestion
               session.getProvenanceReporter().receive(flowFile, request.getRequestURL().toString(), sourceSystemFlowFileIdentifier, details, transferMillis);
   ```

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java
##########
@@ -298,6 +299,56 @@ public void testSecureTwoWaySslPOSTRequestsReceivedWithoutEL() throws Exception
         testPOSTRequestsReceived(HttpServletResponse.SC_OK, true, true);
     }
 
+    @Test
+    public void testSecureTwoWaySslPOSTRequestsReceivedWithAuthorizedSubjectDn() throws Exception {

Review comment:
       Is this test method necessary in light of existing unit tests that rely on the default Authorized DN Pattern?

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenHTTP.java
##########
@@ -159,11 +160,18 @@ public AllowableValue getAllowableValue() {
             .build();
     public static final PropertyDescriptor AUTHORIZED_DN_PATTERN = new PropertyDescriptor.Builder()
         .name("Authorized DN Pattern")
-        .description("A Regular Expression to apply against the Distinguished Name of incoming connections. If the Pattern does not match the DN, the connection will be refused.")
+        .description("A Regular Expression to apply against the Subject's Distinguished Name of incoming connections. If the Pattern does not match the Subject DN, the connection will be refused.")

Review comment:
       Although the existing description says that "the connection will be refused", recommend taking the opportunity to be more precise and write something like "the processor will respond with a status of HTTP 403 Forbidden".

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java
##########
@@ -298,6 +299,56 @@ public void testSecureTwoWaySslPOSTRequestsReceivedWithoutEL() throws Exception
         testPOSTRequestsReceived(HttpServletResponse.SC_OK, true, true);
     }
 
+    @Test
+    public void testSecureTwoWaySslPOSTRequestsReceivedWithAuthorizedSubjectDn() throws Exception {
+        configureProcessorSslContextService(ListenHTTP.ClientAuthentication.REQUIRED, serverConfiguration);
+
+        runner.setProperty(ListenHTTP.PORT, Integer.toString(availablePort));
+        runner.setProperty(ListenHTTP.AUTHORIZED_DN_PATTERN, LOCALHOST_DN);
+        runner.setProperty(ListenHTTP.BASE_PATH, HTTP_BASE_PATH);
+        runner.assertValid();
+
+        testPOSTRequestsReceived(HttpServletResponse.SC_OK, true, true);
+    }
+
+    @Test
+    public void testSecureTwoWaySslPOSTRequestsReceivedWithUnauthorizedSubjectDn() throws Exception {
+        configureProcessorSslContextService(ListenHTTP.ClientAuthentication.REQUIRED, serverConfiguration);
+
+        runner.setProperty(ListenHTTP.PORT, Integer.toString(availablePort));
+        runner.setProperty(ListenHTTP.AUTHORIZED_DN_PATTERN, "CN=other");
+        runner.setProperty(ListenHTTP.BASE_PATH, HTTP_BASE_PATH);
+        runner.assertValid();
+
+        testPOSTRequestsReceived(HttpServletResponse.SC_FORBIDDEN, true, true);
+    }
+
+    @Test
+    public void testSecureTwoWaySslPOSTRequestsReceivedWithAuthorizedIssuerDn() throws Exception {

Review comment:
       Is this test method necessary since the default pattern configuration allows access?

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/ListenHTTPServlet.java
##########
@@ -180,14 +184,22 @@ protected void doPost(final HttpServletRequest request, final HttpServletRespons
 
             final X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
             foundSubject = DEFAULT_FOUND_SUBJECT;
+            foundIssuer = DEFAULT_FOUND_ISSUER;
             if (certs != null && certs.length > 0) {
                 for (final X509Certificate cert : certs) {
                     foundSubject = cert.getSubjectDN().getName();
+                    foundIssuer = cert.getIssuerDN().getName();
                     if (authorizedPattern.matcher(foundSubject).matches()) {
-                        break;
+                        if (authorizedIssuerPattern.matcher(foundIssuer).matches()) {
+                            break;
+                        } else {
+                            logger.warn("Rejecting transfer attempt from " + foundSubject + ", Issuer " + foundIssuer + " because the Issuer is not authorized, host=" + request.getRemoteHost());
+                            response.sendError(HttpServletResponse.SC_FORBIDDEN, "not allowed based on issuer dn");
+                            return;
+                        }
                     } else {
-                        logger.warn("Rejecting transfer attempt from " + foundSubject + " because the DN is not authorized, host=" + request.getRemoteHost());
-                        response.sendError(HttpServletResponse.SC_FORBIDDEN, "not allowed based on dn");
+                        logger.warn("Rejecting transfer attempt from " + foundSubject + ", Issuer " + foundIssuer + " because the Subject is not authorized, host=" + request.getRemoteHost());

Review comment:
       Recommend taking the opportunity to reformat the warning message with placeholders:
   ```suggestion
                           logger.warn("Access Forbidden [Subject not authorized] Host [{}] Subject [{}] Issuer [{}]", request.getRemoteHost(), foundSubject, foundIssuer););
   ```




-- 
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 #4976: NIFI-3862: Added Issuer DN support to ListenHTTP

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



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenHTTP.java
##########
@@ -159,11 +160,20 @@ public AllowableValue getAllowableValue() {
             .build();
     public static final PropertyDescriptor AUTHORIZED_DN_PATTERN = new PropertyDescriptor.Builder()
         .name("Authorized DN Pattern")
-        .description("A Regular Expression to apply against the Distinguished Name of incoming connections. If the Pattern does not match the DN, the connection will be refused.")
+        .description("A Regular Expression to apply against the Subject's Distinguished Name of incoming connections. If the Pattern does not match the Subject DN, " +

Review comment:
       I would add "Subject" in the property name on the UI to make the Subject / Issuer distinction more clear. It can be achieved via adding `displayName` with value "Authorized Subject DN Pattern".
   (The existing `name` cannot be changed due to backward compatibility.)

##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenHTTP.java
##########
@@ -159,11 +160,20 @@ public AllowableValue getAllowableValue() {
             .build();
     public static final PropertyDescriptor AUTHORIZED_DN_PATTERN = new PropertyDescriptor.Builder()
         .name("Authorized DN Pattern")
-        .description("A Regular Expression to apply against the Distinguished Name of incoming connections. If the Pattern does not match the DN, the connection will be refused.")
+        .description("A Regular Expression to apply against the Subject's Distinguished Name of incoming connections. If the Pattern does not match the Subject DN, " +
+                "the the processor will respond with a status of HTTP 403 Forbidden.")
         .required(true)
-        .defaultValue(".*")
+        .defaultValue(MATCH_ALL)
         .addValidator(StandardValidators.REGULAR_EXPRESSION_VALIDATOR)
         .build();
+    public static final PropertyDescriptor AUTHORIZED_ISSUER_DN_PATTERN = new PropertyDescriptor.Builder()
+            .name("Authorized Issuer DN Pattern")

Review comment:
       It is preferred to use separate `name` / `displayName` attributes for new properties, like in case of "Multipart Request Max Size":
   ```
           .name("multipart-request-max-size")
           .displayName("Multipart Request Max Size")
   ```
   Could you please use the same pattern 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.

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



[GitHub] [nifi] gresockj commented on a change in pull request #4976: NIFI-3862: Added Issuer DN support to ListenHTTP

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



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java
##########
@@ -298,6 +299,56 @@ public void testSecureTwoWaySslPOSTRequestsReceivedWithoutEL() throws Exception
         testPOSTRequestsReceived(HttpServletResponse.SC_OK, true, true);
     }
 
+    @Test
+    public void testSecureTwoWaySslPOSTRequestsReceivedWithAuthorizedSubjectDn() throws Exception {

Review comment:
       Good point, will remove this one.




-- 
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] gresockj commented on a change in pull request #4976: NIFI-3862: Added Issuer DN support to ListenHTTP

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



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java
##########
@@ -298,6 +299,56 @@ public void testSecureTwoWaySslPOSTRequestsReceivedWithoutEL() throws Exception
         testPOSTRequestsReceived(HttpServletResponse.SC_OK, true, true);
     }
 
+    @Test
+    public void testSecureTwoWaySslPOSTRequestsReceivedWithAuthorizedSubjectDn() throws Exception {
+        configureProcessorSslContextService(ListenHTTP.ClientAuthentication.REQUIRED, serverConfiguration);
+
+        runner.setProperty(ListenHTTP.PORT, Integer.toString(availablePort));
+        runner.setProperty(ListenHTTP.AUTHORIZED_DN_PATTERN, LOCALHOST_DN);
+        runner.setProperty(ListenHTTP.BASE_PATH, HTTP_BASE_PATH);
+        runner.assertValid();
+
+        testPOSTRequestsReceived(HttpServletResponse.SC_OK, true, true);
+    }
+
+    @Test
+    public void testSecureTwoWaySslPOSTRequestsReceivedWithUnauthorizedSubjectDn() throws Exception {
+        configureProcessorSslContextService(ListenHTTP.ClientAuthentication.REQUIRED, serverConfiguration);
+
+        runner.setProperty(ListenHTTP.PORT, Integer.toString(availablePort));
+        runner.setProperty(ListenHTTP.AUTHORIZED_DN_PATTERN, "CN=other");
+        runner.setProperty(ListenHTTP.BASE_PATH, HTTP_BASE_PATH);
+        runner.assertValid();
+
+        testPOSTRequestsReceived(HttpServletResponse.SC_FORBIDDEN, true, true);
+    }
+
+    @Test
+    public void testSecureTwoWaySslPOSTRequestsReceivedWithAuthorizedIssuerDn() throws Exception {

Review comment:
       I wanted to show that configuring the subject and issuer DN patterns to something other than .* would actually work if the patterns matched, so I'd like to keep this one.




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