forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding hadoop kerberos authentification. (apache#3419)
* adding kerberos authentication * make the 2 functions identical
- Loading branch information
Showing
13 changed files
with
386 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,11 @@ Make sure to [include](../../operations/including-extensions.html) `druid-hdfs-s | |
|--------|---------------|-----------|-------| | ||
|`druid.storage.type`|hdfs||Must be set.| | ||
|`druid.storage.storageDirectory`||Directory for storing segments.|Must be set.| | ||
|`druid.hadoop.security.kerberos.principal`|`[email protected]`| Principal user name |empty| | ||
|`druid.hadoop.security.kerberos.keytab`|`/etc/security/keytabs/druid.headlessUser.keytab`|Path to keytab file|empty| | ||
|
||
If you are using the Hadoop indexer, set your output directory to be a location on Hadoop and it will work | ||
If you are using the Hadoop indexer, set your output directory to be a location on Hadoop and it will work. | ||
If you want to eagerly authenticate against a secured hadoop/hdfs cluster you must set `druid.hadoop.security.kerberos.principal` and `druid.hadoop.security.kerberos.keytab`, this is an alternative to the cron job method that runs `kinit` command periodically. | ||
|
||
## Google Cloud Storage | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,6 +287,19 @@ classification=yarn-site,properties=[mapreduce.reduce.memory.mb=6144,mapreduce.r | |
loads](../tutorials/cluster.html#configure-cluster-for-hadoop-data-loads)" using the XML files from | ||
`/etc/hadoop/conf` on your EMR master. | ||
|
||
### Secured Hadoop Cluster | ||
|
||
By default druid can use the exisiting TGT kerberos ticket available in local kerberos key cache. | ||
Although TGT ticket has a limited life cycle, | ||
therefore you need to call `kinit` command periodically to ensure validity of TGT ticket. | ||
To avoid this extra external cron job script calling `kinit` periodically, | ||
you can provide the principal name and keytab location and druid will do the authentication transparently at startup and job launching time. | ||
|
||
|Property|Possible Values|Description|Default| | ||
|--------|---------------|-----------|-------| | ||
|`druid.hadoop.security.kerberos.principal`|`[email protected]`| Principal user name |empty| | ||
|`druid.hadoop.security.kerberos.keytab`|`/etc/security/keytabs/druid.headlessUser.keytab`|Path to keytab file|empty| | ||
|
||
#### Loading from S3 with EMR | ||
|
||
- In the `jobProperties` field in the `tuningConfig` section of your Hadoop indexing task, add: | ||
|
77 changes: 77 additions & 0 deletions
77
extensions-core/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsKerberosConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.storage.hdfs; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class HdfsKerberosConfig | ||
{ | ||
@JsonProperty | ||
private final String principal; | ||
@JsonProperty | ||
private final String keytab; | ||
|
||
@JsonCreator | ||
public HdfsKerberosConfig(@JsonProperty("principal") String principal,@JsonProperty("keytab") String keytab) { | ||
this.principal = principal; | ||
this.keytab = keytab; | ||
} | ||
|
||
@JsonProperty | ||
public String getPrincipal() | ||
{ | ||
return principal; | ||
} | ||
|
||
@JsonProperty | ||
public String getKeytab() | ||
{ | ||
return keytab; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof HdfsKerberosConfig)) { | ||
return false; | ||
} | ||
|
||
HdfsKerberosConfig that = (HdfsKerberosConfig) o; | ||
|
||
if (getPrincipal() != null ? !getPrincipal().equals(that.getPrincipal()) : that.getPrincipal() != null) { | ||
return false; | ||
} | ||
return getKeytab() != null ? getKeytab().equals(that.getKeytab()) : that.getKeytab() == null; | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
int result = getPrincipal() != null ? getPrincipal().hashCode() : 0; | ||
result = 31 * result + (getKeytab() != null ? getKeytab().hashCode() : 0); | ||
return result; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...ions-core/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsStorageAuthentication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.storage.hdfs; | ||
|
||
|
||
import com.google.common.base.Strings; | ||
import com.google.inject.Inject; | ||
import com.metamx.common.ISE; | ||
import com.metamx.common.lifecycle.LifecycleStart; | ||
import com.metamx.common.lifecycle.LifecycleStop; | ||
import com.metamx.common.logger.Logger; | ||
import io.druid.guice.ManageLifecycle; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
|
||
import java.io.IOException; | ||
|
||
@ManageLifecycle | ||
public class HdfsStorageAuthentication | ||
{ | ||
private static final Logger log = new Logger(HdfsStorageAuthentication.class); | ||
private final HdfsKerberosConfig hdfsKerberosConfig; | ||
private final Configuration hadoopConf; | ||
|
||
@Inject | ||
public HdfsStorageAuthentication(HdfsKerberosConfig hdfsKerberosConfig, Configuration hadoopConf) | ||
{ | ||
this.hdfsKerberosConfig = hdfsKerberosConfig; | ||
this.hadoopConf = hadoopConf; | ||
} | ||
|
||
/** | ||
* Dose authenticate against a secured hadoop cluster | ||
* In case of any bug fix make sure to fix the code in JobHelper#authenticate as well. | ||
*/ | ||
@LifecycleStart | ||
public void authenticate() | ||
{ | ||
String principal = hdfsKerberosConfig.getPrincipal(); | ||
String keytab = hdfsKerberosConfig.getKeytab(); | ||
if (!Strings.isNullOrEmpty(principal) && !Strings.isNullOrEmpty(keytab)) { | ||
UserGroupInformation.setConfiguration(hadoopConf); | ||
if (UserGroupInformation.isSecurityEnabled()) { | ||
try { | ||
if (UserGroupInformation.getCurrentUser().hasKerberosCredentials() == false | ||
|| !UserGroupInformation.getCurrentUser().getUserName().equals(principal)) { | ||
log.info("Trying to authenticate user [%s] with keytab [%s]..", principal, keytab); | ||
UserGroupInformation.loginUserFromKeytab(principal, keytab); | ||
} | ||
} | ||
catch (IOException e) { | ||
throw new ISE(e, "Failed to authenticate user principal [%s] with keytab [%s]", principal, keytab); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@LifecycleStop | ||
public void stop() | ||
{ | ||
//noop | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
extensions-core/hdfs-storage/src/test/java/io/druid/storage/hdfs/HdfsKerberosConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.storage.hdfs; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
public class HdfsKerberosConfigTest | ||
{ | ||
private final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
@Test | ||
public void testSerDesr() throws IOException | ||
{ | ||
HdfsKerberosConfig hdfsKerberosConfig = new HdfsKerberosConfig("principal", "keytab"); | ||
Assert.assertEquals( | ||
hdfsKerberosConfig, | ||
mapper.reader(HdfsKerberosConfig.class).readValue(mapper.writeValueAsString(hdfsKerberosConfig)) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
indexing-hadoop/src/main/java/io/druid/indexer/HadoopKerberosConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.indexer; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class HadoopKerberosConfig | ||
{ | ||
@JsonProperty | ||
private final String principal; | ||
@JsonProperty | ||
private final String keytab; | ||
|
||
@JsonCreator | ||
public HadoopKerberosConfig(@JsonProperty("principal") String principal,@JsonProperty("keytab") String keytab) { | ||
this.principal = principal; | ||
this.keytab = keytab; | ||
} | ||
|
||
@JsonProperty | ||
public String getPrincipal() | ||
{ | ||
return principal; | ||
} | ||
|
||
@JsonProperty | ||
public String getKeytab() | ||
{ | ||
return keytab; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof HadoopKerberosConfig)) { | ||
return false; | ||
} | ||
|
||
HadoopKerberosConfig that = (HadoopKerberosConfig) o; | ||
|
||
if (getPrincipal() != null ? !getPrincipal().equals(that.getPrincipal()) : that.getPrincipal() != null) { | ||
return false; | ||
} | ||
return getKeytab() != null ? getKeytab().equals(that.getKeytab()) : that.getKeytab() == null; | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
int result = getPrincipal() != null ? getPrincipal().hashCode() : 0; | ||
result = 31 * result + (getKeytab() != null ? getKeytab().hashCode() : 0); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.