Skip to content

Commit b413b25

Browse files
committed
Added Framework Authentication.
Modified `MesosScheduler.java` and `configuration.md`. Now `mapred.mesos.framework.principal`, `mapred.mesos.framework.secretfile`, `mapred.mesos.framework.user`, and `mapred.mesos.framework.name` are configureable options. Addresses issue #53 Added Support for Framework Authentication Added Support for Framework Authentication
1 parent bd0fc09 commit b413b25

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

configuration.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,36 @@ default values.
141141
role configured in "mapred.mesos.role".
142142
</description>
143143
</property>
144+
<property>
145+
<name>mapred.mesos.framework.name</name>
146+
<value>hadoop</value>
147+
<description>
148+
This is the Mesos framework name. Defaults to Hadoop plus port information.
149+
</description>
150+
</property>
151+
<property>
152+
<name>mapred.mesos.framework.principal</name>
153+
<value>hadoop</value>
154+
<description>
155+
This is the Mesos framework principal. It is used for framework authentication.
156+
Consult the Mesos documentation for details.
157+
</description>
158+
</property>
159+
<property>
160+
<name>mapred.mesos.framework.secretfile</name>
161+
<value>/location/secretfile</value>
162+
<description>
163+
Location of the file holding the Mesos framework secret. It is used for framework authentication.
164+
Consult the Mesos documentation for details. Caution: avoid newline characters, some editor place these before end of file.
165+
</description>
166+
</property>
167+
<property>
168+
<name>mapred.mesos.framework.user</name>
169+
<value>hadoop</value>
170+
<description>
171+
This is the user the Mesos framework runs as. If left unset, it defaults to the user running the scheduler.
172+
</description>
173+
</property>
144174
145175
<!-- If you're using a custom Mesos Containerizer -->
146176
<property>

src/main/java/org/apache/hadoop/mapred/MesosScheduler.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.apache.hadoop.mapred;
22

33
import com.codahale.metrics.Meter;
4+
import com.google.protobuf.ByteString;
45
import org.apache.commons.httpclient.HttpHost;
56
import org.apache.commons.logging.Log;
67
import org.apache.commons.logging.LogFactory;
@@ -14,6 +15,7 @@
1415
import org.apache.mesos.hadoop.Metrics;
1516

1617
import java.io.File;
18+
import java.io.FileInputStream;
1719
import java.io.IOException;
1820
import java.util.*;
1921
import java.util.concurrent.ConcurrentHashMap;
@@ -364,10 +366,35 @@ public synchronized void start() throws IOException {
364366
String master = conf.get("mapred.mesos.master", "local");
365367

366368
try {
367-
FrameworkInfo frameworkInfo = FrameworkInfo.newBuilder().setUser("") // Let Mesos fill in the user.
368-
.setCheckpoint(conf.getBoolean("mapred.mesos.checkpoint", false)).setRole(conf.get("mapred.mesos.role", "*")).setName("Hadoop: (RPC port: " + jobTracker.port + "," + " WebUI port: " + jobTracker.infoPort + ")").build();
369-
370-
driver = new MesosSchedulerDriver(this, frameworkInfo, master);
369+
FrameworkInfo frameworkInfo;
370+
FrameworkInfo.Builder frameworkInfoBuilder = FrameworkInfo.newBuilder()
371+
.setUser(conf.get("mapred.mesos.framework.user", "")) // Let Mesos fill in the user.
372+
.setCheckpoint(conf.getBoolean("mapred.mesos.checkpoint", false))
373+
.setRole(conf.get("mapred.mesos.role", "*"))
374+
.setName(conf.get("mapred.mesos.framework.name", "Hadoop: (RPC port: " + jobTracker.port + ","
375+
+ " WebUI port: " + jobTracker.infoPort + ")"));
376+
377+
Credential credential = null;
378+
379+
String frameworkPrincipal = conf.get("mapred.mesos.framework.principal");
380+
if (frameworkPrincipal != null) {
381+
frameworkInfoBuilder.setPrincipal(frameworkPrincipal);
382+
String secretFile = conf.get("mapred.mesos.framework.secretfile");
383+
if (secretFile != null) {
384+
credential = Credential.newBuilder()
385+
.setSecret(ByteString.readFrom(new FileInputStream(secretFile)))
386+
.setPrincipal(frameworkPrincipal)
387+
.build();
388+
}
389+
}
390+
if (credential == null) {
391+
LOG.info("Creating Schedule Driver");
392+
driver = new MesosSchedulerDriver(this, frameworkInfoBuilder.build(), master);
393+
} else {
394+
LOG.info("Creatingg Schedule Driver, attempting to authenticate with Principal: " + credential.getPrincipal()
395+
+ ", secret:" + credential.getSecret());
396+
driver = new MesosSchedulerDriver(this, frameworkInfoBuilder.build(), master, credential);
397+
}
371398
driver.start();
372399
} catch (Exception e) {
373400
// If the MesosScheduler can't be loaded, the JobTracker won't be useful

0 commit comments

Comments
 (0)