Skip to content

Storage Backends

Refringe edited this page Oct 28, 2026 · 14 revisions

Storage Backends

Anchor LFS supports two storage backends: local filesystem (default) and S3-compatible object storage.

Local Filesystem

The local backend stores LFS objects on disk in the configured data_directory. This is the default and requires no additional configuration.

Configuration

[options]
data_directory = "./data"

# No [storage] block needed, or explicitly:
[storage]
backend = "local"

Object Layout

Objects are stored using a two-level directory sharding scheme to avoid filesystem performance issues with large numbers of files in a single directory:

Each endpoint has its own directory, named after its path without the leading slash and with / replaced by _: the endpoint /org/repo is stored in org_repo.

data/
├── org_repo/
│   ├── .tmp/  (uploads in progress)
│   ├── ab/
│   │   ├── cd/
│   │   │   └── abcdef0123456789...  (full OID as filename)
│   │   └── ef/
│   │       └── abef...
│   └── 12/
│       └── 34/
│           └── 1234...
├── locks/
│   └── org_repo/
│       └── locks.json
└── signing.key

The first two characters of the OID form the first directory level, the next two form the second level, and the full OID is the filename.

Upload Process

  1. The object is written to a temporary file in the endpoint's .tmp directory
  2. SHA-256 hash is computed during the write and verified against the declared OID
  3. If the hash matches, the temporary file is atomically renamed to the final path
  4. If the hash does not match, the temporary file is deleted and the upload is rejected

Disk Space

The local backend checks available disk space before accepting uploads. If insufficient space is available, the upload is rejected with an appropriate error. The server also detects and reports ENOSPC (disk full) conditions during writes.

When to Use Local Storage

  • Small to medium deployments
  • Single-server setups
  • Development and testing
  • When you want minimal dependencies

S3-Compatible Storage

The S3 backend stores objects in any S3-compatible object storage service, including AWS S3, Cloudflare R2, MinIO, and others.

Configuration

[storage]
backend = "s3"
s3_bucket = "my-lfs-bucket"
s3_region = "us-east-1"

Full S3 Options

Option Default Description
s3_bucket (required) S3 bucket name
s3_region (required) AWS region (e.g., us-east-1, eu-west-1)
s3_endpoint (AWS default) Custom endpoint URL for S3-compatible services
s3_access_key_id (AWS credential chain) Access key ID. If omitted, uses the default AWS credential chain (IAM roles, environment variables, shared credentials file, etc.). Set it together with s3_secret_access_key; setting only one is a configuration error.
s3_secret_access_key (AWS credential chain) Secret access key. If omitted, uses the default AWS credential chain. Set it together with s3_access_key_id.
s3_prefix lfs/ Object key prefix. All objects are stored under this prefix, which must end with / and must not start with one. Set s3_prefix = "" in the configuration file to store objects at the bucket root; ANCHOR_LFS_S3_PREFIX only overrides it with a non-empty value.
s3_presigned_urls true Generate presigned URLs for direct client-to-S3 transfers. When disabled, the server proxies all transfers.
s3_force_path_style false Use path-style addressing (s3.amazonaws.com/bucket) instead of virtual-hosted-style (bucket.s3.amazonaws.com). Required by some S3-compatible services.

Startup Check and Permissions

At startup, and behind GET /ready, the server sends a HeadBucket request to confirm the bucket exists and the credentials and region can reach it. A wrong bucket name, region, endpoint or key stops the server with a checking storage error.

The credentials need s3:ListBucket on the bucket, and s3:GetObject, s3:PutObject and s3:AbortMultipartUpload on its objects.

S3 Object Layout

Objects use the same endpoint directory names and two-level sharding as local storage, prefixed with the configured s3_prefix. For the endpoint /org/repo with the default prefix:

lfs/org_repo/<oid[0:2]>/<oid[2:4]>/<full-oid>

With s3_prefix = "", the same object is at org_repo/<oid[0:2]>/<oid[2:4]>/<full-oid>.

Upgrading from v0.1.x

Before v0.2.0, an empty s3_prefix meant lfs/, and a prefix was joined to the endpoint name exactly as written. Check s3_prefix (and ANCHOR_LFS_S3_PREFIX) before upgrading:

  • s3_prefix = "": v0.2.0 reads and writes at the bucket root, so every existing object returns 404. Set s3_prefix = "lfs/" to keep using them.
  • A prefix without a trailing /, such as "lfs": v0.2.0 refuses to start. The old keys (lfsorg_repo/...) cannot be expressed as a prefix, so move each endpoint's objects, then set s3_prefix = "lfs/":
    aws s3 mv --recursive s3://my-lfs-bucket/lfsorg_repo/ s3://my-lfs-bucket/lfs/org_repo/

No s3_prefix at all, or one that already ends with /, needs no change.

Presigned URLs

When s3_presigned_urls is enabled (the default), the server generates presigned URLs during batch negotiation. Clients then upload to and download from S3 directly, bypassing the Anchor LFS server for data transfer. This significantly reduces bandwidth and load on the server.

