Audit logging
How Oxagen records every security event, IAM decision, and capability call across two independent audit stores.
Oxagen writes an audit record for every action that matters: every sign-in, every IAM decision, every capability call, every billing change, and every org management action. Two independent stores hold the records, each built for a different query pattern. ClickHouse chains each row's hash to the one before it, so a removed or inserted row shows when you recompute the chain.
Two independent audit stores
Postgres: security.security_events
Relational, queryable, and indexed for point lookups and compliance reporting.
- Retention: 7 years, enforced by monthly RANGE partitions. Oxagen drops partitions older than 7 years.
- Schema:
id,occurred_at,event_type,actor_user_id,org_id,workspace_id,capability,outcome,ip,user_agent,request_id. - Query surface: Organization → Audit (filtered UI), or the
query_audit_logcapability over the API. - Use cases: point lookups ("did this person call this capability?"), compliance dashboard queries, and access-review exports.
ClickHouse: audit_events
Append-only ReplacingMergeTree, built for high-volume analytics, with chain-hash tamper evidence.
- Retention: 7-year TTL column.
- Tamper evidence: each organization's rows form one hash chain. Every row takes the next number in that chain,
chain_seq, under a Postgres lock held per organization, so two writers never take the same number. The row storesprev_hash, thechain_hashof the row one number before, and its ownchain_hash: SHA-256 ofprev_hash, the number, the event id, the capability, the payload hash, the outcome, and every other column. An edited value stops a row's hash from matching. A deleted row leaves a gap in the numbers. Postgres keeps the newest number and hash for each organization, so rows cut from the end show too.tools/scripts/verify-audit-chain.tschecks a run of numbers for all of these. Rows written before this chain carrychain_seq0. Two calls at once could chain those onto the same row, so the same script checks them by the looser rule they were written under. - Use cases: high-volume analytics queries, SIEM pulls, tamper checks, and trend analysis over audit event volumes.
Independent code paths write the two stores. For each invoke() call, the Postgres write uses the kernel's emitSecurityEvent() (a pluggable emitter), and the ClickHouse write uses emitAudit(), called inside checkIAM(). Both are independent fire-and-forget calls, and not every event type reaches both stores. Auth and billing events go only to Postgres. ClickHouse receives only IAM capability decisions. A failed write in either path does not fail the capability call.
Event taxonomy
The taxonomy in packages/compliance/src/security-event-types.ts defines the event names. The tables below describe common events and mark reserved names. Consult that file for additions.
Auth lifecycle
| Event | Triggered by |
|---|---|
auth.sign_in | Successful login (any method) |
auth.sign_in_failed | Failed login |
auth.sign_out | Explicit logout or revoked login |
auth.token_refreshed | Reserved, not emitted yet |
auth.password_changed | A completed password reset. Every existing session for the user ends with it |
auth.email_verified | A verified email address, from a verification link or a confirmed change of address |
API key lifecycle
| Event | Triggered by |
|---|---|
api_key.created | New API key created |
api_key.revoked | API key revoked |
api_key.used | Successful API key authentication |
Billing mutations
| Event | Triggered by |
|---|---|
billing.access_denied | Reserved, not emitted yet |
billing.auto_reload_updated | Reserved, no longer emitted |
billing.budget_updated | Spend budget changed |
billing.checkout_initiated | Stripe checkout started |
billing.credits_purchased | Credit pack purchase completed |
billing.payment_method_added | Reserved, not emitted yet |
billing.payment_method_default_changed | Reserved, not emitted yet |
billing.payment_method_removed | Reserved, not emitted yet |
billing.plan_changed | Subscription plan or sandbox slots changed |
billing.seats_changed | Subscription seat count changed |
billing.subscription_canceled | Subscription canceled |
billing.subscription_reactivated | Canceled subscription reactivated |
Capability authorization
| Event | Triggered by |
|---|---|
capability.invoke_allowed | IAM decision: allowed |
capability.invoke_denied | IAM decision: denied |
capability.invoke_error | Capability handler threw an error |
Org management
| Event | Triggered by |
|---|---|
org.member_invited | Invitation sent |
org.member_removed | Member removed |
org.role_changed | Role assignment changed |
Org lifecycle
| Event | Triggered by |
|---|---|
organization.created | New organization provisioned |
workspace.created | New workspace created within an org |
Plugin governance
| Event | Triggered by |
|---|---|
plugin.installed | Plugin installed from the marketplace |
plugin.uninstalled | Plugin removed from the workspace |
plugin.enabled_changed | Plugin enabled or disabled |
plugin.credential_set | Plugin credential stored |
plugin.credential_revoked | Plugin credential revoked |
plugin.denylist_added | Reserved, not emitted yet (there is no plugin denylist) |
plugin.denylist_removed | Reserved, not emitted yet (there is no plugin denylist) |
Secrets
| Event | Triggered by |
|---|---|
secret.revealed | A secret's plaintext value revealed |
secret.exported | Secrets exported in plaintext |
secret.value_changed | A secret's value set or changed |
secret.key_deleted | A secret key deleted |
Data planes and model credentials
| Event | Triggered by |
|---|---|
data_plane.updated | An organization's data plane changed (set_data_plane) |
model_credential.set | An organization's own model key stored or replaced |
model_credential.revoked | An organization's own model key cleared |
model_credential.sent_to_host | Oxagen sent a person's model credentials to an enrolled machine (list_host_model_credentials) |
Agent run integrity
| Event | Triggered by |
|---|---|
agent_run.event_sequence_conflict | A run event conflicted with the recorded event sequence |
agent_run.forged_decision_reference | Reserved, not emitted yet |
agent_run.stale_deny_generation | Reserved, not emitted yet |
agent_run.finalization_grant_misuse | Reserved, not emitted yet |
Security policy
| Event | Triggered by |
|---|---|
security.mfa_policy_updated | Reserved, not emitted yet |
security.session_revoked | A signed-in login force-revoked |
Access review
| Event | Triggered by |
|---|---|
access.review_completed | Reserved, not emitted yet |
access.member_access_confirmed | Reserved, not emitted yet |
Privacy / GDPR
| Event | Triggered by |
|---|---|
privacy.export_requested | Data export requested (Art. 20) |
privacy.erasure_requested | Personal data erasure requested (Art. 17) |
privacy.org_erasure_requested | Org-level erasure requested |
Approvals
| Event | Triggered by |
|---|---|
approval.auto_approved | An auto-approval rule released a call a decision rule sent to a person |
approval.decision_started | A machine's gateway key asked for the link to a held call's approval in Oxagen |
The approval card a chat shows for a held call asks for this link when a person presses Open the approval. A model can call the same tool where the chat app does not keep it from the model, and Oxagen cannot tell the two apart, so the row records what the request said. The link decides nothing: a person approves or denies in Oxagen. An approval.decision_started row's detail holds approvalId, runId, the run that raised the approval, hostId, the machine whose gateway key asked, and harness, the app the machine's gateway named, or null when it named none. The row's actor is the person who enrolled the machine.
MCP server and outside sign-ins
Oxagen's MCP server on mcp.oxagen.sh and its sign-ins to outside MCP servers write these four.
| Event | Triggered by |
|---|---|
mcp.access_token_issued | The MCP server's token endpoint traded a grant from your identity provider for an access token |
mcp.token_request_denied | The token endpoint refused a grant your identity provider made |
mcp.request_label_mismatch | A request's Mcp-Method, Mcp-Name, MCP-Protocol-Version, or Mcp-Param- header was missing, unreadable, or different from its body, and the server answered 400 |
oauth.issuer_mismatch | An outside server's sign-in reply named a different issuer than the one Oxagen recorded, or named none when the server promised one, so Oxagen stopped before it sent the code or read the reply's error |
The grant is an ID-JAG: a short JWT your identity provider makes for one person and one app. An mcp.access_token_issued row's detail holds grant (id_jag), providerId, clientId, subjectHash, grantIdHash, scopes, and expiresAt.
The token endpoint writes an mcp.token_request_denied row only for a grant that checks out against a key one of your organization's SSO providers publishes, with that provider's issuer and tenant. Until then, nothing in the grant is known to come from your organization, because anyone can send a JWT that names it. A request refused before that point is logged and metered with no row: a wrong typ header, an aud that is not Oxagen's MCP server alone, a grant that expired more than an hour ago, a grant no key of your provider made, an issuer or tenant your provider is not set up with, or a grant that names no organization or more than one. So nobody outside your company can write into your audit log or name one of your members in it, even when your identity provider makes other companies' grants with the same keys, or makes a grant for another server that names your organization.
The row's detail holds grant, reason, claim, providerId, clientId, issuer, subjectHash, and grantIdHash. Its reason is one of missing_claim, proof_required, wrong_resource, wrong_client, not_yet_valid, expired, grant_reused, invalid_scope, not_entitled, not_enabled, wrong_workspace, not_a_member, client_not_allowed, or client_authentication_failed. For missing_claim, claim names the claim the grant lacked. proof_required is a grant your identity provider bound to the app's key, sent without proof of that key. client_authentication_failed is an app your organization registered with keys that sent no client assertion made with one of them. The two hashes are SHA-256 of the grant's sub and jti claims, so a reused grant's refusal matches the trade it repeats.
A refused grant sent again gets the same answer. A reused grant writes one grant_reused row however often it comes back. Every other reason writes one row per grant on each Oxagen server that refuses it.
The MCP server writes one mcp.request_label_mismatch row for each request it refuses this way, for its own tools and for the outside tools it serves, under the organization of the API key or the access token that sent it. A request whose credential matches no organization is still refused, with no row, so a stranger cannot write into your log. An mcp.request_label_mismatch row's detail holds label, problem (missing, malformed, or mismatch), labelValue decoded from Base64 when it came encoded, bodyValue, and base64. It also holds method, actorApiKeyId when an API key sent the request, actorMcpClientId and harness when an MCP access token sent it, which name the app by its registration and the harness its calls are recorded under, and runId when the request came in a run: the run Oxagen's gateway names in the request, on the machine the key belongs to. Its label is MCP-Protocol-Version, Mcp-Method, Mcp-Name, or an Mcp-Param- header a tool's input schema names, such as Mcp-Param-Region. An Mcp-Param- row keeps no labelValue or bodyValue, because a tool argument can hold a key or a person's data.
When a person adds or reconnects an outside MCP server, or connects their own account to an MCP Studio server, Oxagen sends them to that server's authorization server and records its issuer from the server's checked metadata. The reply must name the same issuer in its iss parameter (RFC 9207), compared character for character. A reply that names another, or names none when the server's metadata says it always sends one, is refused before Oxagen sends its code anywhere, and the person signing in is the row's actor.
An oauth.issuer_mismatch row's detail holds flow (provider or studio_operator), reason (issuer_mismatch or issuer_missing), expectedIssuer, receivedIssuer, issParameterSupported, and resource, the server's address. A Studio server the local gateway runs has no address, so its resource is the server's name. When a person adds or reconnects a server, a reply whose iss is longer than 16,384 characters is checked as an empty iss, so its row holds an empty receivedIssuer.
No row holds a token, a grant, or a sign-in code. A row cuts each text value it copies from a request, a grant, or a server to 256 characters. Before the cut, the password in an address and the value of each query parameter whose name reads like a secret become ***.
Guards
| Event | Triggered by |
|---|---|
guard.settings_unreadable | A spend budget, a workspace's daily lane budget, the assistant's credit gate or the decision rules gate could not read the settings it checks a call against |
Postgres goes down, and the spend budget gate cannot read your budgets. For 5 minutes after its last successful read, the gate decides each call with the budgets it read then, and writes this row with outcome allow. Once it has no read that recent, it refuses the call and writes the row with outcome deny. A workspace's daily budget on a lane does the same with the lane's spend for the day, and the assistant's credit gate does the same for a turn on your organization's own model key. The decision rules gate does the same with the workspace's rules and the facts those rules read. When the stored rules do not parse, a person's call that reads or writes the auto-approval rules still runs, so the workspace can be repaired, and its row has outcome allow with repair set to true. Saving the rules keeps every decision rule that parses and drops the rest, and that save writes one more row that lists the dropped rules.
A guard.settings_unreadable row's detail holds guard (spend_budget, lane_budget, turn_credits, or decision_rules) and setting (budgets, spend, rules, facts, or billing). It holds readAt, when the guard read the settings it decided with, or null on a refusal, and windowMs, how long a read stands in for one that failed. It holds budgetId, the budget whose spend could not be read, runId, the run the call belongs to, and errorCode, the failed read's code, such as ECONNREFUSED. A repair adds repair, the save that repaired the rules adds droppedRuleIds, and a lane budget row adds lane. The row never holds the settings or the error message, because a database error can quote the values it read.
The audit insert goes to the same Postgres, so it can fail for the same reason the read did. The guard holds each row the database refuses, up to 1,000, and writes them after its next successful read, each with the time the guard decided the call. A row the database refuses for what it holds, such as a value a constraint rejects, is dropped and logged, so the rows behind it are still written.
Adding a new event kind takes one edit to the taxonomy source file. The CI test checks that the Postgres CHECK constraint and the ClickHouse schema match that file, so schema drift fails CI.
Completeness
Every invoke() call, from any surface (app, API, or MCP), emits either a capability.invoke_allowed or a capability.invoke_denied event. No path through the capability boundary skips the emit, and there is no opt-out. A write can still fail, and a failed write does not fail the call. This is the SOC 2 completeness argument.
Accessing audit logs
In the app
Organization → Audit is a filterable view of security.security_events. Filter by:
- Event kind
- Acting principal
- Time range
- Outcome (allowed or denied)
- Capability name
Via API
POST https://api.oxagen.sh/v1/{orgSlug}/{workspaceSlug}/audit/log/query
Authorization: Bearer ox_…
Content-Type: application/json
{
"eventType": "capability.invoke_denied",
"from": "2026-01-01T00:00:00Z"
}The response is a JSON object with events (newest first), total, hasMore, limit, and offset. Page through results with limit (up to 200) and offset.
SIEM export
SIEM export (Splunk, Datadog, S3, or a JSONL webhook) is not available. Call query_audit_log on a schedule to pull audit events into an external SIEM.
Audit event structure
The two stores have different schemas. A capability call produces a row in each.
Postgres security.security_events
{
"id": "uuid",
"occurred_at": "2026-06-07T12:34:56.789Z",
"event_type": "capability.invoke_denied",
"actor_user_id": "uuid",
"org_id": "uuid",
"workspace_id": "uuid",
"capability": "change_member_role",
"outcome": "deny",
"ip": "192.0.2.1",
"user_agent": "Mozilla/5.0 …",
"request_id": "req_uuid"
}ClickHouse audit_events
{
"occurred_at": "2026-06-07T12:34:56.789Z",
"event_id": "uuid",
"org_id": "uuid",
"workspace_id": "uuid",
"capability": "change_member_role",
"scope_kind": "workspace",
"scope_id": "uuid",
"acting_principal_id": "uuid",
"acting_principal_kind": "human",
"human_principal_id": "uuid",
"outcome": "deny",
"decision_reason": "org.enforced_deny",
"payload_hash": "sha256:…",
"chain_hash": "sha256:…",
"ip": "192.0.2.1",
"ua": "Mozilla/5.0 …",
"request_id": "uuid",
"trace_jsonb": "{\"matched_rule\":\"org.enforced_deny\",\"policy_id\":\"uuid\"}"
}Every capability.invoke_denied ClickHouse row has a trace_jsonb field. It holds the resolver's step log, so you can answer "why was this denied?" from the stored decision rather than reconstructing it from logs. Auth and billing events are written only to Postgres and produce no ClickHouse audit_events row.