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

smengcl 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 9005b4af866 HDDS-16156. Create HTTP base dir under java.io.tmpdir 
instead of the working directory (#10997)
9005b4af866 is described below

commit 9005b4af8665822a328216f7504672187d622ddf
Author: Siyao Meng <[email protected]>
AuthorDate: Thu Sep 17 08:08:52 2026 -0700

    HDDS-16156. Create HTTP base dir under java.io.tmpdir instead of the 
working directory (#10997)
    
    Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
---
 .../hadoop/hdds/server/http/HttpServer2.java       | 11 +++---
 .../hadoop/hdds/server/http/TestHttpServer2.java   | 45 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 5 deletions(-)

diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpServer2.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpServer2.java
index 994b4c6fa15..3a0a560a888 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpServer2.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/HttpServer2.java
@@ -37,7 +37,6 @@
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -1800,7 +1799,8 @@ protected List<ServerConnector> getListeners() {
 
   /**
    * Utility method to initialize config key ozone.http.basedir and create a
-   * temporary directory under the current working directory if not set.
+   * temporary directory under the system temporary directory
+   * ({@code java.io.tmpdir}) if not set.
    *
    * @param ozoneConfiguration current configuration.
    * @throws IOException if unable to create a temp directory.
@@ -1809,9 +1809,10 @@ public static void setHttpBaseDir(OzoneConfiguration 
ozoneConfiguration)
           throws IOException {
     if (org.apache.commons.lang3.StringUtils.isEmpty(ozoneConfiguration.get(
             OzoneConfigKeys.OZONE_HTTP_BASEDIR))) {
-      // Setting ozone.http.basedir to cwd if not set so that server setup
-      // doesn't fail.
-      File tmpMetaDir = Files.createTempDirectory(Paths.get(""),
+      // Create the base dir under java.io.tmpdir (not the process working
+      // directory) so server setup does not fail when the CWD is not
+      // writable, e.g. S3 Gateway running in a Kubernetes container.
+      File tmpMetaDir = Files.createTempDirectory(
               "ozone_http_tmp_base_dir").toFile();
       ShutdownHookManager.get().addShutdownHook(() -> {
         try {
diff --git 
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestHttpServer2.java
 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestHttpServer2.java
index dcbee53d42e..53ed18f6da4 100644
--- 
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestHttpServer2.java
+++ 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestHttpServer2.java
@@ -17,10 +17,18 @@
 
 package org.apache.hadoop.hdds.server.http;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 import java.net.URI;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermissions;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
 import org.eclipse.jetty.server.ServerConnector;
 import org.junit.jupiter.api.Test;
 
@@ -50,4 +58,41 @@ public void testIdleTimeout() throws Exception {
       assertEquals(60000, server.getIdleTimeout());
     }
   }
+
+  /**
+   * When ozone.http.basedir is not set, the base dir must be created under the
+   * system temporary directory (java.io.tmpdir), not the process working
+   * directory, so startup does not fail when the CWD is not writable.
+   */
+  @Test
+  public void testSetHttpBaseDirUsesSystemTempDir() throws Exception {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.unset(OzoneConfigKeys.OZONE_HTTP_BASEDIR);
+
+    HttpServer2.setHttpBaseDir(conf);
+
+    String baseDir = conf.get(OzoneConfigKeys.OZONE_HTTP_BASEDIR);
+    assertThat(baseDir).isNotEmpty();
+    Path baseDirPath = Paths.get(baseDir).toAbsolutePath().normalize();
+    assertThat(baseDirPath).exists();
+    Path systemTmpDir = Paths.get(System.getProperty("java.io.tmpdir"))
+        .toAbsolutePath().normalize();
+    assertThat(baseDirPath.startsWith(systemTmpDir)).isTrue();
+  }
+
+  /**
+   * The base dir must be owner-only (rwx------) so that only the user running
+   * the service can access it, since java.io.tmpdir is shared.
+   */
+  @Test
+  public void testSetHttpBaseDirIsOwnerOnly() throws Exception {
+    
assumeTrue(FileSystems.getDefault().supportedFileAttributeViews().contains("posix"));
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.unset(OzoneConfigKeys.OZONE_HTTP_BASEDIR);
+
+    HttpServer2.setHttpBaseDir(conf);
+
+    Path baseDirPath = Paths.get(conf.get(OzoneConfigKeys.OZONE_HTTP_BASEDIR));
+    
assertThat(PosixFilePermissions.toString(Files.getPosixFilePermissions(baseDirPath))).isEqualTo("rwx------");
+  }
 }


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

Reply via email to