use of co.cask.cdap.common.logging.AuditLogConfig in project cdap by caskdata.
the class RouterAuditLookUpTest method testAppFabricEndpoints.
@Test
public void testAppFabricEndpoints() throws Exception {
// endpoints from AppLifecycleHttpHandler
assertContent("/v3/namespaces/default/apps/myApp", DEFAULT_AUDIT);
assertContent("/v3/namespaces/default/apps", new AuditLogConfig(HttpMethod.POST, false, true, ImmutableList.of(AbstractAppFabricHttpHandler.ARCHIVE_NAME_HEADER, AbstractAppFabricHttpHandler.APP_CONFIG_HEADER, AbstractAppFabricHttpHandler.PRINCIPAL_HEADER, AbstractAppFabricHttpHandler.SCHEDULES_HEADER)));
// endpoints from ArtifactHttpHandler
assertContent("/v3/namespaces/default/artifacts/myArtifact/versions/1.0/properties", DEFAULT_AUDIT);
assertContent("/v3/namespaces/default/artifacts/myArtifact", new AuditLogConfig(HttpMethod.POST, false, false, ImmutableList.of("Artifact-Version", "Artifact-Extends", "Artifact-Plugins")));
// endpoints from AuthorizationHandler
assertContent("/v3/security/authorization/privileges/grant", new AuditLogConfig(HttpMethod.POST, true, false, EMPTY_HEADERS));
// endpoints from ConsoleSettingsHttpHandler
assertContent("/v3/configuration/user/", DEFAULT_AUDIT);
// endpoints from DashboardHttpHandler
assertContent("/v3/namespaces/default/configuration/dashboards", new AuditLogConfig(HttpMethod.POST, true, true, EMPTY_HEADERS));
// endpoints from MetadataHttpHandler
assertContent("/v3/namespaces/default/apps/app1/metadata/properties", new AuditLogConfig(HttpMethod.POST, true, false, EMPTY_HEADERS));
// endpoints from MonitorHttpHandler
assertContent("/v3/system/services/appfabric/instances", DEFAULT_AUDIT);
// endpoints from NamespaceHttpHandler
assertContent("/v3/namespaces/default", DEFAULT_AUDIT);
// endpoints from NotificationFeedHttpHandler
assertContent("/v3/namespaces/default/feeds/categories/feed1/names/myFeed", DEFAULT_AUDIT);
// endpoints from PreferencesHttpHandler
assertContent("/v3/preferences", DEFAULT_AUDIT);
// endpoints from ProgramLifecycleHttpHandler
assertContent("/v3/namespaces/default/stop", new AuditLogConfig(HttpMethod.POST, true, true, EMPTY_HEADERS));
// endpoints from RouteConfigHttpHandler
assertContent("/v3/namespaces/default/apps/myApp/services/myService/routeconfig", DEFAULT_AUDIT);
// endpoints from SecureStoreHandler
assertContent("/v3/namespaces/default/securekeys/myKey", DEFAULT_AUDIT);
// endpoints from TransactionHttpHandler
assertContent("/v3/transactions/invalid/remove/until", new AuditLogConfig(HttpMethod.POST, true, false, EMPTY_HEADERS));
}
use of co.cask.cdap.common.logging.AuditLogConfig in project cdap by caskdata.
the class RouterAuditLookUpTest method testExploreEndpoints.
@Test
public void testExploreEndpoints() throws Exception {
// endpoints from ExploreExecutorHttpHandler
assertContent("/v3/namespaces/default/data/explore/datasets/myDataset/update", new AuditLogConfig(HttpMethod.POST, true, false, EMPTY_HEADERS));
// endpoints from NamespacedExploreMetadataHttpHandler
assertContent("/v3/namespaces/default/data/explore/jdbc/tables", new AuditLogConfig(HttpMethod.POST, true, false, EMPTY_HEADERS));
// endpoints from NamespacedExploreQueryExecutorHttpHandler
assertContent("/v3/namespaces/default/data/explore/queries", new AuditLogConfig(HttpMethod.POST, true, false, EMPTY_HEADERS));
}
use of co.cask.cdap.common.logging.AuditLogConfig in project cdap by caskdata.
the class RouterAuditLookUp method createMatcher.
private int createMatcher() {
List<ClassPath.ClassInfo> handlerClasses;
try {
handlerClasses = getAllHandlerClasses();
} catch (IOException e) {
LOG.error("Failed to get all handler classes for audit logging: {}", e.getCause());
return -1;
}
int count = 0;
for (ClassPath.ClassInfo classInfo : handlerClasses) {
Class<?> handlerClass = classInfo.load();
Path classPath = handlerClass.getAnnotation(Path.class);
String classPathStr = classPath == null ? "" : classPath.value();
for (Method method : handlerClass.getMethods()) {
Path methodPath = method.getAnnotation(Path.class);
AuditPolicy auditPolicy = method.getAnnotation(AuditPolicy.class);
HttpMethod httpMethod = getHttpMethod(method);
if (methodPath == null || auditPolicy == null || httpMethod == null) {
continue;
}
String methodPathStr = methodPath.value();
String completePath = classPathStr.endsWith("/") || methodPathStr.startsWith("/") ? classPathStr + methodPathStr : classPathStr + "/" + methodPathStr;
List<AuditDetail> auditContents = Arrays.asList(auditPolicy.value());
List<String> headerNames = new ArrayList<>();
if (auditContents.contains(AuditDetail.HEADERS)) {
Annotation[][] annotations = method.getParameterAnnotations();
for (Annotation[] annotationArr : annotations) {
if (annotationArr.length > 0) {
for (Annotation annotation : annotationArr) {
if (annotation instanceof HeaderParam) {
headerNames.add(((HeaderParam) annotation).value());
}
}
}
}
}
AuditLogConfig auditLogConfig = new AuditLogConfig(httpMethod, auditContents.contains(AuditDetail.REQUEST_BODY), auditContents.contains(AuditDetail.RESPONSE_BODY), headerNames);
LOG.trace("Audit log lookup: bootstrapped with path: {}", completePath);
patternMatcher.add(completePath, auditLogConfig);
// Don't count classes in unit-tests
if (!isTestClass(classInfo)) {
count++;
}
}
}
LOG.debug("Audit log lookup: bootstrapped with {} paths", count);
return count;
}
use of co.cask.cdap.common.logging.AuditLogConfig in project cdap by caskdata.
the class AuditLogHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
// When a request is forwarded to the internal CDAP service
if (msg instanceof HttpRequest) {
HttpRequest request = (HttpRequest) msg;
// Extra configurations for audit log
AuditLogConfig logConfig = AUDIT_LOG_LOOKUP_METHOD.contains(request.method()) ? RouterAuditLookUp.getInstance().getAuditLogContent(request.uri(), request.method()) : null;
if (logConfig == null) {
logEntry = new AuditLogEntry(request, Networks.getIP(ctx.channel().remoteAddress()));
} else {
logEntry = new AuditLogEntry(request, Networks.getIP(ctx.channel().remoteAddress()), logConfig.getHeaderNames());
logRequestBody = logConfig.isLogRequestBody();
logResponseBody = logConfig.isLogResponseBody();
}
} else if (msg instanceof HttpContent && logEntry != null) {
ByteBuf content = ((HttpContent) msg).content();
if (logRequestBody && content.isReadable()) {
logEntry.appendRequestBody(content.toString(StandardCharsets.UTF_8));
}
}
ctx.fireChannelRead(msg);
}
use of co.cask.cdap.common.logging.AuditLogConfig in project cdap by caskdata.
the class RouterAuditLookUpTest method testDataFabricEndpoints.
@Test
public void testDataFabricEndpoints() throws Exception {
// endpoints from DatasetInstanceHandler
assertContent("/v3/namespaces/default/data/datasets/myDataset", DEFAULT_AUDIT);
// endpoints from DatasetTypeHandler
assertContent("/v3/namespaces/default/data/modules/myModule", new AuditLogConfig(HttpMethod.PUT, false, false, ImmutableList.of("X-Class-Name")));
// endpoints from StreamHandler
assertContent("/v3/namespaces/default/streams/myStream", DEFAULT_AUDIT);
// endpoints from StreamViewHttpHandler
assertContent("/v3/namespaces/default/streams/foo/views/myView", DEFAULT_AUDIT);
}
Aggregations