Skip to content

Commit 995ac2d

Browse files
authored
Add support for Kerberized Elasticsearch (#1244)
Elasticsearch supports using Kerberos to authenticate over HTTP by means of SPNEGO. Since most secure Hadoop environments make use of Kerberos to secure their environments, naturally ES-Hadoop should support Kerberos authentication. With the recent addition of API Key authentication to Elasticsearch, we now have a stable means for obtaining long lived and stable tokens for worker process authentication when using Kerberos.
1 parent 23ccecd commit 995ac2d

File tree

166 files changed

+12119
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+12119
-205
lines changed

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/BuildPlugin.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class BuildPlugin implements Plugin<Project> {
214214
exclude group: "org.elasticsearch", module: "elasticsearch-core"
215215
exclude group: "org.elasticsearch", module: "elasticsearch-secure-sm"
216216
}
217+
217218
testRuntime "org.slf4j:slf4j-log4j12:1.7.6"
218219
testRuntime "org.apache.logging.log4j:log4j-api:${project.ext.log4jVersion}"
219220
testRuntime "org.apache.logging.log4j:log4j-core:${project.ext.log4jVersion}"
@@ -224,6 +225,11 @@ class BuildPlugin implements Plugin<Project> {
224225
testRuntime "com.vividsolutions:jts:1.13"
225226

226227
// TODO: Remove when we merge ITests to test dirs
228+
itestCompile("org.apache.hadoop:hadoop-minikdc:${project.ext.minikdcVersion}") {
229+
// For some reason, the dependencies that are pulled in with MiniKDC have multiple resource files
230+
// that cause issues when they are loaded. We exclude the ldap schema data jar to get around this.
231+
exclude group: "org.apache.directory.api", module: "api-ldap-schema-data"
232+
}
227233
itestCompile project.sourceSets.main.output
228234
itestCompile project.configurations.testCompile
229235
itestCompile project.configurations.provided

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/ElasticsearchFixturePlugin.groovy

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package org.elasticsearch.hadoop.gradle.fixture
22

3-
import org.elasticsearch.gradle.BuildPlugin
43
import org.elasticsearch.gradle.Version
54
import org.elasticsearch.gradle.test.ClusterConfiguration
65
import org.elasticsearch.gradle.test.ClusterFormationTasks
76
import org.elasticsearch.gradle.test.NodeInfo
7+
import org.elasticsearch.hadoop.gradle.util.PlaceholderTask
88
import org.gradle.api.Plugin
99
import org.gradle.api.Project
1010
import org.gradle.api.Task
1111
import org.gradle.api.execution.TaskExecutionAdapter
1212
import org.gradle.api.tasks.TaskState
13+
import org.gradle.util.ConfigureUtil
1314

1415
import java.nio.charset.StandardCharsets
1516
import java.nio.file.Files
@@ -27,6 +28,26 @@ import java.util.stream.Stream
2728
*/
2829
class ElasticsearchFixturePlugin implements Plugin<Project> {
2930

31+
static class ElasticsearchCluster {
32+
33+
Project project
34+
ClusterConfiguration configuration
35+
List<Task> tasks = []
36+
37+
ElasticsearchCluster(Project project) {
38+
this.project = project
39+
this.configuration = new ClusterConfiguration(project)
40+
}
41+
42+
void clusterConf(Closure configClosure) {
43+
ConfigureUtil.configure(configClosure, configuration)
44+
}
45+
46+
void addTask(Task task) {
47+
tasks.add(task)
48+
}
49+
}
50+
3051
@Override
3152
void apply(Project project) {
3253

@@ -55,7 +76,9 @@ class ElasticsearchFixturePlugin implements Plugin<Project> {
5576
Task clusterInit = project.tasks.create(name: "esCluster#init", dependsOn: project.testClasses)
5677
integrationTest.dependsOn(clusterInit)
5778

58-
ClusterConfiguration clusterConfig = project.extensions.create("esCluster", ClusterConfiguration.class, project)
79+
ElasticsearchCluster cluster = project.extensions.create("esCluster", ElasticsearchCluster.class, project)
80+
cluster.tasks.add(integrationTest)
81+
ClusterConfiguration clusterConfig = cluster.configuration
5982

6083
// default settings:
6184
clusterConfig.clusterName = "elasticsearch-fixture"
@@ -96,18 +119,21 @@ class ElasticsearchFixturePlugin implements Plugin<Project> {
96119
// Also write a script to a file for use in tests
97120
File scriptsDir = new File(project.buildDir, 'scripts')
98121
scriptsDir.mkdirs()
99-
File script
122+
File script = null
100123
if (majorVersion <= 2) {
101124
scriptsDir.mkdirs()
102125
script = new File(scriptsDir, "increment.groovy").setText("ctx._source.counter+=1", 'UTF-8')
103126
} else if (majorVersion == 5) {
104127
scriptsDir.mkdirs()
105128
script = new File(scriptsDir, "increment.painless").setText("ctx._source.counter = ctx._source.getOrDefault('counter', 0) + 1", 'UTF-8')
106129
}
107-
clusterConfig.extraConfigFile("script", script)
130+
if (script != null) {
131+
clusterConfig.extraConfigFile("script", script)
132+
}
108133

109134
project.gradle.projectsEvaluated {
110-
List<NodeInfo> nodes = ClusterFormationTasks.setup(project, "esCluster", integrationTest, clusterConfig)
135+
Task clusterMain = new PlaceholderTask()
136+
List<NodeInfo> nodes = ClusterFormationTasks.setup(project, "esCluster", clusterMain, clusterConfig)
111137
project.tasks.getByPath("esCluster#wait").doLast {
112138
integrationTest.systemProperty('tests.rest.cluster', "${nodes.collect{it.httpUri()}.join(",")}")
113139
}
@@ -123,11 +149,19 @@ class ElasticsearchFixturePlugin implements Plugin<Project> {
123149
}
124150
}
125151
}
126-
integrationTest.doFirst {
127-
project.gradle.addListener(logDumpListener)
128-
}
129-
integrationTest.doLast {
130-
project.gradle.removeListener(logDumpListener)
152+
for (Task clusterTask : cluster.tasks) {
153+
for (Object dependency : clusterMain.taskDeps) {
154+
clusterTask.dependsOn(dependency)
155+
}
156+
for (Object finalizer : clusterMain.taskFinalizers) {
157+
clusterTask.finalizedBy(finalizer)
158+
}
159+
clusterTask.doFirst {
160+
project.gradle.addListener(logDumpListener)
161+
}
162+
clusterTask.doLast {
163+
project.gradle.removeListener(logDumpListener)
164+
}
131165
}
132166
}
133167
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.hadoop.gradle.fixture.hadoop
21+
22+
class ConfigFormats {
23+
24+
static Closure<String> hadoopXML() {
25+
return { Map conf ->
26+
String props = conf.collect { key, value ->
27+
"<property>\n\t\t<name>${key}</name>\n\t\t<value>${value}</value>\n\t</property>"
28+
}.join("\n\t")
29+
return "<configuration>\n\t${props}\n</configuration>"
30+
}
31+
}
32+
33+
static Closure<String> propertyFile() {
34+
return { Map conf ->
35+
conf.collect { key, value ->
36+
"${key}=${value}"
37+
}.join("\n")
38+
}
39+
}
40+
41+
static Closure<String> whiteSpaced() {
42+
return { Map conf ->
43+
conf.collect { key, value ->
44+
"${key} ${value}"
45+
}.join("\n")
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)