You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ke...@apache.org on 2015/03/11 00:45:58 UTC
incubator-aurora git commit: Support HTTP Basic auth and shiro.ini
configuration
Repository: incubator-aurora
Updated Branches:
refs/heads/master 48dc4c7ad -> d1b0b615b
Support HTTP Basic auth and shiro.ini configuration
* Add dependency on Apache Shiro.
* HTTP Basic Authentication.
* Authorization based on shiro.ini.
* Sample shiro.ini for local mode.
Testing Done:
./gradlew -Pq build
Local testing in the UI and with cURL.
Updates to e2e test and Vagrant environment to follow.
Bugs closed: AURORA-809, AURORA-811
Reviewed at https://reviews.apache.org/r/31820/
Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/d1b0b615
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/d1b0b615
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/d1b0b615
Branch: refs/heads/master
Commit: d1b0b615b700fe97b286358b32d571440d3c0cb7
Parents: 48dc4c7
Author: Kevin Sweeney <ke...@apache.org>
Authored: Tue Mar 10 16:45:50 2015 -0700
Committer: Kevin Sweeney <ke...@apache.org>
Committed: Tue Mar 10 16:45:50 2015 -0700
----------------------------------------------------------------------
build.gradle | 6 +
.../aurora/scheduler/app/SchedulerMain.java | 4 -
.../scheduler/http/JettyServerModule.java | 16 +-
.../aurora/scheduler/http/api/ApiModule.java | 3 +-
.../http/api/security/ApiSecurityModule.java | 132 +++++++++++
.../http/api/security/ShiroIniParser.java | 84 +++++++
.../api/security/ShiroThriftInterceptor.java | 101 +++++++++
.../aurora/scheduler/thrift/ThriftModule.java | 5 +
.../thrift/aop/LoggingInterceptor.java | 5 +
.../scheduler/app/local/LocalSchedulerMain.java | 5 +
.../http/api/security/ApiSecurityIT.java | 223 +++++++++++++++++++
.../http/api/security/ShiroIniParserTest.java | 60 +++++
.../security/ShiroThriftInterceptorTest.java | 106 +++++++++
.../thrift/aop/MockDecoratedThrift.java | 4 +-
.../http/api/security/shiro-example.ini | 11 +
.../security/shiro-malformed-extra-sections.ini | 11 +
.../shiro-malformed-missing-sections.ini | 7 +
17 files changed, 774 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index b723118..46564e0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -230,6 +230,7 @@ sourceSets {
dependencies {
def guiceRev = '3.0'
def jerseyRev = '1.18.1'
+ def shiroRev = '1.2.3'
def gsonDep = "com.google.code.gson:gson:${gsonRev}"
def guavaDep = "com.google.guava:guava:${guavaRev}"
@@ -255,6 +256,11 @@ dependencies {
compile "log4j:log4j:${log4jRev}"
compile 'org.antlr:stringtemplate:3.2.1'
compile 'org.apache.mesos:mesos:0.21.1'
+ compile("org.apache.shiro:shiro-guice:${shiroRev}") {
+ // TODO(ksweeney): Remove this exclusion when https://issues.apache.org/jira/browse/SHIRO-496 is resolved.
+ exclude group: 'com.google.guava'
+ }
+ compile "org.apache.shiro:shiro-web:${shiroRev}"
compile 'org.apache.zookeeper:zookeeper:3.3.4'
compile "org.eclipse.jetty:jetty-rewrite:${jettyDep}"
compile "org.eclipse.jetty:jetty-server:${jettyDep}"
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java b/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
index 8b63d74..c6f8787 100644
--- a/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
+++ b/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
@@ -62,8 +62,6 @@ import org.apache.aurora.scheduler.storage.log.LogStorageModule;
import org.apache.aurora.scheduler.storage.log.SnapshotStoreImpl;
import org.apache.aurora.scheduler.storage.mem.MemStorage.Delegated;
import org.apache.aurora.scheduler.storage.mem.MemStorageModule;
-import org.apache.aurora.scheduler.thrift.ThriftModule;
-import org.apache.aurora.scheduler.thrift.auth.ThriftAuthModule;
import static com.twitter.common.logging.RootLogConfig.Configuration;
@@ -185,8 +183,6 @@ public class SchedulerMain extends AbstractApplication {
Bindings.annotatedKeyFactory(LogStorage.WriteBehind.class),
Bindings.annotatedKeyFactory(Delegated.class))
)
- .add(new ThriftModule())
- .add(new ThriftAuthModule())
.build();
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java b/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java
index 9fad055..50f3775 100644
--- a/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java
@@ -35,6 +35,7 @@ import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.google.inject.servlet.GuiceFilter;
import com.google.inject.servlet.GuiceServletContextListener;
+import com.google.inject.util.Modules;
import com.sun.jersey.api.container.filter.GZIPContentEncodingFilter;
import com.sun.jersey.guice.JerseyServletModule;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
@@ -59,6 +60,9 @@ import com.twitter.common.net.pool.DynamicHostSet.MonitorException;
import org.apache.aurora.scheduler.SchedulerServicesModule;
import org.apache.aurora.scheduler.http.api.ApiModule;
+import org.apache.aurora.scheduler.http.api.security.ApiSecurityModule;
+import org.apache.aurora.scheduler.thrift.ThriftModule;
+import org.apache.aurora.scheduler.thrift.auth.ThriftAuthModule;
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
import org.eclipse.jetty.rewrite.handler.RewriteRegexRule;
import org.eclipse.jetty.server.Connector;
@@ -93,6 +97,8 @@ public class JettyServerModule extends AbstractModule {
// rewritten is stored.
static final String ORIGINAL_PATH_ATTRIBUTE_NAME = "originalPath";
+ public static final String THRIFT_API_PATH_SPEC = "/api";
+
@Nonnegative
@CmdLine(name = "http_port",
help = "The port to start an HTTP server on. Default value will choose a random port.")
@@ -153,8 +159,14 @@ public class JettyServerModule extends AbstractModule {
@Provides
@Singleton
ServletContextListener provideServletContextListener(Injector parentInjector) {
- return makeServletContextListener(parentInjector, new ApiModule());
- };
+ return makeServletContextListener(
+ parentInjector,
+ Modules.combine(
+ new ApiModule(),
+ new ApiSecurityModule(),
+ new ThriftModule(),
+ new ThriftAuthModule()));
+ }
};
// TODO(ksweeney): Factor individual servlet configurations to their own ServletModules.
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java b/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java
index fe2ccda..2408cd1 100644
--- a/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java
@@ -35,7 +35,8 @@ import org.eclipse.jetty.servlets.GzipFilter;
import org.eclipse.jetty.util.resource.Resource;
public class ApiModule extends ServletModule {
- static final String API_PATH = "/api";
+ public static final String API_PATH = "/api";
+
@CmdLine(name = "enable_cors_support", help = "Enable CORS support for thrift end points.")
private static final Arg<Boolean> ENABLE_CORS_SUPPORT = Arg.create(false);
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/main/java/org/apache/aurora/scheduler/http/api/security/ApiSecurityModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/api/security/ApiSecurityModule.java b/src/main/java/org/apache/aurora/scheduler/http/api/security/ApiSecurityModule.java
new file mode 100644
index 0000000..1c3ea24
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/http/api/security/ApiSecurityModule.java
@@ -0,0 +1,132 @@
+/**
+ * Licensed 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.aurora.scheduler.http.api.security;
+
+import javax.inject.Singleton;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.inject.Provides;
+import com.google.inject.matcher.Matchers;
+import com.google.inject.name.Names;
+import com.google.inject.servlet.RequestScoped;
+import com.google.inject.servlet.ServletModule;
+import com.twitter.common.args.Arg;
+import com.twitter.common.args.CmdLine;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.apache.aurora.GuiceUtils;
+import org.apache.aurora.gen.AuroraAdmin;
+import org.apache.aurora.gen.AuroraSchedulerManager;
+import org.apache.aurora.scheduler.http.api.ApiModule;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.config.Ini;
+import org.apache.shiro.guice.aop.ShiroAopModule;
+import org.apache.shiro.guice.web.ShiroWebModule;
+import org.apache.shiro.realm.text.IniRealm;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter;
+
+/**
+ * Provides HTTP Basic Authentication for the API using Apache Shiro. When enabled, prevents
+ * unauthenticated access to write APIs. Write API access must also be authorized, with permissions
+ * configured in a shiro.ini file. For an example of this file, see the test resources included with
+ * this package.
+ */
+public class ApiSecurityModule extends ServletModule {
+ public static final String HTTP_REALM_NAME = "Apache Aurora Scheduler";
+
+ @CmdLine(name = "enable_api_security",
+ help = "Enable security for the Thrift API (beta).")
+ private static final Arg<Boolean> ENABLE_API_SECURITY = Arg.create(false);
+
+ @CmdLine(name = "shiro_ini_path",
+ help = "Path to shiro.ini for authentication and authorization configuration.")
+ private static final Arg<Ini> SHIRO_INI_PATH = Arg.create(null);
+
+ private final boolean enableApiSecurity;
+ private final Optional<Ini> shiroIni;
+
+ public ApiSecurityModule() {
+ this(ENABLE_API_SECURITY.get(), Optional.fromNullable(SHIRO_INI_PATH.get()));
+ }
+
+ @VisibleForTesting
+ ApiSecurityModule(Ini shiroIni) {
+ this(true, Optional.of(shiroIni));
+ }
+
+ private ApiSecurityModule(boolean enableApiSecurity, Optional<Ini> shiroIni) {
+ this.enableApiSecurity = enableApiSecurity;
+ this.shiroIni = shiroIni;
+ }
+
+ @Override
+ protected void configureServlets() {
+ if (enableApiSecurity) {
+ doConfigureServlets();
+ }
+ }
+
+ private void doConfigureServlets() {
+ install(ShiroWebModule.guiceFilterModule(ApiModule.API_PATH));
+ install(new ShiroWebModule(getServletContext()) {
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void configureShiroWeb() {
+ try {
+ bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class));
+ } catch (NoSuchMethodException e) {
+ addError(e);
+ }
+
+ addFilterChain("/**",
+ ShiroWebModule.NO_SESSION_CREATION,
+ config(ShiroWebModule.AUTHC_BASIC, BasicHttpAuthenticationFilter.PERMISSIVE));
+ }
+ });
+
+ if (shiroIni.isPresent()) {
+ bind(Ini.class).toInstance(shiroIni.get());
+ } else {
+ addError("shiro.ini is required.");
+ }
+ bind(IniRealm.class).in(Singleton.class);
+ bindConstant().annotatedWith(Names.named("shiro.applicationName")).to(HTTP_REALM_NAME);
+
+ // TODO(ksweeney): Disable session cookie.
+ // TODO(ksweeney): Disable RememberMe cookie.
+
+ install(new ShiroAopModule());
+ MethodInterceptor apiInterceptor = new ShiroThriftInterceptor("thrift.AuroraSchedulerManager");
+ requestInjection(apiInterceptor);
+ bindInterceptor(
+ Matchers.subclassesOf(AuroraSchedulerManager.Iface.class),
+ GuiceUtils.interfaceMatcher(AuroraSchedulerManager.Iface.class, true),
+ apiInterceptor);
+
+ MethodInterceptor adminInterceptor = new ShiroThriftInterceptor("thrift.AuroraAdmin");
+ requestInjection(adminInterceptor);
+ bindInterceptor(
+ Matchers.subclassesOf(AuroraAdmin.Iface.class),
+ GuiceUtils.interfaceMatcher(AuroraAdmin.Iface.class, true),
+ adminInterceptor);
+ }
+
+ @Provides
+ @RequestScoped
+ Subject provideSubject() {
+ return SecurityUtils.getSubject();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroIniParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroIniParser.java b/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroIniParser.java
new file mode 100644
index 0000000..0163ba1
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroIniParser.java
@@ -0,0 +1,84 @@
+/**
+ * Licensed 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.aurora.scheduler.http.api.security;
+
+import java.util.Set;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableSortedSet;
+import com.google.common.collect.Sets;
+import com.twitter.common.args.ArgParser;
+import com.twitter.common.args.parsers.NonParameterizedTypeParser;
+
+import org.apache.shiro.config.ConfigurationException;
+import org.apache.shiro.config.Ini;
+import org.apache.shiro.realm.text.IniRealm;
+
+/**
+ * Parser for shiro.ini files. Accepts any string that {@link Ini#fromResourcePath(String)} does.
+ * The provided ini file must have only the sections required for configuration
+ * ({@link IniRealm.ROLES_SECTION_NAME} and {@link IniRealm.USERS_SECTION_NAME}) and no extras -
+ * Aurora uses Guice in to configure those sections in
+ * {@link org.apache.aurora.scheduler.http.api.security.ApiSecurityModule}}.
+ */
+@ArgParser
+public class ShiroIniParser extends NonParameterizedTypeParser<Ini> {
+ @VisibleForTesting
+ static final Set<String> REQUIRED_SECTION_NAMES =
+ ImmutableSortedSet.of(IniRealm.ROLES_SECTION_NAME, IniRealm.USERS_SECTION_NAME);
+
+ @VisibleForTesting
+ static class MissingSectionsException extends IllegalArgumentException {
+ MissingSectionsException(Set<String> missingSections) {
+ super("Missing required sections: " + missingSections);
+ }
+ }
+
+ @VisibleForTesting
+ static class ExtraSectionsException extends IllegalArgumentException {
+ ExtraSectionsException(Set<String> extraSections) {
+ super("Extra sections present: " + extraSections);
+ }
+ }
+
+ @VisibleForTesting
+ static class ShiroConfigurationException extends IllegalArgumentException {
+ ShiroConfigurationException(ConfigurationException e) {
+ super(e);
+ }
+ }
+
+ @Override
+ public Ini doParse(String raw) throws IllegalArgumentException {
+ Ini ini;
+ try {
+ ini = Ini.fromResourcePath(raw);
+ } catch (ConfigurationException e) {
+ throw new ShiroConfigurationException(e);
+ }
+
+ Set<String> presentSections = ImmutableSortedSet.copyOf(ini.getSectionNames());
+ Set<String> missingSections = Sets.difference(REQUIRED_SECTION_NAMES, presentSections);
+ if (!missingSections.isEmpty()) {
+ throw new MissingSectionsException(missingSections);
+ }
+
+ Set<String> extraSections = Sets.difference(presentSections, REQUIRED_SECTION_NAMES);
+ if (!extraSections.isEmpty()) {
+ throw new ExtraSectionsException(extraSections);
+ }
+
+ return ini;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroThriftInterceptor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroThriftInterceptor.java b/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroThriftInterceptor.java
new file mode 100644
index 0000000..4e341e0
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroThriftInterceptor.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed 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.aurora.scheduler.http.api.security;
+
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.logging.Logger;
+
+import javax.inject.Provider;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Joiner;
+import com.google.inject.Inject;
+import com.twitter.common.base.MorePreconditions;
+import com.twitter.common.stats.StatsProvider;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.aurora.gen.ResponseCode;
+import org.apache.aurora.scheduler.thrift.Responses;
+import org.apache.shiro.authz.Permission;
+import org.apache.shiro.authz.UnauthenticatedException;
+import org.apache.shiro.authz.permission.WildcardPermission;
+import org.apache.shiro.subject.Subject;
+
+import static java.util.Objects.requireNonNull;
+
+import static com.google.common.base.Preconditions.checkState;
+
+/**
+ * Prevents invocation of intercepted methods if the current {@link Subject} is not authenticated
+ * or the current subject does not have the permission defined a prefix the name of the method
+ * attempting to be invoked. The {@link org.apache.shiro.authz.Permission} checked is a
+ * {@link org.apache.shiro.authz.permission.WildcardPermission} constructed from the prefix and
+ * the name of the method being invoked, for example if the prefix is {@code api} and the method
+ * is {@code snapshot} the current subject must have the permission {@code api:snapshot} permission.
+ */
+class ShiroThriftInterceptor implements MethodInterceptor {
+ private static final Logger LOG = Logger.getLogger(ShiroThriftInterceptor.class.getName());
+ private static final Joiner PERMISSION_JOINER = Joiner.on(":");
+
+ @VisibleForTesting
+ static final String SHIRO_AUTHORIZATION_FAILURES = "shiro_authorization_failures";
+
+ private final String permissionPrefix;
+
+ private volatile boolean initialized;
+
+ private Provider<Subject> subjectProvider;
+ private AtomicLong shiroAuthorizationFailures;
+
+ @Inject
+ void initialize(Provider<Subject> newSubjectProvider, StatsProvider statsProvider) {
+ checkState(!initialized);
+
+ this.subjectProvider = requireNonNull(newSubjectProvider);
+ shiroAuthorizationFailures = statsProvider.makeCounter(SHIRO_AUTHORIZATION_FAILURES);
+
+ initialized = true;
+ }
+
+ public ShiroThriftInterceptor(String permissionPrefix) {
+ this.permissionPrefix = MorePreconditions.checkNotBlank(permissionPrefix);
+ }
+
+ @Override
+ public Object invoke(MethodInvocation invocation) throws Throwable {
+ checkState(initialized);
+
+ Subject subject = subjectProvider.get();
+ if (!subject.isAuthenticated()) {
+ // This is a special exception that will signal the BasicHttpAuthenticationFilter to send
+ // a 401 with a challenge. This is necessary at this layer since we only apply this
+ // interceptor to methods that require authentication.
+ throw new UnauthenticatedException();
+ }
+
+ Permission checkedPermission = new WildcardPermission(
+ PERMISSION_JOINER.join(permissionPrefix, invocation.getMethod().getName()));
+ if (subject.isPermitted(checkedPermission)) {
+ return invocation.proceed();
+ } else {
+ shiroAuthorizationFailures.incrementAndGet();
+ String responseMessage =
+ "Subject " + subject.getPrincipal() + " lacks permission " + checkedPermission;
+ LOG.warning(responseMessage);
+ // TODO(ksweeney): 403 FORBIDDEN would be a more accurate translation of this response code.
+ return Responses.addMessage(Responses.empty(), ResponseCode.AUTH_FAILED, responseMessage);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/main/java/org/apache/aurora/scheduler/thrift/ThriftModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/thrift/ThriftModule.java b/src/main/java/org/apache/aurora/scheduler/thrift/ThriftModule.java
index 3e7483b..b1d6336 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/ThriftModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/ThriftModule.java
@@ -37,6 +37,11 @@ public class ThriftModule extends AbstractModule {
protected void configure() {
bind(ReadOnlyScheduler.Iface.class).to(ReadOnlySchedulerImpl.class);
bind(AuroraAdmin.Iface.class).to(SchedulerThriftInterface.class);
+
+ // Promote to an explicit binding so it's created in the servlet container child injector.
+ // See https://code.google.com/p/google-guice/issues/detail?id=461
+ bind(SchedulerThriftInterface.class);
+
bind(Boolean.class).annotatedWith(EnableUpdater.class).toInstance(ENABLE_BETA_UPDATER.get());
install(new AopModule());
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java b/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
index 1e4ba01..d29cbae 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
@@ -23,6 +23,7 @@ import javax.inject.Inject;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
+import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
@@ -35,6 +36,7 @@ import org.apache.aurora.gen.ResponseCode;
import org.apache.aurora.gen.SessionKey;
import org.apache.aurora.scheduler.storage.Storage;
import org.apache.aurora.scheduler.thrift.Responses;
+import org.apache.shiro.ShiroException;
import static java.util.Objects.requireNonNull;
@@ -102,6 +104,9 @@ class LoggingInterceptor implements MethodInterceptor {
LOG.log(Level.WARNING, "Uncaught transient exception while handling " + message, e);
return Responses.addMessage(Responses.empty(), ResponseCode.ERROR_TRANSIENT, e);
} catch (RuntimeException e) {
+ // We need shiro's exceptions to bubble up to the Shiro servlet filter so we intentionally
+ // do not swallow them here.
+ Throwables.propagateIfInstanceOf(e, ShiroException.class);
LOG.log(Level.WARNING, "Uncaught exception while handling " + message, e);
return Responses.addMessage(Responses.empty(), ResponseCode.ERROR, e);
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java b/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java
index 640acdf..4a8d404 100644
--- a/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java
+++ b/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java
@@ -38,6 +38,7 @@ import org.apache.aurora.scheduler.storage.Storage.NonVolatileStorage;
import org.apache.aurora.scheduler.storage.log.LogStorage;
import org.apache.mesos.Protos;
import org.apache.mesos.SchedulerDriver;
+import org.apache.shiro.io.ResourceUtils;
/**
* A main class that runs the scheduler in local mode, using fakes for external components.
@@ -97,6 +98,10 @@ public class LocalSchedulerMain extends SchedulerMain {
.add("-mesos_master_address=fake")
.add("-thermos_executor_path=fake")
.add("-http_port=8081")
+ .add("-enable_api_security=true")
+ .add("-shiro_ini_path="
+ + ResourceUtils.CLASSPATH_PREFIX
+ + "org/apache/aurora/scheduler/http/api/security/shiro-example.ini")
.build();
AppLauncher.launch(LocalSchedulerMain.class, arguments.toArray(new String[0]));
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/test/java/org/apache/aurora/scheduler/http/api/security/ApiSecurityIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/security/ApiSecurityIT.java b/src/test/java/org/apache/aurora/scheduler/http/api/security/ApiSecurityIT.java
new file mode 100644
index 0000000..2876b1f
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/http/api/security/ApiSecurityIT.java
@@ -0,0 +1,223 @@
+/**
+ * Licensed 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.aurora.scheduler.http.api.security;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import com.google.common.testing.TearDown;
+import com.google.inject.AbstractModule;
+import com.google.inject.Module;
+import com.google.inject.util.Modules;
+import com.twitter.common.stats.StatsProvider;
+
+import org.apache.aurora.gen.AuroraAdmin;
+import org.apache.aurora.gen.Lock;
+import org.apache.aurora.gen.Response;
+import org.apache.aurora.gen.ResponseCode;
+import org.apache.aurora.scheduler.http.JettyServerModuleTest;
+import org.apache.aurora.scheduler.http.api.ApiModule;
+import org.apache.aurora.scheduler.thrift.aop.MockDecoratedThrift;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.shiro.config.Ini;
+import org.apache.shiro.realm.text.IniRealm;
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TJSONProtocol;
+import org.apache.thrift.transport.THttpClient;
+import org.apache.thrift.transport.TTransport;
+import org.apache.thrift.transport.TTransportException;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.apache.aurora.scheduler.http.api.ApiModule.API_PATH;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class ApiSecurityIT extends JettyServerModuleTest {
+ private static final Response OK = new Response().setResponseCode(ResponseCode.OK);
+
+ private static final UsernamePasswordCredentials ROOT =
+ new UsernamePasswordCredentials("root", "secret");
+ private static final UsernamePasswordCredentials WFARNER =
+ new UsernamePasswordCredentials("wfarner", "password");
+ private static final UsernamePasswordCredentials UNPRIVILEGED =
+ new UsernamePasswordCredentials("ksweeney", "12345");
+ private static final UsernamePasswordCredentials BACKUP_SERVICE =
+ new UsernamePasswordCredentials("backupsvc", "s3cret!!1");
+
+ private static final UsernamePasswordCredentials INCORRECT =
+ new UsernamePasswordCredentials("root", "wrong");
+ private static final UsernamePasswordCredentials NONEXISTENT =
+ new UsernamePasswordCredentials("nobody", "12345");
+
+ private static final Set<Credentials> INVALID_CREDENTIALS =
+ ImmutableSet.<Credentials>of(INCORRECT, NONEXISTENT);
+
+ private static final Set<Credentials> VALID_CREDENTIALS =
+ ImmutableSet.<Credentials>of(ROOT, WFARNER, UNPRIVILEGED, BACKUP_SERVICE);
+
+ private Ini ini;
+ private AuroraAdmin.Iface auroraAdmin;
+ private StatsProvider statsProvider;
+
+ @Before
+ public void setUp() {
+ ini = new Ini();
+
+ Ini.Section users = ini.addSection(IniRealm.USERS_SECTION_NAME);
+ users.put(ROOT.getUserName(), ROOT.getPassword() + ", admin");
+ users.put(WFARNER.getUserName(), WFARNER.getPassword() + ", eng");
+ users.put(UNPRIVILEGED.getUserName(), UNPRIVILEGED.getPassword());
+ users.put(BACKUP_SERVICE.getUserName(), BACKUP_SERVICE.getPassword() + ", backupsvc");
+
+ Ini.Section roles = ini.addSection(IniRealm.ROLES_SECTION_NAME);
+ roles.put("admin", "*");
+ roles.put("eng", "thrift.AuroraSchedulerManager:*");
+ roles.put("backupsvc", "thrift.AuroraAdmin:listBackups");
+
+ auroraAdmin = createMock(AuroraAdmin.Iface.class);
+ statsProvider = createMock(StatsProvider.class);
+ expect(statsProvider.makeCounter(anyString())).andStubReturn(new AtomicLong());
+ }
+
+ @Override
+ protected Module getChildServletModule() {
+ return Modules.combine(
+ new ApiModule(),
+ new ApiSecurityModule(ini),
+ new AbstractModule() {
+ @Override
+ protected void configure() {
+ MockDecoratedThrift.bindForwardedMock(binder(), auroraAdmin);
+ bind(StatsProvider.class).toInstance(statsProvider);
+ }
+ });
+ }
+
+ private AuroraAdmin.Client getUnauthenticatedClient() throws TTransportException {
+ return getClient(null);
+ }
+
+ private AuroraAdmin.Client getClient(HttpClient httpClient) throws TTransportException {
+ final TTransport httpClientTransport = new THttpClient(
+ "http://" + httpServer.getHostName() + ":" + httpServer.getPort() + API_PATH,
+ httpClient);
+ addTearDown(new TearDown() {
+ @Override
+ public void tearDown() throws Exception {
+ httpClientTransport.close();
+ }
+ });
+ return new AuroraAdmin.Client(new TJSONProtocol(httpClientTransport));
+ }
+
+ private AuroraAdmin.Client getAuthenticatedClient(Credentials credentials)
+ throws TTransportException {
+
+ DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
+
+ CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+ credentialsProvider.setCredentials(AuthScope.ANY, credentials);
+ defaultHttpClient.setCredentialsProvider(credentialsProvider);
+
+ return getClient(defaultHttpClient);
+ }
+
+ @Test
+ public void testReadOnlyScheduler() throws TException {
+ expect(auroraAdmin.getRoleSummary()).andReturn(OK).times(3);
+
+ replayAndStart();
+
+ assertEquals(OK, getUnauthenticatedClient().getRoleSummary());
+ assertEquals(OK, getAuthenticatedClient(ROOT).getRoleSummary());
+ // Incorrect works because the server doesn't challenge for credentials to execute read-only
+ // methods.
+ assertEquals(OK, getAuthenticatedClient(INCORRECT).getRoleSummary());
+ }
+
+ private void assertKillTasksFails(AuroraAdmin.Client client) throws TException {
+ try {
+ client.killTasks(null, null, null);
+ fail("killTasks should fail.");
+ } catch (TTransportException e) {
+ // Expected.
+ }
+ }
+
+ @Test
+ public void testAuroraSchedulerManager() throws TException, IOException {
+ expect(auroraAdmin.killTasks(null, new Lock().setMessage("1"), null)).andReturn(OK);
+ expect(auroraAdmin.killTasks(null, new Lock().setMessage("2"), null)).andReturn(OK);
+
+ replayAndStart();
+
+ assertEquals(OK,
+ getAuthenticatedClient(WFARNER).killTasks(null, new Lock().setMessage("1"), null));
+ assertEquals(OK,
+ getAuthenticatedClient(ROOT).killTasks(null, new Lock().setMessage("2"), null));
+ assertEquals(
+ ResponseCode.AUTH_FAILED,
+ getAuthenticatedClient(UNPRIVILEGED).killTasks(null, null, null).getResponseCode());
+ assertEquals(
+ ResponseCode.AUTH_FAILED,
+ getAuthenticatedClient(BACKUP_SERVICE).killTasks(null, null, null).getResponseCode());
+
+ assertKillTasksFails(getUnauthenticatedClient());
+ assertKillTasksFails(getAuthenticatedClient(INCORRECT));
+ assertKillTasksFails(getAuthenticatedClient(NONEXISTENT));
+ }
+
+ private void assertSnapshotFails(AuroraAdmin.Client client) throws TException {
+ try {
+ client.snapshot(null);
+ fail("snapshot should fail");
+ } catch (TTransportException e) {
+ // Expected.
+ }
+ }
+
+ @Test
+ public void testAuroraAdmin() throws TException {
+ expect(auroraAdmin.snapshot(null)).andReturn(OK);
+ expect(auroraAdmin.listBackups(null)).andReturn(OK);
+
+ replayAndStart();
+
+ assertEquals(OK, getAuthenticatedClient(ROOT).snapshot(null));
+
+ for (Credentials credentials : INVALID_CREDENTIALS) {
+ assertSnapshotFails(getAuthenticatedClient(credentials));
+ }
+
+ for (Credentials credentials : Sets.difference(VALID_CREDENTIALS, ImmutableSet.of(ROOT))) {
+ assertEquals(
+ ResponseCode.AUTH_FAILED,
+ getAuthenticatedClient(credentials).snapshot(null).getResponseCode());
+ }
+
+ assertEquals(OK, getAuthenticatedClient(BACKUP_SERVICE).listBackups(null));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroIniParserTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroIniParserTest.java b/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroIniParserTest.java
new file mode 100644
index 0000000..cb8b1ad
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroIniParserTest.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed 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.aurora.scheduler.http.api.security;
+
+import org.apache.aurora.scheduler.http.api.security.ShiroIniParser.ExtraSectionsException;
+import org.apache.aurora.scheduler.http.api.security.ShiroIniParser.MissingSectionsException;
+import org.apache.aurora.scheduler.http.api.security.ShiroIniParser.ShiroConfigurationException;
+import org.apache.shiro.io.ResourceUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ShiroIniParserTest {
+ private ShiroIniParser parser;
+
+ private static final String EXAMPLE_RESOURCE = "shiro-example.ini";
+ private static final String EXTRA_SECTIONS_SHIRO_INI = "shiro-malformed-extra-sections.ini";
+ private static final String MISSING_SECTIONS_SHIRO_INI = "shiro-malformed-missing-sections.ini";
+ private static final String NONEXISTENT_RESOURCE = "shiro-nonexistent.ini";
+
+ @Before
+ public void setUp() {
+ parser = new ShiroIniParser();
+ }
+
+ @Test
+ public void testDoParseSuccess() {
+ assertEquals(
+ ShiroIniParser.REQUIRED_SECTION_NAMES,
+ parser.doParse(
+ ShiroIniParserTest.class.getResource(EXAMPLE_RESOURCE).toString()).getSectionNames());
+ }
+
+ @Test(expected = ShiroConfigurationException.class)
+ public void testDoParseNonexistent() {
+ parser.doParse(ResourceUtils.CLASSPATH_PREFIX + NONEXISTENT_RESOURCE);
+ }
+
+ @Test(expected = ExtraSectionsException.class)
+ public void testDoParseExtraSections() {
+ parser.doParse(getClass().getResource(EXTRA_SECTIONS_SHIRO_INI).toString());
+ }
+
+ @Test(expected = MissingSectionsException.class)
+ public void testDoParseMissingSections() {
+ parser.doParse(getClass().getResource(MISSING_SECTIONS_SHIRO_INI).toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroThriftInterceptorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroThriftInterceptorTest.java b/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroThriftInterceptorTest.java
new file mode 100644
index 0000000..d2ba273
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroThriftInterceptorTest.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed 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.aurora.scheduler.http.api.security;
+
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicLong;
+
+import com.google.inject.util.Providers;
+import com.twitter.common.stats.StatsProvider;
+import com.twitter.common.testing.easymock.EasyMockTest;
+
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.aurora.gen.AuroraAdmin;
+import org.apache.aurora.gen.Response;
+import org.apache.aurora.gen.ResponseCode;
+import org.apache.aurora.gen.SessionKey;
+import org.apache.aurora.scheduler.thrift.Responses;
+import org.apache.shiro.authz.UnauthenticatedException;
+import org.apache.shiro.authz.permission.WildcardPermission;
+import org.apache.shiro.subject.Subject;
+import org.easymock.IExpectationSetters;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+
+public class ShiroThriftInterceptorTest extends EasyMockTest {
+ private static final String PERMISSION = "test";
+ private static final String PRINCIPAL = "test-user";
+
+ private ShiroThriftInterceptor interceptor;
+ private Subject subject;
+ private StatsProvider statsProvider;
+ private AtomicLong shiroAuthorizationFailures;
+ private MethodInvocation methodInvocation;
+ private Method interceptedMethod;
+
+ @Before
+ public void setUp() throws Exception {
+ interceptor = new ShiroThriftInterceptor(PERMISSION);
+ subject = createMock(Subject.class);
+ statsProvider = createMock(StatsProvider.class);
+ shiroAuthorizationFailures = new AtomicLong();
+ expect(statsProvider.makeCounter(ShiroThriftInterceptor.SHIRO_AUTHORIZATION_FAILURES))
+ .andReturn(shiroAuthorizationFailures);
+ methodInvocation = createMock(MethodInvocation.class);
+ interceptedMethod = AuroraAdmin.Iface.class.getMethod("snapshot", SessionKey.class);
+ }
+
+ private void replayAndInitialize() {
+ control.replay();
+ interceptor.initialize(Providers.of(subject), statsProvider);
+ }
+
+ @Test(expected = UnauthenticatedException.class)
+ public void testInvokeNotAuthenticated() throws Throwable {
+ expect(subject.isAuthenticated()).andReturn(false);
+
+ replayAndInitialize();
+
+ interceptor.invoke(methodInvocation);
+ }
+
+ private IExpectationSetters<Boolean> expectSubjectPermitted() {
+ return expect(subject.isPermitted(
+ new WildcardPermission(PERMISSION + ":" + interceptedMethod.getName())));
+ }
+
+ @Test
+ public void testInvokeNotAuthorized() throws Throwable {
+ expect(subject.isAuthenticated()).andReturn(true);
+ expect(methodInvocation.getMethod()).andReturn(interceptedMethod);
+ expectSubjectPermitted().andReturn(false);
+ expect(subject.getPrincipal()).andReturn(PRINCIPAL);
+
+ replayAndInitialize();
+
+ assertEquals(
+ ResponseCode.AUTH_FAILED,
+ ((Response) interceptor.invoke(methodInvocation)).getResponseCode());
+ }
+
+ @Test
+ public void testInvokeAuthorized() throws Throwable {
+ expect(subject.isAuthenticated()).andReturn(true);
+ expect(methodInvocation.getMethod()).andReturn(interceptedMethod);
+ expectSubjectPermitted().andReturn(true);
+ expect(methodInvocation.proceed()).andReturn(Responses.ok());
+
+ replayAndInitialize();
+
+ assertEquals(Responses.ok(), interceptor.invoke(methodInvocation));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/test/java/org/apache/aurora/scheduler/thrift/aop/MockDecoratedThrift.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/aop/MockDecoratedThrift.java b/src/test/java/org/apache/aurora/scheduler/thrift/aop/MockDecoratedThrift.java
index 52fe0ea..7b1bf2e 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/aop/MockDecoratedThrift.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/aop/MockDecoratedThrift.java
@@ -33,7 +33,7 @@ import org.apache.aurora.scheduler.thrift.auth.DecoratedThrift;
* https://code.google.com/p/google-guice/wiki/AOP#Limitations
*/
@DecoratedThrift
-class MockDecoratedThrift extends ForwardingThrift {
+public class MockDecoratedThrift extends ForwardingThrift {
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
@@ -45,7 +45,7 @@ class MockDecoratedThrift extends ForwardingThrift {
super(delegate);
}
- static void bindForwardedMock(Binder binder, AuroraAdmin.Iface mockThrift) {
+ public static void bindForwardedMock(Binder binder, AuroraAdmin.Iface mockThrift) {
binder.bind(AuroraAdmin.Iface.class).annotatedWith(MockThrift.class).toInstance(mockThrift);
binder.bind(AuroraAdmin.Iface.class).to(MockDecoratedThrift.class);
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-example.ini
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-example.ini b/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-example.ini
new file mode 100644
index 0000000..5daeabb
--- /dev/null
+++ b/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-example.ini
@@ -0,0 +1,11 @@
+; For documentation on the format see http://shiro.apache.org/configuration.html
+; Note that we only use the [users] and [roles] sections - others are configured by Guice.
+; Unsuitable for production use.
+[users]
+root = secret, admin
+wfarner = password, eng
+ksweeney = 12345
+
+[roles]
+admin = *
+eng = thrift.AuroraSchedulerManager:*
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-malformed-extra-sections.ini
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-malformed-extra-sections.ini b/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-malformed-extra-sections.ini
new file mode 100644
index 0000000..c1e7f4f
--- /dev/null
+++ b/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-malformed-extra-sections.ini
@@ -0,0 +1,11 @@
+; Malformed ini file for test
+[users]
+root = secret, admin
+
+[roles]
+admin = *
+
+; Documentation found with a web search might suggest creating this section; however our shiro
+; wiring is done with Guice.
+[main]
+myRealm = com.company.shiro.realm.MyRealm
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d1b0b615/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-malformed-missing-sections.ini
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-malformed-missing-sections.ini b/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-malformed-missing-sections.ini
new file mode 100644
index 0000000..13016cb
--- /dev/null
+++ b/src/test/resources/org/apache/aurora/scheduler/http/api/security/shiro-malformed-missing-sections.ini
@@ -0,0 +1,7 @@
+; Malformed shiro.ini for test
+[users]
+root = secret, admin
+
+; This section should be present.
+;[roles]
+;admin = *