This is an automated email from the ASF dual-hosted git repository. smengcl pushed a commit to branch ozone-2.1 in repository https://gitbox.apache.org/repos/asf/ozone.git
commit 7d130764acbfad25531eb281c7c84c8ab009cd1e Author: Siyao Meng <[email protected]> AuthorDate: Fri Oct 16 16:52:26 2026 -0700 Align Echo with other container commands in HddsUtils. (cherry picked from commit 56188231787ebbe4366edee3e914f25d050bd21a) --- .../java/org/apache/hadoop/hdds/HddsUtils.java | 1 + .../ozoneimpl/TestOzoneContainerWithTLS.java | 32 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java index 9bcd36442f1..3e7250c0f03 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java @@ -495,6 +495,7 @@ public static boolean requireContainerToken(Type cmdType) { case UpdateContainer: case GetContainerChecksumInfo: case ListBlock: + case Echo: return true; default: return false; diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/ozoneimpl/TestOzoneContainerWithTLS.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/ozoneimpl/TestOzoneContainerWithTLS.java index af42ce3b752..6dac35625c1 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/ozoneimpl/TestOzoneContainerWithTLS.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/ozoneimpl/TestOzoneContainerWithTLS.java @@ -95,6 +95,7 @@ import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.token.Token; import org.apache.ozone.test.GenericTestUtils.LogCapturer; +import org.apache.ratis.thirdparty.com.google.protobuf.ByteString; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -293,6 +294,37 @@ public void testGetContainerMerkleTree() throws IOException { } } + @Test + public void testEchoRequiresContainerToken() throws IOException { + conf.setBoolean(HddsConfigKeys.HDDS_CONTAINER_TOKEN_ENABLED, true); + OzoneContainer container = createAndStartOzoneContainerInstance(); + XceiverClientManager clientManager = + new XceiverClientManager(conf, conf.getObject(ScmClientConfig.class), aClientTrustManager()); + XceiverClientSpi client = null; + try { + client = clientManager.acquireClient(pipeline); + long containerId = createAndCloseContainer(client, true); + TokenHelper tokenHelper = new TokenHelper(new SecurityConfig(conf), keyClient); + String containerToken = encode(tokenHelper.getContainerToken(ContainerID.valueOf(containerId))); + assertNotNull(ContainerProtocolCalls.echo(client, containerToken, containerId, ByteString.EMPTY, 1, 0, true)); + + // A token that can be decoded is not enough, it has to be valid for the container. + String otherContainerToken = encode(tokenHelper.getContainerToken(ContainerID.valueOf(containerId + 1))); + XceiverClientSpi finalClient = client; + StorageContainerException exception = assertThrows(StorageContainerException.class, () -> + ContainerProtocolCalls.echo(finalClient, otherContainerToken, containerId, ByteString.EMPTY, 1, 0, true)); + assertEquals(ContainerProtos.Result.BLOCK_TOKEN_VERIFICATION_FAILED, exception.getResult()); + } finally { + if (container != null) { + container.stop(); + } + if (client != null) { + clientManager.releaseClient(client, true); + } + IOUtils.closeQuietly(clientManager); + } + } + @Test public void testLongLivingClientWithCertRenews() throws Exception { LogCapturer logs = captureLogs(ClientTrustManager.class); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
