# Filesystem storage

AlmaForge stores audit events and session recordings directly on a local filesystem or network share (such as NFS). No external cloud object storage or database is required.

Local storage is handled by three complementary drivers:

1. **`dir` (default & recommended)**: Manages a structured directory hierarchy for both audit events and session recordings.
2. **`file`**: Appends audit events to a single flat file for log forwarders (Fluent Bit, Vector, Splunk).
3. **`stdout`**: Streams audit events to standard output in containerized environments (Kubernetes).

| Driver       | Storage role           | Supported data                      | Best used for                                                            |
| ------------ | ---------------------- | ----------------------------------- | ------------------------------------------------------------------------ |
| **`dir`**    | Structured directory   | Audit events and session recordings | Default local storage, single-node evaluation, and multi-node NFS shares |
| **`file`**   | Flat append file       | Audit events only                   | Forwarding logs to host-level collectors (`tail -f`, SIEM)               |
| **`stdout`** | Standard output stream | Audit events only                   | Kubernetes and containerized log scraping                                |

Zero-configuration default

If you do not author any storage manifests or environment variables, AlmaForge automatically uses the **`dir`** driver under `/var/lib/almaforge/audit`.

## TL;DR[​](#tldr "Direct link to TL;DR")

1. Use the default `dir` storage under `/var/lib/almaforge/audit`, or specify a custom path in `StorageConfig` manifests.
2. Place `StorageConfig` manifests for `recordings` and `audit` in `/etc/almaforge/almad.d` on each Auth host.
3. Restart `almad` and verify session replay and audit search with `alma`.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Before you start, make sure you have:

