Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ TWIGPINE_MAX_CONCURRENT_PIN_TASKS=8
# Max concurrent read ops (upload-pack + the upload-pack info/refs advertisement)
# a single caller may hold, so one caller cannot monopolize the read pool. Keyed
# on the resolved SOURCE IP, never the DID: a signature does not move a caller off
# this cap. The source-IP key is only as granular as TWIGPINE_TRUSTED_PROXY below:
# left unset, a node behind an edge/NAT keys all callers on the edge IP and this
# collapses to one global cap. Set TWIGPINE_TRUSTED_PROXY for per-client keying; a
# this cap. The source-IP key is only as granular as the verified
# TWIGPINE_TRUSTED_PROXY and TWIGPINE_TRUSTED_PROXY_CIDRS pair below: without a
# verified proxy peer, a node behind an edge/NAT keys all callers on the edge IP
# and this collapses to one global cap. Configure both for per-client keying; a
# high-fanout caller (CI behind one NAT) then needs the operator to raise this.
# Default 16.
TWIGPINE_MAX_CONCURRENT_READS_PER_CALLER=16
Expand All @@ -298,7 +299,8 @@ TWIGPINE_MAX_CONCURRENT_READS_PER_CALLER=16
# rate, not in-flight concurrency, and owner enforcement can be turned off for
# a rolling upgrade).
# Keyed on the resolved source IP, never the DID, so a DID farm does not defeat
# them; keying granularity follows TWIGPINE_TRUSTED_PROXY like the read cap above.
# them; keying granularity follows the same verified trusted-proxy pair as the
# read cap above.

# ── Push rate limiting (git-receive-pack flood brake) ─────────────────────
# Max receive-pack requests (info/refs advertisement + push POST) per client
Expand All @@ -314,7 +316,8 @@ TWIGPINE_PUSH_RATE_LIMIT=600
# the served-git pools). Over-cap sheds a 503. Default 32.
TWIGPINE_MAX_CONCURRENT_IPFS_WALKS=32
# Max concurrent /ipfs walks a single SOURCE IP may hold (keyed like the git
# per-caller caps via TWIGPINE_TRUSTED_PROXY; reject-before-insert bounded map).
# per-caller caps through the verified trusted-proxy pair; reject-before-insert
# bounded map).
# Default 4.
TWIGPINE_IPFS_WALK_PER_SOURCE=4
# Max legacy (NULL-provenance) repos probed per single /ipfs request, bounding the
Expand Down Expand Up @@ -377,8 +380,8 @@ TWIGPINE_IPFS_RATE_LIMIT=600
# GET /api/v1/tasks/{id} runs get_visible_task and returns an opaque 404 when
# the task is hidden or missing. These reads can require task, repository,
# and visibility-rule queries even when no task is returned, so the brake
# bounds the cost of anonymous probes. Keyed on the resolved client IP via
# TWIGPINE_TRUSTED_PROXY. 0 disables. Default: 1200 (a list page
# bounds the cost of anonymous probes. Keyed on the client IP resolved through
# the verified trusted-proxy configuration. 0 disables. Default: 1200 (a list page
# followed by per-task reads is a normal client pattern, so this sits above
# the /ipfs budget). The GraphQL/WS task-read brake shares this budget.
TWIGPINE_TASK_READ_RATE_LIMIT=1200
Expand All @@ -388,8 +391,8 @@ TWIGPINE_TASK_READ_RATE_LIMIT=1200
# pulls) per client IP per hour, in addition to the per-DID limit. The per-DID
# limit alone is bypassed by a did:key farm (one throwaway identity per repo),
# which is how spam-repo floods slip past it and the iCaptcha gate; the per-IP
# brake caps a single-source flood. Uses TWIGPINE_TRUSTED_PROXY below to resolve
# the client IP. 0 disables. Default 120.
# brake caps a single-source flood. Uses the verified trusted-proxy configuration
# below to resolve the client IP. 0 disables. Default 120.
TWIGPINE_CREATE_RATE_LIMIT=120
# Per-DID creation requests allowed inside the window below (repo create,
# issue create, PR create, register, fork). 0 is rejected at startup: it would
Expand All @@ -411,14 +414,14 @@ TWIGPINE_RATE_LIMIT_WINDOW_SECS=3600
# after the read gate, rather than in router middleware. Issue close also draws
# on its own TWIGPINE_CLOSE_ISSUE_RATE_LIMIT bucket, and a close refused by
# either cap spends nothing from the other. Separate from the creation and push
# brakes. Uses TWIGPINE_TRUSTED_PROXY to resolve the client IP.
# brakes. Uses the verified trusted-proxy configuration to resolve the client IP.
# NOTE: this is a per-IP aggregate across ALL those write actions, so behind a
# shared NAT/egress IP (or with TWIGPINE_TRUSTED_PROXY unset) many users collapse
# onto one bucket — raise this for automation-heavy or multi-user single-IP
# shared NAT/egress IP (or without a verified proxy peer) many users collapse
# onto one bucket. Raise this for automation-heavy or multi-user single-IP
# deployments. 0 disables. Default 600.
TWIGPINE_WRITE_RATE_LIMIT=600

