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
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.TreeMap;

import org.apache.hadoop.conf.ConfigRedactor;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.annotation.InterfaceStability;
import org.apache.hadoop.hdds.client.BlockID;
import org.apache.hadoop.hdds.conf.ConfigurationException;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProtoOrBuilder;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State;
Expand Down Expand Up @@ -776,4 +779,25 @@ public static ContainerProtos.ContainerCommandResponseProto processForDebug(

return msg;
}

/**
* Redacts sensitive configuration.
* Sorts all properties by key name
*
* @param conf OzoneConfiguration object to be printed.
* @return Sorted Map of properties
*/
public static Map<String, String> processForLogging(OzoneConfiguration conf) {
Map<String, String> ozoneProps = conf.getOzoneProperties();
ConfigRedactor redactor = new ConfigRedactor(conf);
Map<String, String> sortedOzoneProps = new TreeMap<>();
for (Map.Entry<String, String> entry : ozoneProps.entrySet()) {
String value = redactor.redact(entry.getKey(), entry.getValue());
if (value != null) {
value = value.trim();
}
sortedOzoneProps.put(entry.getKey(), value);
}
return sortedOzoneProps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

import com.google.common.base.Preconditions;
import org.apache.commons.lang3.SystemUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.utils.SignalLogger;
import org.apache.hadoop.hdds.utils.VersionInfo;
import org.apache.hadoop.net.NetUtils;
Expand Down Expand Up @@ -105,12 +107,13 @@ public static String toStartupShutdownString(String prefix, String... msg) {
}

public static void startupShutdownMessage(VersionInfo versionInfo,
Class<?> clazz, String[] args, Logger log) {
Class<?> clazz, String[] args, Logger log, OzoneConfiguration conf) {
final String hostname = NetUtils.getHostname();
final String className = clazz.getSimpleName();

if (log.isInfoEnabled()) {
log.info(createStartupShutdownMessage(versionInfo, className, hostname,
args));
args, HddsUtils.processForLogging(conf)));
}

