Detection and incident response
Write detections as code and measure them by what they catch, run the SOC so alerts get answered, and lead a security incident where the adversary adapts, the evidence matters and legal holds the clock
Your team runs 120 detection rules. Which measure tells you most about whether they are working?
Prevention fails: a laptop the antivirus missed, a key in a repository, a supplier with too much access. Detection decides how long an attacker lives in that gap; incident response decides how well the company behaves once they are found. This chapter covers both as a practitioner does them.
It builds on the reliability side of incident response, which the Observability course teaches in Incident response and postmortems: the incident commander, the operations lead, the communications lead, severity levels and the blameless review. Read that first. This chapter assumes it and covers what changes when the cause is a person who is trying not to be caught.
The model: dwell time and the three questions
The number that frames the work is dwell time, the time between an attacker’s first access and the moment the defenders know. In the CircleCI case it was thirteen days to the first outside signal. Everything an attacker does in that window, reconnaissance, privilege escalation, collecting data, moving it out, is something you either see as it happens or reconstruct afterwards from logs, if the logs exist.
So the work splits into three questions, asked in order.
- Will we see it? Do we collect the logs that would show this behaviour, and do we have a rule that turns the behaviour into an alert? This is detection engineering.
- Will someone look? Does the alert reach a person who has the time, context and authority to decide whether it is real, quickly enough to matter? This is the SOC and its triage process.
- Will we handle it well? Once it is real, can we contain it without destroying what we need to know, recover without leaving the attacker a way back, and meet our legal and contractual obligations on time? This is incident response.
NIST’s guidance moved in the same direction. SP 800-61 Revision 2 (2012) drew a four-phase cycle: preparation; detection and analysis; containment, eradication and recovery; post-incident activity. Revision 3, final in April 2025, replaces it with the six functions of the Cybersecurity Framework 2.0. Govern, Identify and Protect are the preparation underneath; Detect, Respond and Recover are the response itself; and lessons feed back continuously rather than at the end. Its reasoning: incidents are no longer rare, narrow and over in a day or two. You will still hear the old phase names in every SOC, and they are still a useful vocabulary for a playbook.
Detection engineering
A detection is a rule that turns raw telemetry into an alert a person must look at. Detection engineering is the discipline of writing those rules deliberately, testing them, and retiring them when they stop paying for themselves.
Start from the logs. You cannot detect what you do not collect. For a cloud-hosted software company, the sources that carry most of the weight are the cloud control-plane audit log (AWS CloudTrail, GCP Cloud Audit Logs, Azure Activity Log), the identity provider’s sign-in and admin logs, endpoint detection and response (EDR) telemetry from laptops and servers, source control and CI audit logs, and your own application’s audit trail for sensitive actions such as an admin changing bank details. Network flow logs come after these. Check retention before you need it: an investigation into a thirteen-day dwell time needs at least a month of every source, and most teams set ninety days or more as a rule of thumb.
Write detections as code. The older model is rules clicked together in a SIEM console, owned by nobody, with no history. The model most mature teams now use treats a detection like any other code: it lives in version control, it is reviewed in a pull request, it has a test that feeds it a sample of malicious and benign events, and a pipeline deploys it. Sigma is the open, vendor-neutral format for writing these rules, with converters to most SIEM query languages; its public repository is a good source of starting rules. The format matters less than the habits: review, tests, an owner, and a change history.
Document each rule. Palantir’s Alerting and Detection Strategy (ADS) framework is the most widely copied template. Before a rule ships it needs a goal, an ATT&CK categorisation, a strategy abstract, technical context, its blind spots and assumptions, its known false positives, how it was validated, a priority, and the response an analyst should take. The blind-spots section is the one that earns its keep: it is where you write down that the rule does not see activity from the break-glass account, so the next person knows to cover it some other way.
Aim at behaviour, not indicators. David Bianco’s Pyramid of Pain ranks what a detection can key on by how much it costs the attacker to change. File hashes and IP addresses are at the bottom: trivial to change, so a rule built on them stops working the day the attacker rotates infrastructure. Tools are near the top, and tactics, techniques and procedures (TTPs) at the top. A rule that fires on an IP from last month’s threat report is cheap to write and nearly worthless. A rule that fires when any identity creates an access key for another identity and uses it from a new network within the hour describes a behaviour the attacker has to change their whole approach to avoid.
Use ATT&CK as a map, not a scorecard. MITRE ATT&CK is the shared catalogue of adversary behaviour, organised as tactics (the attacker’s goal at that stage: initial access, persistence, credential access, lateral movement, exfiltration) and techniques (how they achieve it). It gives you a vocabulary for each rule and a way to see where you have nothing. The failure mode is the coloured matrix: a slide where every technique with a mapped rule is green, presented as coverage. A mapped rule that has never fired against a test is not coverage. Use the matrix to decide what to write next, starting from the techniques your threat model says matter for your systems (threat modelling covers how to build one).
Alert quality
The alert is the product of detection engineering, and the analyst is its user. Poor alerts cost twice: they waste the analyst’s hour, and they teach the analyst that this rule is usually nothing, which is how a real alert gets closed unread. The Observability course covers alert design for reliability in Alert design; the same principle, page only on what needs a human, applies here with sharper consequences.
Every alert is triaged into one of three outcomes: a true positive (malicious, act on it), a benign true positive (the rule worked, the behaviour was real, it was authorised: an engineer running a sanctioned scan), or a false positive (the rule matched something it should not have). Record the outcome on every alert. Without it you cannot measure anything below.
| Measure | What it tells you | What to do when it is bad |
|---|---|---|
| Precision per rule (share of alerts that led to action) | Whether the rule is worth an analyst’s time | Tune, add context, or downgrade to a hunting query that nobody is paged for |
| Validation date (last time the rule fired on a simulated attack) | Whether the rule still works after the logs, the schema or the SIEM changed | Re-test; a rule that fails is broken, not quiet |
| Time to triage, by priority | Whether the queue is staffed for its volume | Cut noisy rules before adding people |
| Share of incidents first detected internally | Whether detection works at all | Each externally reported incident becomes a new detection and a test |
Validation is the habit most teams lack. Red Canary’s Atomic Red Team is an open library of small, scripted tests mapped to ATT&CK techniques; running the relevant test after each change to a rule, or on a schedule, tells you whether the rule still fires. Purple-team exercises, where an attacker and the detection team work in the same room, do the same at larger scale.
The SOC
The security operations centre is whoever answers the alerts. At a large company it is a room, a rota and a tiered team: tier 1 analysts triage the queue, tier 2 investigate what tier 1 escalates, tier 3 hunt for threats the rules miss and lead incident response. At most companies under a few hundred people it is a managed detection and response (MDR) provider for nights and weekends plus one or two engineers in the day.
Practitioners disagree about the tiered model. Defenders say it scales and gives juniors a way in. Its critics say tier 1 becomes a production line of closing noisy alerts, burns people out, and separates the people who see the alerts from the people who could fix the rules. The direction most teams are moving is to automate the enrichment that tier 1 used to do by hand (who owns this host, is this IP known, did this user sign in from here before) and to make the people who triage alerts also own the rules that produce them. When an analyst’s complaint about a noisy rule becomes their own pull request, precision rises.
An MDR is a sound choice for a company that cannot staff a rota. The questions to ask a provider are concrete: which log sources they ingest, which actions they may take without asking (isolating a laptop, disabling a user), how they escalate at 3 am and to whom, and whether you can read and change the detections they run on your data.
How a security incident differs from an outage
The incident command structure from the Observability chapter carries over. Google’s Building Secure and Reliable Systems uses the same roles plus a legal lead, a management liaison, a remediation lead and a note taker. What changes is the opponent. Leading the whole incident, from the commander’s rota to status updates, customer notices and the postmortem, is running a security incident.
| Outage | Security incident | |
|---|---|---|
| Cause | A fault; it does not react to you | An adversary who adapts when they see the response |
| Channel | The normal incident channel, open to anyone | A separate, need-to-know channel under a codename, ideally on infrastructure the attacker cannot reach |
| First move | Mitigate fast; capture evidence if cheap | Scope before acting, unless harm is ongoing; preserve evidence deliberately |
| Who is in the room | Engineering, support | Plus legal, often outside counsel, and sometimes an external forensic firm |
| Clock | The SLO and customer patience | Plus regulatory and contractual notification deadlines |
| Afterwards | Blameless postmortem, widely shared | Postmortem still blameless, but its distribution may be restricted by counsel |
Two operational habits follow from the opponent. First, keep the response quiet. PagerDuty’s public security incident runbook gives the incident an innocuous codename, keeps details within the response team until forensics rule out an insider, and tells responders not to use SMS. Google’s chapter adds: do not sign in to compromised systems with credentials the attacker may hold, do not touch the attacker’s infrastructure, and write indicators in a defanged form so chat tools do not fetch them. Second, preserve evidence before you change anything: snapshot disks and memory from affected hosts, and export audit logs to a store the compromised identities cannot write to. NIST notes that most incidents never reach a court, but that what you collect is still evidence and should be kept with its integrity and provenance intact.
Containment: the argument at the centre of the job
Here practitioners disagree, and the two best public sources take opposite starting positions.
PagerDuty’s runbook opens with “stop the attack in progress”, by any means, shut instances down if you must, and only then cut off the vector and assemble the team. It asks responders to stop instances rather than terminate them so the disks survive for forensics.
Google’s book starts hands-off. Its chapter 17 argues that an attacker who sees you acting may go quiet, hide their footholds or destroy data, so you investigate first and move to remediation when new leads dry up. Chapter 18 adds that you eject the attacker all at once, in one planned move, because partial ejection is a chess game the attacker can answer. Both chapters make the same exception: when the attacker is actively causing harm, you act before the picture is complete.
NIST sits between them. It describes redirecting an attacker to a sandbox to gather evidence, says the delay is dangerous because the attacker may escalate, and tells you to agree the approach with the legal department first.
The positions are less far apart than they look. PagerDuty’s runbook is written for an attack in progress against a SaaS platform, where the harm is ongoing and the exception applies. Google’s is written for an organisation with the people and telemetry to watch an attacker safely. Your judgement is which situation you are in: is harm happening now that you cannot undo (data leaving, systems being destroyed, money moving), and can you see enough to watch safely? In the cloud there is a further point. Control-plane audit logs live outside the compromised resource, so containing a stolen key costs you less evidence than shutting down a server does. What you lose by containing early is not the logs; it is the chance to find the attacker’s other footholds before they know you are looking.
Whatever you choose, eradication and recovery follow the same rules. Rotate every credential the attacker could have seen, starting with administrators and the identities known to be compromised. Rebuild affected systems from known-good images rather than cleaning them, because you cannot prove you found all the malware. Check backups before restoring from them, because they may contain the attacker’s changes. Keep the investigation and the recovery as separate teams in close contact, so recovery is not waiting on a complete forensic answer and does not undo it. The secrets rotation and replay lesson covers the mechanics of rotating a secret without an outage.
Legal, communications and the clocks
A security engineer does not decide whether to notify a regulator. You do need to know that the decision exists, who makes it, and that its clock may already be running.
Legal. Bring counsel in at declaration, not at the end. Their jobs are to decide what is a notifiable breach, to manage privilege, and to own contact with regulators and law enforcement. Many companies engage the external forensic firm through outside counsel so its work is prepared in anticipation of litigation; privilege is not automatic. In 2020 a US federal court ordered Capital One to produce its forensic firm’s report on the 2019 breach, finding it was not protected work product: the firm had been retained under a pre-existing business contract, and the court found it would have produced much the same report without the litigation (the district judge’s June 2020 opinion, affirming the magistrate judge’s May order). Your practical rule: write facts in the incident record, not speculation or blame, because it may be read by people outside the company.
The clocks. Under the GDPR and UK GDPR, a controller must notify the supervisory authority of a personal-data breach without undue delay and, where feasible, within 72 hours of becoming aware of it; a processor must tell the controller without undue delay; cloud and infrastructure security covers when that clock starts. US public companies must file a Form 8-K under Item 1.05 within four business days of determining that a cybersecurity incident is material, a decision security risk and the board covers from the Head’s side. US states each have their own breach-notification laws. Customer contracts frequently set shorter deadlines than any of these, and cyber-insurance policies usually require prompt notice and may require you to use the insurer’s approved forensic firms. The playbook should list every clock that applies to your company, who decides whether it has started, and who sends the notice.
Communications. PagerDuty’s runbook is blunt and right: do not say “we take security very seriously”; be honest about what was taken; put the date in the title of any notice so it is never confused with a new breach; release it as soon as the facts are solid, within days rather than weeks. Prepare a holding statement for support and sales on day one so customers who ask get a consistent answer that does not speculate. The communications lead owns the cadence; legal approves the words.
Day to day
Every day. Work the alert queue or review what the MDR escalated overnight. Record the triage outcome for every alert. When a rule produces a false positive, open a ticket against the rule the same day, while the context is fresh. Spend the rest of the day on detection work: a new rule from the backlog, a log source that needs onboarding, a test that failed.
Every week. A detection review, thirty to sixty minutes, with whoever writes and whoever triages rules: the noisiest rules by volume, the rules with the worst precision, the rules whose validation failed, and the backlog ordered by the threat model. If you share an on-call rotation for security incidents, the handover happens here.
Every month or quarter. A tabletop exercise, monthly on a mature team and quarterly at minimum as a rule of thumb: sixty to ninety minutes in which you walk a scenario through a playbook with the people who would really be in the room, including someone from legal and someone from communications. The output is a list of what the playbook got wrong. Alternate scenarios: a stolen laptop, a leaked cloud key, a compromised supplier, an insider.
Every quarter. A purple-team exercise or a batch of Atomic Red Team tests against the rules that matter most, a review of log retention and coverage against ATT&CK, and a check that every playbook has been exercised in the last year.
During an incident. You will most often be the operations lead or the forensics lead, rarely the incident commander at first. Your work is scoping: building the timeline, finding every identity and system the attacker touched, and telling the commander what containment will cost in visibility. You keep notes as you go, with timestamps, because the notes become the timeline the lawyers, the regulator and the postmortem will all read.
After an incident. A blameless review, run the same way as the reliability postmortem, with two additions: every way the attack could have been detected earlier becomes a detection ticket with a test, and counsel decides who may read the final document.
There is no SOC and probably no security hire. Detection is whatever the cloud provider and identity provider give you switched on: AWS GuardDuty or its equivalent, sign-in alerts from the identity provider, and EDR on every laptop, routed to a channel a named engineer reads every day. Incident response is a one-page playbook for the two likeliest incidents, a leaked key and a compromised laptop, with the CEO as incident commander and an outside law firm and the insurer’s hotline written at the top. Know which customer contracts carry notification deadlines before you need them.
You are building the function, and your first detection hire is choosing a SIEM, moving rules into version control and deciding what an MDR covers at night. The work is deciding which ten detections matter for your systems, writing them well, and testing them, rather than turning on a vendor’s four hundred defaults. Playbooks exist for the top five scenarios and are exercised in quarterly tabletops. A general counsel now exists and should be in the first tabletop. Expect the first real incident to show that one log source you assumed you had was never switched on.
The SOC is a team with tiers, a threat-intelligence function, a computer security incident response team and possibly several regions. Detections number in the thousands and the problem is curating them: retiring dead rules, keeping precision up, and proving coverage to auditors. Incidents involve several legal entities and jurisdictions, a materiality committee if the company is listed, and arguments about who declares, who owns communications, and which business unit pays for the forensic firm. Your value as a practitioner is a playbook that settles those arguments in advance and a timeline the lawyers trust.
Template
# Playbook: <scenario, e.g. 'Compromised CI/CD service credential'>
Owner · Last reviewed · Last exercised (tabletop date) · Version
## Trigger
- Detections that start this playbook: <rule ids and names>
- Other reports: <customer, supplier, employee, researcher>
- Who may declare: <roles>. When unsure, declare; downgrading is cheap.
## Severity
| Sev | Criteria (checkable in minutes) |
|---|---|
| 1 | <e.g. regulated or customer data confirmed accessed; activity ongoing> |
| 2 | <e.g. privileged identity used by an unknown party; no data access seen yet> |
| 3 | <e.g. credential exposed; no use seen in logs> |
## Roles
| Role | Primary | Backup |
|---|---|---|
| Incident commander | | |
| Operations / forensics lead | | |
| Communications lead | | |
| Legal (internal; outside counsel contact) | | |
| Scribe | | |
| Management liaison | | |
## Out-of-band channel and codename
<where the team talks if chat or email may be compromised; how the codename is chosen>
## First 60 minutes
1. Declare, name the IC, open the private channel, start the timeline.
2. Preserve: <each log source and host artefact, where it is copied, by whom>.
3. Scope: <the questions to answer first: which identity, since when, what it touched>.
4. Decide containment (below). Record the decision and who made it.
## Containment options
| Option | Stops | Costs (evidence, visibility, availability) | Authorised by |
|---|---|---|---|
## Eradication and recovery
- Credentials to rotate, in order: <list>
- Systems to rebuild from known-good images: <list>
- Backups to verify before restore: <list>
## Notification clocks
| Obligation | Trigger | Deadline | Decides | Sends |
|---|---|---|---|---|
## Communications
- Internal holding line for support and sales: <text>
- Customer notice: drafted by <role>, approved by <legal>; date in the title
## Exit criteria
<what must be true to close: attacker access removed, credentials rotated, monitoring in place, notifications sent>
## Detections to add afterwards
<every point where this attack could have been seen earlier> WORKED EXAMPLE
Redshank is a fictional UK payroll platform: 220 staff, 3,100 employer customers in the UK and Ireland, about 410,000 employees paid each month. Redshank is a processor for its customers’ payroll data. Its one detection engineer wrote this playbook after a tabletop showed nobody knew who could freeze a pay run.
Scenario: an employer’s admin account is taken over and employees’ bank details are changed before a pay run.
Trigger. Detection D-014: more than five bank-detail changes in one employer account within 24 hours from a session whose IP and device the account has not used before. D-022: an admin sign-in from a new country followed by an MFA reset. Also: any employee report that pay did not arrive. Any on-call engineer may declare.
Severity. Sev 1 if a pay run containing changed details is due within 48 hours or has already been submitted to the bank. Sev 2 otherwise.
First 60 minutes. Export the employer’s audit trail and the identity provider’s sign-in log for 30 days to the write-once incident bucket (forensics lead). Scope: which session, which employees changed, the old and new account numbers, the next pay date.
Containment options. Revoke the session and force password and MFA reset: stops the attacker, costs nothing in evidence because the audit log is held separately; authorised by the IC. Freeze bank-detail changes for that employer: authorised by the IC. Hold the pay run: delays pay for every employee of the customer, so only the customer’s named contact may authorise it, on a recorded call.
Notification clocks. Tell the employer (the controller) without undue delay, target four hours, so they can meet their 72-hour deadline to the ICO, or to the Data Protection Commission for Irish employers; their contract says 24 hours. Decides: Redshank’s general counsel. Sends: customer success lead.
Last exercised: tabletop on 3 September; changed so the pay-run hold needs the customer, not Redshank.
Now you
You are the second security engineer at Dotterel, a fictional verification API that sends one-time passcodes by SMS and voice for 140 customers, most of them banks and fintechs, about 9 million messages a day. Customer contracts require notice of any security incident affecting their data within 24 hours. Delivery logs hold the destination phone number and, for 24 hours, the passcode itself in plain text, a known issue on the roadmap. Last month a detection fired when the CI/CD service account queried the delivery-log store at 02:10 and read 1.2 million rows; it turned out to be a misconfigured analytics job, but nobody knew what to do for forty minutes. The same service account deploys every service, so disabling it stops all deploys, including hotfixes. Write the playbook for a suspected compromise of the CI/CD service credential. It must deal with the deploy dependency, the plaintext codes, and the 24-hour contractual clock.
Self-check
You are on call at Redshank, the payroll platform. At 15:05 on Thursday a detection fires: an access key belonging to the reporting service is being used from a hosting provider's network it has never used, listing buckets and reading objects from the bucket that holds payslip PDFs. In 40 minutes it has read 3,000 of 2.1 million objects. CloudTrail is shipped to a separate logging account the key cannot reach. The next pay run is at 09:00 tomorrow. The IC asks you for a containment recommendation in ten minutes.
- DOC SP 800-61 Rev. 3: Incident Response Recommendations and Considerations for Cybersecurity Risk Management Alexander Nelson, Sanjay Rekhi, Murugiah Souppaya, Karen Scarfone (NIST), 2025
The current US government reference, final in April 2025, which supersedes Rev. 2 and recasts incident response around the CSF 2.0 functions. Read section 2 for the new model and the Respond tables for containment and evidence guidance.
- BOOK Building Secure and Reliable Systems Heather Adkins, Betsy Beyer, Paul Blankinship, Piotr Lewandowski, Ana Oprea, Adam Stubblefield, 2020
The best book-length treatment of running a security incident: triage, taking command, operational security, when to eject the attacker, and recovering without leaving a way back in. Read: Chapter 17, Crisis Management, and chapter 18, Recovery and Aftermath; free online from Google.
- HANDBOOK Security Incident Response PagerDuty
A real company's public runbook, short enough to read in ten minutes. Compare its stop-the-attack-first stance with Google's investigate-first stance and decide where your company sits.
- DOC MITRE ATT&CK MITRE
The shared catalogue of adversary tactics and techniques. Use it to name what each detection covers and to find the gaps your threat model says matter.
- CODE Alerting and Detection Strategy Framework Palantir Incident Response Team
The template for documenting a detection before it ships, with worked examples. Adopt its blind-spots and false-positives sections even if you skip the rest.
- CODE Sigma SigmaHQ
The vendor-neutral rule format for detections as code, with thousands of community rules. Read a dozen rules for your log sources to see what a well-scoped detection looks like.
- POST The Pyramid of Pain David J. Bianco, 2013
The short essay that explains why detections on hashes and IP addresses decay and detections on behaviour last. Read it before you write your next rule.
- POST CircleCI incident report for January 4, 2023 security incident CircleCI, 2023
A candid public timeline from malware to customer notice, with the detection gap stated plainly. Read it as a model for the facts a customer notice should contain.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.