Every allow or deny that a policy engine returns is evidence, and most organisations throw that evidence away. Teams that move authorisation out of application code and into a policy engine gain consistency, but they also create a new, central record of who asked to do what, under which policy version, and with what outcome. Kept and monitored, that record answers auditors, supports incident response and shows what non-human identities and AI agents actually did. Discarded, or kept without masking, it becomes either a blind spot or a new store of sensitive data.
This guide covers what to record from authorisation decisions, how to protect and retain it, and how to turn it into detection. It uses Open Policy Agent (OPA) as the worked example because its decision log format is publicly documented, but the principles apply to any engine or authorisation service. For how to write and ship policies in the first place, see the Policy-as-Code for Authorisation Guide; this page picks up where that one stops, at the evidence the engine produces.
Key takeaways
- A decision log is not an application log. It records the question asked, the answer given, and the policy that produced the answer, which is what an auditor or investigator needs.
- Record the principal, action, resource, result, policy revision, a decision identifier and a trace identifier at minimum. Without the policy revision you cannot explain an old decision.
- Inputs often contain tokens, personal data or secrets. Mask before the log leaves the engine, not afterwards in the SIEM.
- Rate limits and buffers can silently drop events. Decide deliberately whether losing decisions is acceptable, and alert when it happens.
- Denies are the cheapest detection signal you have. A sudden run of denials from one workload identity or agent is often the first sign of misuse or a broken deployment.
- For AI agents, decision logs tie a tool call back to an identity, a delegating user and a policy, which is the core of agent accountability.
Why authorisation decisions need their own log
Application logs tell you a request happened. Authentication logs tell you who proved their identity. Neither reliably tells you why a particular action was permitted. When authorisation is externalised, the engine is the only component that sees the full question (subject, action, resource, context) and the policy that answered it. If the engine does not record that, the reasoning behind every access is lost at the moment it is made.
Three groups need this record:
- Auditors and assessors ask whether access was enforced according to approved policy over a period. Control frameworks such as NIST SP 800-53 expect access enforcement (AC-3) to be backed by event logging (AU-2), adequate record content (AU-3) and protected audit information (AU-9). A decision log with policy revisions is direct evidence for all of these.
- Incident responders need to reconstruct what a compromised identity could reach and what it tried. Denied attempts are as important as successful ones because they show intent and scope.
- Policy authors need to know whether a policy change had the intended effect before and after rollout. Decision logs allow replay and comparison.
Non-human identities make this more pressing. Service accounts, workload identities and agents make far more authorisation requests than people do, rarely complain when they are denied, and are often over-permissioned. The decision log is frequently the only place where their real behaviour is visible.
What a useful decision record contains
OPA's documented decision log event is a good reference schema because it separates identity, query, policy and operational context. According to the OPA decision logs documentation, each event can include:
| Group | OPA fields | Why it matters |
|---|---|---|
| Identifiers | decision_id, trace_id, span_id, req_id, labels | Join the decision to the calling request and to the specific engine instance. |
| Query | path, query, input, result, requested_by, request_context.http.headers | The question and the answer, plus which client asked. |
| Policy | bundles (with each bundle's revision), rule ids and rule_labels | Which policy version decided, so old decisions can be explained. |
| Other | timestamp, metrics, nd_builtin_cache, erased, masked | Timing, replay of non-deterministic built-ins, and a record of what was redacted. |
Whatever engine you run, NHI Mgmt Group recommends that the normalised record you keep contains at least the following:
- Principal: the identity that the decision was about, including its type (human, service account, workload, agent) and issuer. For delegated calls, both the acting identity and the identity on whose behalf it acts.
- Action and resource: in the terms the policy uses, not just a URL.
- Result: allow or deny, and any obligations or reasons the policy returned.
- Policy version: a bundle revision, commit hash or policy store version.
- Decision identifier and trace identifier: so the record can be joined to application, gateway and agent traces.
- Engine identity: which instance, cluster or region made the decision.
- Timestamp: with a consistent clock source.
The OWASP Logging Cheat Sheet gives a wider list of when, where, who and what attributes for security events and is a useful cross-check for the fields above.
Masking and minimising sensitive inputs
The input to an authorisation query is often richer than it needs to be. Callers pass whole request bodies, bearer tokens, headers and user attributes because it is convenient. The OPA documentation warns that input may contain sensitive values such as usernames or passwords, and that parts of the decision itself may be sensitive, and recommends masking policies to remove or redact them before upload.
OPA implements this with a masking policy at data.system.log.mask, which the engine queries before encoding or uploading each event. Mask rules return JSON Pointers to erase, which must start with /input, /result or /nd_builtin_cache, or objects with an op of remove or upsert. Removed paths are listed in the event's erased field and modified paths in masked, so a reviewer can see that redaction took place. The documentation also notes that masking runs for every logged decision, so complex masking logic has a performance cost.
Practical masking rules:
- Never log raw bearer tokens, API keys, session cookies or client secrets. Replace them with a token identifier or hash if correlation is needed.
- Upsert a stable pseudonymous identifier in place of personal data where the policy does not need the raw value in the log.
- Remove large request bodies unless the decision depends on them.
- Test masking rules like any other policy: unit tests that assert a known secret never appears in an encoded event.
- Better still, reduce what callers send. A minimal input contract is easier to mask and cheaper to log.
Volume, sampling and dropped events
Machine callers generate a large volume of decisions, and the temptation is to log less. Do it deliberately rather than by default.
OPA offers a drop rule under system.log that suppresses any decision for which it evaluates to true, with the rule path configurable through decision_logs.drop_decision. A common pattern is to drop routine allowed decisions for low-risk paths while keeping every deny and every decision on sensitive resources.
Buffering and rate limits also matter. The OPA configuration reference documents a size or event buffer type, a default event buffer limit of 10,000 events for the event type, a default upload size limit of 32,768 bytes of compressed payload, and default upload delays of 300 to 600 seconds. If max_decisions_per_second is set, events beyond that rate are dropped. Uploads that do not receive a 2xx response are requeued and retried with exponential backoff, according to the decision logs documentation.
What this means in practice:
- A default upload delay of several minutes is fine for audit, but too slow for near-real-time detection. Tune the delay or use the
immediatetrigger where detection depends on it. - A rate limit protects the engine but creates silent gaps. Monitor engine metrics for dropped events and treat a sustained drop as an incident in its own right.
- An engine that restarts with an in-memory buffer can lose unsent events. Decide whether that is acceptable for each environment.
- Document sampling and drop rules so an auditor knows which decisions are complete and which are sampled.
Shipping, protecting and retaining decision logs
OPA can post compressed batches to a remote service (the default resource path is /logs), send events to a named plugin, or print them to the console with decision_logs.console: true. Console output is convenient in containers that already ship standard output to a log platform, but it puts decision data in the same stream as everything else, with the same access controls.
Treat decision logs as audit records:
- Separate access. Policy authors should be able to read decisions for debugging, but not alter or delete them. NIST SP 800-53 AU-9 covers protection of audit information.
- Integrity. Write to append-only or immutable storage, and record the policy bundle revision alongside each decision so the log and the policy repository can be reconciled.
- Retention. Align retention with your audit and regulatory obligations and with how long credentials and agents remain in service. A long-lived service account deserves a decision history at least as long as its lifetime.
- Clock and identity. Ensure engine instances use synchronised time and carry labels that identify environment and region.
- Credentials of the shipper. The engine's own credential for the log endpoint is a non-human identity. Scope it to write only, rotate it, and inventory it.
NIST SP 800-92 Rev. 1, the Cybersecurity Log Management Planning Guide (initial public draft), is a reasonable reference for planning collection, storage and retention at scale.
Turning decisions into detection
Decision logs are structured, low-noise and identity-centric, which makes them unusually good detection data. Useful starting analytics (illustrative, to be tuned against your own baseline):
- Deny bursts by principal. A workload or agent that normally sees near-zero denials and suddenly produces many is probing, misconfigured or compromised.
- New action or resource for a principal. First-seen combinations for non-human identities are high value because machine behaviour is usually repetitive.
- Decisions outside the expected engine or environment. A production identity being evaluated by a development engine, or the reverse, suggests credential reuse.
- Policy revision drift. Engines reporting an unexpected bundle revision may have failed to update or may be running a tampered bundle.
- Allow after a run of denies. A principal that is denied repeatedly and then allowed may have found a gap or had its permissions changed. Correlate with identity change logs.
- Gaps. No decisions from an engine that should be busy means either an outage or a logging failure.
Valid account misuse (MITRE ATT&CK T1078 Valid Accounts) is hard to see in authentication logs alone because the credential works. The decision log shows what the identity then tried to do, which is where misuse becomes visible.
Decision logging for AI agents
AI agents call tools and APIs on behalf of users, often through several hops. The question an investigator asks after an agent incident is simple: which agent, acting for whom, was allowed to do this, and by which policy? A decision log that records the agent identity, the delegating user, the tool or action, the resource and the policy revision answers it directly.
Recommendations for agent workloads:
- Evaluate every tool call through the policy engine, not just the first request in a session, so each action has its own decision record.
- Carry a trace identifier from the agent runtime into the authorisation input so decisions join to the agent's reasoning trace.
- Record both the agent's identity and the user context it acts under. Logging only the user hides the agent; logging only the agent hides the accountable human.
- Mask prompts and tool arguments unless they are needed for the decision. They often contain personal or confidential data.
- Keep agent decision logs separate from general observability telemetry, so retention and access can follow audit rules. The AI Agent Audit Log Schema Template gives a fuller field list.
For designing the policies that agents are evaluated against, see the AI Agent Authorisation Guide.
Standard interfaces and portability
Organisations often run more than one authorisation engine: one embedded in a gateway, another in a service mesh, a managed authorisation service in the cloud and a library inside an application. Each produces a different log shape. Normalise them into one schema with the minimum fields above, so detection and audit queries work across engines.
Standard authorisation request formats help. The OpenID AuthZEN work defines a common subject, action, resource and context model for policy decision requests; if your engines accept that shape, logging the same four elements gives you a portable record. See the OpenID AuthZEN Authorization API Guide for background. Whatever the engine, confirm in its own documentation which fields it records, whether decision logging is on by default, and whether data-plane calls to a managed service need to be enabled separately.
Common failure patterns
- Logging off by default and never switched on. The engine enforces correctly but leaves no evidence.
- Console logs with no retention. Decisions go to container output that is rotated within days.
- Secrets in the input. Whole request headers, including bearer tokens, are passed to the engine and logged verbatim.
- No policy revision. The log says allow, but nobody can show which policy said so at the time.
- Silent drops. Rate limits or buffer overflow discard events, and nothing alerts.
- Only allowed decisions sampled away, then denials too. Cost cutting removes the most useful detection signal.
- Agent actions logged under the user only. The agent identity is absent, so accountability is unclear.
- Policy authors can delete logs. The people whose changes need audit control the audit record.
Practitioner checklist
- Confirm decision logging is enabled on every policy engine and managed authorisation service, in every environment.
- Define a minimum normalised schema: principal and type, delegating identity, action, resource, result, policy revision, decision and trace identifiers, engine identity, timestamp.
- Implement and unit test masking for tokens, secrets and personal data before events leave the engine.
- Document drop and sampling rules; never drop denials or decisions on sensitive resources.
- Monitor engines for dropped events, upload failures and gaps, and alert on them.
- Store decision logs in append-only storage with access separate from policy authors.
- Set retention to meet audit obligations and the lifetime of the identities concerned.
- Scope, rotate and inventory the credential each engine uses to ship logs.
- Build detections for deny bursts, first-seen actions, environment mismatch and policy revision drift.
- For AI agents, record agent identity, user context, tool and trace identifier on every tool call.
Standards and references
- Open Policy Agent: Decision Logs
- Open Policy Agent: Configuration reference
- NIST SP 800-53 Rev. 5 (AC-3 Access Enforcement, AU-2 Event Logging, AU-3 Content of Audit Records, AU-6 Audit Record Review, AU-9 Protection of Audit Information, AU-12 Audit Record Generation)
- NIST SP 800-92 Rev. 1 Cybersecurity Log Management Planning Guide (initial public draft)
- OWASP Logging Cheat Sheet
- MITRE ATT&CK T1078 Valid Accounts
Related NHI Mgmt Group resources: Policy-as-Code for Authorisation Guide · AI Agent Authorisation Guide · Authorisation Models Guide · AI Agent Audit Log Schema Template