Skip to content

Commit

Permalink
[FLINK-5055][security] skip Hadoop UGI login if unsecured
Browse files Browse the repository at this point in the history
The new Kerberos authentication code in Flink assumed that it's running
against vanilla Hadoop. Original Hadoop's behavior is to skip a secure
login if security is not configured. This is different for other
distributions, e.g. the MapR Hadoop distribution of Hadoop.

Thus, we need to make sure we don't perform any login action if security
is not configured.

This also performs minor code cleanup.

This closes apache#2864.
  • Loading branch information
mxm committed Nov 25, 2016
1 parent 870e219 commit 1b2f3c0
Show file tree
Hide file tree
Showing 16 changed files with 392 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import org.apache.flink.runtime.messages.JobManagerMessages.StoppingFailure;
import org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint;
import org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointSuccess;
import org.apache.flink.runtime.security.SecurityContext;
import org.apache.flink.runtime.security.SecurityUtils;
import org.apache.flink.runtime.util.EnvironmentInformation;
import org.apache.flink.util.Preconditions;
import org.apache.flink.util.StringUtils;
Expand All @@ -97,6 +97,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import static org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint;
Expand Down Expand Up @@ -1111,11 +1112,11 @@ public static void main(final String[] args) {

try {
final CliFrontend cli = new CliFrontend();
SecurityContext.install(new SecurityContext.SecurityConfiguration().setFlinkConfiguration(cli.config));
int retCode = SecurityContext.getInstalled()
.runSecured(new SecurityContext.FlinkSecuredRunner<Integer>() {
SecurityUtils.install(new SecurityUtils.SecurityConfiguration(cli.config));
int retCode = SecurityUtils.getInstalledContext()
.runSecured(new Callable<Integer>() {
@Override
public Integer run() {
public Integer call() {
return cli.parseParameters(args);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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
*
* https://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.flink.runtime.security;

import org.apache.flink.util.Preconditions;
import org.apache.hadoop.security.UserGroupInformation;

import java.security.PrivilegedExceptionAction;
import java.util.concurrent.Callable;

/*
* Process-wide security context object which initializes UGI with appropriate security credentials and also it
* creates in-memory JAAS configuration object which will serve appropriate ApplicationConfigurationEntry for the
* connector login module implementation that authenticates Kerberos identity using SASL/JAAS based mechanism.
*/
class HadoopSecurityContext implements SecurityContext {

private UserGroupInformation ugi;

HadoopSecurityContext(UserGroupInformation ugi) {
this.ugi = Preconditions.checkNotNull(ugi, "UGI passed cannot be null");
}

public <T> T runSecured(final Callable<T> securedCallable) throws Exception {
return ugi.doAs(new PrivilegedExceptionAction<T>() {
@Override
public T run() throws Exception {
return securedCallable.call();
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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
*
* https://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.flink.runtime.security;

import java.util.concurrent.Callable;

/**
* A security context that simply runs a Callable without performing a login action.
*/
class NoOpSecurityContext implements SecurityContext {

@Override
public <T> T runSecured(Callable<T> securedCallable) throws Exception {
return securedCallable.call();
}

}
Loading

0 comments on commit 1b2f3c0

Please sign in to comment.