HDFS-16750. NameNode should use NameNode.getRemoteUser() to log audit event to avoid possible NPE (#4821)

This commit is contained in:
ZanderXu 2022-09-03 01:23:03 +08:00 committed by GitHub
parent c48ed3e96c
commit 7b239a80fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -160,6 +160,7 @@
import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.BlockPoolSlice;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsVolumeImpl;
import org.apache.hadoop.hdfs.util.DataTransferThrottler;
import org.apache.hadoop.ipc.Server;
import org.apache.hadoop.util.*;
import org.apache.hadoop.hdfs.client.BlockReportOptions;
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
@ -1439,7 +1440,7 @@ private void checkSuperuserPrivilege() throws IOException, AccessControlExceptio
return;
}
// Try to get the ugi in the RPC call.
UserGroupInformation callerUgi = ipcServer.getRemoteUser();
UserGroupInformation callerUgi = Server.getRemoteUser();
if (callerUgi == null) {
// This is not from RPC.
callerUgi = UserGroupInformation.getCurrentUser();

View File

@ -417,7 +417,7 @@ void logAuditEvent(boolean succeeded, String cmd, String src)
private void logAuditEvent(boolean succeeded, String cmd, String src,
String dst, FileStatus stat) throws IOException {
if (isAuditEnabled() && isExternalInvocation()) {
logAuditEvent(succeeded, Server.getRemoteUser(), Server.getRemoteIp(),
logAuditEvent(succeeded, NameNode.getRemoteUser(), Server.getRemoteIp(),
cmd, src, dst, stat);
}
}