Each presigned upload URL is signed for the object's declared size and SHA-256 (as an x-amz-checksum-sha256 header), and the batch response tells the client to send that header with the upload. The storage provider then rejects any upload whose bytes do not match the OID, so a corrupt or substituted object is never stored. This relies on the provider checking x-amz-checksum-sha256, which AWS S3, MinIO and RustFS do. A provider that ignores the header still accepts uploads but does not check their hash; a provider that rejects it needs s3_presigned_urls = false.

A presigned upload is a single PUT request, so objects over 5 GiB are refused at batch time with a 422. Disable presigned URLs to store larger objects; proxied uploads have no such limit when the client sends Content-Length. A proxied upload without one (chunked transfer encoding) goes to S3 in parts sized to fit max_upload_size into S3's 10,000-part limit: 8 MiB, or max_upload_size divided by 10,000 when that is larger, up to S3's 5 GiB part limit. Each such upload holds one part in memory while it is sent.

When disabled, the Anchor LFS server proxies all transfers. Clients upload to and download from the server, which then forwards data to/from S3.

In proxy mode, uploads stream through the server in 8 MiB parts, so each upload in progress holds about 8 MiB of memory. Objects up to 8 MiB are sent as a single request and larger objects as an S3 multipart upload (parts grow beyond 8 MiB only for objects over about 78 GiB, to stay within S3's 10,000-part limit, and stop at S3's 5 GiB part limit, so the largest object is 10,000 × 5 GiB, about 48.8 TiB). The server checks the SHA-256 against the OID before the object is written, and abandons the upload on a mismatch, so a corrupt object never appears in the bucket.

Provider-Specific Examples

AWS S3

[storage]
backend = "s3"
s3_bucket = "my-lfs-bucket"
s3_region = "us-east-1"
# Credentials via IAM role or environment variables

Cloudflare R2

[storage]
backend = "s3"
s3_bucket = "my-lfs-bucket"
s3_region = "auto"
s3_endpoint = "https://ACCOUNT_ID.r2.cloudflarestorage.com"
s3_access_key_id = "your-r2-access-key"
s3_secret_access_key = "your-r2-secret-key"

MinIO

[storage]
backend = "s3"
s3_bucket = "lfs"
s3_region = "us-east-1"
s3_endpoint = "https://minio.example.com"
s3_access_key_id = "minioadmin"
s3_secret_access_key = "minioadmin"
s3_force_path_style = true

DigitalOcean Spaces

[storage]
backend = "s3"
s3_bucket = "my-lfs-space"
s3_region = "nyc3"
s3_endpoint = "https://nyc3.digitaloceanspaces.com"
s3_access_key_id = "your-spaces-key"
s3_secret_access_key = "your-spaces-secret"

Environment Variable Overrides

All S3 settings can be overridden via environment variables (useful for keeping credentials out of config files):

export ANCHOR_LFS_STORAGE_BACKEND=s3
export ANCHOR_LFS_S3_BUCKET=my-lfs-bucket
export ANCHOR_LFS_S3_REGION=us-east-1
export ANCHOR_LFS_S3_ACCESS_KEY_ID=your-key
export ANCHOR_LFS_S3_SECRET_ACCESS_KEY=your-secret

ANCHOR_LFS_S3_ACCESS_KEY_ID_FILE and ANCHOR_LFS_S3_SECRET_ACCESS_KEY_FILE read the credentials from files instead, such as Docker secrets (see Secrets from Files).

When to Use S3 Storage

  • Large deployments with many or very large objects
  • When you want offsite or redundant storage
  • When you want to reduce bandwidth through your server (using presigned URLs)

Data That Always Uses Local Storage

Regardless of the storage backend, the following data is always stored locally in the data_directory:

  • File locks (locks/org_repo/locks.json for the endpoint /org/repo): Lock state for each endpoint
  • Signing key (signing.key): Auto-generated HMAC signing key

Ensure the data_directory volume is persistent even when using S3 storage. See Operations for backing it up, moving objects between backends, and removing objects nothing uses.

Running More Than One Instance

Run a single Anchor LFS instance per data_directory. S3 storage moves objects off the server, but lock state and the signing key stay local, and the rate limiter and authentication cache live in each process's memory, so S3 does not make a multi-instance deployment safe.

Lock changes take an advisory file lock (locks/org_repo/locks.json.lock), so two processes that briefly share a data_directory (for example, an old and a new container during a restart) do not lose each other's lock changes. This depends on the filesystem honouring advisory locks; local disks do, but some network filesystems do not.

When an instance is replaced by one with a different data_directory, set signing_key explicitly so transfer URLs signed by the old instance stay valid. See Security.

Next Steps

  • Configuration: Full configuration reference
  • Docker: Docker deployment with storage volumes
  • Security: Integrity verification and signed URLs
  • Operations: Backups, migration between backends, and pruning

Clone this wiki locally

⌂ 换网址