Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 60E8A200B83 for ; Sat, 3 Sep 2016 04:07:48 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 54304160ACB; Sat, 3 Sep 2016 02:07:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 99EC3160A8C for ; Sat, 3 Sep 2016 04:07:47 +0200 (CEST) Received: (qmail 9979 invoked by uid 500); 3 Sep 2016 02:07:46 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 9968 invoked by uid 99); 3 Sep 2016 02:07:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Sep 2016 02:07:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2FA18E04BA; Sat, 3 Sep 2016 02:07:46 +0000 (UTC) From: gparai To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #578: DRILL-4280: Kerberos Authentication Content-Type: text/plain Message-Id: <20160903020746.2FA18E04BA@git1-us-west.apache.org> Date: Sat, 3 Sep 2016 02:07:46 +0000 (UTC) archived-at: Sat, 03 Sep 2016 02:07:48 -0000 Github user gparai commented on a diff in the pull request: https://github.com/apache/drill/pull/578#discussion_r77429451 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/rpc/security/AuthenticationMechanismFactory.java --- @@ -0,0 +1,182 @@ +/** + * 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 + * + * http://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.drill.exec.rpc.security; + +import com.google.common.base.Function; +import com.google.common.base.Strings; +import com.google.common.collect.Iterators; +import com.google.common.collect.Sets; +import org.apache.drill.common.AutoCloseables; +import org.apache.drill.common.config.DrillConfig; +import org.apache.drill.common.map.CaseInsensitiveMap; +import org.apache.drill.common.scanner.persistence.ScanResult; +import org.apache.drill.exec.exception.DrillbitStartupException; +import org.apache.drill.exec.rpc.security.kerberos.KerberosMechanism; +import org.apache.drill.exec.rpc.security.plain.PlainMechanism; +import org.apache.drill.exec.rpc.user.security.UserAuthenticator; +import org.apache.drill.exec.rpc.user.security.UserAuthenticatorFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.CommonConfigurationKeys; +import org.apache.hadoop.security.UserGroupInformation; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class AuthenticationMechanismFactory implements AutoCloseable { + private static final org.slf4j.Logger logger = + org.slf4j.LoggerFactory.getLogger(AuthenticationMechanismFactory.class); + + private final Map mechanisms = CaseInsensitiveMap.newHashMapWithExpectedSize(5); + + @SuppressWarnings("unchecked") + public AuthenticationMechanismFactory(final ScanResult scan, final DrillConfig config, + final List configuredMechanisms) + throws DrillbitStartupException { + logger.debug("Configuring authentication mechanisms: {}", configuredMechanisms); + // transform all names to uppercase + final Set configuredMechanismsSet = Sets.newHashSet(Iterators.transform(configuredMechanisms.iterator(), + new Function() { + @Nullable + @Override + public String apply(@Nullable String input) { + return input == null ? null : input.toUpperCase(); + } + })); + + // First, load Drill provided out-of-box mechanisms + if (configuredMechanismsSet.contains(PlainMechanism.SIMPLE_NAME)) { + logger.trace("Plain mechanism enabled."); + // instantiated here, but closed in PlainMechanism#close + final UserAuthenticator userAuthenticator = UserAuthenticatorFactory.createAuthenticator(config, scan); + mechanisms.put(PlainMechanism.SIMPLE_NAME, new PlainMechanism(userAuthenticator)); + configuredMechanismsSet.remove(PlainMechanism.SIMPLE_NAME); + } + + if (configuredMechanismsSet.contains(KerberosMechanism.SIMPLE_NAME)) { + logger.trace("Kerberos mechanism enabled."); + final String servicePrincipal = config.getString("drill.exec.security.auth.principal"); + final String keytab = config.getString("drill.exec.security.auth.keytab"); + + try { // Kerberos mechanism requires a service to login + final Configuration conf = new Configuration(); + conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "KERBEROS"); + // To parse non-typical principal name, uncomment below line + // CommonConfigurationKeys.HADOOP_SECURITY_AUTH_TO_LOCAL, rules); + UserGroupInformation.setConfiguration(conf); + UserGroupInformation.loginUserFromKeytab(servicePrincipal, keytab); + logger.trace("Login successful for user: {}", servicePrincipal); + } catch (IOException e) { + throw new DrillbitStartupException("Drillbit service login failed", e); --- End diff -- Rather than failing with an exception can we simply not add Kerberos to the list of mechanisms i.e. we do not error out but rather add valid mechanisms. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---