Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurations for allowed protocols for HTTP and HDFS inputSources/firehoses #10830

Merged
merged 16 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public HttpInputSource(
)
{
Preconditions.checkArgument(uris != null && !uris.isEmpty(), "Empty URIs");
throwIfInvalidProtocols(uris);
uris.forEach(uri -> Preconditions.checkArgument(
config.isURIAllowed(uri),
StringUtils.format("Access to [%s] DENIED!", uri)
Expand All @@ -69,6 +70,13 @@ public HttpInputSource(
this.config = config;
}

private static void throwIfInvalidProtocols(List<URI> uris)
{
if (uris.stream().anyMatch(uri -> !"http".equalsIgnoreCase(uri.getScheme()) && !"https".equalsIgnoreCase(uri.getScheme()))) {
throw new IllegalArgumentException("Only HTTP or HTTPS are allowed");
}
}

@JsonProperty
public List<URI> getUris()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
import org.apache.druid.data.input.InputSource;
import org.apache.druid.metadata.DefaultPasswordProvider;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.IOException;
import java.net.URI;
import java.util.Collections;

public class HttpInputSourceTest
{
@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
public void testSerde() throws IOException
{
Expand Down Expand Up @@ -78,6 +83,33 @@ public void testDenyListDomainNoMatch()
);
}

@Test
public void testConstructorAllowsOnlyHttpAndHttpsProtocols()
{
new HttpInputSource(
ImmutableList.of(URI.create("http:///")),
"myName",
new DefaultPasswordProvider("myPassword"),
new HttpInputSourceConfig(null, null)
);

new HttpInputSource(
ImmutableList.of(URI.create("https:///")),
"myName",
new DefaultPasswordProvider("myPassword"),
new HttpInputSourceConfig(null, null)
);

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Only HTTP or HTTPS are allowed");
new HttpInputSource(
ImmutableList.of(URI.create("my-protocol:///")),
"myName",
new DefaultPasswordProvider("myPassword"),
new HttpInputSourceConfig(null, null)
);
}

@Test(expected = IllegalArgumentException.class)
public void testAllowListDomainThrowsException()
{
Expand Down