forge
Explore
Log in

Don't you dare go Hollow

in

Clone
★ 0

0 watching0 forksRustAGPL-3.0528.7 KiB9215377Tahinli26 days ago37 commits

README.md9.4 KiBHistoryRawDownload

in

in is the family's file drive. It keeps folders and files, resumable uploads, previews and thumbnails, a trash, sharing with people and by link, and per-person quotas. It also stores bytes for the other family apps through a machine API. It is one binary, in, with the web UI, the API, the background workers and the operator commands. Files are plain files in a blob tree, and in export writes them out as an ordinary folder tree that needs no in to read.

in depends on im for sign-in (OpenID Connect) and the people directory. Once a person is signed in, their files keep working while im is down. The shared contracts are in docs/contracts.md; the design is in docs/architecture.md; the code rules are in docs/conventions.md.

Build

You need Rust stable (edition 2024). The stylesheet is compiled from style/ at build time, so there is no Node step.

cargo build --release -p in-web      # binary: target/release/in
cargo test --workspace

Install the binary and the unit:

sudo install -m 0755 target/release/in /usr/local/bin/in
sudo useradd --system --home-dir /var/lib/in --shell /usr/sbin/nologin in
sudo install -d -o in -g in -m 0700 /var/lib/in
sudo install -d -m 0755 /etc/in
sudo install -m 0644 deploy/in.service /etc/systemd/system/in.service

Do not enable the unit until the configuration and the im client below are in place.

Configuration

in reads --config <path>, then IN_CONFIG, then config/in.toml. A missing file is created from config/in.example.toml on first run. Unknown keys are an error, so a typo fails at start-up.

The file holds no secrets. The OIDC client secret and the S3 keys are read from files that only the service user can read; in refuses a secret file that group or world can read:

Key Meaning
database, data_dir Database file and data directory (blobs, staging, in.key, in.lock). The data directory is created with mode 0700, and the database file and its -wal and -shm files with mode 0600.
listen Address to bind. Keep it on loopback and put the reverse proxy in front.
base_url Public origin with no trailing slash. An https origin turns on Secure cookies and HSTS. Plain http is accepted only for a loopback host (localhost, 127.0.0.0/8, ::1), and never with userinfo.
trusted_proxies Proxies whose X-Forwarded-For is believed. Behind Ferron on the same host, ["127.0.0.1/32"]; left empty there, every visitor counts as the proxy.
[oidc] issuer (the im origin), client_id (the id im printed for this client), client_secret_file.
[storage] backend = "local" (default) or "s3" with [storage.s3].
[backup] Optional. dir, interval_hours, keep, healthcheck_url. See Backups.
[limits] Optional defaults the admin page may override: quotas, purge days, upload size, link length.

At start-up in logs a warning when listen is a loopback address with no trusted_proxies, when [backup] or [oidc] is not configured, and when database is outside data_dir. None of them stops the server.

The admin page at /admin shows, next to each runtime value, whether it was set there, comes from the file, or is the built-in default. A blank field on that page removes the page's value again.

