Sub topic 14
Access control, encryption, and retention
This chapter assumes you can call an LLM API, use Python's logging module, and read basic regular expressions. It also assumes you have read the earlier chapters on the logging policy and redaction. Those chapters decide what goes into a log. This chapter covers who can read the stored logs, how they are protected, and when they are deleted.
Why stored logs need their own controls
Redaction is imperfect. Patterns catch common cases and miss others, so some sensitive text will end up in your logs. Treat every log store as if it holds some sensitive data. Three controls limit the damage:
- Access control limits who can read the logs.
- Encryption protects the data if storage is stolen or misconfigured.
- Retention limits how long the data exists at all.
Data that has been deleted cannot leak. Short retention is often the most effective of the three.
Separate metadata from content
Metadata logs hold model name, token counts, latency, and status. They are useful to many people, such as engineers and finance staff, and carry little risk. Content logs hold redacted prompts and responses. They are the riskier kind, and the gated logging you set up earlier produces them.
Store the two in different places, so each gets its own rules.
| Log type | Who can read | Retention | Notes |
|---|---|---|---|
| Metadata | All engineers, on-call, cost analysts | 30 to 90 days | Needed for cost and trend analysis |
| Content (gated) | A small named group | 3 to 7 days | Opt-in, tied to a debugging ticket |
| Audit of content access | Security team | 1 year or more | Records who read what and when |
These durations are examples. Set yours from your legal requirements and your privacy commitments to users.
Access control
Apply least privilege. Give people the lowest access that lets them do their job.
- Create separate roles for metadata readers and content readers.
- Grant content access to named people or a small group, not to everyone in engineering.
- Prefer temporary access that expires, for example access granted for the length of one incident.
- Record every read of content logs in an audit trail.
- Do not let the application's own credentials read logs. The app should only be able to write them.
Write-only credentials for the application mean that a compromised app cannot read back old content.
Encryption
Use two layers.
- In transit: send logs over TLS from your app to the log store.
- At rest: turn on encryption in the storage service. Prefer keys you manage in a key management service, so you can restrict and audit key use. Use a separate key for content logs, so removing a person's access to that key blocks them even if they can still reach the storage.
Encryption at rest does not stop an authorized reader from seeing text. It only protects against stolen disks, leaked backups, and storage-level mistakes. It supports access control and does not replace it.
Retention
Set an expiry on every log store when you create it, not later. Most platforms support this directly. Here is an example for Amazon S3 that deletes content logs after seven days:
import boto3
s3 = boto3.client("s3")
s3.put_bucket_lifecycle_configuration(
Bucket="my-llm-content-logs",
LifecycleConfiguration={
"Rules": [
{
"ID": "expire-content-logs",
"Status": "Enabled",
"Filter": {"Prefix": ""},
"Expiration": {"Days": 7},
}
]
},
)
print("Lifecycle rule applied")Check these points as well:
- Backups and replicas count. A seven-day rule on the main store means little if a backup keeps the data for a year.
- Exports and copies count. If someone downloads logs for analysis, those files need the same expiry.
- Deletion requests from users may require you to find and remove their data. Hashed identifiers, covered earlier, make this easier because you can search by hash.
Exercise
Your team keeps redacted prompts for debugging in the same log store as latency metrics, with 90-day retention and read access for all engineers. Name two changes you would make and the reason for each.
Show answer
First, move content logs to a separate store with a short retention period (for example 3 to 7 days), because redaction is imperfect and less retained data means less exposure. Second, restrict read access on the content store to a small named group and audit reads, because most engineers only need metadata. Adding a separate encryption key for the content store is also a good change.