mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -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]>
169 lines
7.5 KiB
Plaintext
169 lines
7.5 KiB
Plaintext
# network rules: devvm network shows the allowlist of this folder's VM,
|
|
# file by file, after its network policy; network allow, deny and rm
|
|
# change the VM's own rules, or with -g every VM's.
|
|
env GLOBAL=$XDG_CONFIG_HOME/devvm/policy
|
|
|
|
# No VM: nothing to show or change, except every VM's rules.
|
|
project net
|
|
! exec devvm network
|
|
stderr '^devvm: no_vm dir=\S*/net$'
|
|
! exec devvm network allow example.com
|
|
stderr '^devvm: no_vm_policy dir=\S*/net$'
|
|
! exec devvm network allow 'a b'
|
|
stderr '^devvm: not_a_rule rule=a b$'
|
|
! stderr no_vm_policy
|
|
exec devvm network allow -g '*.corp.test'
|
|
stdout '^==> rule_added_global rule=\*\.corp\.test$'
|
|
cmp $GLOBAL $WORK/global.policy
|
|
|
|
# allow, deny (a deny gets its !, once) and rm edit the VM's own file;
|
|
# a rule already there isn't added again, in any case.
|
|
exec devvm --network allowlist --no-git-protect
|
|
vm_name NET net
|
|
exec devvm network allow example.com api.example.com:8443
|
|
stdout '^==> rule_added rule=example\.com vm=devvm-net-[0-9a-f]{14}$'
|
|
stdout '^==> rule_added rule=api\.example\.com:8443 vm=devvm-net-[0-9a-f]{14}$'
|
|
exec devvm network deny bad.example.com '!worse.example.com'
|
|
stdout '^==> rule_added rule=!bad\.example\.com vm=devvm-net-[0-9a-f]{14}$'
|
|
stdout '^==> rule_added rule=!worse\.example\.com vm=devvm-net-[0-9a-f]{14}$'
|
|
exec devvm network allow Example.com
|
|
stdout '^==> rule_present file=\S*/vms/[0-9a-f]{14}/policy rule=Example\.com$'
|
|
exec devvm network rm api.example.com:8443 '!worse.example.com'
|
|
stdout '^==> rule_removed rule=api\.example\.com:8443 vm=devvm-net-[0-9a-f]{14}$'
|
|
cmp $NET_dir/policy $WORK/vm.policy
|
|
|
|
# IPv6 rules, with a port in brackets.
|
|
exec devvm network allow '[fd00::1]:22' fd00::/8
|
|
exec devvm network deny '[::1]:8080'
|
|
exec devvm network rm '[fd00::1]:22' fd00::/8 '![::1]:8080'
|
|
cmp $NET_dir/policy $WORK/vm.policy
|
|
|
|
# What isn't a rule is refused, and nothing is added; allow doesn't take
|
|
# a deny.
|
|
! exec devvm network allow ok.example.com 'a b'
|
|
stderr '^devvm: not_a_rule rule=a b$'
|
|
! exec devvm network allow 'x;rm'
|
|
stderr '^devvm: not_a_rule rule=x;rm$'
|
|
! exec devvm network allow '!bad.example.com'
|
|
stderr '^devvm: not_a_rule rule=!bad\.example\.com$'
|
|
! exec devvm network deny 'example.com # c'
|
|
stderr '^devvm: not_a_rule rule='
|
|
! exec devvm network allow
|
|
stderr '^devvm: arg_missing args=RULE\.\.\. command=devvm network allow$'
|
|
! exec devvm network sideways
|
|
stderr '^devvm: arg_not_choice choices=open, internet, allowlist, none command=devvm network given=sideways$'
|
|
cmp $NET_dir/policy $WORK/vm.policy
|
|
|
|
# A rule that isn't there: a warning; the others still go.
|
|
exec devvm network rm nothere.test example.com
|
|
stderr '^devvm: rule_missing file=\S*/vms/[0-9a-f]{14}/policy rule=nothere\.test$'
|
|
stdout '^==> rule_removed rule=example\.com vm=devvm-net-[0-9a-f]{14}$'
|
|
exec devvm network allow example.com
|
|
exec devvm network rm -g '*.corp.test'
|
|
stdout '^==> rule_removed_global rule=\*\.corp\.test$'
|
|
exec devvm network allow --global '*.corp.test'
|
|
|
|
# The VM's tier (allowlist, or unenforced as the stubs leave it), then
|
|
# the rules in effect, file by file, comments left out: devvm's built-in
|
|
# policies first, by name, then your files, by path.
|
|
exec sh -c 'echo "# mine" >> "$GLOBAL"'
|
|
exec devvm network
|
|
stdout '\A(allowlist|unenforced)\n# devvm: layers/base\.policy\n'
|
|
stdout '^ github\.com$'
|
|
stdout '^# \S*/config/devvm/policy\n \*\.corp\.test\n# \S*/vms/[0-9a-f]{14}/policy\n !bad\.example\.com\n example\.com\n'
|
|
! stdout mine
|
|
! stderr .
|
|
# --json: the same, each policy with its rules, a built-in one by name;
|
|
# it only shows.
|
|
exec devvm network --json
|
|
stdout '\A{\n "version": 1,\n "policy": "(allowlist|unenforced)",\n "allowlist": \[\n {\n "builtin": "layers/base\.policy",\n "rules": \[\n'
|
|
! stdout '"file": "\S*/layers/base\.policy"'
|
|
stdout '^ "file": "\S*/vms/[0-9a-f]{14}/policy",\n "rules": \[\n "!bad\.example\.com",\n "example\.com"\n \],\n "not_rules": \[\]\n'
|
|
! stderr .
|
|
! exec devvm network --json off
|
|
stderr '^devvm: json_shows_only command=devvm network$'
|
|
|
|
# A line that isn't a rule: devvm network marks it with its number,
|
|
# --json lists it, and doctor warns of it.
|
|
exec sh -c 'echo "example.com:x # not a port" >> "$GLOBAL"'
|
|
exec devvm network
|
|
stdout '^# \S*/config/devvm/policy\n \*\.corp\.test\n example\.com:x # not a rule, skipped \(line 4\)\n'
|
|
exec devvm network --json
|
|
stdout '"rules": \[\n "\*\.corp\.test"\n \],\n "not_rules": \[\n {\n "line": 4,\n "text": "example\.com:x"\n }\n \]\n'
|
|
exec devvm doctor
|
|
stderr '^devvm: policy_not_rule file=\S*/config/devvm/policy line=4 rule=example\.com:x$'
|
|
# Changing the file warns of it too, and a line that reads as a deny but
|
|
# isn't a rule warns that the VMs' proxies deny everything: on a change,
|
|
# a launch and in doctor.
|
|
exec devvm network allow -g ok2.test
|
|
stdout '^==> rule_added_global rule=ok2\.test$'
|
|
stderr '^devvm: policy_not_rule file=\S*/config/devvm/policy line=4 rule=example\.com:x$'
|
|
exec sh -c 'echo "! worse.test" >> "$GLOBAL"'
|
|
exec devvm network rm -g ok2.test
|
|
stderr '^devvm: policy_broken_deny file=\S*/config/devvm/policy line=5 rule=! worse\.test$'
|
|
stderr '^devvm: policy_not_rule file=\S*/config/devvm/policy line=4 rule=example\.com:x$'
|
|
# (The stubs leave the VM unenforced, so the launch stops it after warning.)
|
|
! exec devvm
|
|
stderr '^devvm: policy_broken_deny file=\S*/config/devvm/policy line=5 rule=! worse\.test$'
|
|
exec devvm doctor
|
|
stderr '^devvm: policy_broken_deny file=\S*/config/devvm/policy line=5 rule=! worse\.test$'
|
|
exec sh -c 'grep -v -e "example.com:x" -e "worse.test" "$GLOBAL" > "$WORK/g" && cat "$WORK/g" > "$GLOBAL"'
|
|
exec devvm doctor
|
|
! stderr 'policy_not_rule|policy_broken_deny'
|
|
exec devvm network allow -g ok3.test
|
|
! stderr .
|
|
exec devvm network rm -g ok3.test
|
|
|
|
# An open VM: devvm network shows its tier and no rules, as none apply,
|
|
# and changing them says so.
|
|
project off
|
|
exec devvm --network open --no-git-protect
|
|
exec devvm network
|
|
stdout '\Aopen\n\z'
|
|
! stderr .
|
|
exec devvm network allow example.com
|
|
stderr '^net_open_policy vm=devvm-off-[0-9a-f]{14}$'
|
|
|
|
# A new VM doesn't get the rules of one by its name deleted outside devvm.
|
|
vm_name OFF off
|
|
exists $OFF_dir/policy
|
|
exec limactl delete $OFF
|
|
exec devvm --network open --no-git-protect
|
|
stdout '^==> creating_from image=base vm=devvm-off-[0-9a-f]{14}$'
|
|
! exists $OFF_dir/policy
|
|
|
|
# The internet tier: every public host on any port, its built-in policy,
|
|
# then the denies alone of your files, so an allow says it changes
|
|
# nothing; none: the VM's agents' policies alone (here it has none), with
|
|
# the same denies. Its proxy reads them as devvm network shows them.
|
|
project tiers
|
|
exec devvm --network allowlist --no-git-protect
|
|
vm_name TIERS tiers
|
|
exec limactl stop $TIERS
|
|
cp $WORK/vm.policy $TIERS_dir/policy
|
|
json_set $TIERS_dir/vm.json net.tier=internet
|
|
exec devvm network
|
|
stdout '\Ainternet\n# devvm: network/internet\.policy\n \*\*:\*\n'
|
|
stdout '^# \S*/vms/[0-9a-f]{14}/policy \(denies only\)\n !bad\.example\.com\n'
|
|
! stdout '^ example\.com$'
|
|
exec devvm network --json
|
|
stdout '"policy": "internet"'
|
|
stdout '"builtin": "network/internet.policy",\n "rules": \[\n "\*\*:\*"\n \]'
|
|
exec devvm network allow ok.test:*
|
|
stderr '^net_allows_unused tier=internet vm=devvm-tiers-[0-9a-f]{14}$'
|
|
exec devvm network deny worse.test
|
|
! stderr net_allows_unused
|
|
json_set $TIERS_dir/vm.json net.tier=none
|
|
exec devvm network
|
|
stdout '\Anone\n# \S*/vms/[0-9a-f]{14}/policy \(denies only\)\n !bad\.example\.com\n !worse\.test\n\z'
|
|
exec devvm
|
|
exec cat $TIERS_dir/run/proxy.json
|
|
stdout '"deny_policies": \['
|
|
! stdout '"builtin_policies"|"open"'
|
|
|
|
-- global.policy --
|
|
*.corp.test
|
|
-- vm.policy --
|
|
example.com
|
|
!bad.example.com
|