|
@@ -25,6 +25,7 @@ import java.net.InetAddress;
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.ipc.CallerContext;
|
|
|
import org.apache.hadoop.ipc.RPC;
|
|
|
import org.apache.hadoop.ipc.Server;
|
|
|
import org.apache.hadoop.ipc.TestRPC.TestImpl;
|
|
@@ -50,6 +51,8 @@ public class TestRMAuditLogger {
|
|
|
private static final ApplicationId APPID = mock(ApplicationId.class);
|
|
|
private static final ApplicationAttemptId ATTEMPTID = mock(ApplicationAttemptId.class);
|
|
|
private static final ContainerId CONTAINERID = mock(ContainerId.class);
|
|
|
+ private static final String CALLER_CONTEXT = "context";
|
|
|
+ private static final byte[] CALLER_SIGNATURE = "signature".getBytes();
|
|
|
|
|
|
@Before
|
|
|
public void setUp() throws Exception {
|
|
@@ -86,15 +89,20 @@ public class TestRMAuditLogger {
|
|
|
expLog.append("\tTARGET=tgt");
|
|
|
assertEquals(expLog.toString(), actLog.toString());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ private void testSuccessLogFormatHelper(boolean checkIP, ApplicationId appId,
|
|
|
+ ApplicationAttemptId attemptId, ContainerId containerId) {
|
|
|
+ testSuccessLogFormatHelper(checkIP, appId, attemptId, containerId, null);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Test the AuditLog format for successful events.
|
|
|
*/
|
|
|
private void testSuccessLogFormatHelper(boolean checkIP, ApplicationId appId,
|
|
|
- ApplicationAttemptId attemptId, ContainerId containerId) {
|
|
|
+ ApplicationAttemptId attemptId, ContainerId containerId,
|
|
|
+ CallerContext callerContext) {
|
|
|
String sLog = RMAuditLogger.createSuccessLog(USER, OPERATION, TARGET,
|
|
|
- appId, attemptId, containerId);
|
|
|
+ appId, attemptId, containerId, callerContext);
|
|
|
StringBuilder expLog = new StringBuilder();
|
|
|
expLog.append("USER=test\t");
|
|
|
if (checkIP) {
|
|
@@ -112,6 +120,14 @@ public class TestRMAuditLogger {
|
|
|
if (containerId != null) {
|
|
|
expLog.append("\tCONTAINERID=container_1");
|
|
|
}
|
|
|
+ if (callerContext != null) {
|
|
|
+ if (callerContext.getContext() != null) {
|
|
|
+ expLog.append("\tCALLERCONTEXT=context");
|
|
|
+ }
|
|
|
+ if (callerContext.getSignature() != null) {
|
|
|
+ expLog.append("\tCALLERSIGNATURE=signature");
|
|
|
+ }
|
|
|
+ }
|
|
|
assertEquals(expLog.toString(), sLog);
|
|
|
}
|
|
|
|
|
@@ -144,18 +160,33 @@ public class TestRMAuditLogger {
|
|
|
testSuccessLogFormatHelper(checkIP, APPID, null, CONTAINERID);
|
|
|
testSuccessLogFormatHelper(checkIP, null, ATTEMPTID, CONTAINERID);
|
|
|
testSuccessLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID);
|
|
|
+ testSuccessLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID, null);
|
|
|
+ testSuccessLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID,
|
|
|
+ new CallerContext.Builder(null).setSignature(null).build());
|
|
|
+ testSuccessLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID,
|
|
|
+ new CallerContext.Builder(CALLER_CONTEXT).setSignature(null).build());
|
|
|
+ testSuccessLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID,
|
|
|
+ new CallerContext.Builder(null).setSignature(CALLER_SIGNATURE).build());
|
|
|
+ testSuccessLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID,
|
|
|
+ new CallerContext.Builder(CALLER_CONTEXT).setSignature(CALLER_SIGNATURE)
|
|
|
+ .build());
|
|
|
testSuccessLogNulls(checkIP);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ private void testFailureLogFormatHelper(boolean checkIP, ApplicationId appId,
|
|
|
+ ApplicationAttemptId attemptId, ContainerId containerId) {
|
|
|
+ testFailureLogFormatHelper(checkIP, appId, attemptId, containerId, null);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Test the AuditLog format for failure events.
|
|
|
*/
|
|
|
private void testFailureLogFormatHelper(boolean checkIP, ApplicationId appId,
|
|
|
- ApplicationAttemptId attemptId, ContainerId containerId) {
|
|
|
+ ApplicationAttemptId attemptId, ContainerId containerId,
|
|
|
+ CallerContext callerContext) {
|
|
|
String fLog =
|
|
|
RMAuditLogger.createFailureLog(USER, OPERATION, PERM, TARGET, DESC,
|
|
|
- appId, attemptId, containerId);
|
|
|
+ appId, attemptId, containerId, callerContext);
|
|
|
StringBuilder expLog = new StringBuilder();
|
|
|
expLog.append("USER=test\t");
|
|
|
if (checkIP) {
|
|
@@ -174,6 +205,14 @@ public class TestRMAuditLogger {
|
|
|
if (containerId != null) {
|
|
|
expLog.append("\tCONTAINERID=container_1");
|
|
|
}
|
|
|
+ if (callerContext != null) {
|
|
|
+ if (callerContext.getContext() != null) {
|
|
|
+ expLog.append("\tCALLERCONTEXT=context");
|
|
|
+ }
|
|
|
+ if (callerContext.getSignature() != null) {
|
|
|
+ expLog.append("\tCALLERSIGNATURE=signature");
|
|
|
+ }
|
|
|
+ }
|
|
|
assertEquals(expLog.toString(), fLog);
|
|
|
}
|
|
|
|
|
@@ -190,6 +229,16 @@ public class TestRMAuditLogger {
|
|
|
testFailureLogFormatHelper(checkIP, APPID, null, CONTAINERID);
|
|
|
testFailureLogFormatHelper(checkIP, null, ATTEMPTID, CONTAINERID);
|
|
|
testFailureLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID);
|
|
|
+
|
|
|
+ testFailureLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID,
|
|
|
+ new CallerContext.Builder(null).setSignature(null).build());
|
|
|
+ testFailureLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID,
|
|
|
+ new CallerContext.Builder(CALLER_CONTEXT).setSignature(null).build());
|
|
|
+ testFailureLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID,
|
|
|
+ new CallerContext.Builder(null).setSignature(CALLER_SIGNATURE).build());
|
|
|
+ testFailureLogFormatHelper(checkIP, APPID, ATTEMPTID, CONTAINERID,
|
|
|
+ new CallerContext.Builder(CALLER_CONTEXT).setSignature(CALLER_SIGNATURE)
|
|
|
+ .build());
|
|
|
}
|
|
|
|
|
|
/**
|