diff --git a/AGENTS.md b/AGENTS.md index c9b33e8f..2a2e2b2c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,6 +19,7 @@ Each package's concerns and identifiers: [The packages](docs/content/docs/contri | `internal/upgrade/` | devvm upgrade; `upgradetest/` (tests only) | | `internal/from/` | `--from`'s references and digests | | `internal/redact/` | passwords out of logs; `Secret`, the type of every secret's value | +| `internal/vmlog/` | every log a VM can drive (but the proxy's own): its rate, its cap while it runs, and the backend's logs, serial consoles' included | | `internal/safefile/` | every read of a file a VM can write or swap | | `internal/devcontainer/`, `internal/jsonc/` | a project's devcontainer.json; JSON with comments | | `internal/tools/` | the shared tools: the lock, host mise, the daily check, tool image builds, the share | @@ -122,7 +123,7 @@ Each package's concerns and identifiers: [The packages](docs/content/docs/contri - **Delete test VMs and temp files afterwards.** Long builds run in the background. Tests that `chflags` real files unlock them (`chflags -R nouchg`), only in their own temp folders. - **The testscript runner stops the sandbox's proxies** (`pkill -f` on `_proxy -config` in the sandbox): the stub hostagent is gone before they look, so they'd wait 15 minutes. It also stops the sandbox's port forwarders, link sessions and stub ssh masters. - **`limactl shell` reads stdin:** give it none unless the input is meant for it. -- **Boot problems:** read `//serialv.log` before restarting; every start overwrites it. +- **Boot problems:** read `//serialv.log` (and its `.1`, past 10 MiB) before restarting; every start overwrites it. ## Gotchas learned diff --git a/CHANGELOG.md b/CHANGELOG.md index a48ad496..0f1c257f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,3 +143,4 @@ These changes are on `main` and go out in the next release. - **A stopped forwarder or link session takes its ssh with it:** devvm stopping a VM's port forwarder or link session, or a `kill` of either, could leave its ssh connection to the VM running on this machine, with its control socket in devvm's run folder. Each signal devvm sends now reaches what the process started too, either one stops its ssh before it exits, and `devvm gc --orphans` also deletes a forwarder's socket that nothing listens on ([how devvm starts them](https://next.devvm.dev/docs/internals/processes/#how-devvm-starts-them)). - **A Nix package is downloaded once:** when two requests for a package that wasn't in the shared Nix cache yet came close together, the second could download it again after the first had kept it, and the cache counted it twice against its cap. It now looks in the cache again before it downloads ([the shared Nix cache](https://next.devvm.dev/docs/internals/network/#the-shared-nix-cache)). - **A refused launch leaves a running VM running:** when `config.toml`'s proxy named a user and no `proxy` secret was saved, `devvm` in the folder of a running VM refused, as it should, but also stopped the VM, and `devvm restart` stopped it before it refused. The same happened when your CAs folder couldn't be used, or the VM's CA or secret files couldn't be readied. On a launch or a `devvm network` change, devvm now checks the company proxy, your CAs, the VM's CA and its secret files before it stops the VM's proxy, and says it left the VM and its proxy running as they were. `devvm restart` checks the company proxy and your CAs before it stops the VM. A `devvm network` change between `internet`, `allowlist` and `none` on a running VM is refused before the VM's tier changes, so its tier never says one thing while its proxy enforces another. A VM whose proxy doesn't enforce the tier the VM has now, or whose proxy is stopped for new settings and then can't start again, is still stopped, because a VM never runs on without its proxy. A `devvm network` change now stops it in that case too, where it left the VM running without its proxy ([the proxy](https://next.devvm.dev/docs/internals/network/#the-proxy)). +- **A VM's logs are held to their caps:** root in a VM could write to its serial console, `/dev/hvc0`, without end, and Lima's console log for the VM grew until this machine's disk was full, and so could Lima's own logs for the VM until its next start. While a VM runs, its proxy now keeps the disk space each of those logs takes under 10 MiB, on a file system with holes such as APFS or ext4, moving its end to the same name with `.1` added, of up to 10 MiB more, with any password in it replaced. It also replaces the VM's proxy password as the logs grow, so a reboot inside the VM, which on Linux hosts writes it to the console's log again, can't leave it there. A VM that's running when you upgrade gets this once a devvm command starts its proxy again. The port forwarder's and the link session's logs now stay under 1 MiB while they run, not only from their next start, a link's warnings take turns with the session's other lines, the build proxy's log stays under 10 MiB as a VM's proxy's does, a run writes at most 128 MiB to its run log, and the run logs take at most 256 MiB together, though devvm never deletes the newest or one that a running devvm still writes ([Lima's hostagent](https://next.devvm.dev/docs/internals/processes/#limas-hostagent)). diff --git a/docs/content/docs/contributing/structure.md b/docs/content/docs/contributing/structure.md index 2de5cc43..6c1a6d2e 100644 --- a/docs/content/docs/contributing/structure.md +++ b/docs/content/docs/contributing/structure.md @@ -65,7 +65,8 @@ Each package owns these concerns, and a package's `doc.go`, where it has one, ma | `internal/fetch` | every HTTP client, with the standard library alone: `NewClient`, with a timeout and `HTTPSOnly` or `SameScheme`, `Retry` and `Transient`, `ReadCapped`, `Get`, `Resolve`, which finds where a HEAD's redirects end, and `Download`, which checks the SHA-256 and caps the size | | `internal/upgrade` | devvm upgrade: how this devvm was installed (`Detect`), the releases (`Source`, with the newest, `Check` for a notice, and `Fetch`, which checks minisign's `ED` signature by the built-in key, then the SHA-256), the unpack, the link's switch and its rollback, and Homebrew. `upgradetest/`, for tests only, has a TLS release server and a minisign signer | | `internal/from` | `--from`: references, registry digests with an anonymous token, Docker's IDs and the recorded digests | -| `internal/redact` | passwords out of logs, with the standard library alone: `String` for the run log's lines, which takes out proxy keys and URL passwords, and `File` for another program's log, in place and keeping its length; and `Secret`, the type of the values that let whoever holds them act as you or as a VM ([Secrets in the code](#secrets-in-the-code)) | +| `internal/redact` | passwords out of logs, with the standard library alone: `String` for the run log's lines, which takes out proxy keys and URL passwords, `In` for another program's log as it grows, in place and keeping its length, reading a line not yet ended again from its start when it's within `MatchMax` of what an earlier look read, else from `MatchMax` back, starring what runs on to an `@` there (`Look.Cut` does the same after a rotation's cut), and `Unended` for a copy's cut end; and `Secret`, the type of the values that let whoever holds them act as you or as a VM ([Secrets in the code](#secrets-in-the-code)) | +| `internal/vmlog` | every log a VM can drive but the proxy's own: `Limit`, the rate and length of what a VM makes devvm's background processes write, which the port forwarder and the link session write through and whose `Allow` the link session's warnings take their turns from; `Capped`, a background process's log held to its cap as it appends, with `Trim` at its next start; and `KeepVM`, which the VM's proxy (through `proxy.IO.KeepLogs`) and a build run on the logs the backend writes as the VM runs (`backend.Run.Logs`), the serial consoles' among them, each in a goroutine of its own, redacting what each gained every second (`redact.In`), so a reboot in place can't leave the proxy's password there, and skipping a log that hasn't grown. `Redact` is Lima's redaction at the end of a start. Each rotation copies the log's end to its `.1` file, redacting only what the last look didn't reach and masking a secret cut at its end, and empties it with `f.Truncate`, counting a log by what it holds past the hole its writer left, as Lima's programs write at their own offset. Every log is opened through `safefile` (`Opts.Write`), never through a link or waiting on a FIFO. The proxy, which imports only the standard library and a few of devvm's leaves, rotates its own logs itself (`proxy.rotating`) | | `internal/safefile` | every read of a file a VM can write or swap, with the standard library alone, so the proxy uses it too ([the checks on owners](#the-checks-on-owners)) | | `internal/devcontainer` | a project's `devcontainer.json`, with no side effects: finding it, mapping it to a new VM's plan, its refusals, and what devvm update's second reading replaces (`Reread`) | | `internal/jsonc` | JSON with comments (`jsonc.Strip`), with the standard library alone | diff --git a/docs/content/docs/contributing/tests.md b/docs/content/docs/contributing/tests.md index f0ef09a6..07963e7a 100644 --- a/docs/content/docs/contributing/tests.md +++ b/docs/content/docs/contributing/tests.md @@ -18,7 +18,7 @@ Every change to devvm's logic comes with a test, and Go tests are table tests ne ## Goroutine leaks -A goroutine that outlives its test is one that would outlive its command in devvm, such as a tunnel the proxy carries after it has closed, or a goroutine that passes signals on after its child has ended. `internal/leaktest` finds them in every package that starts goroutines: `internal/proxy`, `vmssh`, `daemon`, `desktop`, `ui`, `vm`, `backend/lima`, `platform`, `cli`, `gitprotect` and `memnet`. It imports only the standard library, so the proxy's and the daemon's tests use it too. +A goroutine that outlives its test is one that would outlive its command in devvm, such as a tunnel the proxy carries after it has closed, or a goroutine that passes signals on after its child has ended. `internal/leaktest` finds them in every package that starts goroutines: `internal/proxy`, `vmssh`, `daemon`, `desktop`, `ui`, `vm`, `backend/lima`, `platform`, `cli`, `gitprotect`, `vmlog` and `memnet`. It imports only the standard library, so the proxy's and the daemon's tests use it too. - **`leaktest.Main(m)`**, in a package's `TestMain`, runs the tests and, once they've passed, reads every goroutine's stack. It gives the goroutines that are still ending, such as a closed listener's accept loop, five seconds, then fails the test binary with the stacks of any still running. It leaves out the standard library's own goroutines that outlive every test and that no test can end, which `allowed` lists with why: `signal.Notify`'s loop and an HTTP client's idle connections. It then reads Go's `goroutineleak` profile, which names each goroutine blocked for good on a channel, a lock or a wait group that nothing still running can reach, and fails on any it names. A `TestMain` that makes the test binary a helper process runs the helper first and calls `leaktest.Main` last. - **`leaktest.Check(t)`**, called first in a test, fails that test when a goroutine started while it ran is still running once it has ended, its context cancelled and its cleanups run, after the same five seconds. It counts the goroutines the test started, and theirs, followed through those still running, so a test running in parallel doesn't count. Nor does a goroutine that a server shared between tests starts for the test, such as one that `TestMain` or a `sync.Once` started, because it leads back to that server's goroutine, which ran before the test, and `Main` finds those at the end. Its failure names the test, where `Main`'s names only the binary, so a test of something that starts and stops goroutines, such as a link session, the port forwarder or the desktop's relay, calls it. diff --git a/docs/content/docs/internals/design.md b/docs/content/docs/internals/design.md index d1385a70..e4900637 100644 --- a/docs/content/docs/internals/design.md +++ b/docs/content/docs/internals/design.md @@ -42,7 +42,7 @@ These settings guard against the host's ssh asking for a forward that devvm's en - **Which ports.** Which ports each VM forwards, all, none or a list, is in its state (`ports.forward`), and the backend never hears of them: neither `Start`'s `Want` nor any other call of the backend's has them. `vmssh.Forwards.Start`, the one owner of the forwarder, reads them from the VM's state each time it starts one, after a start of the VM and when `devvm ports` changes a running VM's ports, without editing Lima's config. A stopped VM's change is its state's alone, because its next start reads it. When the VM lists ports, the forwarder forwards those less the ports a program on the host has, which the owner leaves out with a `ports_taken` warning. When none is left, no forwarder runs. - **A forwarder per VM, on the host.** The forwarder is `vmssh.Forwarder`, which isn't a backend's. Its owner, `vmssh.Forwards`, runs it detached as `devvm _ports`, one per VM, for project VMs alone, because only a project VM's start goes through it, and builds' starts don't. The owner starts it once the backend's `Start` returns, and again on a running VM when its ports change, each after stopping any forwarder the VM had, which ends the connections open through it. devvm finds that one by its pid file, which it checks against the process's arguments, as it does for the proxy. It sends that forwarder SIGTERM and kills it if it hasn't ended within 2 s, so its ports are free before devvm asks which listed ports a host program has. devvm holds a lock of the VM's own (`ports.lock`, beside its pid file `ports.pid` in the VM's run folder) from stopping the old forwarder until the new one has started, so two devvm runs at once, such as a start and `devvm ports`, leave one forwarder, the one its pid file names. The owner waits up to 10 s for the forwarder to say it forwards while it runs. The forwarder says so in a status file of its own beside its pid file (`ports.status`), which holds its pid and which devvm removes before each start. If it doesn't, devvm warns with `ports_forward_failed`, naming its log, and leaves it to keep trying while the VM runs on. - **Reaching the VM.** The forwarder makes one ssh connection, a master (`ssh -F none -M -S `), to the VM's sshd on Lima's ssh port on the host's loopback. Lima's `SSH` gives the port with the user and the key, the first `IdentityFile` of Lima's ssh config, and devvm refuses that target unless the config names `127.0.0.1` (`vmssh.FromTarget`, the check links and the ssh config use too). It logs in as Lima's user with Lima's key alone (`IdentitiesOnly`, `IdentityAgent=none`), `_config/user` in devvm's Lima home, which every VM there authorizes, and never with the user's agent. The master reads none of the user's configuration and forwards nothing either way, with `ClearAllForwardings`, `PermitRemoteOpen none`, `ProxyCommand none`, and no agent, X11 or tunnel. The VM's sshd allows local forwarding, and remote forwards only to `127.77.0.0/16` for [links](#links-between-vms) (`base.sh`), and `-W` is local forwarding. Its control socket is in `~/.local/share/devvm/run` (mode 700) and is named by a hash of the VM's name, because a socket's path has fewer than 104 characters. When the connection is lost, the forwarder closes its forwards and makes the connection again every 2 s while the lifeline holds. -- **What listens.** The master's session runs `ports.sh` (`assets/guest/ports.sh`) as the VM's user (`sh -s`). It prints the local addresses of the VM's listening TCP sockets, which are the state `0A` lines of `/proc/net/tcp` and `tcp6`, whenever they change and every 10 s regardless, so it ends soon after the connection does. The forwarder treats the report as untrusted. A line over 128 bytes or a report over 4096 lines ends the connection, and anything that isn't a hex address and port is skipped. Reports are applied at least 500 ms apart, and one that comes sooner waits, holding up the VM's ssh channel with it, so the VM can't make the forwarder bind, dial and read devvm's state at its own pace. The VM can make the forwarder write to its log, with ports coming and going and with the session's stderr, so the log takes 200 writes at once and then one every 10 s. Each write is at most 512 bytes, without control characters but newlines and tabs, C1 included, and a start empties the log once it's over 1 MiB. A forwarded port's connections go to `127.0.0.1` for a server on all IPv4 addresses or on that address, and to `::1` for a server on all IPv6 addresses or on that address. A server on another `127.x` address alone gets its connections there. Servers on other addresses alone aren't forwarded. +- **What listens.** The master's session runs `ports.sh` (`assets/guest/ports.sh`) as the VM's user (`sh -s`). It prints the local addresses of the VM's listening TCP sockets, which are the state `0A` lines of `/proc/net/tcp` and `tcp6`, whenever they change and every 10 s regardless, so it ends soon after the connection does. The forwarder treats the report as untrusted. A line over 128 bytes or a report over 4096 lines ends the connection, and anything that isn't a hex address and port is skipped. Reports are applied at least 500 ms apart, and one that comes sooner waits, holding up the VM's ssh channel with it, so the VM can't make the forwarder bind, dial and read devvm's state at its own pace. The VM can make the forwarder write to its log, with ports coming and going and with the session's stderr, so the log takes 200 writes at once and then one every 10 s. Each write is at most 512 bytes, without control characters but newlines and tabs, C1 included, and the log is rotated before it passes 1 MiB, its end kept in `ports.log.1`. A forwarded port's connections go to `127.0.0.1` for a server on all IPv4 addresses or on that address, and to `::1` for a server on all IPv6 addresses or on that address. A server on another `127.x` address alone gets its connections there. Servers on other addresses alone aren't forwarded. - **How many.** With every port, the forwarder takes ports from 1024 up, because the ports below are the host's system services. With listed ports, it takes those alone (`-only`), a listed port below 1024 included, because the user asked for it, and a bind the host refuses is logged. Either way the forwarder takes at most 256 ports at once (`vmssh.MaxForwards`). It records why it couldn't take each port in `ports.forwarded`, by the bind's error: in use (`EADDRINUSE`), past its limit, or refused (`EACCES` or `EPERM`, such as below 1024 on Linux), and `devvm ports` warns each with its own message (`ports_taken`, `ports_limit`, `ports_refused`). Any other error, such as `EMFILE`, `ENOBUFS` or `EADDRNOTAVAIL`, says nothing about the port, so it's logged, not recorded, and the port is tried again at the next report, the log's limit capping the repeats. A port past the limit is tried again at the next report once the forwarder forwards fewer. A record from before the reasons, whose third line holds every port it couldn't take, is read as giving no reason, so it warns of none rather than call a refused port in use. It reads the reserved ports (below) again with each report, and while it can't read them, it takes no new port and keeps those it has. A port it has that has since become reserved, such as one another VM's start has chosen, is given up at that report, though the VM still listens on it, and also within 10 s on the host's own clock (`Forwarder.Recheck`), whether or not the VM reports, so a VM that holds its session open and stays silent can't keep it. A reserved port the VM listens on waits and is tried again at each report until it's no longer reserved. A port that a host program has, or that the host refused, is tried again only once the VM's server on it goes and comes back. - **Listening.** The forwarder listens on `127.0.0.1` and `::1`, or on IPv4 alone on a host without IPv6, which a bind on `::1` reports as `EADDRNOTAVAIL`, `EAFNOSUPPORT` or `EPROTONOSUPPORT`. `EACCES` or `EPERM` on `::1` alone, with `127.0.0.1` bound, also gives IPv4 alone, with a line in the log, because that's a host denying IPv6 rather than a port it refuses. Any other error on `::1` closes the port's `127.0.0.1` listener and counts as that bind's error would on `127.0.0.1`, recorded or tried again at the next report as the bullet above says, so a passing error such as `EMFILE` never leaves a forward on IPv4 alone until its port is opened again. It binds without `SO_REUSEADDR` (`platform.ListenExclusive`). With that option, which Go and Lima set, macOS lets a socket take `127.0.0.1:PORT` while a program has `*:PORT`, and that program's loopback connections go with it. Without the option, the bind is refused when another program has the port on any address. This was checked on macOS for a program on `0.0.0.0`, on `::` (IPv4 and IPv6 at once, as Node's and Go's servers listen), on IPv6 alone and on `127.0.0.1`, each with and without `SO_REUSEADDR` of its own. A port held only by ended connections (`TIME_WAIT`, with nothing answering on it) is taken as usual, so a server that restarts gets its forward back. When a bind is refused, the forwarder dials the port and takes it only if the dial is refused. A full backlog times out, which counts as taken. A port the forwarder took on `127.0.0.1` but finds in use on `::1` is given up, so `localhost` never reaches two programs. On Linux, `SO_REUSEADDR` stays on. Linux refuses that bind with the option too while another socket listens on the port, and without it, the forwarder's own ended connections (`TIME_WAIT`) would keep anyone from listening on the port for a minute, its next forwarder included. - **Each connection.** Each forwarded connection is a channel of the master's (`ssh -S -W HOST:PORT`), with one process per connection and at most 256 at once. The VM's sshd opens it to the VM's own loopback from inside the VM. The channel's ssh has the master's options. If the master is gone, ssh connects on its own, and it then reaches the VM's sshd the same way, never the host's. Each relay's ssh runs with a context of its own, which closing its forward cancels, so the ssh is killed with the forward even when the VM never ends its channel. `pipeSSH`, which carries every relay of the forwarder's, the link sessions' and a login's callback, also cancels that context once the client on the host has closed its side and the VM has sent nothing for 30 seconds (`relayGrace`), and once the client can take nothing more and the ssh hasn't exited within 30 seconds. Each write of the VM's bytes to the client starts the grace again once it's done, and the grace doesn't run while that write waits for the client, so a client that closes for writing alone and waits still gets an answer the VM keeps sending, however slowly it reads. The VM must send something at least every 30 seconds, its first byte included, so a client that half-closes and waits longer than that for a first byte, such as `nc -N` in front of a slow query, is cut. The timer (`graceTimer`) runs only once the client's side has closed, or once the copy to the client has ended, with a write that failed or the VM's EOF, and a relay that ends stops it for good, so the client's goroutine, which can outlive the relay, never starts it again. The relay's own context, its owner's, also closes the client's connection when it ends, so a write that waits on a client that stopped reading ends with its forward, its link or `LoopbackForward.Close`. @@ -861,7 +861,7 @@ devvm handles values that let whoever holds them act as you or as a VM: a VM's p The wire types keep each file's bytes as they were, so a frozen release's `proxy.json` writes back byte for byte (`TestV010ProxyConfigs`), its `Sum` doesn't change and no running VM's proxy starts again for an upgrade. An agent's login file stays the agent's own format, read and written as a map so that fields devvm doesn't know are kept, and a key or token is a `redact.Secret` once it leaves the map, through a lookup, a refresh or a capture. -**Not covered.** The company proxy's URLs as your environment gives them, `HTTPS_PROXY` and `HTTP_PROXY`, can hold a password, and they stay strings, because devvm passes them on as they are, to `proxy.json` and to the programs it runs on the host. So do the URLs `proxy.Upstream.WithPassword` returns, which hold the saved password for devvm's own clients and the programs it runs. The VM's proxy URL, which holds its password, is a string too, because it goes into the VM's Lima config and environment, where the VM needs it. `redact.String` and `redact.File` take the passwords in such URLs out of devvm's run log and Lima's logs ([your company proxy's password](../safety/attack-vectors.md#this-machine)). Two values are strings by design: +**Not covered.** The company proxy's URLs as your environment gives them, `HTTPS_PROXY` and `HTTP_PROXY`, can hold a password, and they stay strings, because devvm passes them on as they are, to `proxy.json` and to the programs it runs on the host. So do the URLs `proxy.Upstream.WithPassword` returns, which hold the saved password for devvm's own clients and the programs it runs. The VM's proxy URL, which holds its password, is a string too, because it goes into the VM's Lima config and environment, where the VM needs it. `redact.String` and `redact.In` take the passwords in such URLs out of devvm's run log and Lima's logs ([your company proxy's password](../safety/attack-vectors.md#this-machine)). Two values are strings by design: - **The Keychain's value,** which `platform.KeychainGet` returns and `KeychainSet` takes as a string, because `internal/platform` imports no devvm package. `secrets.Store` makes it a `Secret` at once in `saved`, and reveals it only for `KeychainSet` in `save`. - **devvm desktop's VNC password,** 8 characters that you must see to type into a VNC viewer. devvm keeps it in the desktop section of `vm.json` and shows it in `desktop_ready`. diff --git a/docs/content/docs/internals/network.md b/docs/content/docs/internals/network.md index 4787dcec..aac64531 100644 --- a/docs/content/docs/internals/network.md +++ b/docs/content/docs/internals/network.md @@ -441,7 +441,7 @@ The proxy's own lines, such as what it loaded and what failed upstream, go to `p The event log also holds the VM's [links](ports.md#links-between-vms)' connections, which `devvm _links` writes in the same format: `link` for a connection it carried, and `link_refused`, `link_target_stopped` or `link_limit` for one it refused, with the link's name as the host and the target VM in `target`. An open VM's event log holds its proxy's events and its links', but nothing it reached directly. -The proxy is the only program that writes `proxy.log`, and the event log has `devvm _links` as its only other writer. The proxy rotates each log before a line would take it past 10 MiB, and `devvm _links` writes the event log with the proxy's own code, so it rotates the log by the same rule and a VM that runs for months keeps at most about 20 MiB of each. A line never spans two files, and lines from the proxy's connections at the same time are written one after another, so a rotation loses none and splits none. Before each line, each writer checks that the file it has open is still `network.jsonl`, and when the other writer has rotated it, the writer opens the new `network.jsonl` and writes there, so its lines go on reaching the file that `devvm network log --follow` follows. Each writer takes the log's size from the file, so it counts the other writer's lines too. A writer rotates the log while it holds a lock on the file and checks the name again first, so when both reach the limit at once, only one renames the file and the other writes to the new one. A rotation renames `network.jsonl` to `network.jsonl.1`, which replaces the one that was there, and starts a new `network.jsonl`. `proxy.log` is also the proxy process's output, where its last error goes when it stops, so the proxy copies it to `proxy.log.1` and empties it instead, and that error still reaches the current file. Every log file and its `.1` file is readable only by you (mode 600). +The proxy is the only program that writes `proxy.log`, and the event log has `devvm _links` as its only other writer. The proxy rotates each log before a line would take it past 10 MiB, and `devvm _links` writes the event log with the proxy's own code, so it rotates the log by the same rule and a VM that runs for months keeps at most about 20 MiB of each. A line never spans two files, and lines from the proxy's connections at the same time are written one after another, so a rotation loses none and splits none. Before each line, each writer checks that the file it has open is still `network.jsonl`, and when the other writer has rotated it, the writer opens the new `network.jsonl` and writes there, so its lines go on reaching the file that `devvm network log --follow` follows. Each writer takes the log's size from the file, so it counts the other writer's lines too. A writer rotates the log while it holds a lock on the file and checks the name again first, so when both reach the limit at once, only one renames the file and the other writes to the new one. A rotation renames `network.jsonl` to `network.jsonl.1`, which replaces the one that was there, and starts a new `network.jsonl`. `proxy.log` is also the proxy process's output, where its last error goes when it stops, so the proxy copies it to `proxy.log.1` and empties it instead, and that error still reaches the current file. The proxy takes `proxy.log`'s size from the file before each line, so what reached it as the process's output counts too, and its HTTP server's errors, such as a handler's panic, go through the proxy's own lines rather than straight to that output. Every log file and its `.1` file is readable only by you (mode 600). `devvm network log` reads `network.jsonl.1` before `network.jsonl`, so the history it shows and the blocks that `devvm network log --blocked` counts carry on across a rotation. `devvm network log --follow` reads the renamed file to its end and then follows the new one from its start. `devvm rm` deletes the `.1` files with the rest of the VM's logs. @@ -476,6 +476,7 @@ The config is one JSON file, `proxy.Config`, which a VM's proxy and a build's pr | `nix_cache_max` | with `nix_cache`: the cache's cap, in bytes (none: 10 GiB) | | `links` | the VM's links' list, which `devvm _links` writes: reach each link through its socket, before any rule ([links through the proxy](#links-through-the-proxy)); a missing list has no links | | `link_sockets` | with `links`: the folder of the links' sockets, devvm's run folder; without it, no link is reached | +| `vm_logs` | the logs that the VM's backend writes as the VM runs and the VM can drive, such as its serial console's, which the proxy holds to their cap for as long as it runs ([Lima's hostagent](processes.md#limas-hostagent)) | | `agent`, `agent_socket` | together, as absolute paths: the SSH agent that the VM's start forwards, your own or devvm's, and the VM's own socket in devvm's run folder, `agent-.sock`, on which the proxy relays it and which the VM's backend forwards instead ([the SSH agents](processes.md#the-ssh-agents)); devvm keeps a running VM's as its start set them | | `devvm_sha256`, `ca_sha256`, `ca_next_sha256` | the SHA-256 of devvm's binary, of the VM's CA certificate and of its next CA's that the proxy started with; the proxy doesn't read them, and they're there so that a new binary or a new CA makes another config ([how long a proxy runs](#how-long-a-proxy-runs)) | diff --git a/docs/content/docs/internals/overview.md b/docs/content/docs/internals/overview.md index 12ae345c..d55fa97d 100644 --- a/docs/content/docs/internals/overview.md +++ b/docs/content/docs/internals/overview.md @@ -190,13 +190,13 @@ Each write replaces a file whole, so a file is never left half written. devvm ma ### The run log -Each run that runs a command has one log, `~/.local/share/devvm/logs/runs/-