Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/configuration/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ layout: doc_page
|`druid.escalator.type`|String|Type of the Escalator that should be used for internal Druid communications. This Escalator must use an authentication scheme that is supported by an Authenticator in `druid.auth.authenticationChain`.|"noop"|no|
|`druid.auth.authorizers`|JSON List of Strings|List of Authorizer type names |["allowAll"]|no|
|`druid.auth.unsecuredPaths`| List of Strings|List of paths for which security checks will not be performed. All requests to these paths will be allowed.|[]|no|
|`druid.auth.disableHttpOptionsAuthentication`|Boolean|If true, skip authentication checks for HTTP OPTIONS requests. Note that disabling authentication checks for OPTIONS requests will allow unauthenticated users to determine what Druid endpoints are valid, and this may leak sensitive information (for example, the `/druid/indexer/v1//task/{taskid}` endpoint on the Overlord and `/druid/coordinator/v1/datasources` endpoints on the Coordinator contain resource names), so the authentication checks should not be disabled unless truly necessary. |false|no|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Should be /druid/indexer/v1/task (typo with the slashes).
  • The docs should explain when you might want to set this to true: for example, if you want to use CORS.
  • druid.auth.allowUnauthenticatedHttpOptions might be a better name.
  • I'd remove the "truly", it sounds a bit too scary.

I'd replace the parenthetical,

(for example, the /druid/indexer/v1//task/{taskid} endpoint on the Overlord and /druid/coordinator/v1/datasources endpoints on the Coordinator contain resource names)

With,

(for example, callers can attempt to enumerate valid datasources via OPTIONS requests to /druid/coordinator/v1/datasources/{dataSource}/intervals endpoints on the Coordinator)

Although is this true? Will anything be leaked? It seems strange to me that Jetty would be clairvoyant enough to know whether a dataSource embedded in the resource is valid or not, at the time it serves the OPTIONS request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right, at the time I wrote that section I was checking to see what authenticated but unauthorized users could see (authenticated users can determine if a resource exists with non-OPTIONS requests in some cases by checking for access denied vs. resource not found), and incorrectly made that assumption for unauthenticated OPTIONS requests.

I changed the doc there to mention a more general and less serious caveat about determining valid endpoints by checking for 200 vs 404 status, which you can do with the unauthenticated OPTIONS requests.


## Enabling Authentication/Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ public void testAuthConfiguration() throws Exception

LOG.info("Testing Avatica query on router with incorrect credentials.");
testAvaticaAuthFailure(routerUrl);

LOG.info("Checking OPTIONS requests on services...");
testOptionsRequests(adminClient);
}

private void testOptionsRequests(HttpClient httpClient)
{
makeRequest(httpClient, HttpMethod.OPTIONS, config.getCoordinatorUrl() + "/status", null);
makeRequest(httpClient, HttpMethod.OPTIONS, config.getIndexerUrl() + "/status", null);
makeRequest(httpClient, HttpMethod.OPTIONS, config.getBrokerUrl() + "/status", null);
makeRequest(httpClient, HttpMethod.OPTIONS, config.getHistoricalUrl() + "/status", null);
makeRequest(httpClient, HttpMethod.OPTIONS, config.getRouterUrl() + "/status", null);
}

private void checkUnsecuredCoordinatorLoadQueuePath(HttpClient client)
Expand Down
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.server.security;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.HttpMethod;
import java.io.IOException;

public class AllowOptionsResourceFilter implements Filter
{
private final boolean disableAuthentication;

public AllowOptionsResourceFilter(
boolean disableAuthentication
)
{
this.disableAuthentication = disableAuthentication;
}

@Override
public void init(FilterConfig filterConfig) throws ServletException
{

}

@Override
public void doFilter(
ServletRequest request, ServletResponse response, FilterChain chain
) throws IOException, ServletException
{
HttpServletRequest httpReq = (HttpServletRequest) request;

// Druid itself doesn't explictly handle OPTIONS requests, no resource handler will authorize such requests.
// so this filter catches all OPTIONS requests and authorizes them.
if (HttpMethod.OPTIONS.equals(httpReq.getMethod())) {
if (disableAuthentication) {
httpReq.setAttribute(
AuthConfig.DRUID_AUTHENTICATION_RESULT,
new AuthenticationResult(AuthConfig.ALLOW_ALL_NAME, AuthConfig.ALLOW_ALL_NAME, null)
);
}

httpReq.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
}

chain.doFilter(request, response);
}

@Override
public void destroy()
{

}
}
45 changes: 32 additions & 13 deletions server/src/main/java/io/druid/server/security/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,23 @@ public class AuthConfig

public AuthConfig()
{
this(null, null, null);
this(null, null, null, null);
}

