From df27f1e0bc3926c5be2f89bdd9ceb0a47dceeef7 Mon Sep 17 00:00:00 2001 From: pgunapal Date: Thu, 20 Feb 2025 13:33:58 -0500 Subject: [PATCH 1/4] Added test for bridging audit logs to OTLP --- .../container/fat/LoggingServletTest.java | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java index 46eba07169c8..5af9ed0965ec 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2024 IBM Corporation and others. + * Copyright (c) 2024, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.util.Collections; import java.util.concurrent.TimeUnit; import org.jboss.shrinkwrap.api.ShrinkWrap; @@ -32,7 +33,6 @@ import componenttest.annotation.Server; import componenttest.containers.SimpleLogConsumer; import componenttest.custom.junit.runner.FATRunner; -import componenttest.custom.junit.runner.RepeatTestFilter; import componenttest.topology.impl.LibertyServer; import io.openliberty.microprofile.telemetry.internal_fat.shared.TelemetryActions; @@ -44,9 +44,12 @@ public class LoggingServletTest { @Server("TelemetryLogsServer") public static LibertyServer server; + public static final String APP_NAME = "MpTelemetryLogApp"; + public static final String SERVER_XML_MSG_SOURCES = "msgSourceServer.xml"; public static final String SERVER_XML_TRACE_SOURCE = "traceSourceServer.xml"; public static final String SERVER_XML_FFDC_SOURCE = "FFDCSourceServer.xml"; + public static final String SERVER_XML_AUDIT_SOURCE = "auditSourceServer.xml"; private static final String[] EXPECTED_FAILURES = { "CWMOT5005W", "SRVE0315E", "SRVE0777E" }; @@ -193,6 +196,58 @@ public void testFFDCLogs() throws Exception { } } + /* + * Ensures that audit events generated by a Liberty application are bridged over to the OTLP container. + */ + @Test + public void testAuditEventLogs() throws Exception { + assertTrue("The server was not started successfully.", server.isStarted()); + + TestUtils.isContainerStarted("LogsExporter", container); + + RemoteFile messageLogFile = server.getDefaultLogFile(); + setConfig(SERVER_XML_AUDIT_SOURCE, messageLogFile, server); + + // Hit the application to trigger an audit event. + TestUtils.runApp(server, "logs"); + + //Allow time for the collector to receive and bridge logs. + TimeUnit.SECONDS.sleep(WAIT_TIMEOUT); + + final String logs = container.getLogs(); + + // Verify audit event attributes generated by an application's audit event. + assertTrue("Audit type message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.type: Str(liberty_audit)")); + assertTrue("The Audit Event can not be found in the body.", TestUtils.assertLogContains("testAuditEventLogs", logs, "Body: Str(SECURITY_AUTHN)")); + assertTrue("The Audit event name attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.event_name: Str(SECURITY_AUTHN)")); + assertTrue("The Audit observer name attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.observer.name: Str(SecurityService)")); + assertTrue("The Audit observer type URI attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.observer.type_uri: Str(service/server)")); + assertTrue("The Audit outcome attribute can not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.outcome: Str(success)")); + assertTrue("The Audit reason code attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.reason.reason_code: Str(200)")); + assertTrue("The Audit reason type attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.reason.reason_type: Str(HTTP)")); + assertTrue("The Audit target app name attribute can not be found.", TestUtils + .assertLogContains("testAuditEventLogs", logs, + "io.openliberty.audit.target.appname: Str(io.openliberty.microprofile.telemetry.logging.internal.fat.MpTelemetryLogApp.LogServlet)")); + assertTrue("The Audit target method attribute can not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.method: Str(GET)")); + assertTrue("The Audit target name attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.name: Str(/MpTelemetryLogApp/LogURL)")); + assertTrue("The Audit target realm attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.realm: Str(defaultRealm)")); + assertTrue("The Audit target type URI attribute can not be found.", + TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.type_uri: Str(service/application/web)")); + + // Verify common Logging attributes + assertTrue("SeverityNumber message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "SeverityNumber: Info2(10)")); + assertTrue("Sequence message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.sequence: Str")); + assertTrue("Thread ID message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "thread.id: Int")); + + } + @AfterClass public static void tearDown() throws Exception { //catch if a server is still running. @@ -201,10 +256,10 @@ public static void tearDown() throws Exception { } } - private static String setConfig(String fileName, RemoteFile logFile, LibertyServer server) throws Exception { + private static void setConfig(String fileName, RemoteFile logFile, LibertyServer server) throws Exception { server.setMarkToEndOfLog(logFile); server.setServerConfigurationFile(fileName); - return server.waitForStringInLogUsingMark("CWWKG0017I.*|CWWKG0018I.*"); + server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), new String[] {}); } } From 1c20afbc6f1e37dc0383452361a73f3df1193907 Mon Sep 17 00:00:00 2001 From: pgunapal Date: Thu, 20 Feb 2025 13:35:01 -0500 Subject: [PATCH 2/4] Added new server configuration file to support audit logs --- .../publish/files/auditSourceServer.xml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml new file mode 100644 index 000000000000..a2b2d87daa5b --- /dev/null +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml @@ -0,0 +1,26 @@ + + + + audit-1.0 + servlet-6.0 + mpTelemetry-2.0 + + + + + + + + + + + + + + + + + + From 3bdd5915903b549f956ae2edd78f5d0e5ad97c89 Mon Sep 17 00:00:00 2001 From: pgunapal Date: Thu, 20 Feb 2025 13:35:29 -0500 Subject: [PATCH 3/4] Added beta JVM property to enable beta code --- .../bnd.bnd | 6 +++++- .../logging/internal/container/fat/LoggingServletTest.java | 2 +- .../publish/files/auditSourceServer.xml | 7 ++++--- .../publish/servers/TelemetryLogsServer/jvm.options | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd index 85b28b97eb61..ad4e1006e431 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd @@ -62,7 +62,11 @@ tested.features=mpTelemetry-2.0,\ pages-3.0,\ jsp-2.3,\ jsp-2.2,\ - el-3.0 + el-3.0,\ + appsecurity-6.0,\ + appsecurity-5.0,\ + appsecurity-4.0,\ + appsecurity-3.0 -buildpath: \ io.openliberty.jakarta.servlet.6.0;version=latest,\ diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java index 5af9ed0965ec..3f7c0316a336 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/fat/src/io/openliberty/microprofile/telemetry/logging/internal/container/fat/LoggingServletTest.java @@ -232,7 +232,7 @@ public void testAuditEventLogs() throws Exception { TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.reason.reason_type: Str(HTTP)")); assertTrue("The Audit target app name attribute can not be found.", TestUtils .assertLogContains("testAuditEventLogs", logs, - "io.openliberty.audit.target.appname: Str(io.openliberty.microprofile.telemetry.logging.internal.fat.MpTelemetryLogApp.LogServlet)")); + "io.openliberty.audit.target.appname: Str(io.openliberty.microprofile.telemetry.logging.internal.container.fat.MpTelemetryLogApp.LogServlet)")); assertTrue("The Audit target method attribute can not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.method: Str(GET)")); assertTrue("The Audit target name attribute can not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.name: Str(/MpTelemetryLogApp/LogURL)")); diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml index a2b2d87daa5b..e5237df90487 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/files/auditSourceServer.xml @@ -1,9 +1,10 @@ - audit-1.0 - servlet-6.0 - mpTelemetry-2.0 + audit-1.0 + mpTelemetry-2.0 + servlet-6.1 + appSecurity-6.0 diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/servers/TelemetryLogsServer/jvm.options b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/servers/TelemetryLogsServer/jvm.options index e69de29bb2d1..9ec5b94cf71a 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/servers/TelemetryLogsServer/jvm.options +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/publish/servers/TelemetryLogsServer/jvm.options @@ -0,0 +1 @@ +-Dcom.ibm.ws.beta.edition=true \ No newline at end of file From f5075576b82ae7808e9d7807610db9ffb8fe7716 Mon Sep 17 00:00:00 2001 From: pgunapal Date: Mon, 24 Feb 2025 13:21:50 -0500 Subject: [PATCH 4/4] Review comments - Add copyright year --- .../bnd.bnd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd index ad4e1006e431..59175b1f7583 100644 --- a/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd +++ b/dev/io.openliberty.microprofile.telemetry.2.0.logging.internal.container_fat/bnd.bnd @@ -1,5 +1,5 @@ #******************************************************************************* -# Copyright (c) 2024 IBM Corporation and others. +# Copyright (c) 2024, 2025 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 # which accompanies this distribution, and is available at