diff --git a/Cargo.lock b/Cargo.lock index 5040c46..e971124 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -588,6 +588,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" dependencies = [ "clap_builder", + "clap_derive", ] [[package]] @@ -602,6 +603,18 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_derive" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "clap_lex" version = "1.1.1" @@ -1968,6 +1981,7 @@ name = "in-web" version = "0.1.0" dependencies = [ "base64 0.23.1", + "clap", "ed25519-dalek", "futures-util", "grass", @@ -1979,6 +1993,7 @@ dependencies = [ "jsonwebtoken", "rand 0.10.3", "reqwest", + "rustix 1.1.6", "serde", "serde_json", "serde_urlencoded", diff --git a/Cargo.toml b/Cargo.toml index 3c81460..0cae844 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ argon2 = "0.6.0" async-trait = "0.1.92" base64 = "0.23.1" bytes = "1.12.1" +clap = { version = "4.6.7", features = ["derive"] } chacha20poly1305 = "0.11.0" ed25519-dalek = "2.1.1" futures-util = "0.3.34" @@ -59,6 +60,7 @@ ipnet = "2.12.2" jsonwebtoken = { version = "11.1.0", default-features = false, features = ["rust_crypto"] } object_store = { version = "0.14.2", features = ["aws"] } rand = "0.10.3" +rustix = { version = "1.1.6", default-features = false, features = ["fs"] } reqwest = { version = "0.13.5", default-features = false, features = ["form", "rustls", "stream"] } serde = "1.0.229" serde_json = "1.0.154" diff --git a/README.md b/README.md new file mode 100644 index 0000000..0cc5210 --- /dev/null +++ b/README.md @@ -0,0 +1,148 @@ +# 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. + +```sh +cargo build --release -p in-web # binary: target/release/in +cargo test --workspace +``` + +Install the binary and the unit: + +```sh +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 `, 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: + +| Key | Meaning | +|---|---| +| `database`, `data_dir` | Database file and data directory (blobs, staging, `in.key`, `in.lock`). The data directory is created with mode 0700. | +| `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. | +| `trusted_proxies` | Proxies whose `X-Forwarded-For` is believed. | +| `[oidc]` | `issuer` (the `im` origin), `client_id` (`in`), `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. | + +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: + + ```sh + 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 `` with + the value of `base_url`: + + ```sh + im client add --name in \ + --redirect-uri "/auth/callback" \ + --post-logout-uri "/" \ + --backchannel-uri "/auth/backchannel-logout" \ + --family-key in + ``` + + `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`). The default scopes (`openid profile email`) are + what `in` needs; the family's `directory.read` scope is granted to every family client by default. + +3. Put the reverse proxy in front (see `deploy/ferron.kdl`, 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. + +4. Start the service: + + ```sh + sudo systemctl enable --now in + curl -s http://127.0.0.1:7655/healthz # ok + ``` + + 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). + +A set is a directory `set-