This is an automated email from the ASF dual-hosted git repository. smengcl pushed a commit to branch ozone-2.2 in repository https://gitbox.apache.org/repos/asf/ozone.git
commit c669b0c0ce979750f298ca5bb99909f7b2d2a0d1 Author: Andy Huang <[email protected]> AuthorDate: Thu Oct 15 12:07:18 2026 +0800 HDDS-16842. Check admin rights in OM bootstrap RPC (#11502) (cherry picked from commit 347e210acd0a0e8f85efbc028732eaf4cfe4f542) Conflicts: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMAdminRpcAuthorization.java Co-Authored-By: Claude Opus 5.5 <[email protected]> --- .../hadoop/ozone/om/TestAddRemoveOzoneManager.java | 3 ++- .../ozone/om/TestOMAdminRpcAuthorization.java | 31 ++++++++++++++++++++-- .../OMInterServiceProtocolServerSideImpl.java | 7 +++++ 3 files changed, 38 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 926d97c24e1..c142d27eb83 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 654f8ab2a5b..0a22936a496 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 @@ -22,6 +22,8 @@ import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_AUTHORIZER_CLASS_NATIVE; 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; @@ -29,6 +31,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.io.IOException; import java.security.PrivilegedExceptionAction; import java.util.UUID; import org.apache.hadoop.fs.SafeModeAction; @@ -41,6 +44,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; @@ -57,11 +61,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 { @@ -118,6 +123,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( @@ -175,6 +193,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]