# ── Peer-sync rate limiting (per client IP, uses TWIGPINE_TRUSTED_PROXY below) ─
# ── Peer-sync rate limiting (per client IP, uses the verified proxy pair) ──────
# /api/v1/peers/announce and /api/v1/sync/notify accept unsigned requests from
# known peers and run at higher frequency, so a generous bucket. Separate from
# the trigger bucket so an unsigned notify flood can't drain trigger's quota.
Expand All @@ -429,15 +432,27 @@ TWIGPINE_PEER_WRITE_RATE_LIMIT=600
TWIGPINE_SYNC_TRIGGER_RATE_LIMIT=60

# Which forwarded header the edge is trusted to set, used to resolve the real
# client IP for the push limiter. One of:
# client IP for every source-IP brake. One of:
# (unset) — no trusted proxy: key on the socket peer address, ignore headers.
# fly — behind Fly's edge (trust Fly-Client-IP).
# x-forwarded-for — behind a single reverse proxy like Caddy/NGINX (trust the
# rightmost X-Forwarded-For hop).
# Only set this when a proxy you control actually fronts the node; trusting a
# forwarded header on a directly-exposed node lets clients spoof the key.
# The header mode is not sufficient by itself. The node uses the forwarded value
# only when the socket peer matches TWIGPINE_TRUSTED_PROXY_CIDRS below.
TWIGPINE_TRUSTED_PROXY=

# Comma-separated exact IPv4/IPv6 addresses or CIDR ranges for the proxy peers
# allowed to assert the forwarded header selected above. Exact addresses are
# host prefixes. Blank trusts no proxy peer. Any malformed entry invalidates the
# whole list and fails closed: the node still starts, logs an error, and ignores
# forwarded headers. With a header mode set and this list
# empty, forwarded headers are ignored; behind a proxy all clients then collapse
# onto the proxy socket-peer bucket, and the node logs a warning. Example:
# TWIGPINE_TRUSTED_PROXY_CIDRS=10.0.0.8/32,2001:db8::10/128
# Full client-IP keys are still cheaply rotatable for a caller that controls a
# routed IPv6 /64; this boundary stops header spoofing, not address-space rotation.
TWIGPINE_TRUSTED_PROXY_CIDRS=

