Get alerts for attacks
Send an alert to Slack or PagerDuty when LumoAuth detects password spraying, credential stuffing or a replayed token.
What it shows
- Add an alert channel in the portal: Slack, Microsoft Teams, PagerDuty, Opsgenie or email. Send a test alert.
- Lower the threshold of the password spraying rule in a sandbox organization, and choose an automated response.
- Make five failed sign-ins for five accounts. LumoAuth opens an incident and sends the alert.
- Read the incident in the portal.
- React in your own systems: a webhook receiver handles
threat.incident.openedandthreat.incident.resolved.
Before you start
- A sandbox organization for the test. The test changes a rule, and the automated response can block an address.
- Check that your plan includes alert channels and threat detection in the plans matrix.
- An account in the portal that holds the permission
settings.manage. - For Slack, the address of an incoming webhook. Create it in Slack under Apps, Incoming Webhooks.
- For the last step, a receiver at a public HTTPS address, and a webhook for the two events. Receive webhooks shows how to create the webhook: set
WEBHOOK_EVENTS=threat.incident.opened,threat.incident.resolved.
| Variable | Value |
|---|---|
LUMOAUTH_WEBHOOK_SECRET | The signing secret of the webhook. LumoAuth shows it once, when you create the webhook. |
PORT | Optional. The port of the receiver. Default: 3000. |
LUMOAUTH_URL | The address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region. |
LUMOAUTH_ORG_ID | For the setup script: your sandbox organization. |
LUMOAUTH_API_KEY | For the setup script: an API key of the sandbox organization with the scope admin:users:write. |
The setup script creates five test users in the sandbox organization, for the test of the rule. You can run it again at any time.
node operations/alerts-and-threats/setup.mjs
setup.mjs
// Creates five test users for the test of the password spraying rule.
// Run it in a sandbox organization. Run it again at any time.
//
// node operations/alerts-and-threats/setup.mjs
//
// The API key needs the scope admin:users:write.
import { randomBytes } from 'node:crypto';
import { ensure, org, url } from '../../_lib/admin.mjs';
for (let n = 1; n <= 5; n++) {
const email = `spray-test-${n}@example.com`;
await ensure('/admin/users', (u) => u.email === email, {
email,
name: `Spray Test ${n}`,
// Nobody signs in as these users: the test needs failed sign-ins only.
password: `${randomBytes(18).toString('base64url')}#Aa1`,
emailVerified: true,
});
console.log(`ready: ${email}`);
}
console.log(`\nSign-in page: ${url}/orgs/${org}/login`);
Add the alert channel
- In the portal, open Settings, Integrations, and select the tab Alerting & notifications.
- On the card Slack, select Configure. The page Add Slack alert channel opens. The portal can ask for your password again.
- Enter a Name, for example
#security-alerts. - Leave Minimum severity at High. The channel then gets high and critical alerts.
- Paste the address into Slack incoming webhook URL, and select Create channel.
- In the list Configured channels, open the menu of the channel and select Send test alert. Slack shows a message that is marked as a test.
For email, use the card Email in step 2, and enter up to 10 addresses in Recipients.
Set the rule
- Open Security, Threat detection, and select Rules.
- Under Password spraying, set Accounts tried by one source to
5. Leave Time span at10minutes. - Under Automated responses, tick Block the sources.
- Select Save changes.
Make the failed sign-ins
- Run the setup script. It creates the users
spray-test-1@example.comtospray-test-5@example.com, and prints the address of the sign-in page. - Open the sign-in page. For each of the five users, enter the address, select Continue, enter a wrong password, and select Sign in.
- Wait one or two minutes. LumoAuth checks the rules once a minute.
Code
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. The portal steps for the alert channel were followed on an organization with an email channel: the test alert arrived. The steps for the rule and for the incident were written from the docs and from the pages of the portal.
- Node.js
// React to the incidents of threat detection in your own systems: a webhook
// receiver for threat.incident.opened and threat.incident.resolved.
//
// node operations/alerts-and-threats/js/incidents.mjs
import { createHmac, timingSafeEqual } from 'node:crypto';
import express from 'express';
const secret = process.env.LUMOAUTH_WEBHOOK_SECRET;
const port = Number(process.env.PORT ?? 3000);
if (!secret) {
console.error('Set LUMOAUTH_WEBHOOK_SECRET to the signing secret of the webhook.');
process.exit(1);
}
const seen = new Set();
/** Checks the signature header. Returns the delivery ID, or null. */
function verify(header, rawBody) {
if (!header) return null;
// The header is "kid=...,t=<unix time>,id=<delivery ID>,v1=<hex HMAC>".
const fields = Object.fromEntries(
header.split(',').map((field) => {
const at = field.indexOf('=');
return [field.slice(0, at), field.slice(at + 1)];
}),
);
if (!fields.t || !fields.id || !fields.v1) return null;
if (Math.abs(Date.now() / 1000 - Number(fields.t)) > 300) return null;
const expected = createHmac('sha256', secret).update(`${fields.t}.${fields.id}.`).update(rawBody).digest();
const given = Buffer.from(fields.v1, 'hex');
return given.length === expected.length && timingSafeEqual(given, expected) ? fields.id : null;
}
const app = express();
app.post('/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
const deliveryId = verify(req.get('X-LumoAuth-Signature'), req.body);
if (!deliveryId) return res.status(401).json({ error: 'invalid_signature' });
res.json({ received: true });
if (seen.has(deliveryId)) return;
seen.add(deliveryId);
const { event, data } = JSON.parse(req.body.toString('utf8'));
// The incident is the target of the event. Its type and severity are in
// the metadata. The event carries counts, not the accounts or the addresses.
const incident = { id: data.target_id, title: data.target_name, ...data.metadata };
if (event === 'threat.incident.opened') opened(incident);
if (event === 'threat.incident.resolved') resolved(incident);
});
/** Replace the two functions with calls to your own systems. */
function opened(incident) {
// A critical incident means that an attacking source signed in to an account.
const action = incident.severity === 'critical' ? 'page the person on call' : 'open a ticket';
console.log(`opened ${incident.incident_type} (${incident.severity}) ${incident.id}: ${action}`);
}
function resolved(incident) {
// The resolution is "resolved", or "dismissed" for a false alarm.
console.log(`${incident.resolution} ${incident.incident_type} ${incident.id}: close the ticket`);
}
app.listen(port, '127.0.0.1', () => console.log(`listening on http://localhost:${port}/webhooks`));
node operations/alerts-and-threats/js/incidents.mjs
Compiles. Not run against an organization. The receiver handled requests that were signed with the documented scheme and had the documented fields. No incident of an organization reached it: the test organization had no public receiver, and no incident was opened there.
Check the result
listening on http://localhost:3000/webhooks
opened password_spraying (medium) 0192b7c1-6a1e-7c55-9d2e-3f0a8b1c2d4e: open a ticket
resolved password_spraying 0192b7c1-6a1e-7c55-9d2e-3f0a8b1c2d4e: close the ticket
- The alert channel shows one alert for the incident. An incident of medium or high severity raises a high alert.
- Security, Threat detection, Incidents lists the incident with the type Password spraying. Its page shows the evidence, the sources and the accounts that were tried.
- Under Responses, the incident says whether the source was blocked. An address that an administrator of your organization signed in from during the last 30 days is never blocked automatically, and the incident says so.
- Select Resolve on the incident. The receiver prints the second line.
- Configured channels counts the alerts of each channel under Delivered / failed.
Limits
- An alert channel gets alerts of high and critical risk only. For every audit event, see Stream events to your SIEM.
- A failed delivery of an alert is not sent again.
- When the same event repeats for the same account in a short time, LumoAuth sends one alert.
- The webhook carries the type, the severity and the counts of the incident. It does not carry the accounts or the addresses: read them on the page of the incident.
- The block list applies to the interactive sign-in. It does not apply to API clients or to the token endpoint.
- Put the thresholds back after the test. Low thresholds give false alarms in an organization with real users.