Skip to content

Commit

Permalink
DRILL-6189: Security: passwords logging and file permisions
Browse files Browse the repository at this point in the history
1. Overrided serialization methods for instances with passwords
2. Changed file permissions for configuration files

closes apache#1139
  • Loading branch information
vladimirtkach authored and arina-ielchiieva committed Mar 4, 2018
1 parent f2ac874 commit 863ff0b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
*/
package org.apache.drill.exec.store.jdbc;

import com.fasterxml.jackson.annotation.JsonFilter;
import org.apache.drill.common.logical.StoragePluginConfig;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;

@JsonTypeName(JdbcStorageConfig.NAME)
@JsonFilter("passwordFilter")
public class JdbcStorageConfig extends StoragePluginConfig {

public static final String NAME = "jdbc";
Expand Down
12 changes: 8 additions & 4 deletions distribution/src/assemble/bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@
<file>
<source>src/resources/drill-override.conf</source>
<outputDirectory>conf</outputDirectory>
<fileMode>0640</fileMode>
</file>
<file>
<source>src/resources/logback.xml</source>
<outputDirectory>conf</outputDirectory>
<fileMode>0640</fileMode>
</file>
<file>
<source>src/resources/yarn-client-log.xml</source>
Expand All @@ -373,12 +375,12 @@
</file>
<file>
<source>src/resources/drill-env.sh</source>
<fileMode>0755</fileMode>
<fileMode>0750</fileMode>
<outputDirectory>conf</outputDirectory>
</file>
<file>
<source>src/resources/distrib-env.sh</source>
<fileMode>0755</fileMode>
<fileMode>0750</fileMode>
<outputDirectory>conf</outputDirectory>
</file>
<file>
Expand All @@ -388,21 +390,23 @@
</file>
<file>
<source>src/resources/drill-setup.sh</source>
<fileMode>0755</fileMode>
<fileMode>0750</fileMode>
<outputDirectory>conf</outputDirectory>
</file>
<file>
<source>src/resources/distrib-setup.sh</source>
<fileMode>0755</fileMode>
<fileMode>0750</fileMode>
<outputDirectory>conf</outputDirectory>
</file>
<file>
<source>src/resources/drill-override-example.conf</source>
<outputDirectory>conf</outputDirectory>
<fileMode>0640</fileMode>
</file>
<file>
<source>src/resources/core-site-example.xml</source>
<outputDirectory>conf</outputDirectory>
<fileMode>0640</fileMode>
</file>
<file>
<source>src/resources/saffron.properties</source>
Expand Down
Empty file modified distribution/src/resources/distrib-env.sh
100644 → 100755
Empty file.
Empty file modified distribution/src/resources/drill-env.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.fasterxml.jackson.databind.ser.PropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import org.apache.calcite.plan.RelOptCostImpl;
import org.apache.calcite.plan.RelOptLattice;
import org.apache.calcite.plan.RelOptMaterialization;
Expand Down Expand Up @@ -158,7 +162,9 @@ protected void logAndSetTextPlan(final String description, final Prel prel, fina

protected void log(final String name, final PhysicalPlan plan, final Logger logger) throws JsonProcessingException {
if (logger.isDebugEnabled()) {
String planText = plan.unparse(context.getLpPersistence().getMapper().writer());
PropertyFilter filter = new SimpleBeanPropertyFilter.SerializeExceptFilter(Sets.newHashSet("password"));
String planText = plan.unparse(context.getLpPersistence().getMapper()
.writer(new SimpleFilterProvider().addFilter("passwordFilter", filter)));
logger.debug(name + " : \n" + planText);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.net.SocketAddress;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -92,6 +93,40 @@ public class UserServer extends BasicServer<RpcType, BitToUserConnection> {
userConnectionMap = new ConcurrentHashMap<>();
}

/**
* Serialize {@link org.apache.drill.exec.proto.UserProtos.BitToUserHandshake} instance without password
* @param inbound handshake instance for serialization
* @return String of serialized object
*/
private String serializeUserToBitHandshakeWithoutPassword(UserToBitHandshake inbound) {
StringBuilder sb = new StringBuilder();
sb.append("rpc_version: ");
sb.append(inbound.getRpcVersion());
sb.append("\ncredentials:\n\t");
sb.append(inbound.getCredentials());
sb.append("properties:");
List<Property> props = inbound.getProperties().getPropertiesList();
for (Property p: props) {
if (!p.getKey().equalsIgnoreCase("password")) {
sb.append("\n\tproperty:\n\t\t");
sb.append("key: \"");
sb.append(p.getKey());
sb.append("\"\n\t\tvalue: \"");
sb.append(p.getValue());
sb.append("\"");
}
}
sb.append("\nsupport_complex_types: ");
sb.append(inbound.getSupportComplexTypes());
sb.append("\nsupport_timeout: ");
sb.append(inbound.getSupportTimeout());
sb.append("sasl_support: ");
sb.append(inbound.getSaslSupport());
sb.append("\nclient_infos:\n\t");
sb.append(inbound.getClientInfos().toString().replace("\n", "\n\t"));
return sb.toString();
}

public UserServer(BootStrapContext context, BufferAllocator allocator, EventLoopGroup eventLoopGroup,
UserWorker worker) throws DrillbitStartupException {
super(UserRpcConfig.getMapping(context.getConfig(), context.getExecutor()),
Expand Down Expand Up @@ -320,8 +355,9 @@ protected void consumeHandshake(ChannelHandlerContext ctx, UserToBitHandshake in

@Override
public BitToUserHandshake getHandshakeResponse(UserToBitHandshake inbound) throws Exception {
logger.trace("Handling handshake from user to bit. {}", inbound);

if (logger.isTraceEnabled()) {
logger.trace("Handling handshake from user to bit. {}", serializeUserToBitHandshakeWithoutPassword(inbound));
}
// if timeout is unsupported or is set to false, disable timeout.
if (!inbound.hasSupportTimeout() || !inbound.getSupportTimeout()) {
connection.disableReadTimeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Set;

import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import org.apache.drill.common.expression.LogicalExpression;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.logical.FormatPluginConfigBase;
Expand Down Expand Up @@ -52,6 +53,7 @@ public LogicalPlanPersistence(DrillConfig conf, ScanResult scanResult) {
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
mapper.configure(Feature.ALLOW_COMMENTS, true);
mapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
registerSubtypes(LogicalOperatorBase.getSubTypes(scanResult));
registerSubtypes(StoragePluginConfigBase.getSubTypes(scanResult));
registerSubtypes(FormatPluginConfigBase.getSubTypes(scanResult));
Expand Down

0 comments on commit 863ff0b

Please sign in to comment.