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
8 changes: 8 additions & 0 deletions docs/security/threat-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ evidence.
(never raw sample inputs or sensitive strings). Pack installs require two-person
approval (the requester cannot approve) and write desired-policy hashes plus audit rows
atomically; every collector still verifies pack signatures independently on load.
- Alert notifications and mutes (`AlertNotificationJob`, `/api/alerts/*`): outbound Teams
webhook URLs (`BOWER_ALERT_TEAMS_WEBHOOK_FILE`, HTTPS required) and SMTP passwords
(`BOWER_ALERT_EMAIL_PASSWORD_FILE`) are loaded strictly from server-side files and are
never persisted in the management database or returned over HTTP. Notification bodies
carry fixed plain-language condition wording, affected counts, suggested fixes and a
console link requiring Entra sign-in — never raw event payloads or collector secrets.
Alert mutes require the `Operate` role with a mandatory reason and bounded expiry, and
every mute, unmute and dispatched notification writes an audit row.
- Management API abuse: Entra-only endpoints (except token enrolment and the
enrolled-collector credential, above), per-principal rate limiting, HSTS on
HTTPS, restricted CORS headers and methods, and fixed error messages that never
Expand Down
69 changes: 69 additions & 0 deletions src/Bower.Management.Api/AlertCatalogue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace Bower.Management.Api;

/// <summary>
/// Deterministic mapping from internal health condition IDs and collector EventIds to plain
/// wording and suggested fixes. Single source of truth for alert validation and catalogue reads.
/// </summary>
public static class AlertCatalogue
{
public static readonly IReadOnlyList<AlertCatalogueEntry> Entries =
[
new("offline", HomeStates.Red, "Collector offline",
"A collector has not checked in for more than 15 minutes.",
"Check that the machine is switched on and can reach Bower.", "/collectors", ["2101"]),
new("history-changed", HomeStates.Red, "Event history changed unexpectedly",
"A collector reported a queue ledger sequence or hash that regressed.",
"Treat this as a possible tampering sign: check the machine and the Audit page.", "/audit", ["1600"]),
new("not-sending", HomeStates.Red, "Delivery stopped",
"A collector has not been able to send events for more than 15 minutes.",
"Open Collectors to see which machine is affected and check its connection to Azure.", "/collectors", ["1008"]),
new("stale", HomeStates.Amber, "Collector check-in delayed",
"A collector has not checked in for a few minutes.",
"This usually clears by itself. If it lasts, check the machine.", "/collectors", ["2101"]),
new("queue-full", HomeStates.Amber, "Queue or disk capacity reached",
"A collector has a full queue or critically low free disk space and is refusing new events.",
"Free disk space on the machine, or let it catch up once its connection to Azure works.", "/collectors", ["1500", "1501"]),
new("send-trouble", HomeStates.Amber, "Delivery trouble",
"A collector had trouble sending events to its destination.",
"Bower keeps trying. If it lasts more than 15 minutes, check the machine's connection to Azure.", "/collectors", ["1008"]),
new("pending", HomeStates.Amber, "Collector awaiting approval",
"A new collector has asked to join the fleet.",
"Review the request on the Approvals page.", "/approvals", []),
new("suspended", HomeStates.Amber, "Collector paused",
"A collector has been suspended by an administrator or inactivity policy.",
"Ask a Bower administrator to check why and reinstate it if it is still needed.", "/collectors", []),
new("set-aside", HomeStates.Amber, "Events set aside in dead-letter queue",
"Events could not be delivered after retries and were set aside.",
"Open Collectors to see which machine has them.", "/collectors", ["1510", "1511"]),
new("backlog", HomeStates.Amber, "Delivery backlog",
"Queued events have been waiting more than 15 minutes to be sent.",
"Check the machine's connection to Azure.", "/collectors", ["1008"]),
new("quiet-source", HomeStates.Amber, "Expected source went quiet",
"An expected application or event source stopped sending events within its allowance.",
"Check that the app is running and still sends events to Bower.", "/collectors", ["1110", "1120"]),
new("policy-not-applied", HomeStates.Amber, "Policy rules out of sync",
"A collector has not switched to its assigned event rules yet.",
"Open Collectors to see which rules it is using.", "/collectors", ["1702"]),
new("privacy-not-applied", HomeStates.Amber, "Privacy profile out of sync",
"A collector has not applied its assigned privacy profile yet.",
"Open Privacy profiles to check the rollout.", "/privacy-profiles", ["1702"]),
new("job-failed", HomeStates.Amber, "Maintenance job failed",
"A collector maintenance job failed on its last run.",
"Open the collector's details to see which job; it runs again on its schedule.", "/collectors", ["1302"]),
new("no-collectors", HomeStates.Amber, "No collectors connected",
"No collectors are connected to management yet.",
"Follow the Setup page to connect your first collector.", "/setup", []),
new(HomeProofStates.NotProven, HomeStates.Amber, "Sentinel delivery not yet proven",
"No recent test event has been verified in Microsoft Sentinel by query.",
"Send a test event from the Setup page.", "/setup", []),
new(HomeProofStates.Simulated, HomeStates.Amber, "Simulated delivery only",
"The last test event ran in simulated mode and was not verified in Microsoft Sentinel.",
"Send a real test event from the Setup page once Sentinel credentials are configured.", "/setup", [])
];

private static readonly HashSet<string> KnownIds =
Entries.Select(entry => entry.ConditionId).ToHashSet(StringComparer.Ordinal);

public static bool IsKnownCondition(string? conditionId) =>
!string.IsNullOrWhiteSpace(conditionId) && KnownIds.Contains(conditionId);
}
87 changes: 87 additions & 0 deletions src/Bower.Management.Api/AlertEndpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;

