> ## Documentation Index
> Fetch the complete documentation index at: https://docs.barndoor.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Export audit logs to your own storage

> Stream Barndoor audit events to your own S3-compatible or Azure Blob storage in near real time

## Overview

Barndoor can stream every audit event from your tenant — authentication, authorization decisions, AI agent requests, tool calls, policy changes, and more — to storage you own: an S3-compatible bucket or an Azure Blob Storage container. Events are batched, gzipped, and uploaded as JSON Lines files partitioned by date and hour. Once configured, logs land in your storage within a minute of being generated and remain under your retention and access policies.

This guide walks through configuring a destination, choosing an authentication method, and verifying that events are flowing. The delivery format is identical for both destination types — only the connection fields and the credential differ.

> [!NOTE]
>
> **Estimated time**: 10–20 minutes (longer if you need to provision a new bucket, container, or IAM role)

## Before You Begin

You'll need a Barndoor account with **admin** privileges on the organization whose events you want to export, plus one of the two destinations below.

**For an S3-compatible destination:**

* A bucket you own. AWS S3, Google Cloud Storage (via the S3 interop endpoint), MinIO, and SeaweedFS are all supported.
* Either:
  * **An IAM role** (AWS S3 only) whose trust policy permits Barndoor to assume it, **or**
  * **An access key pair** with `s3:PutObject` permission on your bucket

**For an Azure Blob Storage destination:**

* An Azure storage account and a container that already exists. Barndoor writes into the container but doesn't create it.
* Either:
  * **The storage account's access key**, **or**
  * **The ability to mint a container-scoped SAS** (shared access signature) with **Read**, **List**, **Write**, and **Create** permissions

> [!TIP]
>
> If your bucket is in AWS S3, we strongly recommend IAM-role authentication over access keys. It avoids handing long-lived credentials to Barndoor and is the standard pattern for cross-account access in AWS.
>
> On Azure, the equivalent least-privilege choice is a container-scoped SAS token rather than the storage account's access key — it limits Barndoor to the one container you're exporting to.

## Authentication Methods

Pick a credential when you configure the destination — you can switch later without recreating the export. The options depend on which destination type you choose.

### S3-compatible destinations

| | **IAM role** (AWS only) | **Access keys** |
| - | - | - |
| **Cloud support** | AWS S3 only | AWS S3, GCS, MinIO, SeaweedFS, any S3-compatible service |
| **Credentials in Barndoor** | None — we assume your role on every batch via STS | Long-lived `access_key_id` / `secret_access_key` stored in our secret vault |
| **Rotation** | Automatic — Barndoor mints short-lived credentials each batch | Manual — you rotate the keys and re-paste them into the Barndoor UI |
| **Setup effort** | Create one IAM role with trust + permissions policies | Create one IAM user and generate access keys |

### Azure Blob Storage destinations

| | **Account key** | **SAS token** |
| - | - | - |
| **Scope** | The entire storage account — every container in it | Whatever you sign; scope it to the single container you're exporting to |
| **Expiry** | None — valid until you regenerate the key | Built into the token, so exports stop when it lapses |
| **Rotation** | Regenerate the key in Azure, paste the new value into Barndoor | Mint a fresh token before the current one expires and re-save the destination |
| **Setup effort** | Copy one value out of the Azure portal | Generate a signature with the permissions and expiry you want |

A container-scoped SAS is the recommended choice: it's the least-privilege option, and rotating it is a single field edit. Use the account key when a SAS doesn't fit your workflow and you'd rather not track an expiry date.

## Configure with IAM Role Authentication

This is the recommended path for AWS S3 destinations.

### Step 1: Start the configuration in Barndoor

1. Sign in to your Barndoor portal and navigate to **Audit Log Export** in the side nav.
2. For the destination provider, choose **Amazon S3 / S3-compatible**.
3. Fill in the connection details:
   * **Endpoint URL** — `https://s3.<region>.amazonaws.com` (e.g. `https://s3.us-east-1.amazonaws.com`)
   * **Bucket Name** — the bucket events will land in
   * **Region** — matching AWS region (e.g. `us-east-1`)
   * **Path Prefix** *(optional)* — key prefix for every object. Defaults to `audit-events/`.
4. Under **Authentication**, choose **IAM role (AWS only)**.

The UI will display two values you'll need in the next step:

* **Barndoor principal** — the IAM role ARN that Barndoor will use to assume your role
* **External ID** — a random 64-character string unique to your destination. This is a shared secret used as the `sts:ExternalId` to defend against the [confused-deputy problem](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html).

