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 3772ec53894 Improve setSafeMode handling in OzoneManager.
3772ec53894 is described below
commit 3772ec5389479f7a5ce83c2e9d3ca26a6da2d881
Author: Siyao Meng <[email protected]>
AuthorDate: Wed Oct 14 01:38:20 2026 -0700
Improve setSafeMode handling in OzoneManager.
---
.../ozone/om/TestOMAdminRpcAuthorization.java | 25 ++++++++++++++++++++++
.../org/apache/hadoop/ozone/om/OzoneManager.java | 2 ++
2 files changed, 27 insertions(+)
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMAdminRpcAuthorization.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMAdminRpcAuthorization.java
index f84636ed842..654f8ab2a5b 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMAdminRpcAuthorization.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMAdminRpcAuthorization.java
@@ -31,6 +31,7 @@
import java.security.PrivilegedExceptionAction;
import java.util.UUID;
+import org.apache.hadoop.fs.SafeModeAction;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.security.symmetric.ManagedSecretKey;
import org.apache.hadoop.hdds.security.symmetric.SecretKeyClient;
@@ -117,6 +118,30 @@ private static OMConfiguration
getOMConfiguration(UserGroupInformation user)
});
}
+ private static boolean setSafeMode(UserGroupInformation user, SafeModeAction
action) throws Exception {
+ return user.doAs((PrivilegedExceptionAction<Boolean>) () -> {
+ try (OzoneManagerProtocolClientSideTranslatorPB omClient = new
OzoneManagerProtocolClientSideTranslatorPB(
+ OmTransportFactory.create(conf, user, null),
ClientId.randomId().toString())) {
+ return omClient.setSafeMode(action, false);
+ }
+ });
+ }
+
+ @Test
+ void forceExitSafeModeNonAdminIsDenied() throws Exception {
+ UserGroupInformation nonAdmin =
UserGroupInformation.createUserForTesting("nonadmin", new String[] {"users"});
+ OMException ex = assertThrows(OMException.class, () ->
setSafeMode(nonAdmin, SafeModeAction.FORCE_EXIT));
+ assertEquals(OMException.ResultCodes.PERMISSION_DENIED, ex.getResult());
+ // Querying safe mode stays open to every user.
+ assertFalse(setSafeMode(nonAdmin, SafeModeAction.GET));
+ }
+
+ @Test
+ void forceExitSafeModeAdminIsAllowed() throws Exception {
+ UserGroupInformation admin =
UserGroupInformation.createUserForTesting("admin", new String[] {"admins"});
+ assertTrue(setSafeMode(admin, SafeModeAction.FORCE_EXIT));
+ }
+
@Test
void refetchSecretKeyNonAdminIsDenied() {
UserGroupInformation nonAdmin =
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
index 6ce97108c2d..de6b83b653c 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
@@ -5736,6 +5736,8 @@ public boolean setSafeMode(SafeModeAction action, boolean
isChecked)
throw new OMException("Enter safe mode is unsupported",
INTERNAL_ERROR);
case FORCE_EXIT:
+ // SCM sees this call as coming from the OM user, so the caller has to
be checked here.
+ checkAdminUserPrivilege("force exit safe mode.");
return getScmClient().getContainerClient().forceExitSafeMode();
case GET:
return getScmClient().getContainerClient().inSafeMode();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]