namespace Bower.Management.Api;

/// <summary>
/// Plain-language alert catalogue, notification channel status, and audited mute/unmute endpoints.
/// </summary>
internal static class AlertEndpoints
{
private const long BodyLimit = 16 * 1024;

public static void Map(RouteGroupBuilder api)
{
api.MapGet("/alerts/catalogue", () => Results.Ok(AlertCatalogue.Entries))
.RequireAuthorization("View");

api.MapGet("/alerts/channels", (AlertNotificationOptions options) => Results.Ok(options.Status()))
.RequireAuthorization("View");

api.MapGet(
"/alerts/mutes",
async (ManagementStore store, TimeProvider clock, CancellationToken cancellationToken) =>
Results.Ok(await store.ListActiveMutesAsync(clock.GetUtcNow(), cancellationToken)))
.RequireAuthorization("View");

api.MapPost(
"/alerts/mute",
async (
AlertMuteRequest request,
ClaimsPrincipal user,
ManagementStore store,
TimeProvider clock,
CancellationToken cancellationToken) =>
{
string conditionId = request.ConditionId?.Trim() ?? string.Empty;
int duration = request.DurationMinutes ?? ManagementStore.DefaultMuteMinutes;
try
{
AlertMuteRecord created = await store.MuteAlertAsync(
conditionId,
request.CollectorId,
duration,
request.Reason,
ManagementApplication.ObjectId(user),
ManagementApplication.DisplayName(user),
clock.GetUtcNow(),
cancellationToken);
return Results.Created($"/api/alerts/mutes/{created.Id}", created);
}
catch (ArgumentOutOfRangeException exception)
{
return Results.BadRequest(new ErrorResponse(exception.Message));
}
catch (ArgumentException exception)
{
return Results.BadRequest(new ErrorResponse(exception.Message));
}
})
.WithMetadata(new RequestSizeLimitAttribute(BodyLimit))
.RequireAuthorization("Operate");

api.MapPost(
"/alerts/mutes/{id}/unmute",
async (
string id,
ClaimsPrincipal user,
ManagementStore store,
TimeProvider clock,
CancellationToken cancellationToken) =>
{
if (string.IsNullOrWhiteSpace(id) || id.Length != 32 || !id.All(Uri.IsHexDigit))
{
return Results.NotFound();
}

AlertMuteRecord? updated = await store.UnmuteAlertAsync(
id,
ManagementApplication.ObjectId(user),
ManagementApplication.DisplayName(user),
clock.GetUtcNow(),
cancellationToken);
return updated is null ? Results.NotFound() : Results.Ok(updated);
})
.RequireAuthorization("Operate");
}
}
49 changes: 49 additions & 0 deletions src/Bower.Management.Api/AlertModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace Bower.Management.Api;

/// <summary>One entry in the plain-language alert catalogue mapping internal codes to operator fixes.</summary>
public sealed record AlertCatalogueEntry(
string ConditionId,
string Severity,
string Title,
string PlainDescription,
string SuggestedFix,
string Page,
IReadOnlyList<string> RelatedEventIds);

/// <summary>Request to mute one alert condition (fleet-wide or for one collector) with a required reason.</summary>
public sealed record AlertMuteRequest(
string? ConditionId,
string? CollectorId,
int? DurationMinutes,
string? Reason);

/// <summary>An active or historical audited alert mute.</summary>
public sealed record AlertMuteRecord(
string Id,
string ConditionId,
string? CollectorId,
string Reason,
string MutedByObjectId,
string MutedByName,
DateTimeOffset MutedAt,
DateTimeOffset ExpiresAt,
DateTimeOffset? UnmutedAt,
string? UnmutedByName);

/// <summary>Metadata-only status of configured notification channels (never URLs, paths or secrets).</summary>
public sealed record AlertChannelStatus(
bool TeamsConfigured,
bool EmailConfigured,
bool ConsoleUrlConfigured,
int DedupWindowMinutes);

/// <summary>Metadata-only outbound notification payload. Never contains raw event content or secrets.</summary>
public sealed record AlertNotificationMessage(
string DedupKey,
string ConditionId,
string Severity,
string Summary,
string SuggestedFix,
int AffectedCount,
string? ConsoleAlertsUrl,
DateTimeOffset DetectedAt);
Loading