Leave this tab open while you set up the role in AWS.

### Step 2: Create the IAM role in your AWS account

In the AWS console, go to **IAM → Roles → Create role**:

1. **Trusted entity type**: **Custom trust policy**. Paste the snippet below, substituting `<barndoor-principal>` and `<external-id>` with the values from the Barndoor UI:

   ```json theme={null}
   {
     "Version": "2012-10-17",
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": { "AWS": "<barndoor-principal>" },
         "Action": "sts:AssumeRole",
         "Condition": {
           "StringEquals": { "sts:ExternalId": "<external-id>" }
         }
       }
     ]
   }
   ```

   > [!TIP]
   >
   > The Barndoor UI provides a copy-pasteable version of this exact policy with the values filled in — click the copy button next to "Trust policy JSON".

2. **Permissions**: skip the AWS managed-policies screen — we'll add an inline policy after the role is created.

3. **Name**: any name you like, e.g. `barndoor-audit-export`. **Copy the role ARN** once it's created.

4. On the role's detail page, **Add permissions → Create inline policy**. Paste the snippet below, replacing `<your-bucket-name>`:

   ```json theme={null}
   {
     "Version": "2012-10-17",
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "s3:PutObject",
           "s3:ListBucket",
           "s3:GetBucketLocation"
         ],
         "Resource": [
           "arn:aws:s3:::<your-bucket-name>",
           "arn:aws:s3:::<your-bucket-name>/*"
         ]
       }
     ]
   }
   ```

   > [!NOTE]
   >
   > `ListBucket` and `GetBucketLocation` are used by Barndoor's "Check connection" health check. `PutObject` is what audit-consumer uses at runtime to upload event files.

### Step 3: Paste the role ARN back into Barndoor

Back in the Audit Log Export page:

