-
Notifications
You must be signed in to change notification settings - Fork 565
[security] Redact sensitive config values in startup logs #3486
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| package org.apache.fluss.config; | ||
|
|
||
| import org.apache.fluss.utils.CollectionUtils; | ||
| import org.apache.fluss.utils.TimeUtils; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
@@ -38,6 +39,37 @@ | |
|
|
||
| /** Utility class for {@link Configuration} related helper functions. */ | ||
| public class ConfigurationUtils { | ||
|
|
||
| private static final String[] SENSITIVE_KEY_PARTS = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also #3526 adds a second S3-cred list that already diverges, is it worth unifying?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I agree it is worth unifying the S3 credential detection, but I would prefer to handle that in #3526 or a focused follow-up. The matching in this PR is intentionally generic and conservative for log redaction, following Flink-style sensitive-key substring matching. The #3526 logic is S3-specific and should probably use a more precise matcher for supported S3 config prefixes/suffixes, such as I will keep this PR scoped to the generic redaction path and avoid folding a filesystem config refactor into it. We can extract a shared S3 credential matcher separately so #3526 and the S3 filesystem code do not drift. |
||
| "password", | ||
| "secret", | ||
| "fs.azure.account.key", | ||
| "apikey", | ||
| "api-key", | ||
| "auth-params", | ||
| "service-key", | ||
| "token", | ||
|
litiliu marked this conversation as resolved.
|
||
| "basic-auth", | ||
| "jaas.config", | ||
| "http-headers", | ||
| "private.key", | ||
| "private-key", | ||
| "access.key", | ||
| "access-key", | ||
| "access_key", | ||
| "accesskey" | ||
| }; | ||
|
|
||
| // Exact allowlist for non-secret options that match broad sensitive key parts. | ||
| private static final Set<String> NON_SENSITIVE_KEYS = | ||
| Arrays.stream( | ||
| new String[] { | ||
| ConfigOptions.FILESYSTEM_SECURITY_TOKEN_RENEWAL_RETRY_BACKOFF.key(), | ||
| ConfigOptions.FILESYSTEM_SECURITY_TOKEN_RENEWAL_TIME_RATIO.key() | ||
| }) | ||
| .map(key -> key.toLowerCase(Locale.ROOT)) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| // -------------------------------------------------------------------------------------------- | ||
| // Type conversion | ||
| // -------------------------------------------------------------------------------------------- | ||
|
|
@@ -81,6 +113,47 @@ public static <T> T convertValue(Object rawValue, Class<?> clazz) { | |
| throw new IllegalArgumentException("Unsupported type: " + clazz); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a log-safe representation for a configuration value. | ||
| * | ||
| * @param key configuration key | ||
| * @param value configuration value | ||
| * @return {@link Password#HIDDEN_CONTENT} for sensitive values, otherwise the original value | ||
| */ | ||
| public static Object hideSensitiveValue(String key, Object value) { | ||
| if (value == null) { | ||
| return null; | ||
| } | ||
| return value instanceof Password || isSensitiveKey(key) ? Password.HIDDEN_CONTENT : value; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a copy of the given configuration map with sensitive values hidden. | ||
| * | ||
| * @param values configuration key/value pairs | ||
| * @return a new map containing log-safe values | ||
| */ | ||
| public static Map<String, String> hideSensitiveValues(Map<String, String> values) { | ||
| Map<String, String> hiddenValues = | ||
| CollectionUtils.newHashMapWithExpectedSize(values.size()); | ||
| values.forEach( | ||
| (key, value) -> hiddenValues.put(key, (String) hideSensitiveValue(key, value))); | ||
| return hiddenValues; | ||
| } | ||
|
|
||
| static boolean isSensitiveKey(String key) { | ||
| String lowerKey = key.toLowerCase(Locale.ROOT); | ||
| if (NON_SENSITIVE_KEYS.contains(lowerKey)) { | ||
| return false; | ||
| } | ||
| for (String sensitiveKeyPart : SENSITIVE_KEY_PARTS) { | ||
| if (lowerKey.contains(sensitiveKeyPart)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| static <T> T convertToList(Object rawValue, Class<?> atomicClass) { | ||
| if (rawValue instanceof List) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.fluss.config; | ||
|
|
||
| import org.apache.logging.log4j.Level; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.core.LogEvent; | ||
| import org.apache.logging.log4j.core.Logger; | ||
| import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
| import org.apache.logging.log4j.core.config.Property; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** Tests for {@link GlobalConfiguration}. */ | ||
| public class GlobalConfigurationTest { | ||
|
|
||
| @Test | ||
| void testSensitiveConfigurationValuesAreHiddenInLogs(@TempDir Path tempDir) throws Exception { | ||
| Files.write( | ||
| tempDir.resolve(GlobalConfiguration.FLUSS_CONF_FILENAME), | ||
| Arrays.asList( | ||
| "fs.s3a.access.key: s3-access-key", | ||
| "fs.gs.auth.service.account.private.key: gs-private-key", | ||
| "fs.oss.accessKeyId: oss-access-key", | ||
| "client.security.sasl.password: sasl-password", | ||
| "client.filesystem.security.token.renewal.backoff: 10 s", | ||
| "client.request.timeout: 30 s"), | ||
| StandardCharsets.UTF_8); | ||
|
|
||
| Logger logger = (Logger) LogManager.getLogger(GlobalConfiguration.class); | ||
| Level previousLevel = logger.getLevel(); | ||
| boolean previousAdditive = logger.isAdditive(); | ||
| TestAppender appender = new TestAppender(); | ||
| appender.start(); | ||
| logger.addAppender(appender); | ||
| logger.setLevel(Level.INFO); | ||
| logger.setAdditive(false); | ||
|
|
||
| try { | ||
| GlobalConfiguration.loadConfiguration(tempDir.toString(), null); | ||
| } finally { | ||
| logger.removeAppender(appender); | ||
| logger.setLevel(previousLevel); | ||
| logger.setAdditive(previousAdditive); | ||
| appender.stop(); | ||
| } | ||
|
|
||
| String logs = String.join("\n", appender.getMessages()); | ||
| assertThat(logs) | ||
| .contains("Loading configuration property: fs.s3a.access.key=******") | ||
| .contains( | ||
| "Loading configuration property: " | ||
| + "fs.gs.auth.service.account.private.key=******") | ||
| .contains("Loading configuration property: fs.oss.accessKeyId=******") | ||
| .contains("Loading configuration property: client.security.sasl.password=******") | ||
| .contains( | ||
| "Loading configuration property: " | ||
| + "client.filesystem.security.token.renewal.backoff=10 s") | ||
| .contains("Loading configuration property: client.request.timeout=30 s") | ||
| .doesNotContain( | ||
| "s3-access-key", "gs-private-key", "oss-access-key", "sasl-password"); | ||
| } | ||
|
|
||
| private static class TestAppender extends AbstractAppender { | ||
|
|
||
| private final List<String> messages = new ArrayList<>(); | ||
|
|
||
| TestAppender() { | ||
| super("test-appender", null, null, true, Property.EMPTY_ARRAY); | ||
| } | ||
|
|
||
| @Override | ||
| public void append(LogEvent event) { | ||
| messages.add(event.getMessage().getFormattedMessage()); | ||
| } | ||
|
|
||
| private List<String> getMessages() { | ||
| return messages; | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.