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

ivandika3 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 3139098b6ee HDDS-17361. S3 Gateway can set another user as the owner 
of a new key (#11707)
3139098b6ee is described below

commit 3139098b6eec614cd29754b2c1f91fffcf4ffa28
Author: Peter Lee <[email protected]>
AuthorDate: Sun Oct 25 10:10:51 2026 +0800

    HDDS-17361. S3 Gateway can set another user as the owner of a new key 
(#11707)
---
 .../apache/hadoop/ozone/client/rpc/RpcClient.java  | 10 ++-----
 .../hadoop/ozone/client/rpc/TestRpcClient.java     | 34 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git 
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
 
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
index 88014d62e61..6ce6966934c 100644
--- 
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
+++ 
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
@@ -222,7 +222,6 @@ public class RpcClient implements ClientProtocol {
   private final OzoneManagerClientProtocol ozoneManagerClient;
   private final XceiverClientFactory xceiverClientManager;
   private final UserGroupInformation ugi;
-  private UserGroupInformation s3gUgi;
   private final ClientId clientId = ClientId.randomId();
   private final boolean unsafeByteBufferConversion;
   private Text dtService;
@@ -280,9 +279,6 @@ public RpcClient(ConfigurationSource conf, String 
omServiceId)
     this.ozoneManagerClient = TracingUtil.createProxy(
         ozoneManagerProtocolClientSideTranslatorPB,
         OzoneManagerClientProtocol.class, conf);
-    if (getThreadLocalS3Auth() != null) {
-      this.s3gUgi = 
UserGroupInformation.createRemoteUser(getThreadLocalS3Auth().getUserPrincipal());
-    }
     dtService = omTransport.getDelegationTokenService();
     ServiceInfoEx serviceInfoEx = ozoneManagerClient.getServiceInfo();
     omVersion = getOmVersion(serviceInfoEx);
@@ -754,8 +750,9 @@ private UserGroupInformation getRealUserInfo() {
     // After HDDS-5881 the user will not be different,
     // as S3G uses single RpcClient. So we should be checking thread-local
     // S3Auth and use it during proxy.
-    if (ozoneManagerClient.getThreadLocalS3Auth() != null) {
-      return s3gUgi;
+    S3Auth s3Auth = ozoneManagerClient.getThreadLocalS3Auth();
+    if (s3Auth != null) {
+      return UserGroupInformation.createRemoteUser(s3Auth.getUserPrincipal());
     }
     return ugi;
   }
@@ -3054,7 +3051,6 @@ public OzoneKey headS3Object(String bucketName, String 
keyName)
   public void setThreadLocalS3Auth(
       S3Auth ozoneSharedSecretAuth) {
     ozoneManagerClient.setThreadLocalS3Auth(ozoneSharedSecretAuth);
-    this.s3gUgi = 
UserGroupInformation.createRemoteUser(getThreadLocalS3Auth().getUserPrincipal());
   }
 
   @Override
diff --git 
a/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
 
b/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
index 79b125bc50f..431da719f88 100644
--- 
a/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
+++ 
b/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
@@ -397,6 +397,40 @@ public void testListMultipartUploadsValidatesNames(String 
volume, String bucket,
     }
   }
 
+  /**
+   * S3 Gateway serves all users with one RpcClient. A request from bob on 
another thread must not change the owner
+   * of the key that alice creates.
+   */
+  @Test
+  public void testKeyOwnerComesFromS3AuthOfCallingThread() throws Exception {
+    List<String> owners = new ArrayList<>();
+    RpcClient client = createRpcClient(new MockOmTransport() {
+      @Override
+      public OMResponse submitRequest(OMRequest request) throws IOException {
+        if (request.getCmdType() == Type.CreateKey) {
+          
owners.add(request.getCreateKeyRequest().getKeyArgs().getOwnerName());
+        }
+        return super.submitRequest(request);
+      }
+    });
+    try {
+      client.createVolume("vol1");
+      client.createBucket("vol1", "bucket1");
+      client.setThreadLocalS3Auth(new S3Auth("stringToSign", "signature", 
"alice", "alice"));
+      Thread otherRequest = new Thread(
+          () -> client.setThreadLocalS3Auth(new S3Auth("stringToSign", 
"signature", "bob", "bob")));
+      otherRequest.start();
+      otherRequest.join();
+
+      ReplicationConfig replication = 
RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE);
+      client.createKey("vol1", "bucket1", "key1", 0, replication, 
Collections.emptyMap()).close();
+      assertThat(owners).containsExactly("alice");
+    } finally {
+      client.clearThreadLocalS3Auth();
+      client.close();
+    }
+  }
+
   @ParameterizedTest
   @EnumSource(value = OzoneManagerVersion.class,
       names = {"GET_FILE_STATUS_REJECTS_OBS", "ZDU", 
"S3_VOLUME_CONTEXT_RESOLUTION"})


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

Reply via email to