* A local directory or network mount (e.g. NFS) with sufficient disk space for audit logs and session recordings.
* Root access or appropriate write permissions on the target storage path.
* A cluster state backend already configured ([SQLite](https://almaforge.com/storage/sqlite.md), [PostgreSQL](https://almaforge.com/storage/postgresql.md), [DynamoDB](https://almaforge.com/storage/dynamodb.md), [etcd](https://almaforge.com/storage/etcd.md), or [Firestore](https://almaforge.com/storage/firestore.md)).

## Configuration[​](#configuration "Direct link to Configuration")

This fast path configures local filesystem storage using declarative manifests in `/etc/almaforge/almad.d`. For flat-file streaming, container stdout, NFS clustering, or internal storage layout, see [Advanced](#advanced).

### Step 1. Choose your storage path[​](#step-1-choose-your-storage-path "Direct link to Step 1. Choose your storage path")

By default, AlmaForge writes to `/var/lib/almaforge/audit` (typically `/var/lib/almaforge/audit/`). You can use this default or specify an alternative path (such as a mounted disk or network share).

note

A cluster upgraded from an earlier release wrote audit events to `/var/lib/almaforge/log` and recordings to `/var/lib/almaforge/records`. Those files stay where they are and are not read from the new path. See the [changelog](https://almaforge.com/news.md) for what to move.

| Parameter | Required | Default                    | Description                                             |
| --------- | -------- | -------------------------- | ------------------------------------------------------- |
| `path`    | yes      | `/var/lib/almaforge/audit` | Directory path on every Auth host, writable by `almad`. |

### Step 2. Configure session recordings[​](#step-2-configure-session-recordings "Direct link to Step 2. Configure session recordings")

To store recordings locally, place a `StorageConfig` manifest with `metadata.name: recordings` in `/etc/almaforge/almad.d` on every Auth host (see [Bootstrap configuration](https://almaforge.com/storage.md#bootstrap-only)). There is exactly one `recordings` instance per cluster.

[`recordings.yaml`](https://almaforge.com/examples/storage/local/recordings.yaml):

examples/storage/local/recordings.yaml

```yaml
# Session recordings on each Auth host's filesystem, under records/ and

# records-index/ of the path given.

apiVersion: almaforge.com/v1

kind: StorageConfig

metadata:

  name: recordings

spec:

  dir:

    path: /var/lib/almaforge/audit
```

### Step 3. Configure audit events[​](#step-3-configure-audit-events "Direct link to Step 3. Configure audit events")

To store audit events locally, place a `StorageConfig` manifest with `metadata.name: audit` in `/etc/almaforge/almad.d` on every Auth host:

[`audit.yaml`](https://almaforge.com/examples/storage/local/audit.yaml):

examples/storage/local/audit.yaml

```yaml
# Audit events on each Auth host's filesystem. One path also serves the

# recordings instance, which writes under records/ beside events/.

apiVersion: almaforge.com/v1

kind: StorageConfig

metadata:

  name: audit

spec:

  dir:

    path: /var/lib/almaforge/audit
```

### Step 4. Restart and verify[​](#step-4-restart-and-verify "Direct link to Step 4. Restart and verify")

Restart the Auth Service and verify that your storage resources are active:

******Terminal

```bash
sudo systemctl restart almad
alma get storageconfig/audit -o yaml
alma get storageconfig/recordings -o yaml
```

Next, open and terminate an SSH session, then confirm that recordings and audit events are searchable:

******Terminal

```bash
# List recent recordings
alma recording ls --last=1h

# Search recent audit events
alma audit --last=1h
```

If both commands return your test session, your read and write paths are fully operational.

## Advanced[​](#advanced "Direct link to Advanced")

### Storage layout and compression internals[​](#storage-layout-and-compression-internals "Direct link to Storage layout and compression internals")

The `dir` driver organizes session recordings and audit events under dedicated subdirectories of your configured `path`:

text

```text
/var/lib/almaforge/audit/

├── records/

│   └── <session-id>.pb                          Session recording payload

├── records-index/

│   └── 2026/11/16/09/

│       └── <unix-nanos>-<session-id>.jsonl.gz   Fast listing index

└── events/

    └── 2026/11/

        ├── 14/

        │   └── 2026-11-14-<host-id>.jsonl.gz    Older days: automatically compressed

        ├── 15/

        │   └── 2026-11-15-<host-id>.jsonl       Yesterday: plain text grace period

        └── 16/

            ├── 2026-11-16-<host-id>.jsonl       Today: active plain text append

            └── 2026-11-16-<other-host>.jsonl    Safe multi-node writes (one file per host)
```

**Session recordings**

Session recordings are stored exclusively under `records/`. Each recording is named by its session ID (`<session-id>.pb`), accompanied by an index entry under `records-index/` so that replay listings sort chronologically without scanning entire files.

**Audit events and delayed compression**

Audit events are stored under `events/`, partitioned by day and host ID:

* **Grace period**: The current day and the previous day always remain uncompressed plain text (`.jsonl`) so that log forwarders and live searches can read events without contention.
* **Automatic delayed compression**: Days older than yesterday are automatically compressed in place to `.jsonl.gz`, saving 80–90% disk space while remaining fully searchable.
* **Multi-node safety**: Because each file includes `<host-id>`, multiple Auth Service instances sharing an NFS mount write to their own files without locks or write collisions.

Both audit events and session recordings live under one unified path because each uses dedicated prefixes (`events/`, `records/`, `records-index/`). This mirrors [S3 bucket layout conventions](https://almaforge.com/storage/s3.md#s3-storage-layout-and-internals), making future cloud migrations straightforward.

### Streaming audit events to log collectors (`file` driver)[​](#streaming-audit-events-to-log-collectors-file-driver "Direct link to streaming-audit-events-to-log-collectors-file-driver")

If you use a host log forwarder (such as Fluent Bit, Vector, or Splunk Universal Forwarder) that tails a fixed file path, add a `file` instance alongside your primary `dir` instance using [audit fan-out](https://almaforge.com/storage.md#audit-events):

[`audit-file.yaml`](https://almaforge.com/examples/storage/local/audit-file.yaml):

examples/storage/local/audit-file.yaml

```yaml
# A second audit destination for a log collector to follow. The path is

# the file itself, appended to and never rotated by AlmaForge, and it

# holds no recordings.

apiVersion: almaforge.com/v1

kind: StorageConfig

metadata:

  name: audit-collector

spec:

  file:

    path: /var/log/almaforge/audit.jsonl
```

* **Behavior**: The `file` driver continuously appends JSON Lines to the target path without in-process rotation, renaming, or compression.
* **Collector friendly**: Log forwarders can run `tail -f /var/log/almaforge/audit.jsonl` without handling symlink switches or mid-stream file resets.

### Streaming to standard output in containers (`stdout` driver)[​](#streaming-to-standard-output-in-containers-stdout-driver "Direct link to streaming-to-standard-output-in-containers-stdout-driver")

In Kubernetes or container runtimes where log aggregators read directly from container stdout, use the `stdout` driver:

[`audit-stdout.yaml`](https://almaforge.com/examples/storage/local/audit-stdout.yaml):

examples/storage/local/audit-stdout.yaml

```yaml
# Audit events on the process's standard output, for a container

# platform that collects it. Nothing can be searched back out of this,

# so pair it with an instance that can be read.

apiVersion: almaforge.com/v1

kind: StorageConfig

metadata:

  name: audit-stdout

spec:

  stdout: {}
```

`stdout` is write-only

Because `stdout` cannot be queried back, `alma audit` and the Web UI Audit Log will have nothing to display if `stdout` is your only audit sink. Keep a `dir` instance configured alongside `stdout` if you want events queryable within AlmaForge.

### Multi-node clusters with shared network storage (NFS / EFS)[​](#multi-node-clusters-with-shared-network-storage-nfs--efs "Direct link to Multi-node clusters with shared network storage (NFS / EFS)")

To run a multi-node Auth Service pool with shared filesystem storage instead of cloud object storage, mount an NFS, AWS EFS, or CephFS share at the same path on all Auth hosts.

* **Why it works**: The `dir` driver isolates writes by appending `-<host-id>` to daily event filenames. No file locking or distributed synchronization is required.
* **Cluster state requirement**: Keep cluster state (`name: state`) off NFS. SQLite requires a local POSIX block device. For multi-node clusters, use PostgreSQL or another networked state store.

### Environment variables (URI syntax)[​](#environment-variables-uri-syntax "Direct link to Environment variables (URI syntax)")

If you configure AlmaForge via environment variables instead of YAML manifests, use the `dir:///` URI scheme:

env

```env
ALMA_AUDIT_URI=dir:///var/lib/almaforge/audit

ALMA_RECORDINGS_URI=dir:///var/lib/almaforge/audit
```

### Migrating to Amazon S3[​](#migrating-to-amazon-s3 "Direct link to Migrating to Amazon S3")

When scaling up to AWS S3:

1. **Recordings**: Sync directly to your S3 bucket. Because `dir` and `s3` use identical structures for recordings (see [S3 storage layout and internals](https://almaforge.com/storage/s3.md#s3-storage-layout-and-internals)), index entries transfer seamlessly:

   ******Terminal

   ```bash
   aws s3 sync /var/lib/almaforge/audit/records s3://my-bucket/audit/records
   aws s3 sync /var/lib/almaforge/audit/records-index s3://my-bucket/audit/records-index
   ```

2. **Audit events**: Do not sync existing local audit files to S3. Local disk partitions by day (`events/YYYY/MM/DD/`), whereas S3 partitions by hour flushes (`events/YYYY/MM/DD/HH/`). Instead, keep the existing `dir` instance configured as a secondary audit sink so historical events remain queryable.

## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting")

### Search returns no results from `file` or `stdout`[​](#search-returns-no-results-from-file-or-stdout "Direct link to search-returns-no-results-from-file-or-stdout")

`stdout` cannot be queried. A `file` instance only searches the single currently configured file (rotated-out files are invisible to the search engine). To ensure full search functionality in the Web UI and CLI, always maintain an active `dir` instance.

### Partial audit data across a multi-node cluster[​](#partial-audit-data-across-a-multi-node-cluster "Direct link to Partial audit data across a multi-node cluster")

If each Auth host writes to its own unshared local disk, each node only knows about the events it processed. To get a unified cluster view, mount a shared NFS volume using the `dir` driver, or transition to [Amazon S3](https://almaforge.com/storage/s3.md).

The same applies to recordings, and more sharply: a recording is written by whichever Auth host terminated its upload and is never moved afterwards, so on unshared disks it can only be replayed from that host.

### A search reports too many events in a day[​](#a-search-reports-too-many-events-in-a-day "Direct link to A search reports too many events in a day")

A `dir` search reads one day at a time and will not return more than 100,000 matching events from a single day. The size of the day itself does not matter, so asking for the last few minutes of a very busy day is fine. Narrow the window, or ask for specific event types. A cluster that routinely wants more than that out of one day belongs on a database driver or [Amazon S3](https://almaforge.com/storage/s3.md), which answer a search without reading a day's worth of events.

## Operations[​](#operations "Direct link to Operations")

### Log rotation for `file` instances[​](#log-rotation-for-file-instances "Direct link to log-rotation-for-file-instances")

A `dir` instance needs no rotation. It starts a file each day on its own and compresses the days that stop being current.

A `file` instance appends to one path indefinitely, so rotate it with `logrotate` in the ordinary way. `almad` holds the file open, so tell it to pick up the new one afterwards: SIGHUP makes it start a replacement process, which opens the configured path fresh, and the outgoing process then shuts down gracefully.

/etc/logrotate.d/almaforge

```text
/var/log/almaforge/audit.jsonl {

    daily

    rotate 14

    compress

    delaycompress

    missingok

    notifempty

    postrotate

        systemctl kill -s HUP almad

    endscript

}
```

`delaycompress` matters when `compress` is on. The outgoing process keeps writing to the rotated file for as long as it takes to drain, and compressing that file while it is still open would discard whatever it writes after the compressed copy is taken. Waiting one cycle lets the old process exit first.

### Retention and pruning[​](#retention-and-pruning "Direct link to Retention and pruning")

AlmaForge does not automatically delete expired recordings or audit events from the filesystem:

* **Audit events**: You can delete old day directories under `events/YYYY/MM/DD/` at any time using standard cron jobs or `find` commands.
* **Recordings**: When deleting old recordings from `records/`, always delete the corresponding index entries under `records-index/`. Removing a recording without its index entry leaves broken listings in `alma recording ls`.

### Permissions and security[​](#permissions-and-security "Direct link to Permissions and security")

* **`dir` driver**: Kept private to AlmaForge. Directories are created with mode `0700` and files with mode `0600`, owned by the process user (`root`).
* **`file` driver**: Created with mode `0640` in a `0750` directory so that unprivileged log collection agents (running in the file's group) can tail the file without root privileges.
* Pre-existing paths retain their existing ownership and permissions.

## References[​](#references "Direct link to References")

* [Storage backends overview](https://almaforge.com/storage.md)
* [Audit events reference](https://almaforge.com/reference/audit.md)
* [S3 storage](https://almaforge.com/storage/s3.md)