First run

  1. Start the server once to create the configuration and the instance key, then stop it:

    IN_CONFIG=/etc/in/in.toml in serve
    
  2. Register in as a client of im (run on the im host, where its data directory is). Replace <base> with the value of base_url:

    im client add --name in \
      --redirect-uri "<base>/auth/callback" \
      --post-logout-uri "<base>/" \
      --backchannel-uri "<base>/auth/backchannel-logout" \
      --family-key in --public-url "<base>" \
      --scopes "openid profile email directory.read"
    

    im prints the client id and its secret once. Save the secret to the file named by client_secret_file (/var/lib/in/oidc_client_secret, mode 0600, owned by in), and copy the printed client id into client_id. The scopes must include directory.read, which in uses to read the people directory; im does not grant it unless it is listed.

  3. Put the reverse proxy in front (see deploy/ferron.conf, an example for Ferron that proxies https://in.example.com to 127.0.0.1:7655). Ferron must not buffer responses: the live update stream depends on it. Set trusted_proxies = ["127.0.0.1/32"], so the share-password throttle sees each visitor's address, and keep /s/ paths out of the access log: a share link's token is in its path.

  4. Start the service:

    sudo systemctl enable --now in
    curl -s http://127.0.0.1:7655/healthz    # ok <build>
    

    The first person who signs in becomes a member. Administrators are the people im marks as admins.

The service unit runs in serve as the in user with systemd hardening (read-only system, no capabilities, a system-call filter). Its writable paths are the state directory and, when [backup] is set, the backup directory, which you add to ReadWritePaths.

Backups

With [backup] set, in serve writes a backup set every interval_hours, keeps the newest keep sets, and pings healthcheck_url after each good run (a failed ping is logged and nothing else). The server checks once a minute and runs when no attempt is recorded or the last attempt is at least interval_hours old. The attempt time is stored in the database before each run, so restarting the server does not start a run or move the schedule. A failing run is retried at the interval, not every minute.

While the server runs, the Backups section of /admin has a Back up now button that starts a run at once. It is for administrators only and needs the form's CSRF token. At most one run is pending or running: a press made meanwhile starts nothing. The press is written to the audit log (backup.requested). Without [backup] the button is refused.

A set is a directory set-<time> in dir, holding:

  • in.db: a consistent snapshot of the database (VACUUM INTO, checkpointed to one file).
  • manifest.json: the snapshot's size and SHA-256, and every blob with its key, size and SHA-256.
  • manifest.mac: an HMAC-SHA256 of the exact bytes of manifest.json, keyed with a subkey of the instance key (in.key, in the data directory). Anyone who can write to the backup directory can rewrite a set, but cannot make an edited manifest pass without in.key. Keep in.key with the rest of the server's secrets, and back it up separately from the backup directory.

Blob bytes are not copied. Keep the blob tree (data_dir/blobs) under its own backup, or use an S3 bucket with its own versioning. The manifest is what lets in fsck --hash and a restore check what should be there.

Restore

  1. Stop the service. in restore refuses to run while the server holds the data-directory lock.

  2. Run the restore with the set you want:

    in --config /etc/in/in.toml restore --from /var/lib/in/backups/set-2026-10-28T09-00-00-000000000Z
    

    It checks the manifest's MAC against in.key first (a set without that key, or one that was edited, is refused), then the manifest format, the snapshot's size and hash, and the snapshot's integrity before it changes anything. A set that fails a check is refused with a plain message, and nothing is replaced or created in the data directory. The database it replaces is moved to data_dir/restore-<time>/ and is not deleted.

  3. Run in fsck to see whether every row has its blob. Blobs listed in the manifest but missing from the blob tree are reported by the restore; they were deleted after the set was written.

  4. Start the service.

The database must lie inside data_dir. Restore does not replace anything outside it.

Command line

Command What it does
in serve Runs the server. A bare in does the same.
in export --member <sub or email> --out <dir> Copies one person's live files into <dir> as a folder tree with their names. Names are sanitized so nothing is written outside <dir>. Each file is hashed as it is copied and checked against its row.
in fsck [--hash] [--quarantine] Checks PRAGMA integrity_check, that every file, ready thumbnail and object has a blob of the recorded size, and with --hash the SHA-256 of every blob. Lists orphan blobs. Changes nothing unless --quarantine is given: then each orphan blob whose modification time is over an hour old is moved (not deleted) from blobs/ to the same path under quarantine/ in the data directory, and each move is printed. Younger orphans stay in place, so an upload that is still finishing is never touched. Local storage only. Exit status 1 when a problem is found.
in restore --from <set> Replaces the database with the one in a backup set, after verification (see Restore).
in quota recompute Recomputes every person's used bytes from their files and prints the ones that were wrong.

The commands other than serve take the data-directory lock. While the server runs they stop with in is running on this data directory. Stop the server first, then run the command again.

Layout

crates/in-core/   domain, store, migrations, config, settings, blobs, backup, export, fsck
crates/in-web/    the `in` binary: pages, sign-in, machine API, workers, CLI
deploy/           systemd unit and reverse-proxy example
docs/             contracts, architecture, conventions