Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-8286][Security] Fix kerberos security configuration for YarnTaskExecutor #5896

Closed
wants to merge 3 commits into from

Conversation

suez1224
Copy link

What is the purpose of the change

Fix broken YARN kerberos integration for flip-6.

Brief change log

  • Fix kerberos onfigurations.
  • Refactor code.
  • Add unittest.

Verifying this change

This change added tests and can be verified as follows:

  • *Added test that validates kerberos credentials are set correctly *

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): ( no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (no )
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (not applicable)

FileSystem.initialize(configuration);
} catch (Throwable t) {
LOG.error(t.getMessage(), t);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this exception being swallowed?

Copy link
Author

Choose a reason for hiding this comment

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

Good point. Added exceptions to method signature and let caller handle it.

UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();

LOG.info("YARN daemon is running as: {} Yarn client user obtainer: {}",
currentUser.getShortUserName(), yarnClientUsername);

File f = new File(currDir, Utils.KEYTAB_FILE_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the only change really that we always do this instead of having the check on remoteKeytabPath, as the old code had?

The old code had this on line 120:

if (remoteKeytabPath != null) {
	File f = new File(currDir, Utils.KEYTAB_FILE_NAME);
	keytabPath = f.getAbsolutePath();
	LOG.info("keytab path: {}", keytabPath);
}

Copy link
Author

Choose a reason for hiding this comment

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

No, this is a refactoring becaust that part of code is kinda redundant.

The real change is moving this code block below before the call to "new SecurityConfiguration()":

configuration.setString(SecurityOptions.KERBEROS_LOGIN_KEYTAB, f.getAbsolutePath());
configuration.setString(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL, remoteKeytabPrincipal);

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, could you maybe split this PR in two commits then? One that does the refactoring and one that does the actual fix. This way, it's clearer what exactly the fix is.

Copy link
Author

Choose a reason for hiding this comment

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

@aljoscha done, please take another look. Thanks.

Copy link
Author

@suez1224 suez1224 left a comment

Choose a reason for hiding this comment

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

@aljoscha thanks for the review. I've replied to the comments, could you please take another look?

FileSystem.initialize(configuration);
} catch (Throwable t) {
LOG.error(t.getMessage(), t);
Copy link
Author

Choose a reason for hiding this comment

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

Good point. Added exceptions to method signature and let caller handle it.

UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();

LOG.info("YARN daemon is running as: {} Yarn client user obtainer: {}",
currentUser.getShortUserName(), yarnClientUsername);

File f = new File(currDir, Utils.KEYTAB_FILE_NAME);
Copy link
Author

Choose a reason for hiding this comment

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

No, this is a refactoring becaust that part of code is kinda redundant.

The real change is moving this code block below before the call to "new SecurityConfiguration()":

configuration.setString(SecurityOptions.KERBEROS_LOGIN_KEYTAB, f.getAbsolutePath());
configuration.setString(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL, remoteKeytabPrincipal);

@aljoscha
Copy link
Contributor

aljoscha commented May 8, 2018

@suez1224 I'll now merge the actual fix, but I'm not 100 % sure the refactoring is correct.

After the fix, we have roughly this path through the code:

if (keytabPath != null && remoteKeytabPrincipal != null) {
	configuration.setString(SecurityOptions.KERBEROS_LOGIN_KEYTAB, keytabPath);
	configuration.setString(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL, remoteKeytabPrincipal);
}

SecurityConfiguration sc = new SecurityConfiguration(configuration);

SecurityUtils.install(sc);

SecurityUtils.getInstalledContext().runSecured(new Callable<Void>() {
	@Override
	public Void call() throws Exception {
		TaskManagerRunner.runTaskManager(configuration, new ResourceID(containerId));
		return null;
	}
});

after the fix, that becomes

// in main()
SecurityUtils.getInstalledContext().runSecured(
   YarnTaskExecutorRunnerFactory.create(System.getenv()));

// in YarnTaskExecutorRunnerFactory.create()
if (keytabPath != null && remoteKeytabPrincipal != null) {
	configuration.setString(SecurityOptions.KERBEROS_LOGIN_KEYTAB, keytabPath);
	configuration.setString(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL, remoteKeytabPrincipal);
}

SecurityConfiguration sc = new SecurityConfiguration(configuration);

SecurityUtils.install(sc);

return new Runner()

Meaning, that if someone messes with how things are called it can happen that SecurityUtils.getInstalledContext() is called before SecurityUtils.install(sc) is called in YarnTaskExecutorRunnerFactory.create. I think this can potentially lead to problems and the old path is much clearer. What do you think?

@aljoscha
Copy link
Contributor

aljoscha commented May 8, 2018

Merged, could you please close the PR after discussion of the refactoring?

@suez1224
Copy link
Author

suez1224 commented May 9, 2018

@aljoscha that's a very good catch. I added another commit to make sure the call order is always correct (1298b04). Could you please let me know what you think? I think we should have the unittest in place since this is the second time it breaks. I can create another PR for the refactoring commit.

@EronWright
Copy link
Contributor

This PR seems to obfuscate the fix. The issue was with the interpretation of the keytab path, right? But the bulk of the change was to clarify the ordering of context installation vs use?

@aljoscha
Copy link
Contributor

@EronWright the fix is really one this: ba3e271 But I haven't yet managed to reproduce a failure on my system without the fix. Still working on it.

@aljoscha
Copy link
Contributor

@suez1224 Did you rebase on master? I think that krb5-specific could should not be there anymore.

@rmetzger
Copy link
Contributor

@aljoscha @suez1224 This PR appears to be a stale open PR, even though it seem to contain something merged.
I propose to close this PR, and file a JIRA ticket for the refactoring?

@tillrohrmann
Copy link
Contributor

Closing this PR as it seems to be abandoned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants