From 2b207ea4029acbfd88bf69292aeb7b606bf50249 Mon Sep 17 00:00:00 2001 From: maobaolong <307499405@qq.com> Date: Tue, 10 Nov 2020 13:01:10 +0800 Subject: [PATCH] HDFS-15667. Audit log record the unexpected allowed result when delete (#2437) (cherry picked from commit 95c96605b30cc31839a04bd5d4061a2c89e4c09c) --- .../hadoop/hdfs/server/namenode/FSNamesystem.java | 2 +- .../namenode/TestAuditLoggerWithCommands.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index 194f1aff64..ba52441828 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -3256,7 +3256,7 @@ boolean delete(String src, boolean recursive, boolean logRetryCache) throw e; } getEditLog().logSync(); - logAuditEvent(true, operationName, src); + logAuditEvent(ret, operationName, src); if (toRemovedBlocks != null) { removeBlocks(toRemovedBlocks); // Incremental deletion of blocks } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java index 0814d4aab8..4d379b177a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java @@ -51,6 +51,7 @@ import org.junit.Test; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; import org.mockito.Mockito; @@ -1205,6 +1206,18 @@ public void testGetDatanodeStorageReport() throws Exception { } } + @Test + public void testDeleteRoot() throws Exception { + Path srcDir = new Path("/"); + fileSys = DFSTestUtil.getFileSystemAs(user1, conf); + boolean result = fileSys.delete(srcDir, true); + fileSys.close(); + assertFalse(result); + String aceDeletePattern = + ".*allowed=false.*ugi=theDoctor.*cmd=delete.*"; + verifyAuditLogs(aceDeletePattern); + } + private void verifyAuditRestoreFailedStorageACE( FSNamesystem fsNamesystem, String arg) throws IOException { String operationName = fsNamesystem.getFailedStorageCommand(arg);