This is an automated email from the ASF dual-hosted git repository.
luoyuxia pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fluss.git
The following commit(s) were added to refs/heads/main by this push:
new 258e9f119 [fs] Mask S3 delegation token access keys in logs (#3421)
258e9f119 is described below
commit 258e9f11916a68eac53da7611365a42eb2b0dab5
Author: QuakeWang <[email protected]>
AuthorDate: Fri Jun 5 09:22:24 2026 +0800
[fs] Mask S3 delegation token access keys in logs (#3421)
---
.../fs/s3/token/S3DelegationTokenProvider.java | 4 +-
.../fs/s3/token/S3DelegationTokenReceiver.java | 2 +-
.../apache/fluss/fs/s3/token/S3TokenLogUtils.java | 40 +++++++++++++++++++
.../fluss/fs/s3/token/S3TokenLogUtilsTest.java | 46 ++++++++++++++++++++++
4 files changed, 89 insertions(+), 3 deletions(-)
diff --git
a/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3DelegationTokenProvider.java
b/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3DelegationTokenProvider.java
index 5c3100c9e..2a5ee6212 100644
---
a/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3DelegationTokenProvider.java
+++
b/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3DelegationTokenProvider.java
@@ -107,14 +107,14 @@ public class S3DelegationTokenProvider {
} else {
LOG.info(
"Obtaining session credentials via GetSessionToken
with access key: {}",
- accessKey);
+ S3TokenLogUtils.maskAccessKey(accessKey));
GetSessionTokenResult result = stsClient.getSessionToken();
credentials = result.getCredentials();
}
LOG.info(
"Session credentials obtained successfully with access
key: {} expiration: {}",
- credentials.getAccessKeyId(),
+
S3TokenLogUtils.maskAccessKey(credentials.getAccessKeyId()),
credentials.getExpiration());
return new ObtainedSecurityToken(
diff --git
a/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3DelegationTokenReceiver.java
b/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3DelegationTokenReceiver.java
index e3e2d7346..e391f92ed 100644
---
a/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3DelegationTokenReceiver.java
+++
b/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3DelegationTokenReceiver.java
@@ -89,7 +89,7 @@ public class S3DelegationTokenReceiver implements
SecurityTokenReceiver {
LOG.info(
"Session credentials updated successfully with access key:
{}.",
- credentials.getAccessKeyId());
+ S3TokenLogUtils.maskAccessKey(credentials.getAccessKeyId()));
}
public static Credentials getCredentials() {
diff --git
a/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3TokenLogUtils.java
b/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3TokenLogUtils.java
new file mode 100644
index 000000000..1798112e5
--- /dev/null
+++
b/fluss-filesystems/fluss-fs-s3/src/main/java/org/apache/fluss/fs/s3/token/S3TokenLogUtils.java
@@ -0,0 +1,40 @@
+/*
+ * 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.fs.s3.token;
+
+import javax.annotation.Nullable;
+
+/** Utilities for logging S3 delegation token values safely. */
+final class S3TokenLogUtils {
+
+ private static final int ACCESS_KEY_VISIBLE_PREFIX_LENGTH = 3;
+ private static final String ACCESS_KEY_MASK = "******";
+
+ private S3TokenLogUtils() {}
+
+ @Nullable
+ static String maskAccessKey(@Nullable String accessKey) {
+ if (accessKey == null) {
+ return null;
+ }
+ if (accessKey.length() <= ACCESS_KEY_VISIBLE_PREFIX_LENGTH) {
+ return ACCESS_KEY_MASK;
+ }
+ return accessKey.substring(0, ACCESS_KEY_VISIBLE_PREFIX_LENGTH) +
ACCESS_KEY_MASK;
+ }
+}
diff --git
a/fluss-filesystems/fluss-fs-s3/src/test/java/org/apache/fluss/fs/s3/token/S3TokenLogUtilsTest.java
b/fluss-filesystems/fluss-fs-s3/src/test/java/org/apache/fluss/fs/s3/token/S3TokenLogUtilsTest.java
new file mode 100644
index 000000000..4b0c42081
--- /dev/null
+++
b/fluss-filesystems/fluss-fs-s3/src/test/java/org/apache/fluss/fs/s3/token/S3TokenLogUtilsTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.fs.s3.token;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link S3TokenLogUtils}. */
+class S3TokenLogUtilsTest {
+
+ @Test
+ void testMaskAccessKeyWithNull() {
+ assertThat(S3TokenLogUtils.maskAccessKey(null)).isNull();
+ }
+
+ @Test
+ void testMaskAccessKeyHidesShortValues() {
+ assertThat(S3TokenLogUtils.maskAccessKey("A")).isEqualTo("******");
+ assertThat(S3TokenLogUtils.maskAccessKey("AS7")).isEqualTo("******");
+ }
+
+ @Test
+ void testMaskAccessKeyKeepsPrefixForLongValues() {
+ String accessKey = "AS7124FSDFER";
+
+ assertThat(S3TokenLogUtils.maskAccessKey(accessKey))
+ .isEqualTo("AS7******")
+ .doesNotContain(accessKey);
+ }
+}