| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
| |
Without --home, /home is now simply part of the guest's root file
system (a tmpfs, gone when it exits, as before), instead of a scratch
disk. With --home, the disk is attached after the images, and the run
script puts fc.home on the kernel command line, which makes a small
generator in the guest mount it, so a guest without it doesn't wait for
a drive that isn't there. The images are back at vdb, vdc, ...
|
| |
|
|
|
|
|
|
|
|
| |
/home is now on its own disk: a scratch file, removed when the guest
exits, or with --home FILE, one that persists (created if it doesn't
exist, sparse, --home-size, default 16G), handled like the store's
(--store), and also locked against use by two VMs. Separate from the
store, so either can be kept or thrown away.
The images move one drive up (vdc, vdd, ...).
|
| |
|
|
|
|
|
| |
So a log line's destination can be copied into fc-egress allow: HTTPS
connections now log https://SERVER, decrypted requests METHOD
https://HOST/URI, and fc-egress log adds tcp://DST:PORT (or udp://)
after the tap to the kernel's lines for other connections.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The new argument layers is a list of NixOS modules, each a layer on top
of the ones before, the first on top of the base system. The guest runs
the top layer's system. Each layer gets its own erofs image with only
the store paths of its system's closure that the layers below don't
have, so the base image (and those of layers below) stays the same
whatever goes on top:
nix-build pkgs/run-firecracker-vm --arg layers '[ ./my-service.nix ]'
The images become read-only drives, mounted as overlay lower layers
(with the host store below them, as before). The writable store disk
is now the first drive (/dev/vda), the images follow (vdb, vdc, ...).
|
| |
|
|
|
|
|
|
|
|
| |
Like tcp:// and udp:// rules, HTTPS rules are now URIs:
https://DOMAIN (with subdomains, passed through) and
https://DOMAIN/PATH-PREFIX (decrypted to check the path), instead of
DOMAIN and DOMAIN/PATH-PREFIX. The old forms are refused by fc-egress
and ignored by egress.lua; to convert existing lists:
sed -i -E '/^[a-z]+:\/\//!s#^#https://#' /var/lib/fc-egress/*/*
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The guests' DNS resolves every name to the host, so ssh somename went
to the host, even with a rule for somename's address. Now the rules
can take names, tcp://NAME:PORT[-PORT]: the firewall update resolves
them on the host (IPv4) into the VM's set, and writes their addresses
to a hosts file per tap in /run/fcbr0-hosts, which the guests' dnsmasq
reads (--hostsdir; such entries win over address=/#/). A timer
resolves them again every 5 minutes.
dnsmasq can't tell guests apart, so every guest gets those addresses
for those names, but only VMs whose list has the rule can connect.
fcbr0-firewall now runs as a static user, fcbr0-firewall, which owns
/run/fcbr0-hosts, and may use IPv4 and IPv6 sockets, for resolving.
|
| |
|
|
|
|
| |
A named VM uses the list of the same name unless given another with
--egress; without a name, still the list default. A missing list means
no egress (with a warning), as before; there's no fallback to default.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
A VM can now have a name: run-firecracker-vm --name NAME. It's unique
among the user's running VMs (a lock in the user's runtime directory,
like the taps'), becomes the guest's host name (systemd.hostname= on the
kernel command line), and goes to /run/fc-egress/TAP.name while the VM
runs, for fc-egress. Names are letters, digits and -, and can't look
like a tap's.
fc-egress takes a running VM's name or tap where it takes a VM:
-v VM works on the list the VM uses, use VM LIST switches it to another
list, and vms shows tap, name and list. The logs keep saying taps
(fc-egress vms maps them).
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Whitelists are now named, any number per user, in
/var/lib/fc-egress/USER/LIST, and each VM uses one of them:
run-firecracker-vm --egress LIST (default: default). The run script
writes the list's name to /run/fc-egress/TAP when it takes the tap, and
empties it when the VM exits; a list that doesn't exist allows nothing.
A user's VMs can only use that user's lists.
So the unit of policy is the tap (i.e. the running VM) rather than the
user: nftables sets allow_TAP, nginx decrypt sockets decrypt-TAP.sock,
egress_taps.lua maps guest addresses to tap and user. fcbr0-firewall
updates a tap when its file in /run/fc-egress changes, and all of a
user's taps when anything in the user's directory does. nginx's
connection limit stays per user.
fc-egress takes -l LIST (default: default), and has new commands lists
and vms (running VMs' taps and their lists). Log lines now say user,
tap and (nginx's) list: "ALLOW|DENY USER TAP LIST ...", kernel:
"fc-egress ALLOW|DENY USER TAP".
The old rules file, /var/lib/fc-egress/USER/allowed, is now just a list
named "allowed"; rename it to "default" to keep using it.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- denyDestinations (default: loopback, private, link-local, CGNAT,
multicast, ...): no user's rules can open those, neither tcp:// and
udp:// rules nor the proxy, whatever a name resolves to: nginx's own
outgoing connections may only go to port 443 outside them, and not to
the host. tcp:// rules no longer open anything on the host itself.
- fcbr0-firewall no longer runs as root, but with only CAP_NET_ADMIN,
doesn't follow symlinks, and gets started per user when that user's
rules change, so one user can't stop the others' updates. Rules files
are read up to 64k only, by egress.lua, too.
- Limits per guest (maxConnections open, maxNewConnections per second),
and per user in nginx, so one user can't starve the others.
- tcp:// and udp:// connections, and refused ones, get logged
(rate-limited) with the user; fc-egress log shows them.
- The run script keeps its lock files in a directory of the user's own,
not in /tmp, where others could take them first.
|
| |
|
|
|
|
|
|
|
|
|
| |
The host's NAT rules are for connections to the host, but they got
applied to the guests', too: e.g. a redirect of port 11423 to the host's
sshd turned a guest's allowed connection to some address's port 11423
into one to the host, which got rejected ("No route to host").
Our prerouting chain now runs before the host's, and gives everything
from fcbr0 a NAT that changes nothing. A connection only ever gets one
NAT, so the host's rules don't touch it any more.
|
| |
|
|
|
|
|
|
|
|
| |
Rules like tcp://192.0.2.7:22 or udp://192.0.2.0/24:5000-5100 in a user's
egress rules (managed with fc-egress as before) go into the nftables set
allow_USER, and connections from that user's guests that match get
forwarded (NATed to the host's address), or let in, if they're for one
of the host's addresses. fcbr0-firewall fills the sets whenever a
user's rules change, and after nftables reloads. Forwarding needs
net.ipv4.ip_forward, which networking.nat used to set.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
The host module takes users = { NAME = TAPS; ... } instead of a single
user: each user gets that many taps, and rules of their own, in
/var/lib/fc-egress/USER/allowed, managed with fc-egress as before.
The proxy tells whose a guest is by its address: each tap has a fixed
one, handed out by dnsmasq by MAC address (derived from the tap's number,
as the run script does), and the bridge drops anything a guest sends from
another address. The decrypting server gets a socket per user, as it
can't see the guest's address. The run script only takes the user's own
taps.
|
| |
|
|
|
|
|
|
|
|
| |
/nixpkgs isn't cached in the guest, so changes to a checkout show up
right away, but evaluating is slow. --nixpkgs-cache sets 9P's cache
mode for it, e.g. loose, which made evaluating tmux several times
faster. It gets passed on the kernel command line as fc.9p566=cache=MODE,
and mount.vsock9p appends such options for the port it mounts.
Options also take the --option=value form now.
|
| |
|
|
|
|
|
|
|
| |
A <nixpkgs> outside the store got copied (i.e. hashed) to the store on
every evaluation, for the guest's NIX_PATH, so no-op builds still took
~25s with a checkout. Now a third 9P server serves nixpkgs from wherever
it is, read-only, at /nixpkgs in the guest, which NIX_PATH points to.
It's in neither the closure nor the registration any more, and
run-firecracker-vm --nixpkgs DIR can serve another one.
|
| |
|
|
|
|
|
| |
"${pkgs.path}" copies nixpkgs to the store, which means hashing all of
it, on every evaluation, even when it's a store path already. That
took no-op builds from ~3s to ~25s. Use builtins.storePath when it's a
store path; only a nixpkgs outside the store still gets copied.
|
| | |
|
| |
|
|
|
| |
egress.lua goes along. The host now imports it as
(import .../modules/host { user = ...; }).
|
| |
|
|
|
| |
So default.nix (or shell.nix, flake.nix) at the top can become something
else. kernel.nix goes along, as it's only an argument of the runner.
|
| |
|
|
|
|
|
|
|
|
| |
The store's writable layer was a tmpfs, i.e. guest RAM (half of it at
most), and gone with every reboot. Now it's an ext4 file system on a
second drive: by default a sparse scratch file that gets removed when
the guest exits, or with --store FILE one that persists across boots
(created if missing, of --store-size, default 16G). nix's database
lives there, too, so it matches the store, and stale entries get
dropped on first use. The file is locked, so two VMs can't share it.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
With the whole store via 9P, boot took twice as long: everything gets
read over a single 9P channel. Now the guest's own closure comes from
an erofs image, built by Nix from closureInfo (no more runtime image
building or cache), as the top layer, with the host's store via 9P
below it for everything else, like nixpkgs, which stays out of the
closure (and thus the image): NIX_PATH refers to it without context.
Also drop nixos-rebuild & co. (and with them python), and mask a few
units that have nothing to do here but get started at boot anyway.
|
| |
|
|
|
|
|
|
|
| |
Nothing got forwarded, but the host itself was wide open to the guests:
its own services (sshd, ...) at 172.16.0.1, where DNS sends every name,
or any of its other addresses, and ICMP. Now the input chain rejects
everything from fcbr0 but DHCP and DNS to dnsmasq and the redirected TLS
to nginx. And a bridge table drops frames between the taps, so the
guests can't talk to each other either.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
The erofs image of the closure grew to 7 GiB with nixpkgs in it.
Now only /etc is erofs, and the run script serves the host's /nix/store
read-only via 9P over vsock, like xchg, and the guest's initrd mounts
it, under the tmpfs overlay. No drive, no image, no cache, no image
builds. mount.xchg becomes mount.vsock9p, taking the vsock port, for
both.
The registration of the guest's closure comes from closureInfo now,
passed on the kernel command line. run-firecracker-vm no longer takes
store paths: the guest sees the whole store anyway.
|
| |
|
|
|
|
|
|
| |
/nix/store becomes an overlay of the image and a tmpfs, so nix can add
to it. The run script puts the registration of the image's paths into
the image, and the guest loads it before nix-daemon starts; root goes
through the daemon too, so that happens on first use, not at boot.
NIX_PATH has the host's nixpkgs, for nix-shell -p.
|
| |
|
|
|
|
|
| |
github.com's response headers are bigger than nginx's default buffer
for them, so requests got a 502 ("upstream sent too big header"). Give
them 64k. Also remove a stale decrypt.sock before starting, else nginx
can't bind to it.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
OpenResty replaces the plain nginx SNI proxy, and egress.lua decides by
server name and the rules in /var/lib/fc-egress/allowed: DOMAIN passes
the domain and its subdomains through without decrypting; DOMAIN/PREFIX
decrypts, with certificates made on the fly from the host's own CA, and
only forwards requests whose path starts with PREFIX. Upstream is
always port 443 of the server name, as resolved by the host, and its
certificate gets verified. The rules get read on every connection, so
the path unit and reloads are gone.
The CA certificate gets published as /var/lib/fcbr0-egress/ca.pem, and
the guest trusts it when built on the host.
|
| |
|
|
|
|
|
| |
The host's own web server listens on 0.0.0.0:443, which keeps nginx from
binding to 172.16.0.1:443. nginx now listens on 172.16.0.1:proxyPort
(default 10443), and nftables redirects the guests' tcp port 443 there,
whatever address they connect to.
|
| |
|
|
|
|
|
|
| |
With networkd, fcbr0 only got its address while it had carrier, i.e.
while a VM was running, so nginx failed with "bind() to 172.16.0.1:443
failed (99: Cannot assign requested address)" and gave up after a few
restarts. Configure fcbr0 without carrier, and let nginx retry without
start limit until the address is there.
|
| |
|
|
|
|
|
|
|
| |
The guests' DNS now resolves every name to 172.16.0.1, where nginx reads
the server name from the TLS ClientHello and, if it's allowed, connects
to port 443 of that name as resolved by the host. The guests need no
proxy settings any more, and a faked server name can't get them to any
other address. fc-egress keeps managing the list (now plain domains),
and a reload regenerates nginx's map from it.
|
| |
|
|
|
|
|
|
|
|
|
| |
Instead of forwarding to addresses dnsmasq resolved for allowed names,
nothing gets forwarded from fcbr0 any more (and no NAT). The guests use
squid on 172.16.0.1:3128 as their proxy, which only allows CONNECT to
port 443 of the domains in /var/lib/fc-egress/allowed. That list can be
changed at any time with fc-egress (list, allow, deny, log); a path unit
makes squid re-read it. DNS answers NXDOMAIN for everything.
host.nix no longer takes allowedDomains.
|
| |
|
|
|
|
|
|
|
|
| |
host.nix takes allowedDomains (default none). The guests' dnsmasq only
resolves those names and their subdomains, answers NXDOMAIN for anything
else, and adds the addresses it resolves to an nftables set. The new
table inet firecracker rejects everything from fcbr0 except tcp port 443
to addresses in that set. dnsmasq runs without cache, so it refills the
set after an nftables reload, and without AAAA records, as the guests
only have IPv4.
|
| |
|
|
|
|
|
| |
The socat-and-mount dance moves from a boot service into the mount
helper mount.xchg, so /xchg can be an x-systemd.automount like before.
No more modules-load of the vsock transport either: udev loads it for
the device, and it's built in into the cut-down kernel.
|
| |
|
|
|
|
|
|
|
| |
unpfs now listens on a Unix socket next to Firecracker's vsock uds_path,
where Firecracker forwards the guest's connections to vsock port 564.
The kernel's 9P client can't use vsock itself, so the guest's
xchg.service connects with socat and hands the socket to mount
(trans=fd). xchg no longer depends on the network: no TCP ports, no
firewall rules, no waiting for DHCP.
|
| |
|
|
|
|
|
|
|
|
| |
The run script starts unpfs (as the user) on 172.16.0.1, port 5640 plus
the tap's number, and tells the guest to mount it at /xchg via
systemd.mount-extra on the kernel command line. VMs started in the same
directory share xchg, writes land on the host right away, and nothing is
lost when a guest doesn't shut down cleanly. No more debugfs rdump.
The cut-down kernel gets 9P as modules.
|
| |
|
|
|
|
| |
It forwards to the servers in the host's resolv.conf and listens only on
fcbr0, so it doesn't get in the way of a resolver on the host's loopback.
The service is renamed from fcbr0-dhcp to fcbr0-dnsmasq.
|
| |
|
|
|
| |
The guest's resolv.conf and the DHCP server now point at 172.16.0.1, so
the host's resolver has to answer there.
|
| |
|
|
|
|
|
|
|
|
| |
host.nix now makes a bridge fcbr0 with a number of tap devices (default 8)
and runs a dnsmasq of its own for DHCP. The run script takes the first
tap device it can lock and derives the guest MAC from its number. The
guest uses DHCP, with the MAC as client identifier, as the machine-id
(and thus the default DUID) is the same in every VM.
host.nix now takes { user, taps ? 8 } instead of just the user.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When starting, PID 1 asks /dev/console for its terminal type (see
main.c, unless TERM or systemd.tty.term.console is on the kernel command
line), which costs the 333ms timeout twice, in the initrd and again
after switching root:
[0.161825] systemd[1]: IPE support is disabled in the kernel, ignoring: ...
[0.495506] systemd[1]: Failed to query /dev/console for terminfo: Operation not supported
...
[1.051161] systemd[1]: IPE support is disabled in the kernel, ignoring: ...
[1.385218] systemd[1]: Failed to query /dev/console for terminfo: Operation not supported
Pass systemd.tty.term.console along with systemd.tty.term.ttyS0, and
fall back to "dumb" without $TERM, as then nobody would answer either.
|
| |
|
|
|
|
|
| |
After switching root, systemd runs 15 generators before it loads any
units, each a separate process loading libsystemd-shared from the store
image. Only fstab and getty generate anything here; the others report
things like "not an EFI boot" or "sshd is not installed".
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In the initrd, NixOS Activation spends ~0.1s before its first output and
~0.15s in total, running prepare-root and the activation script in bash
from the (cold) store image:
[0.907724] Starting NixOS Activation...
[1.009663] booting system configuration /nix/store/...
[1.054987] Finished NixOS Activation.
nixos-init does the same from a single program. perlless already
gives us what it requires: systemd in the initrd, an overlay /etc and
userborn.
Mount the store with nodev,nosuid right away, so nixos-init doesn't
have to remount it.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
Creating the ten setuid wrappers takes ~130ms and is the last thing
sysinit.target waits for:
[1.896068] Starting Create SUID/SGID Wrappers...
[2.025499] Finished Create SUID/SGID Wrappers.
[2.027817] Reached target System Initialization.
The only wrapper needed during boot is unix_chkpwd, for the autologin,
so order the wrappers before systemd-user-sessions.service instead.
|
| |
|
|
|
|
|
|
|
|
| |
With an empty /var on every boot, systemd-journal-catalog-update and
systemd-update-done run every time (ConditionNeedsUpdate=/var), and
they're in the critical path to sysinit.target. Suppress them.
Keep the journal in /run, so systemd-journal-flush has nothing to do, and
drop pam_lastlog2 from login, which also gets rid of
lastlog2-import.service.
|
| |
|
|
|
|
|
|
|
| |
With a tmpfs root, every boot is a first boot, which makes systemd
apply presets and commit a transient machine-id.
There's no display, so the getty on tty1 only opens a session nobody
sees. The serial getty is pulled in by systemd-getty-generator, not
by getty.target.wants.
|
| |
|
|
|
|
|
|
|
|
| |
Passing the terminal size didn't help: the serial login still completes
~0.39s after the getty started. Unless systemd.tty.term.ttyS0 is on
the kernel command line, systemd also asks the terminal for its type
(via DCS +q, see query_term_for_tty in src/basic/terminal-util.c),
which many terminals don't answer, so it waits for the 333ms timeout.
Pass $TERM along with the size.
|
| |
|
|
|
|
| |
Fixes:
evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'
|
| |
|
|
|
|
|
|
|
|
| |
debugfs' rdump tries to restore the owner of every file it extracts,
which fails when not running as root:
dump_file: Operation not permitted while changing ownership of xchg.new//boot.txt
The files end up owned by the user running the VM, which is what we
want, so drop these messages.
|
| |
|
|
|
|
|
|
|
|
| |
Firecracker can't share directories, so run-firecracker-vm copies the
directory xchg (in the current working directory) into an ext4 image
before booting, and replaces it with the image's contents when the
guest exits. The guest automounts the image at /xchg.
Changes made in the guest only arrive if it exits cleanly (e.g. via
reboot), as debugfs doesn't replay the ext4 journal.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
When starting the serial getty, systemd asks the terminal for its size
via ANSI sequences and waits up to 333ms for an answer (see
CONSOLE_ANSI_SEQUENCE_TIMEOUT_USEC in src/basic/terminal-util.c). The
journal shows the serial login completing ~0.4s after the getty started,
while the getty on tty1 took 0.08s.
systemd skips the query if systemd.tty.rows.ttyS0 and
systemd.tty.columns.ttyS0 are on the kernel command line, so take them
from the terminal run-firecracker-vm is started from. This also gives
the guest the right terminal size.
|
| |
|
|
|
|
|
|
| |
Building the erofs image takes ~2.5s, as long as the guest's initrd.
Keep the image of the last closure in $XDG_CACHE_HOME/run-firecracker-vm,
named by the hash of the store path list, and rebuild it only when the
closure changes. Older images get deleted; running VMs keep theirs
open.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
systemd processes at most 5 mount events per second (see
src/core/mount.c). Booting from a tmpfs root with an erofs store and
an overlay /etc exceeds that, and each time the next mount waits for
the next one-second window. The boot journal shows three such stalls,
two of them exactly one second apart:
[0.789652] Finished Virtual Console Setup.
[1.588264] Mounting /sysroot...
[1.675477] initrd-parse-etc.service: Triggering OnSuccess= dependencies.
[2.588523] Mounting /run/nixos-etc-metadata...
[3.799810] Finished Virtual Console Setup.
[4.446154] Mounting /run/wrappers...
The limit can be overridden via PID 1's environment, which the kernel
populates from unrecognized command line parameters. A burst of 0
disables it. systemd passes its original environment on when
switching root, so this covers the initrd and stage 2.
|