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 2020/02/27 03:09:15 UTC

[GitHub] [nifi] jtstorck opened a new pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

jtstorck opened a new pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095
 
 
   …ssor supporting kerberos passwords
   
   AbstractHadoopProcessor will always authenticate the principal with a KerberosUser implementation and a UGI will be acquired from the Subject associated with the KerberosUser implementation
   AbstractHadoopProcessor's getUserGroupInformation method will now attempt to check the TGT and relogin if a KerberosUser impelmentation is available, otherwise it will return the UGI referenced in the HdfsResource instance
   Updated AbstractHadoopProcessor's customValidate method to consider the provided password and updated validation failure explanations when a KerberosCredentialsService is specified together with a principal, password, or keytab
   Added toString method override to AbstractKerberosUser
   Updated Hive/HBase components to be compatible with the KerberosProperties.validatePrincipalWithKeytabOrPassword method
   Fixed null ComponentLog in GetHDFSSequenceFileTest
   
   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 `master`)?
   
   - [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?
   - [ ] Have you verified that the full build is successful on both JDK 8 and JDK 11?
   - [n/a] 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 travis-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


With regards,
Apache Git Services

[GitHub] [nifi] bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#discussion_r385716783
 
 

 ##########
 File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
 ##########
 @@ -216,20 +230,20 @@ protected KerberosProperties getKerberosProperties(File kerberosConfigFile) {
                     .build());
         }
 
