HDFS-15667. Audit log record the unexpected allowed result when delete (#2437)

(cherry picked from commit 95c96605b3)
This commit is contained in:
maobaolong 2020-11-10 13:01:10 +08:00 committed by Wei-Chiu Chuang
parent 90bbaca88b
commit 2b207ea402
2 changed files with 14 additions and 1 deletions

View File

@ -3256,7 +3256,7 @@ boolean delete(String src, boolean recursive, boolean logRetryCache)
throw e; throw e;
} }
getEditLog().logSync(); getEditLog().logSync();
logAuditEvent(true, operationName, src); logAuditEvent(ret, operationName, src);
if (toRemovedBlocks != null) { if (toRemovedBlocks != null) {
removeBlocks(toRemovedBlocks); // Incremental deletion of blocks removeBlocks(toRemovedBlocks); // Incremental deletion of blocks
} }

View File

@ -51,6 +51,7 @@
import org.junit.Test; import org.junit.Test;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY; 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.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.mockito.Mockito; 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( private void verifyAuditRestoreFailedStorageACE(
FSNamesystem fsNamesystem, String arg) throws IOException { FSNamesystem fsNamesystem, String arg) throws IOException {
String operationName = fsNamesystem.getFailedStorageCommand(arg); String operationName = fsNamesystem.getFailedStorageCommand(arg);