1. Paste the role's ARN into **IAM Role ARN**.
2. Pick the event types to include (see [Selecting event types](#selecting-event-types) below) or leave the default (all types).
3. Click **Save Configuration**. The destination saves in a **paused** state so you can verify the connection before any events flow.
4. Click **Check Connection**. Barndoor assumes your role, performs a `HeadBucket` against your destination, and reports the result.

If you see **Connection Healthy**, you're done with setup. If not, jump to [Troubleshooting](#troubleshooting).

### Step 4: Start the stream

Once the connection is healthy, click **Start** in the **Current Status** card. The badge flips to **Streaming Active** and new audit events begin flowing to your bucket within \~30 seconds.

## Configure with Access Keys

Use this path for non-AWS S3-compatible destinations or when an IAM user fits your team's workflow better.

### Step 1: Create the IAM user / equivalent

In AWS:

1. **IAM → Users → Create user**, name it (e.g. `barndoor-audit-export`).
2. Skip the AWS Management Console access option — this user only needs programmatic access.
3. Once the user is created, **Security credentials → Create access key → Application running outside AWS** (or equivalent). Save the access key and secret.
4. **Add inline policy** with the same S3 permissions snippet from [Step 2 of the IAM-role flow](#step-2-create-the-iam-role-in-your-aws-account).

For non-AWS S3 services (GCS HMAC, MinIO, SeaweedFS), follow the service's instructions for creating an access key pair scoped to your bucket.

### Step 2: Paste the keys into Barndoor

1. Navigate to **Audit Log Export**, choose **Amazon S3 / S3-compatible** as the destination provider, and fill in **Endpoint URL**, **Bucket Name**, **Region**, **Path Prefix**.
2. Under **Authentication**, choose **Access keys**.
3. Paste the **Access Key ID** and **Secret Access Key**.
4. Click **Save Configuration**, then **Check Connection**, then **Start** — same flow as the IAM-role path.

> [!WARNING]
>
> The access key and secret never leave Barndoor's encrypted secret store and are never displayed again in the UI. To rotate, edit the destination and paste new values.

## Configure with Azure Blob Storage

Use this path when your events should land in an Azure storage account instead of an S3-compatible bucket. Region, path-style addressing, and the IAM-role flow are S3-only concepts — they don't apply here and the form doesn't ask for them.

### Step 1: Get a credential from Azure

Pick whichever method you settled on in [Authentication Methods](#azure-blob-storage-destinations).

**Account key**

1. In the Azure portal, open the storage account that holds your container.
2. Go to **Security + networking → Access keys**.
3. Click **Show** next to **key1** (or **key2**) and copy the **Key** value. Barndoor wants that key on its own — not the full connection string.

**Container-scoped SAS token**

1. In the Azure portal, open the storage account and go to **Data storage → Containers**.
2. Click the container you're exporting to, then **Shared access tokens** in its menu.
3. Under **Permissions**, select at least **Read**, **List**, **Write**, and **Create**.
4. Set an expiry you're comfortable rotating on, then click **Generate SAS token and URL**.
5. Copy the **Blob SAS token** — the query string, not the full blob URL.

The same signature from the Azure CLI:

```bash theme={null}
az storage container generate-sas \
  --account-name <storage-account> \
  --name <container> \
  --permissions rlwc \
  --expiry 2027-01-01T00:00:00Z \
  --output tsv
```

> [!TIP]
>
> Paste the SAS token with or without its leading `?` — Barndoor accepts either.

### Step 2: Fill in the destination in Barndoor

1. Sign in to your Barndoor portal and navigate to **Audit Log Export** in the side nav.
2. For the destination provider, choose **Azure Blob Storage**.
3. Fill in the connection details:
   * **Blob Service URL** — the blob service root for your account, `https://<storage-account>.blob.core.windows.net`. It must be `https`, and it must not include the container — that's a separate field.
   * **Container** — the name of the existing container events will land in.
   * **Path Prefix** *(optional)* — blob-name prefix for every upload. Defaults to `audit-events/`.
4. Under **Authentication**, choose **Account key** or **SAS token** and paste the value you copied into the credential field.
5. Pick the event types to include (see [Selecting event types](#selecting-event-types) below) or leave the default (all types).
6. Click **Save Configuration**. The destination saves in a **paused** state so you can verify the connection before any events flow.

> [!NOTE]
>
> Sovereign clouds work the same way — only the endpoint domain changes, for example `https://<storage-account>.blob.core.chinacloudapi.cn` or `https://<storage-account>.blob.core.usgovcloudapi.net`.

### Step 3: Verify and start the stream

1. Click **Check Connection**. Barndoor reads the container's properties with the credential you supplied and reports the result. The credential needs at least **Read**, **List**, and **Write** on the container — the health check reads, and delivery writes.
2. If you see **Connection Healthy**, click **Start** in the **Current Status** card. The badge flips to **Streaming Active** and new audit events begin flowing to your container within \~30 seconds.

Delivery is identical to the S3 path: batched, gzipped JSON Lines blobs, partitioned by date and hour under your path prefix. See [Object format and partitioning](#object-format-and-partitioning).

### Rotating a SAS token

A SAS token carries its own expiry, so plan a rotation before it lapses. Rotating is just re-saving the destination:

1. Mint a fresh token with the same permissions.
2. Open the destination, paste the new token into the **SAS token** field, and save.

Delivery picks up the new token automatically within a minute — no need to pause, remove, or recreate the destination.

> [!WARNING]
>
> If a token expires before you replace it, the **Current Status** card starts reporting delivery errors. Saving a fresh token clears them and delivery resumes. Account keys don't expire, but they're account-wide — regenerate them on whatever schedule your team uses for storage credentials.

## Selecting Event Types

The right-hand panel of the configuration form lets you pick which event categories to export. By default all 16 event types are included.

Available categories:

* **Policy** — `AUTHORIZATION`, `POLICY_DECISION`
* **Identity** — `AUTHENTICATION`, `SESSION_CREATED`, `SESSION_TERMINATED`, `SESSION_UPDATED`, `TOKEN_EXCHANGE`
* **AI Agent & Data** — `AI_REQUEST`, `DATA_ACCESS`, `TOOL_CALL`
* **Platform & Activity** — `AUDIT`, `REQUEST_COMPLETED`, `REQUEST_FORWARDED`, `REQUEST_RECEIVED`, `SYSTEM`, `USER_ACTION`

Click a category header to expand it and toggle individual event types. The badge shows how many you've selected out of the total. **Select all** / **Clear all** reset the selection for the whole list.

Event-type filters apply only to future events. Changing them doesn't backfill or remove already-exported objects.

## Object Format and Partitioning

Exported objects use this layout:

```
<bucket-or-container>/<path-prefix>/dt=YYYY-MM-DD/hour=HH/archive_HHMMSS.<seq>.<batch-id>.json.gz
```

For example, with the default prefix `audit-events/`:

```
my-bucket/audit-events/dt=2026-05-15/hour=07/archive_073825.0000.96568337-7073-4ab6-b431-c7d3d7251877.json.gz
```

Azure Blob destinations use the same naming, with your container standing in for the bucket.

Inside each gzipped file is one JSON object per line, in a shape compatible with Datadog's log-ingestion format. Trace and span IDs are included on events that originated within a traced request so you can correlate audit logs with traces in your observability stack.

Batches flush every 30 seconds or when the buffer reaches 100 events, whichever comes first.

## Pausing and Resuming

The **Pause** / **Start** button on the destination page is independent of the destination configuration. Pausing buffers new audit events on the Barndoor side; resuming drains the buffer to your destination. You can also delete the destination entirely with **Remove** — this clears any stored credential (access keys, an Azure account key, or a SAS token) and stops exports until a new destination is configured.

## Troubleshooting

### "Connection Unhealthy" after Check Connection (S3)

Look at the message under the badge. Common causes:

* **`AccessDenied` on `HeadBucket`** — the IAM role or user is missing `s3:ListBucket` and `s3:GetBucketLocation` on the bucket. Re-check the inline permissions policy.
* **`not authorized to perform: sts:AssumeRole`** — the trust policy's `Principal` doesn't match Barndoor's principal ARN exactly. Re-copy from the Barndoor UI.
* **`Invalid ExternalId`** — the `sts:ExternalId` in your trust policy doesn't match what Barndoor expects. Open the destination in the UI and re-copy the External ID; the value is stable per destination.
* **`NoSuchBucket`** — bucket name typo, or the bucket is in a different region than what you entered.

### "Last delivery issue: ... AccessDenied" but Check Connection passes

Health check uses `HeadBucket` (`ListBucket` / `GetBucketLocation` permissions). Actual uploads use `PutObject`. If health check is green but uploads fail with `AccessDenied`, your role / user is missing `s3:PutObject`. Add it to the inline permissions policy.

### "Connection Unhealthy" or delivery errors on an Azure destination

* **`AuthorizationPermissionMismatch` or `AuthenticationFailed`** — the credential needs at least **Read**, **List**, and **Write** on the container (a container SAS also needs **Create**). Re-mint the signature with the missing permissions, or check that you pasted the account key rather than the connection string.
* **`AuthenticationFailed` with a signature-expiry message** — the SAS token has passed its expiry. Mint a new one and save it on the destination; see [Rotating a SAS token](#rotating-a-sas-token).
* **`ContainerNotFound`** — container name typo, or the container doesn't exist. Barndoor writes into an existing container and never creates one.
* **`ResourceNotFound` or connection errors on the endpoint** — the **Blob Service URL** must be the account root (`https://<storage-account>.blob.core.windows.net`) over `https`, with no container path appended. Move the container name into the **Container** field.

### No objects appearing in the bucket or container even though the stream is "Active"

Audit events are only emitted when traffic flows through Barndoor. If you've just configured an empty test organization and there's no activity, the buffer may genuinely have nothing to upload. Generate some events by logging in/out, navigating around the portal, or making an API call against your tenant — anything that crosses Barndoor's authorization or proxy paths.

### Switching between IAM-role and access-keys mode

Editing an existing destination to switch modes is supported. When you switch from access keys to IAM role, Barndoor automatically deletes the stored access keys from its vault. When you switch the other way, you'll be prompted to enter new access keys.

### Switching between S3 and Azure Blob Storage

Editing an existing destination to switch providers is also supported. Changing the provider — or the authentication method — always requires entering the new destination's credentials; the previously stored credential is replaced when you save. The export itself (delivery settings, event-type selection) carries over unchanged, and streaming resumes against the new destination once its connection check passes.

## Frequently Asked Questions

> [accordion] What happens if my IAM role's trust policy or bucket permissions change?
>
> The next upload attempt will fail. The destination's status banner in the Barndoor UI will show the AWS error message. Re-check the trust and permissions policies — Barndoor doesn't cache anything that survives an updated AWS-side configuration.

> [accordion] Can the same IAM role serve multiple Barndoor organizations?
>
> Each Barndoor destination has its own External ID, so even within a single AWS account a single role can support multiple Barndoor tenants by allowing multiple `sts:ExternalId` values in the trust policy. In practice we recommend one role per Barndoor organization for clean auditing.

> [accordion] Is there a backfill option for historical events?
>
> Not currently — exports start from the moment you click **Start**. Historical events remain queryable in the Barndoor portal but aren't replayed to your bucket.

> [accordion] What's the data retention on Barndoor's side while paused?
>
> Buffered events are retained for 30 days while the stream is paused. If you resume within that window, all buffered events stream out in order. If you exceed it, older buffered events are dropped.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.