@JsonCreator
public AuthConfig(
@JsonProperty("authenticatorChain") List<String> authenticationChain,
@JsonProperty("authorizers") List<String> authorizers,
@JsonProperty("unsecuredPaths") List<String> unsecuredPaths
@JsonProperty("unsecuredPaths") List<String> unsecuredPaths,
@JsonProperty("disableHttpOptionsAuthentication") Boolean disableHttpOptionsAuthentication
)
{
this.authenticatorChain = authenticationChain;
this.authorizers = authorizers;
this.unsecuredPaths = unsecuredPaths == null ? Collections.emptyList() : unsecuredPaths;
this.disableHttpOptionsAuthentication = disableHttpOptionsAuthentication == null
? false
: disableHttpOptionsAuthentication;
}

@JsonProperty
Expand All @@ -68,6 +72,9 @@ public AuthConfig(
@JsonProperty
private final List<String> unsecuredPaths;

@JsonProperty
private final boolean disableHttpOptionsAuthentication;

public List<String> getAuthenticatorChain()
{
return authenticatorChain;
Expand All @@ -83,14 +90,9 @@ public List<String> getUnsecuredPaths()
return unsecuredPaths;
}

@Override
public String toString()
public boolean isDisableHttpOptionsAuthentication()
{
return "AuthConfig{" +
"authenticatorChain='" + authenticatorChain + '\'' +
", authorizers='" + authorizers + '\'' +
", unsecuredPaths='" + unsecuredPaths + '\'' +
'}';
return disableHttpOptionsAuthentication;
}

@Override
Expand All @@ -103,14 +105,31 @@ public boolean equals(Object o)
return false;
}
AuthConfig that = (AuthConfig) o;
return Objects.equals(authenticatorChain, that.authenticatorChain) &&
Objects.equals(authorizers, that.authorizers) &&
Objects.equals(unsecuredPaths, that.unsecuredPaths);
return isDisableHttpOptionsAuthentication() == that.isDisableHttpOptionsAuthentication() &&
Objects.equals(getAuthenticatorChain(), that.getAuthenticatorChain()) &&
Objects.equals(getAuthorizers(), that.getAuthorizers()) &&
Objects.equals(getUnsecuredPaths(), that.getUnsecuredPaths());
}

@Override
public int hashCode()
{
return Objects.hash(authenticatorChain, authorizers, unsecuredPaths);
return Objects.hash(
getAuthenticatorChain(),
getAuthorizers(),
getUnsecuredPaths(),
isDisableHttpOptionsAuthentication()
);
}

@Override
public String toString()
{
return "AuthConfig{" +
"authenticatorChain=" + authenticatorChain +
", authorizers=" + authorizers +
", unsecuredPaths=" + unsecuredPaths +
", disableHttpOptionsAuthentication=" + disableHttpOptionsAuthentication +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@

public class AuthenticationUtils
{
public static void addAllowOptionsFilter(ServletContextHandler root, boolean disableHttpOptionsAuthentication)
{
FilterHolder holder = new FilterHolder(new AllowOptionsResourceFilter(disableHttpOptionsAuthentication));
root.addFilter(
holder,
"/*",
null
);
}

public static void addAuthenticationFilterChain(
ServletContextHandler root,
List<Authenticator> authenticators
Expand Down
2 changes: 2 additions & 0 deletions services/src/main/java/io/druid/cli/CliOverlord.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ public void initialize(Server server, Injector injector)
AuthenticationUtils.addNoopAuthorizationFilters(root, UNSECURED_PATHS);
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths());

AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isDisableHttpOptionsAuthentication());

authenticators = authenticatorMapper.getAuthenticatorChain();
AuthenticationUtils.addAuthenticationFilterChain(root, authenticators);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ public void initialize(Server server, Injector injector)
AuthenticationUtils.addNoopAuthorizationFilters(root, CliOverlord.UNSECURED_PATHS);
}

AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isDisableHttpOptionsAuthentication());

authenticators = authenticatorMapper.getAuthenticatorChain();
AuthenticationUtils.addAuthenticationFilterChain(root, authenticators);

JettyServerInitUtils.addExtensionFilters(root, injector);


// Check that requests were authorized before sending responses
AuthenticationUtils.addPreResponseAuthorizationCheckFilter(
root,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ public void initialize(Server server, Injector injector)
AuthenticationUtils.addNoopAuthorizationFilters(root, UNSECURED_PATHS);
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths());

AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isDisableHttpOptionsAuthentication());

authenticators = authenticatorMapper.getAuthenticatorChain();
AuthenticationUtils.addAuthenticationFilterChain(root, authenticators);


JettyServerInitUtils.addExtensionFilters(root, injector);

// Check that requests were authorized before sending responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public void initialize(Server server, Injector injector)
AuthenticationUtils.addNoopAuthorizationFilters(root, UNSECURED_PATHS);
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths());

AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isDisableHttpOptionsAuthentication());

authenticators = authenticatorMapper.getAuthenticatorChain();
AuthenticationUtils.addAuthenticationFilterChain(root, authenticators);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public void initialize(Server server, Injector injector)
AuthenticationUtils.addNoopAuthorizationFilters(root, UNSECURED_PATHS);
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths());

AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isDisableHttpOptionsAuthentication());

final List<Authenticator> authenticators = authenticatorMapper.getAuthenticatorChain();
AuthenticationUtils.addAuthenticationFilterChain(root, authenticators);

Expand Down