Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void Decision_allow_emits_one_entry_on_audit_category()
Assert.That(ecs.GetProperty("user").GetProperty("id").GetString(), Is.EqualTo("alice-sub-001"));
Assert.That(ecs.GetProperty("user").GetProperty("name").GetString(), Is.EqualTo("Alice Smith"));
Assert.That(ecs.GetProperty("event").GetProperty("action").GetString(), Is.EqualTo("error:messages:retry"));
Assert.That(ecs.GetProperty("ecs").GetProperty("version").GetString(), Is.EqualTo("8.11.0"));
Assert.That(entries[0].Level, Is.EqualTo(LogLevel.Information));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void Operation_emits_one_entry_on_operation_category()
Assert.That(ecs.GetProperty("servicecontrol").GetProperty("resource").GetString(), Is.EqualTo("group-1"));
Assert.That(ecs.GetProperty("servicecontrol").GetProperty("count").GetInt32(), Is.EqualTo(42));
Assert.That(ecs.GetProperty("servicecontrol").GetProperty("operation").GetProperty("id").GetString(), Is.EqualTo("op-1"));
Assert.That(ecs.GetProperty("ecs").GetProperty("version").GetString(), Is.EqualTo("8.11.0"));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public sealed class AuthorizationAuditLog(ILoggerFactory loggerFactory) : IAutho
{
public const string AuditCategory = "ServiceControl.Audit"; // Logger name is used in logging configuration to write audit entries to a separate file.

// The ECS version the emitted documents conform to, surfaced as the ecs.version field so downstream
// pipelines can pick the matching mappings. 8.11.0 is the latest ECS schema release; the fields used
// here (event.category/type/outcome, user.*) are stable across the 8.x line. Shared with
// MessageActionAuditLog so both streams declare the same version.
internal const string EcsVersion = "8.11.0";

readonly ILogger logger = loggerFactory.CreateLogger(AuditCategory);

// Relaxed escaping keeps the JSON readable for log sinks (no \uXXXX for '+', '<', accented names, …);
Expand Down Expand Up @@ -49,6 +55,7 @@ static string BuildEcsEvent(string subjectId, string subjectName, string permiss
var ecs = new Dictionary<string, object?>
{
["@timestamp"] = DateTimeOffset.UtcNow.ToString("O"),
["ecs"] = new { version = EcsVersion },
["event"] = new
{
kind = "event",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static string BuildEcsEvent(AuditUser user, MessageActionKind kind, string permi
var ecs = new Dictionary<string, object?>
{
["@timestamp"] = DateTimeOffset.UtcNow.ToString("O"),
["ecs"] = new { version = AuthorizationAuditLog.EcsVersion },
["event"] = new
{
kind = "event",
Expand Down
Loading