sq3 is a lightweight, single-binary S3-compatible object store. It keeps
bucket and object metadata in SQLite and stores payloads on the local
filesystem. The SQLite driver is pure Go, so the server builds with
CGO_ENABLED=0.
This repository is an MVP intended for local development and small, single-node deployments. It does not yet implement authentication, versioning, multipart uploads, replication, or distributed locking.
Go 1.22 or newer is required.
CGO_ENABLED=0 go build -o sq3 main.go
./sq3The server listens on :9000 and writes data beneath ./data by default:
data/
├── sq3.db
└── blobs/
└── {bucket}/
└── {sha256-of-object-key}
Runtime options:
-addr string HTTP listen address (default ":9000")
-in-memory run the server entirely in-memory (disables persistence)
-data-dir string metadata and blob data directory (default "./data")
-db string SQLite database path (default "<data-dir>/sq3.db")
-cors-allowed-origins string comma-separated CORS origins; empty disables CORS
-cors-allow-credentials allow credentials on CORS requests
-cors-max-age duration browser preflight cache duration (default 10m)
-max-object-size int maximum PutObject size in bytes (default 5 GiB; 0 disables)
-read-header-timeout duration HTTP header read timeout (default 10s)
-read-timeout duration complete request read timeout (default 0, disabled)
-write-timeout duration response write timeout (default 0, disabled)
-idle-timeout duration keep-alive idle timeout (default 2m)
-shutdown-timeout duration graceful shutdown timeout (default 10s)
For example:
./sq3 -addr 127.0.0.1:9000 -data-dir /var/lib/sq3The process handles SIGINT and SIGTERM with a ten-second graceful
shutdown window by default.
CORS is disabled by default. Enable it when a browser application accesses
sq3 directly:
./sq3 \
-cors-allowed-origins 'https://app.example.com,https://admin.example.com'For unrestricted local development:
./sq3 -cors-allowed-origins '*'Allowed preflight requests return 204 No Content. The server permits the
implemented GET, HEAD, PUT, and DELETE methods, reflects requested
preflight headers, and exposes ETag, Last-Modified, Content-Length,
Content-Type, and x-amz-request-id to browser code.
Use -cors-allow-credentials only for trusted origins. When credentials are
enabled together with *, sq3 returns the concrete requesting origin
instead of the invalid Access-Control-Allow-Origin: * and credentials
combination.
If nginx, Caddy, or another reverse proxy manages CORS, leave the sq3 CORS setting empty to avoid duplicate headers. TLS, authentication, rate limiting, compression, and public access logs are intentionally left to that proxy.
Uploads are limited to 5 GiB by default:
# Limit objects to 100 MiB.
./sq3 -max-object-size 104857600
# Disable the application-level limit.
./sq3 -max-object-size 0The limit is enforced for both known Content-Length requests and streamed
request bodies. Configure the read and write timeouts to suit the largest
expected upload; their defaults are disabled so long transfers are not
terminated unexpectedly.
The MVP implements these S3 operations:
| Operation | Request |
|---|---|
| ListBuckets | GET / |
| CreateBucket | PUT /{bucket} |
| DeleteBucket | DELETE /{bucket} |
| ListObjectsV2 | GET /{bucket}?list-type=2 |
| PutObject | PUT /{bucket}/{key...} |
| GetObject | GET /{bucket}/{key...} |
| HeadObject | HEAD /{bucket}/{key...} |
| DeleteObject | DELETE /{bucket}/{key...} |
For clients using the root-form API, bucket creation and deletion are also
available as PUT /?bucket={bucket} and DELETE /?bucket={bucket}. The
X-Sq3-Bucket header can be used instead of the query parameter.
Example lifecycle:
# Create a bucket.
curl -i -X PUT http://localhost:9000/photos
# Upload and inspect an object.
curl -i -X PUT \
-H 'Content-Type: text/plain' \
--data-binary 'hello from sq3' \
http://localhost:9000/photos/notes/hello.txt
curl -I http://localhost:9000/photos/notes/hello.txt
# List and download objects.
curl 'http://localhost:9000/photos?list-type=2&prefix=notes/'
curl http://localhost:9000/photos/notes/hello.txt
# Delete the object and then its bucket.
curl -i -X DELETE http://localhost:9000/photos/notes/hello.txt
curl -i -X DELETE http://localhost:9000/photosListObjectsV2 supports prefix, max-keys, and continuation-token.
Responses and errors use the S3 XML shapes, and object ETags are the MD5
digest of the stored payload.
SQLite owns metadata in these tables:
CREATE TABLE buckets (
name TEXT PRIMARY KEY,
created_at DATETIME NOT NULL
);
CREATE TABLE objects (
bucket TEXT NOT NULL,
key TEXT NOT NULL,
size INTEGER NOT NULL,
etag TEXT NOT NULL,
content_type TEXT NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (bucket, key)
);Payload names are SHA-256 hashes of object keys. This keeps arbitrary object keys from becoming filesystem paths and prevents path traversal. Each upload is staged to a temporary file and atomically renamed into place. Overwrites restore the previous payload if the metadata update fails.
sq3 is designed as a single-process server. Do not point multiple server
processes at the same data directory.
Run the complete local verification:
CGO_ENABLED=0 go test -v ./...
CGO_ENABLED=0 go test -cover ./internal/...
CGO_ENABLED=0 go build -o sq3 main.goThe test suite covers the SQLite metadata operations, filesystem storage
engine, persistence, failure recovery, S3 handlers, XML responses,
pagination, and validation. CI repeats the CGO-free tests and vets the code,
then cross-compiles Linux, macOS, and Windows binaries on every push and pull
request targeting main.