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

Ease of hidding sensitive properties from /status/proper… #12950

Merged
merged 6 commits into from
Sep 2, 2022
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
8 changes: 8 additions & 0 deletions docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,14 @@ All Druid components can communicate with each other over HTTP.
|`druid.global.http.unusedConnectionTimeout`|The timeout for idle connections in connection pool. The connection in the pool will be closed after this timeout and a new one will be established. This timeout should be less than `druid.global.http.readTimeout`. Set this timeout = ~90% of `druid.global.http.readTimeout`|`PT4M`|
|`druid.global.http.numMaxThreads`|Maximum number of I/O worker threads|`max(10, ((number of cores * 17) / 16 + 2) + 30)`|

### Common endpoints Configuration

This section contains the configuration options for endpoints that are supported by all processes.

|Property| Description | Default |
|--------|----------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
|`druid.server.hiddenProperties`| If property names or substring of property names (case insensitive) is in this list, responses of the `/status/properties` endpoint do not show these properties | `["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password", "password", "key", "token", "pwd"]` |

## Master Server

This section contains the configuration options for the processes that reside on Master servers (Coordinators and Overlords) in the suggested [three-server configuration](../design/processes.md#server-types).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ druid.indexing.doubleStorage=double
#
# Security
#
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password"]
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password", "password", "key", "token", "pwd"]


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ druid.indexing.doubleStorage=double
#
# Security
#
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password"]
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password", "password", "key", "token", "pwd"]


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ druid.indexing.doubleStorage=double
#
# Security
#
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password"]
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password", "password", "key", "token", "pwd"]


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ druid.indexing.doubleStorage=double
#
# Security
#
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password"]
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password", "password", "key", "token", "pwd"]


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ druid.indexing.doubleStorage=double
#
# Security
#
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password"]
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password", "password", "key", "token", "pwd"]


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ druid.indexing.doubleStorage=double
#
# Security
#
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password"]
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password", "password", "key", "token", "pwd"]


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ druid.indexing.doubleStorage=double
#
# Security
#
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password"]
druid.server.hiddenProperties=["druid.s3.accessKey","druid.s3.secretKey","druid.metadata.storage.connector.password", "password", "key", "token", "pwd"]


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class DruidServerConfig

@JsonProperty
@NotNull
private Set<String> hiddenProperties = Sets.newHashSet("druid.s3.accessKey", "druid.s3.secretKey", "druid.metadata.storage.connector.password");
private Set<String> hiddenProperties = Sets.newHashSet("druid.s3.accessKey", "druid.s3.secretKey",
"druid.metadata.storage.connector.password",
"password", "key", "token", "pwd");

private SegmentLoaderConfig segmentLoaderConfig;

Expand Down
31 changes: 28 additions & 3 deletions server/src/main/java/org/apache/druid/server/StatusResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.druid.utils.JvmUtils;
import org.apache.druid.utils.RuntimeInfo;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
Expand All @@ -48,6 +49,7 @@
import java.util.Set;

/**
*
*/
@Path("/status")
public class StatusResource
Expand All @@ -60,7 +62,8 @@ public class StatusResource
public StatusResource(
final Properties properties,
final DruidServerConfig druidServerConfig,
final ExtensionsLoader extnLoader)
final ExtensionsLoader extnLoader
)
{
this.properties = properties;
this.druidServerConfig = druidServerConfig;
Expand All @@ -74,8 +77,30 @@ public StatusResource(
public Map<String, String> getProperties()
{
Map<String, String> allProperties = Maps.fromProperties(properties);
Set<String> hidderProperties = druidServerConfig.getHiddenProperties();
return Maps.filterEntries(allProperties, (entry) -> !hidderProperties.contains(entry.getKey()));
Set<String> hiddenProperties = druidServerConfig.getHiddenProperties();
return filterHiddenProperties(hiddenProperties, allProperties);
}

/**
* filter out entries from allProperties with key containing elements in hiddenProperties (case insensitive)
*
* @return map of properties that are not filtered out.
*/
@Nonnull
private Map<String, String> filterHiddenProperties(
Set<String> hiddenProperties,
Map<String, String> allProperties
)
{
return Maps.filterEntries(
allProperties,
(entry) -> hiddenProperties
.stream()
.anyMatch(
hiddenPropertyElement ->
!StringUtils.toLowerCase(entry.getKey()).contains(StringUtils.toLowerCase(hiddenPropertyElement))
)
);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.druid.guice.PropertiesModule;
import org.apache.druid.initialization.DruidModule;
import org.apache.druid.initialization.ServerInjectorBuilderTest;
import org.apache.druid.java.util.common.StringUtils;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -35,6 +36,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class StatusResourceTest
{
Expand Down Expand Up @@ -62,13 +64,36 @@ public void testLoadedModules()
}

@Test
public void testPropertiesWithRestrictedConfigs()
public void testHiddenProperties()
{
testHiddenPropertiesWithPropertyFileName("status.resource.test.runtime.properties");
}

@Test
public void testHiddenPropertiesContain()
{
testHiddenPropertiesWithPropertyFileName("status.resource.test.runtime.hpc.properties");
}

private void testHiddenPropertiesWithPropertyFileName(String fileName)
{
Injector injector = Guice.createInjector(Collections.singletonList(new PropertiesModule(Collections.singletonList(
"status.resource.test.runtime.properties"))));
fileName))));
Map<String, String> returnedProperties = injector.getInstance(StatusResource.class).getProperties();
Set<String> lowerCasePropertyNames = returnedProperties.keySet()
.stream()
.map(StringUtils::toLowerCase)
.collect(Collectors.toSet());
Set<String> hiddenProperties = new HashSet<>();
Splitter.on(",").split(returnedProperties.get("druid.server.hiddenProperties")).forEach(hiddenProperties::add);
hiddenProperties.forEach((property) -> Assert.assertNull(returnedProperties.get(property)));
hiddenProperties.forEach(
(property) -> {
lowerCasePropertyNames.forEach(
lowerCasePropertyName -> Assert.assertFalse(lowerCasePropertyName.contains(StringUtils.toLowerCase(
property)))
);
}
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF 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.
#

druid.server.hiddenProperties=["password","key","token","pwd"]
druid.storage.type=s3
druid.storage.bucket=your-bucket
druid.storage.baseKey=druid/segments
druid.s3.accessKey=s3accesskey
druid.s3.secretKey=s3secretkey

druid.metadata.storage.type=mysql
druid.metadata.storage.connector.connectURI=jdbc:mysql://db.example.com:3306/druid
druid.metadata.storage.connector.user=druiduser
druid.metadata.storage.connector.password=password123