This is an automated email from the ASF dual-hosted git repository.
jojochuang 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 347e210acd0 HDDS-16842. Check admin rights in OM bootstrap RPC (#11502)
347e210acd0 is described below
commit 347e210acd0a0e8f85efbc028732eaf4cfe4f542
Author: Andy Huang <[email protected]>
AuthorDate: Thu Oct 15 12:07:18 2026 +0800
HDDS-16842. Check admin rights in OM bootstrap RPC (#11502)
---
.../hadoop/ozone/om/TestAddRemoveOzoneManager.java | 3 ++-
.../ozone/om/TestOMAdminRpcAuthorization.java | 29 ++++++++++++++++++++--
.../OMInterServiceProtocolServerSideImpl.java | 7 ++++++
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestAddRemoveOzoneManager.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestAddRemoveOzoneManager.java
index 113b9d30b41..4533ddf87f5 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestAddRemoveOzoneManager.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestAddRemoveOzoneManager.java
@@ -222,7 +222,8 @@ private List<String> testBootstrapListenerOMs(int
numNewOMs) throws Exception {
*/
@Test
public void testBootstrap() throws Exception {
- setupCluster(1);
+ // With admin authorization on, the new OMs are admitted as the user that
runs the OMs.
+ setupCluster(1, true);
OzoneManager oldOM = cluster.getOzoneManager();
// 1. Add 2 new OMs to an existing 1 node OM cluster.
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 817cb575f68..02b214af9bc 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
@@ -23,6 +23,7 @@
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_FAILOVER_MAX_ATTEMPTS_KEY;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -45,6 +46,7 @@
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.protocol.OMConfiguration;
import org.apache.hadoop.ozone.om.protocolPB.OMAdminProtocolClientSideImpl;
+import
org.apache.hadoop.ozone.om.protocolPB.OMInterServiceProtocolClientSideImpl;
import org.apache.hadoop.ozone.om.protocolPB.OmTransportFactory;
import
org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB;
import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.EchoRPCRequest;
@@ -61,11 +63,12 @@
import org.junit.jupiter.params.provider.ValueSource;
/**
- * Tests admin authorization of two OM administrative RPCs that are only ever
driven by admin
+ * Tests admin authorization of OM administrative RPCs that are only ever
driven by admin
* CLI tooling: refetchSecretKey() on the client protocol (mirrors the
checkAdminUserPrivilege
* gate used by transferLeadership/listOpenFiles), and getOMConfiguration() on
the OM admin
* protocol (mirrors the isAdmin check used by decommission()). Both must
reject non-admin
- * callers and serve admins.
+ * callers and serve admins. bootstrap() on the OM inter service protocol
carries the same
+ * isAdmin check and must reject non-admin callers.
*/
public class TestOMAdminRpcAuthorization {
@@ -123,6 +126,19 @@ private static OMConfiguration
getOMConfiguration(UserGroupInformation user)
});
}
+ private static void bootstrap(UserGroupInformation user) throws Exception {
+ OzoneConfiguration bootstrapConf = new OzoneConfiguration(conf);
+ bootstrapConf.setInt(OZONE_CLIENT_FAILOVER_MAX_ATTEMPTS_KEY, 1);
+ user.doAs((PrivilegedExceptionAction<Void>) () -> {
+ try (OMInterServiceProtocolClientSideImpl interServiceClient =
+ new OMInterServiceProtocolClientSideImpl(bootstrapConf, user,
null)) {
+ // Use the existing OM details to exercise authorization without
introducing another OM.
+
interServiceClient.bootstrap(cluster.getOzoneManager().getNodeDetails());
+ }
+ return null;
+ });
+ }
+
private static boolean setSafeMode(UserGroupInformation user, SafeModeAction
action) throws Exception {
return user.doAs((PrivilegedExceptionAction<Boolean>) () -> {
try (OzoneManagerProtocolClientSideTranslatorPB omClient = new
OzoneManagerProtocolClientSideTranslatorPB(
@@ -196,6 +212,15 @@ void getOMConfigurationAdminIsAllowed() throws Exception {
assertFalse(omConfig.getCurrentPeerList().isEmpty());
}
+ @Test
+ void bootstrapNonAdminIsDenied() {
+ UserGroupInformation nonAdmin =
+ UserGroupInformation.createUserForTesting("nonadmin", new String[]
{"users"});
+ assertThatThrownBy(() -> bootstrap(nonAdmin))
+ .isInstanceOf(IOException.class)
+ .hasMessageContaining("Only administrators are authorized to perform
bootstrap.");
+ }
+
private static int echoRPC(UserGroupInformation user, boolean writeToRatis)
throws Exception {
return user.doAs((PrivilegedExceptionAction<Integer>) () -> {
try (OzoneManagerProtocolClientSideTranslatorPB omClient = new
OzoneManagerProtocolClientSideTranslatorPB(
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OMInterServiceProtocolServerSideImpl.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OMInterServiceProtocolServerSideImpl.java
index f6a4339ff44..0c1a8cd4381 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OMInterServiceProtocolServerSideImpl.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OMInterServiceProtocolServerSideImpl.java
@@ -17,10 +17,14 @@
package org.apache.hadoop.ozone.protocolPB;
+import static org.apache.hadoop.hdds.utils.HddsServerUtil.getRemoteUser;
+import static
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.PERMISSION_DENIED;
+
import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException;
import java.io.IOException;
import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.OMNodeDetails;
import org.apache.hadoop.ozone.om.protocolPB.OMInterServiceProtocolPB;
import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer;
@@ -64,6 +68,9 @@ public BootstrapOMResponse bootstrap(RpcController controller,
.build();
try {
+ if (ozoneManager.isAdminAuthorizationEnabled() &&
!ozoneManager.isAdmin(getRemoteUser())) {
+ throw new OMException("Only administrators are authorized to perform
bootstrap.", PERMISSION_DENIED);
+ }
omRatisServer.addOMToRatisRing(newOmNode);
} catch (IOException ex) {
return BootstrapOMResponse.newBuilder()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]