Skip to content

Commit

Permalink
Mask properties from logging (apache#3332)
Browse files Browse the repository at this point in the history
* Mask properties from logging

* mask "password" by default
  • Loading branch information
navis authored and nishantmonu51 committed Aug 8, 2016
1 parent ed5b92d commit 39351fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/content/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ All nodes can log debugging information on startup.
|Property|Description|Default|
|--------|-----------|-------|
|`druid.startup.logging.logProperties`|Log all properties on startup (from common.runtime.properties, runtime.properties, and the JVM command line).|false|
|`druid.startup.logging.maskProperties`|Masks sensitive properties (passwords, for example) containing theses words.|["password"]|

Note that some sensitive information may be logged if these settings are enabled.

Expand Down
11 changes: 11 additions & 0 deletions server/src/main/java/io/druid/server/log/StartupLoggingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,25 @@
package io.druid.server.log;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;

import java.util.List;

public class StartupLoggingConfig
{
@JsonProperty
private boolean logProperties = false;

@JsonProperty
private List<String> maskProperties = ImmutableList.of("password");

public boolean isLogProperties()
{
return logProperties;
}

public List<String> getMaskProperties()
{
return maskProperties;
}
}
12 changes: 11 additions & 1 deletion services/src/main/java/io/druid/cli/GuiceRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.base.Throwables;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Module;
Expand All @@ -32,6 +33,7 @@

import java.util.List;
import java.util.Properties;
import java.util.Set;

/**
*/
Expand Down Expand Up @@ -80,10 +82,18 @@ public Lifecycle initLifecycle(Injector injector)
);

if (startupLoggingConfig.isLogProperties()) {
final Set<String> maskProperties = Sets.newHashSet(startupLoggingConfig.getMaskProperties());
final Properties props = injector.getInstance(Properties.class);

for (String propertyName : Ordering.natural().sortedCopy(props.stringPropertyNames())) {
log.info("* %s: %s", propertyName, props.getProperty(propertyName));
String property = props.getProperty(propertyName);
for (String masked : maskProperties) {
if (propertyName.contains(masked)) {
property = "<masked>";
break;
}
}
log.info("* %s: %s", propertyName, property);
}
}

Expand Down

0 comments on commit 39351fb

Please sign in to comment.