Alerting on security events in Loki: what it covers and when teams need it
LogQL alert rules can detect defined log patterns such as repeated authentication failures, privilege change messages and specific error signatures in logs you already collect in Loki. If your team is already shipping application and system logs into Loki, the ruler can evaluate those patterns on a schedule and fire alerts when a threshold is crossed. What it cannot do is decide what is suspicious on your behalf. Loki ships no built-in detection content, no entity correlation across sources and no case management. Every rule is one you write, test and maintain, and the alert logic is only as good as the log fields and labels your sources emit.
The ruler is one stage of the alerting path, not the whole path. It evaluates the expression and produces alerts, which are then delivered either to Prometheus Alertmanager, where routing, grouping, silencing and receivers are configured, or to Grafana Alerting, which can also manage notification policies and contact points. Before you commit to a design, confirm which of these your team will operate, where rule files will live, and who receives and acknowledges each notification. Check the current behavior of the ruler and its alert delivery in the Loki documentation for your Loki version, since the rule storage and sharding details are covered in a sibling section.
Whether Loki alone is enough depends on what the alerts must support. A log-based rule suits a narrow, well-understood signal, such as failed logins from one application or sudo use outside a change window, where the team can write the pattern and act on the result. A SIEM is usually the better tool when you need broad detection content maintained by others, correlation of events across endpoints, network and identity systems, entity-level timelines, case workflows and long-term security analytics. Wazuh, covered elsewhere on this site, is one open-source option that bundles rules, agents and an alert store. Ask your security team to list the detections they must answer for, then map each one to either a Loki rule with a named owner or a SIEM use case. Confirm the retention and access requirements for alert evidence as well, because Loki retention and tenancy settings govern the logs behind each alert, not the alert history itself.
Which security signals suit Loki alert rules and which need a SIEM
Authentication failures are the most common security signal that Loki can alert on, because application and operating system logs usually record them as discrete lines with stable wording. A LogQL alert rule can count matching lines over a window and fire when the count crosses a threshold you choose. The threshold is a policy decision for your team, so set it from your own baseline rather than from a generic number.
- Required sources: SSH, sudo and PAM logs from Linux hosts, plus sign-in logs from the applications and identity provider that your users actually authenticate against.
- Parsing: Failed-login wording differs between distributions and applications, so confirm the exact message formats in your environment before writing matchers.
- Loki fit: A rule can alert on repeated failures per host or per application, which covers many brute-force and credential-stuffing patterns at the log level.
- SIEM adds: Correlating failures with successful logins, geolocation, device identity and directory events across several systems is usually easier in a SIEM.
- Retention: Confirm that the authentication logs you alert on are retained long enough for investigation, since retention is set in Loki and is disabled by default.
Before you deploy the rule, check that every source you rely on is actually shipped to Loki and that the labels let you separate hosts and applications.
Privilege and group changes are discrete, high-value events such as a user added to a sudo group, a role granted in an application or a change to an administrator list. Loki can alert on them when the change is written to a log line with a recognizable message. The alert is only as good as the audit trail behind it, so confirm that the originating system logs these changes at all before building the rule.
- Required sources: Auditd or equivalent OS audit output for group and sudoers changes, and audit or admin logs from applications and identity platforms.
- Loki fit: A single-line match on a privilege change can alert quickly, and the rule is simple to review and version with the rest of your configuration.
- Gap to check: Some changes happen through APIs or config management and may not produce a readable log line in every system. Test each change path and confirm what the log records.
- SIEM adds: Linking a privilege change to the ticket, the requester, the change window and other activity by the same account is typically a SIEM or case-management task.
- Review: Ask whether changes to the rule itself are logged and approved, since a silent rule change can hide a gap.
Before relying on these alerts for compliance evidence, confirm with your auditors which change records they expect to see.
Patterns such as many requests from one source, unusual error spikes or sudden volume changes are where Loki rules are useful and also where they are easiest to misconfigure. LogQL can aggregate counts by label, which makes per-source bursts natural to express. The thresholds, windows and exclusions must come from your own traffic, and they will need tuning as traffic changes. Do not copy thresholds from examples without testing them against your logs.
- Required sources: Web server, reverse proxy, API gateway and application error logs with a source address or user identifier in a stable field.
- Labels: Keep source identifiers out of stream labels where cardinality would be high, and use parsed fields or structured metadata for them instead.
- Loki fit: Rate and count expressions handle per-source bursts and error spikes well for alerting on the service itself.
- Noise: Health checks, scanners you run and batch jobs create false positives, so plan allowlists and review them regularly.
- SIEM adds: Behavioral baselines across users, hosts and time, and scoring that combines many weak signals, are generally the strength of a SIEM.
Before going live, replay a representative period of logs against the rule and count how many alerts it would have produced.
Cross-source correlation and long-horizon hunting are the signals where a SIEM is usually the better tool. Correlating an authentication failure on one system with a privilege change on another, across days or weeks, needs joined data sets, enrichment and analyst workflow. Loki can hold the raw logs and answer many queries, but the ruler evaluates each rule against its own query window, which limits how well it fits multi-step investigations.
- Required sources: Consistent timestamps, host and user identifiers across every source, and time synchronization on all systems that produce logs.
- Loki fit: Loki is well suited to storing raw logs and running targeted LogQL queries during an investigation, especially when Grafana is already in use.
- Limit: Ruler rules are individual queries, so multi-stage attack chains and entity-level correlation are harder to express and maintain.
- SIEM adds: Entity models, correlation rules across sources, case management, threat intelligence matching and analyst queues are typical SIEM features.
- Decision: Many teams keep Loki for log storage and fast alerts on single-source patterns, and send normalized events to a SIEM for correlation. Confirm the SIEM's licensing and ingestion costs with the vendor before you choose.
Before you decide, write down which investigations must span sources and how long evidence must stay searchable.
Alert rule options and where each fits
This table compares the three places a log alert on security events can live: the Loki ruler, Grafana-managed alerts and a SIEM. Read each row as a design question, then check the trade-offs for GitOps and tenancy before choosing a home for the rules. The main takeaway is that alert location decides who can change a detection and how it is routed.
| Decision | Loki ruler (LogQL rules) | Grafana-managed alerts |
|---|---|---|
| Evaluation engine | LogQL rule groups evaluated by the Loki ruler inside the tenant | Grafana alert rules that can combine Loki with other data sources |
| Routing to responders | Rule labels and annotations sent to Alertmanager for routing | Contact points and notification policies managed in Grafana |
| Handling missing data | Absence of matching lines does not fire by default, so silent log sources need a separate check | Explicit no-data and error states can be set per rule |
| For duration | Set per rule to suppress brief spikes such as a single failed login | Set per rule with the same intent, reviewed in the Grafana interface |
| GitOps fit | Rule files live in object storage or source control and deploy like config | Rules can be provisioned or managed through the API, but review workflows need confirmation |
| Multi-tenancy fit | Rules are scoped to a tenant, which matches per-team security ownership | Tenant scoping depends on how Grafana data sources and folders are set up, so confirm before relying on it |
| Best fit for this topic | Authentication failure and privilege change rules that must stay close to the log store | Cross-source checks, such as a log event joined with an identity provider status |
How to set up security alert rules in Loki
This sequence takes security log events from their source to a tested alert in Loki, so that authentication failures and privilege changes reach the right responders with fewer false alarms. Each step closes with a check you can run before moving on.
Confirm security fields and stable labels
Your platform or security engineers list the events you need to alert on, such as failed logins, sudo or role changes and admin actions, and confirm each source logs the user, source IP, outcome and target account. Decide which values become labels (low-cardinality items such as host, application and environment) and which stay in the log line for parsing. Done means you have a written field map per source and a sample line from each showing every required field is present.
Ship logs to Loki with Grafana Alloy
The team configuring collection points Grafana Alloy, Grafana's supported log shipper, or another client listed in the Loki documentation at the sources from the field map. Confirm the agent attaches the labels you chose and does not attach values such as user names or IP addresses as labels. Check by running a query in Grafana Explore for one known host and confirming the entries arrive with the expected label set within a few minutes of a test login.
Test selectors and parsers on real samples
Using a copy of real log lines, your security engineers write the LogQL stream selector and parser expressions, such as a pattern or regexp parser that extracts the user, source IP and outcome. Run them in Grafana Explore against a recent time range and compare extracted fields with the raw lines. Done means every sample in your set parses to the expected fields, and lines from other applications do not match the selector.
Write the rules in a dedicated rule group
Place the alert expressions, typically a count_over_time or rate aggregation with a threshold, in a rule group named for the security use case, such as authentication failures, so it can be reviewed and version-controlled separately from operational alerts. Add labels for severity and an annotation that names the affected host and user. Confirm the rule file loads without errors in the ruler and that the rule group appears with the expected evaluation state.
Set for durations to reduce noise
Set the for duration on each rule so a condition must persist before the alert fires, which filters out single mistyped passwords and brief bursts from automated jobs. Set thresholds from your own baseline of normal failure counts rather than from a generic value, and record the chosen numbers with the reason for each. Check by replaying a known benign pattern and confirming the alert stays in the pending state and does not fire.
Route alerts to a receiver
Configure the alert manager receiver the rule group sends to, such as Prometheus Alertmanager or the Grafana-managed path your team has chosen, with routes that send security severities to the on-call group that handles them. Confirm which contact points and silences apply, and check who owns the routing configuration. Done means a firing test alert reaches the intended receiver and the notification contains the labels and annotations you defined.
Verify with controlled test events
Generate controlled events on a test host, such as a set number of failed logins from a designated test account and a supervised privilege change, and record the time and expected outcome of each. Confirm each event is ingested, the rule fires only when the threshold and for duration are met, and the notification arrives with correct fields. Also confirm the tenant header your clients send, and the auth_enabled setting, so that the rule evaluates the tenant where the logs were written. Done means a signed test record shows each expected alert fired and each benign event did not.
How a log event becomes a security alert
The path starts at servers, applications and identity provider logs, which Grafana Alloy ships into Loki. Every request into Loki and the ruler passes an authenticating reverse proxy, because Loki has no built-in authentication layer. The ruler evaluates LogQL alert rules per tenant, and matching alerts go to Alertmanager or Grafana Alerting. The SIEM or case tool receives events as a separate downstream consumer, not as a replacement for the ruler. Check that tenant headers are set at the proxy and that the trust boundary covers every path that can reach the ruler.
Log events flow from sources through Loki to alert receivers, with the SIEM downstream.
Security and operational considerations for log-based alerts
Log-based alerts inherit the security posture of the logs and the cluster behind them. The cards below cover access, data exposure, credentials, evidence integrity, alert quality and change ownership, which together decide whether a Loki alerting setup can be trusted during an investigation.
Identity must sit in front of Loki
Loki has no built-in authentication layer, so the documentation requires an authenticating reverse proxy such as nginx, HAProxy, OAuth2 Proxy or Pomerium in front of it. Tenant selection depends on the X-Scope-OrgID header, which means a caller who can set that header can read another tenant unless the proxy overwrites it. Check that the proxy strips client-supplied tenant headers, that the ruler and API endpoints are not reachable without authentication, and that administrative endpoints are restricted to the security team.
Loki authentication docsAlert payloads can leak log content
Annotations and notifications often copy log lines, usernames, source addresses or tokens into chat channels, tickets and email. A failed-login rule that includes the raw line may expose a password typed into the wrong field. Review each annotation template, keep identifiers such as user hashes or truncated IPs where possible, and confirm which receivers are allowed to hold which classes of data before rules go live.
Protect rule and receiver credentials
Alertmanager receivers hold webhook URLs, SMTP passwords and API tokens, and remote-write configurations for downstream metric stores carry credentials too. Store these in a secrets manager or the platform's secret mechanism rather than in rule files committed to Git. Limit who can read the configuration, rotate tokens on staff changes, and confirm the approach with your own platform team, since the exact secret handling depends on how you deploy Loki and Alertmanager.
Keep source logs tamper-evident
An alert is only as useful as the logs behind it, so an attacker who can delete or rewrite log chunks can also erase the evidence of their own activity. Restrict write and delete permissions on the object storage bucket, separate the retention settings from routine operator access, and ship a copy of security-relevant logs to a location the Loki administrators cannot change. Retention is disabled by default, so set it deliberately and align it with how long investigations and reviews need the data.
Loki retention docsPattern rules produce false positives
Rules that match words such as failed, denied or sudo generate noise from health checks, scanners, password managers and routine administration. Noise trains responders to ignore pages, which is the most common way a log alert stops protecting anything. Start with narrow label selectors, add thresholds and for durations, measure how often each rule fires without a real incident, and retire rules that no one acts on.
Assign owners for rule changes
Alert rules encode security decisions, so a change that widens a pattern or silences a receiver can hide an attack without anyone noticing. Decide who authors rules, who reviews them, and who approves changes that alter severity or routing. Store rules in version control with pull request review, and record which rules are owned by security and which by platform or application teams so that an on-call engineer knows who to ask.
Limits to confirm before relying on Loki for security alerts
Which Loki version and deployment mode should I confirm before writing security alert rules?
Confirm the exact Loki version and deployment mode you run before you write any rule, because rule behavior and supported topology change between releases. The current release listed in the supplied facts is v3.7.8, published September 17, 2026, so check the Loki releases on GitHub page and the release notes for the version you run. Loki documents monolithic, simple scalable and microservices modes, but simple scalable mode is being deprecated and will be removed with the Loki 4.0 release. If you run simple scalable today, plan the move to another mode as part of the alerting project, not after it. Record the version and mode in the design document so later upgrades can be tested against the same rules.
How do Loki ruler rules evaluate in my version, and what happens during evaluation gaps?
Confirm how your version's ruler schedules evaluations, how it handles a rule that fails or times out, and what it writes when a query returns no series. Behavior around evaluation intervals, the for duration and alert state can differ between releases, so test each rule against a known log sample on the exact version you run. Ask whether a failed evaluation produces any signal of its own, since a silent failure looks identical to a quiet period. Keep a separate health check on the ruler itself so you know when rules stopped running. Document the expected evaluation interval so responders understand the delay between an event and an alert.
Will missing or delayed logs raise a Loki alert, or will they fail silently?
By default, a LogQL alert only fires when matching log lines exist, so a shipper outage, a stopped agent or a full buffer can look like no attacks at all. Test this directly: stop the log shipper on a test host and confirm whether anything alerts. Build a separate absence rule for critical sources, such as a login log stream that has gone quiet for longer than you expect, and confirm how it behaves when the label set disappears entirely. Also measure ingestion delay, because a rule can evaluate correctly against data that arrived late. Your investigation timeline depends on that delay, so record it for each source.
How does the ruler store and recover rule state after a restart or failure?
Confirm where your ruler keeps rule definitions and alert state, and what survives a restart, a pod reschedule or a storage failure. Rule files and their storage location depend on your configuration and version, so check the ruler documentation for your release and test a restart during a known alert condition. Ask whether pending alerts resume their for timer or start again, because a restart that resets the timer can delay or suppress a page. If you use remote write for recording rules, confirm how samples are protected across crashes and whether your version clears that write-ahead state on startup. Write these answers into your runbook.
How long must logs be retained for security investigations?
Retention is set by your organization's investigation and audit needs, not by Loki's defaults, and Loki does not decide it for you. Loki retention is disabled by default, so logs are kept until you enable retention_enabled, and you can set retention globally, per tenant or per stream selector, with each stream rule at least 24 hours. Confirm with incident response how far back analysts need to query, and make sure the period you choose covers the detection window that your alerts expect. Test that a query over the oldest retained data still returns results after compaction runs. Record who approved the period and where that decision is documented.
Do my identity provider and OS logs contain the fields the alert rules need?
Confirm the fields each source emits before you write a rule that depends on them, because a rule that matches a field name that never arrives will never fire. Look at real events from your identity provider, Linux hosts and Windows endpoints, and check for user, source address, outcome, target account and group change fields. Field names differ across identity products and OS log formats, and some events only appear when specific audit policy is enabled. Pull a sample of each event type into Loki, then confirm which values become labels and which need to be parsed from the line. Keep a test set of expected events so a log format change in an upgrade is caught quickly.
Can Loki alerts replace a SIEM for security monitoring?
Loki alerts can cover a narrow set of known log patterns, but a SIEM is usually the better tool when you need correlation across many sources, a maintained detection content library, case management or long-term investigation workflows. Loki's strengths are cost-efficient log storage on object storage and fast queries by label, and it has no built-in authentication layer, so access control needs a reverse proxy in front of it. Decide which detections must page someone and which can wait for review, then compare each against what your SIEM already does. Many teams keep Loki for high-volume application and system logs and forward only selected alerts to a SIEM. Confirm the design with your security operations lead before you retire any existing detection.
When a SIEM is still the better tool
Loki alert rules are the right place for application and system log signals, but they stop short of a security operations function. A LogQL rule sees the streams you ship to Loki and nothing else. It does not join a failed login on a web application with an endpoint process start, a firewall session and an identity provider change for the same user, and it has no built-in entity timeline, case queue or analyst workflow. Before you extend this design to security monitoring, list the detections that need data from more than one source, and ask whether the team responding to them will work in Grafana or in a dedicated tool. If the answer is the second, a SIEM is likely the better fit for those detections.
Look at four capabilities in particular. Cross-source correlation across endpoints, identity and network data needs collectors and a common data model for each source. Curated detection content means someone maintains rules against known attacker techniques, which Loki does not supply. Case management, entity timelines and compliance reporting depend on workflow and evidence handling that alerting pipelines do not provide. Retained history for hunting also matters: Loki retention is disabled by default and set per tenant or stream selector, so you must decide how long security-relevant streams are kept and confirm that the same retention serves investigators as well as operators. Ask each vendor, including Loki-based or Grafana-based options, to demonstrate these capabilities on your own log samples.
A security platform may fit where those needs are real. Wazuh, licensed under GPLv2 with an OpenSSL linking exception, pairs its own indexer, rules and dashboard with endpoint agents and provides compliance views for frameworks such as PCI DSS, GDPR, HIPAA and NIST 800-53. Confirm with the Wazuh project which correlation, case handling and reporting features your target version provides, and which parts depend on agents you would have to deploy. The two tools can coexist: keep application authentication failures and privilege-change logs on Loki ruler alerts routed to the owning engineering team, and forward the security-relevant events that need cross-source correlation to the SIEM. Document which system is the system of record for each alert so that one event is not handled twice or dropped.
Questions teams ask before building Loki security alerts
What drives the effort of building security alerts in Loki?
The effort is driven mainly by how many log sources feed the alerts, how consistent their fields are, and how many rules you need. Each source has its own format, so authentication logs from an identity provider, sudo events from Linux hosts, and application audit trails each need parsing and labeling before a rule can match them reliably. Rule count and tuning add work because every noisy rule needs threshold review against real traffic. Notification integration and testing round out the work: each alert path must be exercised end to end, including the no-data and failure cases.
How long does a Loki security alerting build take?
Duration depends on scope: the number of log sources, how much normalization they need, the number of rules, and how many notification channels are involved. DeployOpen scopes timing in writing as part of the agreed deliverables and timelines before work starts, so this page does not give a general figure. Ask for a schedule that separates source onboarding, rule development, tuning, and the test window, because the tuning period is the most often underestimated part.
What does the work need from our team?
Expect to provide read access to the relevant logs or the Loki query path, administrator help from the identity provider owners to confirm event formats and enable the right audit events, and named on-call owners who will receive and act on each alert. You also need a test window in which controlled events can be generated and alerts observed without triggering real incident response. Confirm log retention and data handling rules with your compliance team before rules are deployed, since alert rules can surface personal data in notifications.
Can our internal team build these alerts without a partner?
Yes, a team with Loki and LogQL experience, access to the log sources, and time for tuning can build basic alert rules alone. The harder parts are usually consistent field extraction across many sources, validating that rules fire on real attack-like behavior without flooding on-call staff, and documenting the rules for audit. If your team has no one who has operated Loki's ruler and alert routing before, a scoped review of the design and a test plan can reduce rework. Compare that against the time your own engineers would spend on the same steps.
Can Loki alone replace a SIEM for security monitoring?
No. Loki is a log aggregation system that answers queries and evaluates alert rules over the logs it stores, but it does not provide the correlation engine, case management, threat intelligence matching, or prebuilt detection content that a SIEM typically offers. It also has no built-in authentication layer, so access controls must come from an authenticating reverse proxy, and it does not ship with an analyst workflow for triaging and closing incidents. Loki works well for targeted alerts on known log patterns and for keeping logs in infrastructure you control. Where you need broad detection coverage, cross-source correlation across endpoints and network data, or formal incident workflows, a SIEM or an open-source security analytics platform such as Wazuh is the better fit, often alongside Loki.
What are the main ways a Loki alert rule fails in production?
The most common failures are rules that match too broadly and page on-call staff for normal activity, rules that never fire because the log field names changed after a software upgrade, and missing data that goes unnoticed because the source stopped sending logs. Teams should check each rule against both benign and deliberately generated events, and monitor ingestion so that a silent source raises its own alert. Confirm how the ruler stores rules and where alerts are routed, since a misconfigured route can deliver alerts to the wrong team.
Do we need to modify our applications or identity provider to alert on security events?
Often not, but it depends on what the source already records. Many identity providers and operating systems emit authentication and privilege events that can be shipped to Loki as they are, while some applications log too little detail, such as the actor, target, or result of a privilege change. In that case the fix may be enabling audit logging or adding structured fields, which requires changes by the application owner. Confirm the event formats and whether the needed audit events are enabled before estimating the work, because missing fields are a frequent source of delay.
How DeployOpen scopes Loki security alert work
Security alert work on Loki is scoped as a fixed engagement, and the scope is agreed in writing before any rule is written. The written scope names the log sources in play (for example, the sshd and PAM logs on Linux hosts, the identity provider audit stream, and the application logs that record login and role changes), the event types each rule must catch, the rules themselves, and the receivers that will be notified. It also sets the test plan and the handover. The test plan should show, for each rule, a replayed or synthetic event that fires it and a benign event that does not. The handover should cover the rule files, the Alertmanager or Grafana contact points, runbooks for each alert, and the access needed to change them. Ask for each of these items to be listed by name in the quote, because an unnamed log source is the most common reason an alert never fires.
A security review of the alert setup can be paired with the build or run as a separate step afterward. The review checks the parts that decide whether the alerts can be trusted: the authenticating reverse proxy in front of Loki (since Loki has no built-in authentication layer and relies on a proxy such as nginx, HAProxy, OAuth2 Proxy or Pomerium), how the X-Scope-OrgID tenant header is set and protected, where the Alertmanager and webhook credentials are stored, who can edit rule files, and whether alert payloads expose sensitive log content to chat or ticketing tools. Pairing the review with the build lets findings change the design before rules go live. DeployOpen tests the setup and reports findings with fixes, but it does not issue audit reports or attestations, and any formal assessment remains with an independent auditor.
Rule tuning and upgrades after handover can be covered by a retainer. Tuning matters because authentication-failure and privilege-change rules generate noise as users, service accounts and deployments change, and each threshold change should be tested against recent logs. Upgrades matter because Loki and its ruler change between releases, so the retainer should name which versions are covered and who runs the upgrade test. Confirm the current Loki release and its upgrade notes with the Loki documentation before the quote is signed, and ask whether the retainer includes retesting the rules after each upgrade.
How DeployOpen implements and tests Loki security alerting
DeployOpen scopes, builds, tests and hands over Loki security alerting inside infrastructure you control. Each engagement starts from the events your team needs to catch and the log sources that carry them, so alert rules, routing and access controls are agreed before anything is deployed. The work is delivered as a fixed-scope engagement with written deliverables.
How we scope
- Inventory the authentication, privilege change and application logs that the alerts depend on
- Agree in writing which detection patterns are in scope and which stay with your SIEM
- Confirm the Loki deployment mode, tenant layout and who may read security log streams
- Record alert owners, severity levels and the on-call path for each rule group
How we build
- Write LogQL alert rules for failed logins, privilege grants and agreed suspicious patterns
- Confirm label and structured metadata design so rules stay fast and do not overload the cluster
- Route alerts to your chosen receiver and set for durations and annotations to cut noise
- Test each rule against replayed or sample log lines, including the no-data case
How we hand over
- Deliver rule files, routing configuration and access settings as version-controlled artifacts
- Document each rule's purpose, data source, expected false positives and tuning owner
- Run a walkthrough with your security and operations staff on triage and escalation
- Provide a test record showing which events fired, which were missed and what was changed
How we support
- Offer ongoing support, upgrades and rule tuning as a retainer after handover
- Re-test alert rules when log formats, sources or Loki versions change
- Review alert volume with your team and adjust thresholds through the agreed change process
- Keep a clear boundary between Loki alerting and the SIEM or case tooling you keep

