This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 945c4040d5f HDDS-17928. Omit credentials in S3 Gateway audit log 
(#12177)
945c4040d5f is described below

commit 945c4040d5f3b988be57327bd4eaba2eb009e546
Author: rajeshkumarchandolu <[email protected]>
AuthorDate: Thu Nov 26 19:01:05 2026 +0530

    HDDS-17928. Omit credentials in S3 Gateway audit log (#12177)
---
 .../apache/hadoop/ozone/s3/util/AuditUtils.java    | 10 +++-
 .../hadoop/ozone/s3/util/TestAuditUtils.java       | 64 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/AuditUtils.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/AuditUtils.java
index 978f96ddb35..dbe59cdebe9 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/AuditUtils.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/AuditUtils.java
@@ -21,13 +21,19 @@
 
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 import javax.ws.rs.container.ContainerRequestContext;
 
 /**
  * Common utilities for operation auditing purposes.
  */
 public final class AuditUtils {
+  /** Lower-case names of the SigV4 and SigV2 presigned-request query 
parameters that carry credentials. */
+  private static final Set<String> CREDENTIAL_QUERY_PARAMETERS = Set.of(
+      "x-amz-signature", "x-amz-credential", "x-amz-security-token", 
"signature", "awsaccesskeyid");
+
   private AuditUtils() {
   }
 
@@ -41,7 +47,9 @@ public static Map<String, String> getAuditParameters(
       }
       for (Map.Entry<String, List<String>> entry :
           context.getUriInfo().getQueryParameters().entrySet()) {
-        res.put(entry.getKey(), entry.getValue().toString());
+        if 
(!CREDENTIAL_QUERY_PARAMETERS.contains(entry.getKey().toLowerCase(Locale.ROOT)))
 {
+          res.put(entry.getKey(), entry.getValue().toString());
+        }
       }
     }
     return res;
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestAuditUtils.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestAuditUtils.java
new file mode 100644
index 00000000000..a5aead20d84
--- /dev/null
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestAuditUtils.java
@@ -0,0 +1,64 @@
+/*
+ * 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.hadoop.ozone.s3.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Map;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link AuditUtils}.
+ */
+public class TestAuditUtils {
+
+  @Test
+  public void testPresignedRequestCredentialsAreNotAudited() {
+    MultivaluedMap<String, String> query = new MultivaluedHashMap<>();
+    // SigV4 and SigV2 credentials, including a differently cased name
+    query.add("X-Amz-Signature", "secret");
+    query.add("X-Amz-Credential", "secret");
+    query.add("X-Amz-Security-Token", "secret");
+    query.add("AWSAccessKeyId", "secret");
+    query.add("Signature", "secret");
+    query.add("x-amz-SIGNATURE", "secret");
+    query.add("X-Amz-Date", "20130524T000000Z");
+    query.add("prefix", "photos/");
+
+    Map<String, String> params = 
AuditUtils.getAuditParameters(requestContext(query));
+
+    assertThat(params).containsOnlyKeys("bucket", "X-Amz-Date", "prefix");
+  }
+
+  private static ContainerRequestContext requestContext(MultivaluedMap<String, 
String> query) {
+    MultivaluedMap<String, String> path = new MultivaluedHashMap<>();
+    path.add("bucket", "bucket1");
+    UriInfo uriInfo = mock(UriInfo.class);
+    when(uriInfo.getPathParameters()).thenReturn(path);
+    when(uriInfo.getQueryParameters()).thenReturn(query);
+    ContainerRequestContext context = mock(ContainerRequestContext.class);
+    when(context.getUriInfo()).thenReturn(uriInfo);
+    return context;
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to