mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
vmname.VM is the name of every machine devvm runs on a backend: a project VM, an image's machine (devvm-img-<key>), a build VM and a remake's aside. Fields, parameters, results and map keys that held a VM's name as a string now hold a VM, from the backend interface down to the CLI's --json structs, whose output is byte for byte the same. Boundary parsers, the only places a string becomes a VM: - vmname.Parse: a project VM's name (state's vm.json name, export file names, devvm _links's argument, the forwarder's -vm, project.Nth) - vmname.ParseListed: one path element, for what a backend lists - VM.UnmarshalText: JSON (Lima's list, proxy config and events, links' targets in state, link lists); empty stays no VM - vmname.Image(key), VM.Aside(), and typed constants for Lima's build VMs - msg.M.VM: the VM a message's function took, read back vmname's functions on names became methods (Hash, Slug, Short, Aside, AsideHash, ImageKey, IsProject); Lima's image prefix moved to vmname; vmname.Join joins VM lists. Messages' vm and vm_name fields are typed by the generator. Seven messages whose field took something else became what= (backend_lacks, backend_unreviewed, backend_unreviewed_used, starting, deleting, configuring, running_script) and rm_vm_failed's name=: the text is unchanged, the names-mode scripts follow. Review.RequireFor names an image or the tools being built. Typed sites per package (added lines with vmname.VM, non-test): msg 347 (generated), vm 124, lima 48, backendtest 32, vmssh 31, netpolicy 22, backend 16, gitprotect 14, proxy 11, cli 11, project 10, state 8, ports 6, paths 3, sshagent 2, sshconfig 2, tools 2. The structure test's owners rule now fails on a field, parameter or result named for a VM (vm, vms, otherVM, vmName) typed string, []string or map[string]…, and on converting anything but a literal to vmname.VM outside the files it lists; internal/stubtest is free. depguard holds internal/vmname to the standard library, and the proxy may import it. ParseListed and UnmarshalText refuse a name starting with -, which would read as a flag in limactl's argv, and vmname.Image refuses a key that's empty, holds a / or NUL, or makes a project VM's name, so Lima's ImageSize and DeleteImage no longer check it themselves. The check also fails on a *string VM name and an alias of vmname.VM, and says what it doesn't see. Co-Authored-By: Claude Opus 5.5 <[email protected]>
88 lines
3.7 KiB
Plaintext
88 lines
3.7 KiB
Plaintext
# Rules by method and path, and a secret by method, on devvm 0.1.0's
|
|
# state (testdata/v0.1.0/GOOS, which 0.1.0 itself made): app, on the
|
|
# allowlist tier with the github secret and Codex's API key, takes them
|
|
# as a VM this devvm made does, its launch keeps 0.1.0's bindings file
|
|
# byte for byte, and only a secret by method makes it of version 2.
|
|
[!darwin] [!linux] skip 'a fixture for macOS and Linux only'
|
|
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
|
|
mkdir $HOME/src/db $HOME/src/app $HOME/src/web $HOME/src/scratch
|
|
cd $HOME/src/app
|
|
exec git init -q -b main
|
|
exec git commit -q --allow-empty -m one
|
|
cd $HOME/src/web
|
|
exec git init -q -b main
|
|
exec git commit -q --allow-empty -m one
|
|
cd $HOME/src/scratch
|
|
exec git init -q
|
|
fixture v0.1.0
|
|
vm_name APP app
|
|
cd $HOME/src/app
|
|
|
|
# devvm's own rules allow api.github.com whole, so an allow by method
|
|
# narrows nothing on app, and devvm says so and names the deny.
|
|
exec devvm network allow api.github.com --method GET
|
|
stderr '^devvm: rule_narrows_nothing host=api\.github\.com rule=api\.github\.com GET vms=devvm-app-[0-9a-f]{14}$'
|
|
! stderr '^rule_narrows host='
|
|
exec devvm network rm api.github.com --method GET
|
|
|
|
# A deny by method is in app's rules, as devvm network --json shows them.
|
|
exec devvm network deny api.github.com --method POST,DELETE
|
|
stdout '^==> rule_added rule=!api\.github\.com POST,DELETE vm=devvm-app-[0-9a-f]{14}$'
|
|
stderr '^rule_narrows host=api\.github\.com$'
|
|
exec devvm network --json
|
|
stdout '"!api\.github\.com POST,DELETE"'
|
|
! stdout '"not_rules": \[\n *\{'
|
|
|
|
# The next launch starts app with the deny, and writes its bindings file
|
|
# again byte for byte as 0.1.0 wrote it: of version 1, which a proxy from
|
|
# before an upgrade reads alike.
|
|
cp $APP_dir/run/secrets.json $WORK/secrets-before.json
|
|
grep '^\{"version":1,' $APP_dir/run/secrets.json
|
|
exec devvm
|
|
stdout '^==> starting what=devvm-app-[0-9a-f]{14}$'
|
|
! stderr 'unreadable|corrupt|layout_|refused|failed|policy_not_rule|policy_broken_deny'
|
|
cmp $APP_dir/run/secrets.json $WORK/secrets-before.json
|
|
|
|
# 0.1.0 recorded no transparent mode: app, confined, follows the default,
|
|
# on, and its launch gave its setup the stand-in address. Its own setting
|
|
# goes in its state and applies from its next launch.
|
|
exec devvm network transparent
|
|
stdout '\Aon # devvm: default\n\z'
|
|
exec tar -xOf $STUB_DIR/sync.tar vm
|
|
stdout '^DEVVM_TRANSPARENT_ADDR=''198\.18\.0\.1''$'
|
|
exec devvm network transparent off
|
|
stdout '^==> net_transparent_set mode=off vm=devvm-app-[0-9a-f]{14}$'
|
|
vm_state $APP_dir/vm.json
|
|
stdout '^net\.transparent=off$'
|
|
exec devvm stop
|
|
exec devvm
|
|
! stderr 'unreadable|corrupt|layout_|refused|failed'
|
|
exec tar -xOf $STUB_DIR/sync.tar vm
|
|
stdout '^DEVVM_TRANSPARENT_ADDR=''''$'
|
|
exec devvm network transparent on
|
|
exec devvm stop
|
|
exec devvm
|
|
exec tar -xOf $STUB_DIR/sync.tar vm
|
|
stdout '^DEVVM_TRANSPARENT_ADDR=''198\.18\.0\.1''$'
|
|
|
|
# A secret of yours by method makes app's bindings file of version 2, with
|
|
# 0.1.0's bindings kept in it.
|
|
stdin $WORK/key.token
|
|
exec devvm secret set reports --host api.example.com --env REPORTS_API_KEY --method GET --stdin
|
|
exec devvm secret use reports
|
|
stdout '^==> custom_secret_used hosts=api\.example\.com secret=reports vm=devvm-app-[0-9a-f]{14}$'
|
|
exec cat $APP_dir/run/secrets.json
|
|
stdout '^\{"version":2,"bindings":\[\{"name":"github",'
|
|
stdout '"name":"reports","kind":"secret","hosts":\["api\.example\.com"\],"methods":"GET",'
|
|
stdout '"name":"codex-key"'
|
|
|
|
# The deny comes out by its flags, a deny with its !.
|
|
exec devvm network rm '!api.github.com' --method POST,DELETE
|
|
stdout '^==> rule_removed rule=!api\.github\.com POST,DELETE vm=devvm-app-[0-9a-f]{14}$'
|
|
exec devvm network --json
|
|
! stdout 'POST,DELETE'
|
|
exec devvm secret rm reports --force
|
|
|
|
-- key.token --
|
|
rk_e2efake_reports
|