mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
The command line names the four network tiers. --network TIER (open,
internet, allowlist or none) chooses a new VM's tier, checked before
anything runs (arg_not_choice). devvm network open|internet|allowlist|none
gives the folder's VM a tier through Net.SetTier, and devvm network -g
takes the tiers and ask. config.toml's and settings.json's network is ask
or a tier (settings.NetworkChoices, checked against netpolicy.TierNames
by a test, since settings can't import netpolicy).
The question on creation is Proxy.Choose(vm): net_about says what each
tier reaches, net_ask asks for one (Answer, AnsweredBy("--network")),
Enter or a refusal gives allowlist, and an answer that isn't a tier is
warned of (net_tier_unknown) and asked again. devvm setup's picker
offers ask and the four tiers (network_default_open, _internet,
_allowlist, _none). On an existing VM, --network is ignored with the
devvm network TIER command that changes it.
devvm network --json: policy is the tier or unenforced, and each policy
file whose denies alone apply (internet and none) has denies_only: true,
as the text output's "(denies only)", so a script can tell a file's
denies from all of its rules without knowing the tier rules.
Messages reworded: net_tier_backend (--network open), net_open_policy
(devvm network allowlist), net_about, net_ask, network_default*,
net_default_failed, network_failed, setting_already's and
widen_parent_vm*'s descriptions. safety/network's "Choosing a tier"
replaces its on/off section; docs, the cli skill, testscripts and e2e
use the new forms, and e2e's internet and none checks go through devvm
network.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
103 lines
2.8 KiB
Plaintext
103 lines
2.8 KiB
Plaintext
# The scripts' own commands, which every other script uses.
|
|
|
|
# The sandbox shows messages by name and names devvm's folders.
|
|
exec sh -c 'test "$DEVVM_MESSAGES" = names && test "$DATA" = "$XDG_DATA_HOME/devvm" && test "$VMS" = "$DATA/vms" && test "$RUN" = "$DATA/run" && test "$CFG" = "$XDG_CONFIG_HOME/devvm"'
|
|
|
|
# stub_reset forgets the stubs' calls, and empties stdout as an exec does.
|
|
exec open x
|
|
stub_calls
|
|
stdout '^open x$'
|
|
stub_reset
|
|
! stdout .
|
|
! stub_calls
|
|
exec open y
|
|
stub_calls
|
|
cmp stdout calls
|
|
|
|
# catg cats the one file a glob matches; a glob matching none or two
|
|
# fails it.
|
|
mkdir $VMS/0123456789abcd
|
|
cp vm.json $VMS/0123456789abcd/vm.json
|
|
catg $VMS/*/vm.json
|
|
cmp stdout vm.json
|
|
! catg $VMS/*/policy
|
|
cp vm.json $VMS/0123456789abcd/policy
|
|
! catg $VMS/0123456789abcd/*
|
|
catg $VMS/*/vm.json
|
|
cmp stdout vm.json
|
|
|
|
# vm_name sets a variable to the one VM whose state records a name made
|
|
# for a folder, and VAR_dir to its folder; a folder without state, another
|
|
# folder's VM, no VM or two fail it.
|
|
mkdir $VMS/0123456789abce
|
|
cp policy $VMS/0123456789abce/vm.json
|
|
vm_name WEB web
|
|
exec echo $WEB $WEB_dir
|
|
stdout '^devvm-web-0123456789abcd .*/vms/0123456789abcd$'
|
|
! vm_name API api
|
|
mkdir $VMS/fedcba98765432
|
|
cp other.json $VMS/fedcba98765432/vm.json
|
|
! vm_name WEB web
|
|
|
|
# vm_state prints a VM's state as sorted KEY=VALUE lines: a section's
|
|
# fields dotted, a list of strings space-separated, a list of objects by
|
|
# index, anything but a string as JSON.
|
|
vm_state $VMS/0123456789abcd/vm.json
|
|
cmp stdout flat
|
|
|
|
# json_set sets strings, any JSON with :=, and fields of objects by dotted
|
|
# keys, made when they're missing; the rest stays.
|
|
json_set $VMS/0123456789abcd/vm.json image=docker net.made.check=ok ports.host:={"ssh":2222} version:=2
|
|
vm_state $VMS/0123456789abcd/vm.json
|
|
stdout '^image=docker$'
|
|
stdout '^net.made.check=ok$'
|
|
stdout '^net.tier=allowlist$'
|
|
stdout '^ports.host.ssh=2222$'
|
|
stdout '^version=2$'
|
|
stdout '^tools.names=node claude$'
|
|
json_set $WORK/new.json a.b=c
|
|
exec cat $WORK/new.json
|
|
stdout '"a": \{\n "b": "c"\n \}'
|
|
|
|
# project makes a folder in $WORK and goes to it; with git, a repo.
|
|
project app
|
|
exec pwd
|
|
stdout '/app$'
|
|
! exists .git
|
|
project repo git
|
|
exec pwd
|
|
stdout '/repo$'
|
|
exists .git
|
|
|
|
-- calls --
|
|
open y
|
|
-- vm.json --
|
|
{
|
|
"version": 1,
|
|
"id": "x",
|
|
"name": "devvm-web-0123456789abcd",
|
|
"image": "base",
|
|
"dir": "/p",
|
|
"backend": "lima",
|
|
"net": {"tier": "allowlist"},
|
|
"tools": {"names": ["node", "claude"]},
|
|
"links": {"links": [{"name": "db", "port": 5432}]},
|
|
"secrets": {"names": []}
|
|
}
|
|
-- flat --
|
|
backend=lima
|
|
dir=/p
|
|
id=x
|
|
image=base
|
|
links.links.0.name=db
|
|
links.links.0.port=5432
|
|
name=devvm-web-0123456789abcd
|
|
net.tier=allowlist
|
|
secrets.names=
|
|
tools.names=node claude
|
|
version=1
|
|
-- policy --
|
|
example.com
|
|
-- other.json --
|
|
{"version": 1, "id": "y", "name": "devvm-web-fedcba98765432", "image": "base", "dir": "/q", "backend": "lima"}
|