HDFS-17469. Audit log for reportBadBlocks RPC (#6731)

This commit is contained in:
cxzl25 2024-04-24 09:39:57 +08:00 committed by GitHub
parent 782c501441
commit 23286b0632
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -993,6 +993,7 @@ public boolean complete(String src, String clientName,
public void reportBadBlocks(LocatedBlock[] blocks) throws IOException { public void reportBadBlocks(LocatedBlock[] blocks) throws IOException {
checkNNStartup(); checkNNStartup();
namesystem.reportBadBlocks(blocks); namesystem.reportBadBlocks(blocks);
namesystem.logAuditEvent(true, "reportBadBlocks", null);
} }
@Override // ClientProtocol @Override // ClientProtocol

View File

@ -33,6 +33,7 @@
import org.apache.hadoop.hdfs.protocol.CachePoolEntry; import org.apache.hadoop.hdfs.protocol.CachePoolEntry;
import org.apache.hadoop.hdfs.protocol.CachePoolInfo; import org.apache.hadoop.hdfs.protocol.CachePoolInfo;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorageReport; import org.apache.hadoop.hdfs.server.protocol.DatanodeStorageReport;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.ipc.RPC;
@ -1218,6 +1219,25 @@ public void testDeleteRoot() throws Exception {
verifyAuditLogs(aceDeletePattern); verifyAuditLogs(aceDeletePattern);
} }
@Test
public void testReportBadBlocks() throws IOException {
String auditLogString =
".*allowed=true.*cmd=reportBadBlocks.*";
FSNamesystem fsNamesystem = spy(cluster.getNamesystem());
when(fsNamesystem.isExternalInvocation()).thenReturn(true);
Server.Call call = spy(new Server.Call(
1, 1, null, null, RPC.RpcKind.RPC_BUILTIN, new byte[] {1, 2, 3}));
when(call.getRemoteUser()).thenReturn(
UserGroupInformation.createRemoteUser(System.getProperty("user.name")));
Server.getCurCall().set(call);
try {
cluster.getNameNodeRpc().reportBadBlocks(new LocatedBlock[]{});
verifyAuditLogs(auditLogString);
} catch (Exception e) {
fail(" The operation threw an exception" + e);
}
}
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);