if (SystemUtils.IS_OS_UNIX) {
Expand All @@ -135,7 +138,8 @@ public static void startupShutdownMessage(VersionInfo versionInfo,
* @return a string to log.
*/
public static String createStartupShutdownMessage(VersionInfo versionInfo,
String className, String hostname, String[] args) {
String className, String hostname, String[] args,
Map<String, String> conf) {
return toStartupShutdownString("STARTUP_MSG: ",
"Starting " + className,
" host = " + hostname,
Expand All @@ -146,7 +150,8 @@ public static String createStartupShutdownMessage(VersionInfo versionInfo,
+ versionInfo.getRevision()
+ " ; compiled by '" + versionInfo.getUser()
+ "' on " + versionInfo.getDate(),
" java = " + System.getProperty("java.version"));
" java = " + System.getProperty("java.version"),
" conf = " + conf);
}

public static String appendIfNotPresent(String str, char c) {
Expand Down

Choose a reason for hiding this comment

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

this ozoneregex not contains "dfs.datanode.use.datanode.hostname",so "dfs.datanode.use.datanode.hostname" init only once and not modifiy

Copy link
Contributor

Choose a reason for hiding this comment

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

These dfs configs are supposed to be deprecated, but it looks like Ozone is still using some of them instead of migrating them to its own config keys. We migrated most of them, but missed the ones in DFSConfigKeysLegacy. I filed HDDS-12026 to fix this. Would you like to work on it?

Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ public Properties getAllPropertiesByTag(String tag) {
return props;
}

public Map<String, String> getOzoneProperties() {
String ozoneRegex = ".*(ozone|hdds|ratis|container|scm|recon)\\..*";
return getValByRegex(ozoneRegex);
}

@Override
public Collection<String> getConfigKeys() {
return getProps().keySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.ozone.ha.ConfUtils;
import org.apache.ozone.test.LambdaTestUtils;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;

import static org.apache.hadoop.hdds.HddsUtils.getSCMAddressForDatanodes;
import static org.apache.hadoop.hdds.HddsUtils.processForLogging;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_ADDRESS_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DATANODE_PORT_DEFAULT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DATANODE_PORT_KEY;
Expand All @@ -50,6 +52,11 @@
*/
public class TestHddsUtils {

private static final String REDACTED_TEXT = "<redacted>";
private static final String ORIGINAL_VALUE = "Hello, World!";
private static final String SENSITIVE_CONFIG_KEYS =
CommonConfigurationKeysPublic.HADOOP_SECURITY_SENSITIVE_CONFIG_KEYS;

@Test
public void testGetHostName() {
assertEquals(Optional.of("localhost"),
Expand Down Expand Up @@ -248,4 +255,24 @@ public void testGetNumberFromConfigKeys() {
serviceId, nodeId),
OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT).orElse(0));
}

@Test
public void testRedactSensitivePropsForLogging() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(SENSITIVE_CONFIG_KEYS, String.join("\n",
"password$",
"key$"));
/* Sensitive properties */
conf.set("ozone.test.password", ORIGINAL_VALUE);
conf.set("hdds.test.secret.key", ORIGINAL_VALUE);
/* Non-Sensitive properties */
conf.set("ozone.normal.config", ORIGINAL_VALUE);
Map<String, String> processedConf = processForLogging(conf);

/* Verify that sensitive properties are redacted */
assertEquals(processedConf.get("ozone.test.password"), REDACTED_TEXT);
assertEquals(processedConf.get("hdds.test.secret.key"), REDACTED_TEXT);
/* Verify that non-sensitive properties retain their value */
assertEquals(processedConf.get("ozone.normal.config"), ORIGINAL_VALUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ public static Logger getLogger() {

@Override
public Void call() throws Exception {
OzoneConfiguration configuration = createOzoneConfiguration();
if (printBanner) {
StringUtils.startupShutdownMessage(HddsVersionInfo.HDDS_VERSION_INFO,
HddsDatanodeService.class, args, LOG);
HddsDatanodeService.class, args, LOG, configuration);
}
start(createOzoneConfiguration());
start(configuration);
ShutdownHookManager.get().addShutdownHook(() -> {
try {
stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void commonInit() {
String[] originalArgs = getCmd().getParseResult().originalArgs()
.toArray(new String[0]);
StringUtils.startupShutdownMessage(HddsVersionInfo.HDDS_VERSION_INFO,
StorageContainerManager.class, originalArgs, LOG);
StorageContainerManager.class, originalArgs, LOG, conf);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public class CsiServer extends GenericCli implements Callable<Void> {

@Override
public Void call() throws Exception {
String[] originalArgs = getCmd().getParseResult().originalArgs()
.toArray(new String[0]);
OzoneConfiguration ozoneConfiguration = createOzoneConfiguration();
StringUtils.startupShutdownMessage(OzoneVersionInfo.OZONE_VERSION_INFO,
CsiServer.class, originalArgs, LOG, ozoneConfiguration);
CsiConfig csiConfig = ozoneConfiguration.getObject(CsiConfig.class);

OzoneClient rpcClient = OzoneClientFactory.getRpcClient(ozoneConfiguration);
Expand Down Expand Up @@ -85,8 +89,6 @@ public Void call() throws Exception {
}

public static void main(String[] args) {
StringUtils.startupShutdownMessage(OzoneVersionInfo.OZONE_VERSION_INFO,
CsiServer.class, args, LOG);
new CsiServer().run(args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void commonInit() {
String[] originalArgs = getCmd().getParseResult().originalArgs()
.toArray(new String[0]);
StringUtils.startupShutdownMessage(OzoneVersionInfo.OZONE_VERSION_INFO,
OzoneManager.class, originalArgs, LOG);
OzoneManager.class, originalArgs, LOG, conf);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public static void main(String[] args) {
public Void call() throws Exception {
String[] originalArgs = getCmd().getParseResult().originalArgs()
.toArray(new String[0]);
StringUtils.startupShutdownMessage(OzoneVersionInfo.OZONE_VERSION_INFO,
ReconServer.class, originalArgs, LOG);

configuration = createOzoneConfiguration();
StringUtils.startupShutdownMessage(OzoneVersionInfo.OZONE_VERSION_INFO,
ReconServer.class, originalArgs, LOG, configuration);
ConfigurationProvider.setConfiguration(configuration);

injector = Guice.createInjector(new ReconControllerModule(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void start() throws IOException {
String[] originalArgs = getCmd().getParseResult().originalArgs()
.toArray(new String[0]);
StringUtils.startupShutdownMessage(OzoneVersionInfo.OZONE_VERSION_INFO,
Gateway.class, originalArgs, LOG);
Gateway.class, originalArgs, LOG, ozoneConfiguration);

LOG.info("Starting Ozone S3 gateway");
HddsServerUtil.initializeMetrics(ozoneConfiguration, "S3Gateway");
Expand Down