Sub topic 12
Security and compliance requirements
This chapter assumes you can tell functional requirements from non-functional ones, and that you know how SLIs and SLOs make a quality target measurable. You should also know basic HTTP, TLS, and how a service talks to a database.
Why security needs its own requirements
Security is a quality attribute, so it belongs with the non-functional requirements. A statement like "the system must be secure" can't be tested and can't guide design. A useful security requirement names an asset, a threat or rule, and a verifiable condition.
Security also has a functional side. "A user can delete a short URL they created" (FR-3 in the URL shortener) implies an authorization rule: only the creator may delete it. Write the rule down explicitly, because a missing rule becomes a vulnerability.
The qualities to cover
| Quality | Question it answers | Example requirement |
|---|---|---|
| Authentication | Who is making this request? | Users sign in with a password plus a second factor. |
| Authorization | What may this identity do? | Only the creator of a short URL can delete it. |
| Confidentiality | Who can read the data? | Personal data is encrypted in transit and at rest. |
| Integrity | Can data be changed undetected? | Stored records carry a checksum, and tampering raises an alert. |
| Auditability | Can we reconstruct what happened? | Every delete is logged with actor, time and target. |
| Availability under attack | Does abuse take the service down? | One client may make at most 100 create requests per minute. |
Availability appears here because denial of service is a security threat. This ties the chapter to the availability targets you wrote earlier.
Finding requirements with threat modeling
You don't need to be a security specialist to find most requirements. Draw the data flow, mark each trust boundary (a point where data crosses from one level of trust to another), and ask what can go wrong at each crossing. The STRIDE checklist helps: spoofing, tampering, repudiation, information disclosure, denial of service, and elevation of privilege. Each answer becomes a requirement or an explicit out-of-scope decision.
Writing testable security requirements
Extend the requirements document from the worked example with a security section. Each item carries an ID and a condition someone can check.
security:
- id: SEC-1
quality: authorization
text: Only the creator of a short URL can delete it; other users receive HTTP 403.
- id: SEC-2
quality: confidentiality
text: All client traffic uses TLS 1.2 or higher; plain HTTP requests are redirected or refused.
- id: SEC-3
quality: auditability
text: Every create and delete is written to an audit log retained for 365 days.
- id: SEC-4
quality: abuse resistance
text: A single client is limited to 100 create requests per minute; excess requests receive HTTP 429.
compliance:
- id: COMP-1
text: Access logs containing IP addresses are deleted after 90 days.
- id: COMP-2
text: Personal data of EU users is stored only in EU regions.Each item can be turned into a test. SEC-1 becomes an automated test that logs in as user B and tries to delete user A's URL. SEC-2 becomes a scan that fails if a port serves plain HTTP content.
Compliance requirements
Compliance requirements come from outside the team: laws, industry standards, and customer contracts. You can't negotiate them the way you can negotiate a latency target, so record them as constraints with a named source.
| Source | Applies when | Typical design consequences |
|---|---|---|
| GDPR | You handle personal data of people in the EU | Deletion on request, data minimization, restrictions on where data is stored |
| PCI DSS | You store or process payment card data | Network segmentation, strict key management, no raw card numbers in logs |
| HIPAA | You handle US health information | Access controls, audit trails, signed agreements with vendors |
| SOC 2 | Customers ask for an audit report | Documented access reviews, change control, monitoring |
Ask early whether any of these apply, and get the answer from legal or compliance staff rather than guessing. Compliance often has the biggest architectural effect of any requirement, because it can dictate regions, retention periods, and which vendors you may use.
Making retention rules executable
Retention is a good example of a compliance rule you can automate and test. The sketch below finds records that have outlived the limit for their kind.
from datetime import date, timedelta
RETENTION_DAYS = {"access_log": 90, "audit_log": 365}
def expired(records, today):
"""Return records older than the retention period for their kind."""
result = []
for record in records:
limit = timedelta(days=RETENTION_DAYS[record["kind"]])
if today - record["created"] > limit:
result.append(record)
return result
records = [
{"id": 1, "kind": "access_log", "created": date(2026, 6, 1)},
{"id": 2, "kind": "audit_log", "created": date(2026, 6, 1)},
]
print([r["id"] for r in expired(records, date(2026, 11, 26))]) # [1]Both records are 178 days old on 26 November 2026. The access log exceeds its 90-day limit and the audit log does not.
Edge cases and common errors
- Retention conflicts. Audit logs must be kept for a year, while access logs containing IP addresses must be deleted after 90 days. If audit entries embed IP addresses, the two rules collide. Resolve this at requirements time, for example by hashing or omitting the address in audit entries.
- Deletion versus backups. "Delete on request" is hard to meet if backups are immutable. State whether backups are in scope and how long they take to age out.
- Secrets in logs. A logging requirement without a "never log" list leaks tokens and personal data. Add one.
- Unspecified actors. Requirements that don't say which role may perform an action leave authorization to whoever codes it.
- Third parties. Data sent to analytics or email vendors falls under the same rules. List those flows.
Security trades against other qualities
Security requirements cost something, and the cost should be visible before the architecture is chosen.
- Latency. TLS handshakes, token validation, and authorization checks add time to each request. Count them against the p99 budget, not just the median.
- Operability. Strict access controls slow down incident response if engineers can't reach production quickly. Define an emergency access procedure that is itself audited.
- Durability and availability. Audit logging on the request path can block requests if the log store is down. Decide whether a failed audit write rejects the request or is buffered.
- Cost and complexity. Regional data residency means separate deployments, which multiplies operational work.
Record these choices next to the requirement that caused them, so a later reader knows why the design has the shape it does.
Exercise
A team writes the requirement "User data must be protected." Rewrite it as two testable requirements for a service that stores email addresses, then name one compliance source that might also apply.
Show answer
Example: (1) "Email addresses are encrypted at rest with AES-256, and the encryption keys are stored in a managed key service, not in the application config." (2) "Only the account owner and the support role can read an email address; every support read is written to the audit log." Each is checkable by inspecting configuration or running an access test. GDPR may apply if any users are in the EU, adding deletion-on-request and residency constraints.
Exercise
SEC-3 requires audit entries kept for 365 days, and COMP-1 requires IP addresses deleted after 90 days. Describe the conflict and one way to resolve it.
Show answer
If audit entries contain IP addresses, keeping them for 365 days violates the 90-day deletion rule. One resolution is to leave the IP address out of audit entries, or store only a salted hash or a coarse region, so the audit log meets its retention need without holding the regulated field. Another is to purge or null the IP field from audit entries at 90 days while keeping the rest of the entry.