-        if (credentialsService != null && (explicitPrincipal != null || explicitKeytab != null)) {
+        if (credentialsService != null && (explicitPrincipal != null || explicitKeytab != null || explicitPassword != null)) {
             results.add(new ValidationResult.Builder()
                 .subject("Kerberos Credentials")
                 .valid(false)
-                .explanation("Cannot specify both a Kerberos Credentials Service and a principal/keytab")
+                .explanation("Cannot specify a Kerberos Credentials Service while also specifying a Kerberos Principal, Kerberos Keytab, or Kerberos Password")
                 .build());
         }
 
-        final String allowExplicitKeytabVariable = System.getenv(ALLOW_EXPLICIT_KEYTAB);
-        if ("false".equalsIgnoreCase(allowExplicitKeytabVariable) && (explicitPrincipal != null || explicitKeytab != null)) {
+        final String allowExplicitKeytabVariable = getAllowExplicitKeytabEnvironmentVariable();
+        if ("false".equalsIgnoreCase(allowExplicitKeytabVariable) && explicitKeytab != null) {
 
 Review comment:
   Do we want this line to be unchanged from the original logic?
   
   Before it was `&& (explicitPrincipal != null || explicitKeytab != null)`

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


With regards,
Apache Git Services

[GitHub] [nifi] jtstorck commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
jtstorck commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#discussion_r385384759
 
 

 ##########
 File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/hadoop/SecurityUtil.java
 ##########
 @@ -69,6 +79,37 @@ public static synchronized UserGroupInformation loginKerberos(final Configuratio
         return UserGroupInformation.getCurrentUser();
     }
 
+    public static synchronized UserGroupInformation loginKerberosWithPassword(final Configuration config, final String principal, final String password) throws IOException {
+        Validate.notNull(config);
+        Validate.notNull(principal);
+        Validate.notNull(password);
+
+        KerberosPasswordUser kerberosPasswordUser = new KerberosPasswordUser(principal, password);
+        return getUgiForKerberosUser(config, kerberosPasswordUser);
+    }
+
+    public static synchronized UserGroupInformation getUgiForKerberosUser(final Configuration config, final KerberosUser kerberosUser) throws IOException {
+        UserGroupInformation.setConfiguration(config);
+        try {
+            if (kerberosUser.isLoggedIn()) {
+                kerberosUser.checkTGTAndRelogin();
+            } else {
+                kerberosUser.login();
+            }
+            return kerberosUser.doAs((PrivilegedExceptionAction<UserGroupInformation>) () -> {
+                AccessControlContext context = AccessController.getContext();
+                Subject subject = Subject.getSubject(context);
+                Validate.notEmpty(
+                        subject.getPrincipals(KerberosPrincipal.class).stream().filter(p -> p.getName().startsWith(kerberosUser.getPrincipal())).collect(Collectors.toSet()),
+                        "No Subject was found matching the given principal");
+                return UserGroupInformation.getUGIFromSubject(subject);
+            });
+        } catch (PrivilegedActionException | LoginException e) {
+            throw new IOException("Unable to acquire UGI for KerberosUser: " + e.getLocalizedMessage(),
 
 Review comment:
   Updated the code to use the message from the wrapped exception, and split the unified catch into two distinct catch clauses.

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


With regards,
Apache Git Services

[GitHub] [nifi] bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#discussion_r385266765
 
 

 ##########
 File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/hadoop/SecurityUtil.java
 ##########
 @@ -69,6 +79,37 @@ public static synchronized UserGroupInformation loginKerberos(final Configuratio
         return UserGroupInformation.getCurrentUser();
     }
 
+    public static synchronized UserGroupInformation loginKerberosWithPassword(final Configuration config, final String principal, final String password) throws IOException {
 
 Review comment:
   I think this unused at this point since the KerberoUser's are created outside and everything goes through getUgiFromKerberosUser, but I'm not against keeping the method if you want.

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


With regards,
Apache Git Services

[GitHub] [nifi] jtstorck commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
jtstorck commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#discussion_r385456587
 
 

 ##########
 File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
 ##########
 @@ -216,21 +230,22 @@ protected KerberosProperties getKerberosProperties(File kerberosConfigFile) {
                     .build());
         }
 
-        if (credentialsService != null && (explicitPrincipal != null || explicitKeytab != null)) {
+        if (credentialsService != null && (explicitPrincipal != null || explicitKeytab != null || explicitPassword != null)) {
             results.add(new ValidationResult.Builder()
                 .subject("Kerberos Credentials")
                 .valid(false)
-                .explanation("Cannot specify both a Kerberos Credentials Service and a principal/keytab")
+                .explanation("Cannot specify a Kerberos Credentials Service while also specifying a Kerberos Principal, Kerberos Keytab, or Kerberos Password")
                 .build());
         }
 
         final String allowExplicitKeytabVariable = System.getenv(ALLOW_EXPLICIT_KEYTAB);
-        if ("false".equalsIgnoreCase(allowExplicitKeytabVariable) && (explicitPrincipal != null || explicitKeytab != null)) {
+        if ("false".equalsIgnoreCase(allowExplicitKeytabVariable) && (explicitPrincipal != null || explicitKeytab != null || explicitPassword != null)) {
 
 Review comment:
   Updated the code to allow that scenario, and added a unit test to verify the validation logic in AbstractHadoopProcessor.  This works in conjunction with the added test cases in TestKerberosProperties  to validate principal/keytab/password combinations.

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


With regards,
Apache Git Services

[GitHub] [nifi] bbende commented on issue #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
bbende commented on issue #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#issuecomment-592555067
 
 
   Everything looks good here, going to merge

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


With regards,
Apache Git Services

[GitHub] [nifi] bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#discussion_r385745477
 
 

 ##########
 File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
 ##########
 @@ -216,20 +230,20 @@ protected KerberosProperties getKerberosProperties(File kerberosConfigFile) {
                     .build());
         }
 
-        if (credentialsService != null && (explicitPrincipal != null || explicitKeytab != null)) {
+        if (credentialsService != null && (explicitPrincipal != null || explicitKeytab != null || explicitPassword != null)) {
             results.add(new ValidationResult.Builder()
                 .subject("Kerberos Credentials")
                 .valid(false)
-                .explanation("Cannot specify both a Kerberos Credentials Service and a principal/keytab")
+                .explanation("Cannot specify a Kerberos Credentials Service while also specifying a Kerberos Principal, Kerberos Keytab, or Kerberos Password")
                 .build());
         }
 
-        final String allowExplicitKeytabVariable = System.getenv(ALLOW_EXPLICIT_KEYTAB);
-        if ("false".equalsIgnoreCase(allowExplicitKeytabVariable) && (explicitPrincipal != null || explicitKeytab != null)) {
+        final String allowExplicitKeytabVariable = getAllowExplicitKeytabEnvironmentVariable();
+        if ("false".equalsIgnoreCase(allowExplicitKeytabVariable) && explicitKeytab != null) {
 
 Review comment:
   Never mind this comment, I see now that we need to change the logic for the case where ALLOW_EXPLICIT_KEYTAB is false and they use a principal + password.

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


With regards,
Apache Git Services

[GitHub] [nifi] jtstorck commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
jtstorck commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#discussion_r385457230
 
 

 ##########
 File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/hadoop/SecurityUtil.java
 ##########
 @@ -69,6 +79,37 @@ public static synchronized UserGroupInformation loginKerberos(final Configuratio
         return UserGroupInformation.getCurrentUser();
     }
 
+    public static synchronized UserGroupInformation loginKerberosWithPassword(final Configuration config, final String principal, final String password) throws IOException {
 
 Review comment:
   Agreed on removing it.  We don't want, at this point anyway, to get a UGI without being able to associate the KerberosUser from which it was created.  I removed the 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


With regards,
Apache Git Services

[GitHub] [nifi] bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#discussion_r385260904
 
 

 ##########
 File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/hadoop/SecurityUtil.java
 ##########
 @@ -69,6 +79,37 @@ public static synchronized UserGroupInformation loginKerberos(final Configuratio
         return UserGroupInformation.getCurrentUser();
     }
 
+    public static synchronized UserGroupInformation loginKerberosWithPassword(final Configuration config, final String principal, final String password) throws IOException {
+        Validate.notNull(config);
+        Validate.notNull(principal);
+        Validate.notNull(password);
+
+        KerberosPasswordUser kerberosPasswordUser = new KerberosPasswordUser(principal, password);
+        return getUgiForKerberosUser(config, kerberosPasswordUser);
+    }
+
+    public static synchronized UserGroupInformation getUgiForKerberosUser(final Configuration config, final KerberosUser kerberosUser) throws IOException {
+        UserGroupInformation.setConfiguration(config);
+        try {
+            if (kerberosUser.isLoggedIn()) {
+                kerberosUser.checkTGTAndRelogin();
+            } else {
+                kerberosUser.login();
+            }
+            return kerberosUser.doAs((PrivilegedExceptionAction<UserGroupInformation>) () -> {
+                AccessControlContext context = AccessController.getContext();
+                Subject subject = Subject.getSubject(context);
+                Validate.notEmpty(
+                        subject.getPrincipals(KerberosPrincipal.class).stream().filter(p -> p.getName().startsWith(kerberosUser.getPrincipal())).collect(Collectors.toSet()),
+                        "No Subject was found matching the given principal");
+                return UserGroupInformation.getUGIFromSubject(subject);
+            });
+        } catch (PrivilegedActionException | LoginException e) {
+            throw new IOException("Unable to acquire UGI for KerberosUser: " + e.getLocalizedMessage(),
 
 Review comment:
   In the case of PrivilegedActionException, the message is always null because they expect you to get the message from first calling getException() or getCause() and then getting the message from that, so you may want to do that first here depending which type of exception.

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


With regards,
Apache Git Services

[GitHub] [nifi] bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095#discussion_r385264638
 
 

 ##########
 File path: nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
 ##########
 @@ -216,21 +230,22 @@ protected KerberosProperties getKerberosProperties(File kerberosConfigFile) {
                     .build());
         }
 
-        if (credentialsService != null && (explicitPrincipal != null || explicitKeytab != null)) {
+        if (credentialsService != null && (explicitPrincipal != null || explicitKeytab != null || explicitPassword != null)) {
             results.add(new ValidationResult.Builder()
                 .subject("Kerberos Credentials")
                 .valid(false)
-                .explanation("Cannot specify both a Kerberos Credentials Service and a principal/keytab")
+                .explanation("Cannot specify a Kerberos Credentials Service while also specifying a Kerberos Principal, Kerberos Keytab, or Kerberos Password")
                 .build());
         }
 
         final String allowExplicitKeytabVariable = System.getenv(ALLOW_EXPLICIT_KEYTAB);
-        if ("false".equalsIgnoreCase(allowExplicitKeytabVariable) && (explicitPrincipal != null || explicitKeytab != null)) {
+        if ("false".equalsIgnoreCase(allowExplicitKeytabVariable) && (explicitPrincipal != null || explicitKeytab != null || explicitPassword != null)) {
 
 Review comment:
   I'm not sure if we want to include password into this logic. If ALLOW_EXPLICIT_KEYTAB=false, it seems valid to still use principal+password.

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


With regards,
Apache Git Services

[GitHub] [nifi] asfgit closed pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #4095: NIFI-7018: Initial commit of processors extending AbstractHadoopProce…
URL: https://github.com/apache/nifi/pull/4095
 
 
   

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


With regards,
Apache Git Services