Skip to content

NIFI-5041 Adds SPNEGO authentication to LivySessionController#2630

Closed
peter-toth wants to merge 7 commits intoapache:masterfrom
peter-toth:NIFI-5041
Closed

NIFI-5041 Adds SPNEGO authentication to LivySessionController#2630
peter-toth wants to merge 7 commits intoapache:masterfrom
peter-toth:NIFI-5041

Conversation

@peter-toth
Copy link

Thank you for submitting a contribution to Apache NiFi.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

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

  • Has your PR been rebased against the latest commit within the target branch (typically master)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit tests to verify your changes?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • 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.

@peter-toth
Copy link
Author

This improvement of LivySessionController uses the KerberosCredentialsService to fetch a principal and a keytab and provide SPNEGO authentication towards a Livy server.

In the implementation I switched from HttpURLConnections to HttpClient, which can be configured to do an SPNEGO handshake.

@peter-toth
Copy link
Author

Some of the travis builds failed, but I don't see any issue in the logs except that the size of log exceeded 4MB. Could someone help me with this please?

@ottobackwards
Copy link
Contributor

It looks like the downloads are taking so long in travis that it is filling the log and causing the build to be terminated.

@mgaido91
Copy link
Contributor

@ottobackwards yes, I agree and since the build passing is the one in France, I assume we are downloading from an European mirror. Can we change this according to the place of build?

pom.xml Outdated
<org.slf4j.version>1.7.25</org.slf4j.version>
<ranger.version>0.7.1</ranger.version>
<jetty.version>9.4.3.v20170317</jetty.version>
<httpclient.version>4.5.5</httpclient.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per NIFI-4936, this needs to be pushed down to each NAR/bundle. In your case since you are using it in nifi-hadoop-utils, each NAR that has this as a dependency should declare it. If they already bring in httpclient, you'd likely need to reuse that version rather than setting it to 4.5.5, to avoid eviction.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I got this issue right. I removed this property and replaced it to a direct version specification where it was used. Is that enough?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see the issue now. I changed the httpclient and hadoop-auth dependency to "provided" in nifi-hadoop-util so they won't be included into all NARs depending on nifi-hadoop-util.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattyb149, could you please review my change and let me know if I did the right thing? Any suggestions are welcome.

I changed the httpclient dependency to provided so it won't get into all NARs depending on nifi-hadoop-utils. Unfortunately httpclient seems to change a lot from version to version and the minimum required version that my changes can work with is 4.4.1.

All my additions to hadoop-utils are in new classes, so I believe even a hadoop-utils dependent NAR that specifies a lower version of httpclient will be fine as long as it doesn't start to use my classes directly.

Change-Id: I1b87ec4752ff6e1603025883a72113919aba5dd4
Change-Id: I868fdf3ea7cfd28cf415164e420f23bf3f6eefeb
* Modified Kerberos configuration class from {@link org.apache.hadoop.security.authentication.client.KerberosAuthenticator.KerberosConfiguration}
* that requires authentication from a keytab.
*/
public class KerberosConfiguration extends javax.security.auth.login.Configuration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need an entry in the NOTICE for this class as it is derived from a class in hadoop-auth. See here for an example of such attribution. @joewitt does that sound right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the new entries.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattyb149, @joewitt can you please help me and review this PR and let me know if I need to change anything.

@mattyb149
Copy link
Contributor

The changes LGTM, and I tested on a secure cluster, verifying that I could connect, get a session, and execute some simple Scala/Spark code. However, when I tested with various unhappy paths including no Kerberos Credentials Service and a bad keytab, it seems we could be handling these situations better.

In the first case (no credentials), the /sessions endpoint will return HTML not JSON. This causes a bulletin to be issued, but the flow file is not penalized and/or the processor is not yielded, and the LivyControllerService thread to manage the sessions exits, meaning the flow will never proceed until the CS is restarted with the correct credentials. This could be considered a Livy bug (I didn't see an existing Jira), but we need to handle it for now.

I believe something similar happens for a bad keytab, but I didn't trace it back to the manageSessions thread or anything. I think we need to ensure that the manageSessions() thread is always running while the CS is enabled, we can pass any exceptions back to the CS so when the processor makes a call to the CS, we can throw the appropriate exception, etc.

…andling in session manager thread, fixes error returned in KerberosKeytabSPNegoScheme on authentication failure

Change-Id: I443e063ae21c446980087e5464a4b70373d730f6
@peter-toth
Copy link
Author

Hi @mattyb149,
Thanks for the feedback, I amended the error handling a bit:

  • Processor is yielded now if there is no session available
  • KerberosKeytabSPNegoScheme throws a ProcessException on a Kerberos error, so the flow file will be penalized automatically
  • CS session manager thread no longer dies on an exception, it goes to sleep instead and then retries to fill up the sessions

try {
manageSessions();
} catch (Exception e) {
getLogger().error("Livy Session Manager Thread run into an error, but continues to run", e);
Copy link
Contributor

@mattyb149 mattyb149 May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This keeps the manageSessions() thread alive, but will there be an indication on the UI that the error is not recoverable? I'm thinking specifically about the 401 Authorization Required error where the Livy API returns HTML rather than JSON when you try to log in without Kerberos when the server has been Kerberized. Should we set an AtomicReference<Exception> or something on the LivySessionController and throw a checked exception when any API call is made (such as isEmpty() which is called from ExecuteSparkInteractive)? I think we need to make it obvious (at least in that case) that the processor and/or CS is suffering from a non-recoverable error and needs manual intervention.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, changed to what you suggested.

… users

Change-Id: I33fde5df6933cec2a87a4d82e681d4464f21b459
private void checkSessionManagerError() throws IOException {
Exception exception = sessionManagerError;
if (exception != null) {
throw new IOException(exception);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this should be a custom exception type, probably thrown from the manageSession() thread itself and just propagated to the client via this method, in order to be able to tell the difference between an IOException that occurred from the mgmt thread vs an IOException that occurred from the operation the client is trying to perform. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea @mattyb149, added a new SessionManagerException

…urred on session manager thread

Change-Id: I25a52c025376a0cd238f14bda533d6f5f3e5fb4a
@mattyb149
Copy link
Contributor

+1 LGTM, ran full build with contrib-check, also tested on HDP 2.6.4 and HDP 3.0 with and without Kerberos enabled, verified all behaviors are as expected. Thanks for this improvement! Merging to master

@asfgit asfgit closed this in a1794b1 May 31, 2018
thenatog pushed a commit to thenatog/nifi that referenced this pull request Jun 4, 2018
NIFI-5041: fixes http client version issue

Change-Id: I1b87ec4752ff6e1603025883a72113919aba5dd4

NIFI-5041: fixes Kerberos configuration

Change-Id: I868fdf3ea7cfd28cf415164e420f23bf3f6eefeb

NIFI-5041: adds new NOTICE entries

NIFI-5041: yields processor if no session is available, fixes error handling in session manager thread, fixes error returned in KerberosKeytabSPNegoScheme on authentication failure

Change-Id: I443e063ae21c446980087e5464a4b70373d730f6

NIFI-5041: makes the session manager thread exceptions visible to the users

Change-Id: I33fde5df6933cec2a87a4d82e681d4464f21b459

NIFI-5041: adds special SessionManagerException to identify error occurred on session manager thread

Change-Id: I25a52c025376a0cd238f14bda533d6f5f3e5fb4a

This closes apache#2630

Signed-off-by: Matthew Burgess <mattyb149@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants