mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
ls, images, tools, size, ports, network (and -g), network log (and --blocked), ssh-agent, git-protect, secret, history, space, retention and doctor take --json: one JSON object on stdout with "version": 1 first, messages on stderr (ui.DataOnly), lists [] when empty. Settings commands only show with --json and refuse a value (json_shows_only). doctor --json replaces --fixes: problems with key, fix (null without one) and message, warnings, docker and every backend's features; it prints nothing else and succeeds whatever is missing, and install.sh reads its problems with awk. TestJSONShapes holds each command's field names and types. Each shape is documented on its command's page, with the contract under Everyday commands' Output for scripts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
111 lines
4.7 KiB
Plaintext
111 lines
4.7 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 DEVVM_MESSAGES=names
|
|
env VMS=$XDG_DATA_HOME/devvm/vms
|
|
env GLOBAL=$XDG_CONFIG_HOME/devvm/policy
|
|
|
|
# No VM: nothing to show or change, except every VM's rules.
|
|
mkdir $WORK/net
|
|
cd $WORK/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-policy --no-git-protect base
|
|
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/devvm-net-[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}$'
|
|
exec sh -c 'cat "$VMS"/devvm-net-*.policy'
|
|
cmp stdout $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'
|
|
exec sh -c 'cat "$VMS"/devvm-net-*.policy'
|
|
cmp stdout $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=on, off command=devvm network given=sideways$'
|
|
exec sh -c 'cat "$VMS"/devvm-net-*.policy'
|
|
cmp stdout $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/devvm-net-[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 network policy (on, or unenforced as the stubs leave it), then
|
|
# the rules in effect, file by file, comments left out.
|
|
exec sh -c 'echo "# mine" >> "$GLOBAL"'
|
|
exec devvm network
|
|
stdout '\A(on|unenforced)\n# \S*/data/devvm/assets/[0-9a-f]{16}/layers/base\.policy\n'
|
|
stdout '^ github\.com$'
|
|
stdout '^# \S*/config/devvm/policy\n \*\.corp\.test\n# \S*/vms/devvm-net-[0-9a-f]{14}\.policy\n !bad\.example\.com\n example\.com\n'
|
|
! stdout mine
|
|
! stderr .
|
|
# --json: the same, each file with its rules; it only shows.
|
|
exec devvm network --json
|
|
stdout '\A{\n "version": 1,\n "policy": "(on|unenforced)",\n "allowlist": \[\n {\n "file": "\S*/layers/base\.policy",\n "rules": \[\n'
|
|
stdout '^ "file": "\S*/vms/devvm-net-[0-9a-f]{14}\.policy",\n "rules": \[\n "!bad\.example\.com",\n "example\.com"\n \]\n'
|
|
! stderr .
|
|
! exec devvm network --json off
|
|
stderr '^devvm: json_shows_only command=devvm network$'
|
|
|
|
# A VM without network policy: devvm network shows it off, with its
|
|
# rules, and changing them says they don't apply.
|
|
mkdir $WORK/off
|
|
cd $WORK/off
|
|
exec devvm --no-network-policy --no-git-protect base
|
|
exec devvm network
|
|
stdout '\Aoff\n# \S*/layers/base\.policy\n'
|
|
! stderr .
|
|
exec devvm network allow example.com
|
|
stderr '^net_off_policy vm=devvm-off-[0-9a-f]{14}$'
|
|
|
|
# A new VM doesn't get the rules of one by its name deleted outside devvm.
|
|
exec sh -c 'limactl delete "$(basename "$VMS"/devvm-off-*[0-9a-f])"'
|
|
exec devvm --no-network-policy --no-git-protect base
|
|
stdout '^==> creating_from image=base vm=devvm-off-[0-9a-f]{14}$'
|
|
exec sh -c 'ls "$VMS"'
|
|
! stdout 'devvm-off-.*\.policy'
|
|
|
|
-- global.policy --
|
|
*.corp.test
|
|
-- vm.policy --
|
|
example.com
|
|
!bad.example.com
|