# ── Sync ─────────────────────────────────────────────────────────────────
# Enable automatic background sync from known peers
TWIGPINE_AUTO_SYNC=false
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ Important node settings:
| `TWIGPINE_WRITE_LOCK_HOLD_TIMEOUT_SECS` | Max seconds a repo write guard may hold its advisory-lock pool connection, measured from lock-take. One deadline covers every phase under the lock: the under-lock refresh, the caller's under-lock work (for a push, the whole `receive-pack` subprocess, clamped to the lesser of `TWIGPINE_GIT_SERVICE_TIMEOUT_SECS` and the remaining budget), and the release-side upload/unlock. It bounds the lock-pool slot's hold, so a slow push cannot starve other writers for the sum of every per-phase bound. It does not bound the acquire-side lock wait (`TWIGPINE_GIT_ACQUIRE_TIMEOUT_SECS`), post-git outcome bookkeeping, the few seconds the detached reaper holds the session while the git process group dies, or merge writes, which take their guards without this deadline: their git runs unbounded under the lock, and their refresh, publish and unlock keep their own bounds, so a slow merge is never rolled back for overrunning it. Issue writes keep the deadline: an expired one refuses the write before the ref is touched, and the create's ref write and every git child of the close are clamped to it. Create's rollback after a refused publish keeps its own git-timeout budget. Unset, the effective bound is `TWIGPINE_GIT_SERVICE_TIMEOUT_SECS` itself (600 by default), tracking the git budget. The `gitlawb_push_duration_seconds` histogram is the evidence for tightening it below that: set the hold near the tail latency your pushes actually need, not lower. Merge is intentionally not bounded by it: it is owner-only, and a stamped deadline mid-merge would rewind a completed merge, so merge keeps its own per-phase bounds instead. An explicit value above `TWIGPINE_GIT_SERVICE_TIMEOUT_SECS` is rejected at boot. |
| `TWIGPINE_MAX_CONCURRENT_GIT_OPS` | Max concurrent served git READ ops (upload-pack and its `info/refs` advertisement) across all callers; over-cap sheds a 503 + Retry-After. Anonymous reads draw from this pool, so pair it with `TWIGPINE_MAX_CONCURRENT_READS_PER_CALLER`. Pushes and the receive-pack advertisement have their own pools, so a read flood cannot shed an authenticated push. Default 128. |
| `TWIGPINE_MAX_CONCURRENT_GIT_PUSHES` | Max concurrent `git-receive-pack` POST operations, in a pool separate from the read pool. The anon receive-pack `info/refs` advertisement runs in a third pool of the same size, disjoint from both, so an advertisement flood cannot shed a push either. Two per-source push caps are derived from this value (`/8`, floor 1) and have no env var of their own. Over-cap sheds a 503 + Retry-After. Default 32. |
| `TWIGPINE_MAX_CONCURRENT_READS_PER_CALLER` | Max concurrent read ops a single caller may hold, so one caller cannot monopolize the read pool. Keyed on the resolved source IP, never the DID, and only as granular as `TWIGPINE_TRUSTED_PROXY`: left unset, a node behind an edge or NAT keys every caller on the edge IP and this collapses to one global cap. Default 16. |
| `TWIGPINE_TRUSTED_PROXY` | Selects which forwarded header a verified edge proxy may assert: `fly` for `Fly-Client-IP`, or `x-forwarded-for` for the rightmost `X-Forwarded-For` hop. Unset ignores forwarded headers. The header is honored only when the socket peer matches `TWIGPINE_TRUSTED_PROXY_CIDRS`. |
| `TWIGPINE_TRUSTED_PROXY_CIDRS` | Comma-separated exact IPv4/IPv6 addresses or CIDR ranges for trusted proxy socket peers. Exact addresses are host prefixes. Blank trusts no proxy; any malformed entry invalidates the whole list and fails closed: the node starts, logs an error, and ignores forwarded headers. With a header mode set and no matching proxy peer, clients are keyed on the socket peer instead of the attacker-controlled header. Behind a proxy with no verified peer range they collapse onto the proxy's address. Even correct full-IP keys remain cheaply rotatable for a caller controlling a routed IPv6 `/64`; this setting stops header spoofing, not address-space rotation. |
| `TWIGPINE_MAX_CONCURRENT_READS_PER_CALLER` | Max concurrent read ops a single caller may hold, so one caller cannot monopolize the read pool. Keyed on the resolved source IP, never the DID, and only as granular as the verified `TWIGPINE_TRUSTED_PROXY` and `TWIGPINE_TRUSTED_PROXY_CIDRS` pair: without a verified proxy peer, a node behind an edge or NAT keys every caller on the edge IP and this collapses to one global cap. Default 16. |
| `TWIGPINE_MAX_CONCURRENT_PIN_TASKS` | Max post-push pin loops (IPFS + Pinata) running concurrently across all repos. This caps how many loops RUN at once, not how much object-id list memory the node retains: on the local IPFS path a loop parked waiting for a permit still holds its full list. Do not size memory from this knob alone. A loop over cap waits, never drops a pin. Up to two loops run per push that starts its own encrypt/pin task when both IPFS and Pinata are configured; a push coalesced onto an in-flight task adds at most one warm loop. See [docs/STORAGE-AND-PINNING.md](docs/STORAGE-AND-PINNING.md) for the two-tier model, dedup, and parked-list memory. Default 8. |
| `TWIGPINE_REPO_LEASE_MAX_WAITERS` | Max pushes parked at once waiting for the same repo's write lease. Each waiter pins its buffered pack body, so this bounds that memory for a hot repo; past the cap the newest push sheds a 503 + Retry-After instead of queueing. Pushes to other repos are unaffected, and the lease holder is not counted. Default 8. |
| `TWIGPINE_MAX_CONCURRENT_IPFS_WALKS` | Max concurrent `GET /ipfs/{cid}` visibility walks across all callers (own pool, disjoint from the served-git pools); over-cap sheds 503. Default 32. |
Expand All @@ -449,7 +451,7 @@ Important node settings:
| `TWIGPINE_IPFS_REQUEST_BUDGET_SECS` | Absolute wall-clock budget for one admitted `/ipfs/{cid}` request's acquire+walk lifetime. Per-stage clamps bound the acquire and walk stages to the remaining budget, and no stage starts once it is exhausted; the scan then stops with a retryable 503. The object-type probe and content-read `cat-file` subprocesses are budget-checked before starting and each also run under their own deadline (the lesser of `TWIGPINE_GIT_SERVICE_TIMEOUT_SECS` and the remaining budget), reaped via process-group teardown, so a hung `cat-file` cannot hold the request's walk slot past it. One hang path is still unbounded: the probe's object-store readability check is a plain filesystem sweep with nothing to reap, so a wedged filesystem can hold the slot past the deadline. Default 600. Accepted range is 1 to 3153600000 (100 years), since the node derives a deadline from this value and a larger one cannot be represented. |
| `TWIGPINE_IPFS_RESOLVE_BUDGET_SECS` | Shorter budget for the pre-walk CID resolve inside an admitted `/ipfs/{cid}` request: the lookup that maps the requested CID to its git oid(s), which runs while the scarce walk admission is already held. A well-formed CID with no pin row does no probe and no walk work, so without this it could hold a walk slot for the whole request budget while nothing walked, and enough such requests shed every real retrieval at admission. The effective deadline is the lesser of this and the remaining request budget, so a value above `TWIGPINE_IPFS_REQUEST_BUDGET_SECS` degrades to the request budget. Only the resolve is on this clock; walk and probe work stay on the request budget, so a slow but progressing scan is never shed by it. Default 10. Accepted range is 1 to 3153600000 (100 years). |
| `TWIGPINE_IPFS_RATE_LIMIT` | Max `/ipfs/{cid}` requests per client IP per hour (route flood brake). 0 disables. Default 600. |
| `TWIGPINE_TASK_READ_RATE_LIMIT` | Max anonymous task-read requests (`GET /api/v1/tasks`, `GET /api/v1/tasks/{id}`) per client IP per hour, sharing the budget with the GraphQL/WS task-read brake. Uses `TWIGPINE_TRUSTED_PROXY` to resolve the client IP. 0 disables. Default 1200 (above the `/ipfs` budget to allow list pages followed by per-task reads). |
| `TWIGPINE_TASK_READ_RATE_LIMIT` | Max anonymous task-read requests (`GET /api/v1/tasks`, `GET /api/v1/tasks/{id}`) per client IP per hour, sharing the budget with the GraphQL/WS task-read brake. Uses the verified trusted-proxy configuration to resolve the client IP. 0 disables. Default 1200 (above the `/ipfs` budget to allow list pages followed by per-task reads). |
| `TWIGPINE_TIGRIS_BUCKET` | Optional S3/Tigris shared repo storage bucket. |
| `TWIGPINE_PINATA_JWT` | Optional Pinata/IPFS warm-storage pinning. |
| `TWIGPINE_IRYS_URL` | Optional Irys/Arweave permanent anchoring. |
Expand Down
1 change: 1 addition & 0 deletions crates/twigpine-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ libp2p-dns = { version = "0.45.0", features = ["tokio"] }
# Optional: only needed by the test-harness feature's lib modules
# (test_git_shim, test_harness); dev-deps are invisible to lib code.
tempfile = { version = "3", optional = true }
ipnet = "2.12.0"

[dev-dependencies]
multibase = { workspace = true }
Expand Down
Loading
Loading