mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
A built-in policy's `quiet HOST[:PORT]` line, for one exact host name, marks a host devvm leaves out on purpose. A quiet host is blocked as any host no rule allows, and an allow of the user's still lifts it. A block is quiet only when its reason is "not on the allowlist" (notAllowed), it isn't refused, and no rule covers the host (an allow, a deny or one that narrows): then it's logged with "quiet": true but never counted in /blocked or /blocked/new, so neither the VM's prompt nor devvm-why shows it, its 403 page suggests no command, devvm network log --blocked shows it as a row of its own with "- (quiet)", and devvm network lock never offers it. - proxy: rule.quiet, parseQuiet (exact hosts only), PolicyLine.Quiet, policy.quiet, Allowlist.Quiet, Event.Quiet, server.blocked (proxy and transparent paths), notAllowed; loadPolicy skips and logs quiet lines in the user's files. - netpolicy: Judge.Quiet, Block.Quiet (its own row key), FormatEvent's ", quiet", RuleFile.Quiet, quietMark, policy_quiet_not_own in PolicyWarnings. - cli: quiet in network log --json, log --blocked --json and network --json; the agents' table leaves quiet lines out. - Quiet hosts, each with its source: api3.cursor.sh (the host Cursor documents for Tab requests; Cursor's CLI uses it for its metrics) and telemetry.go.dev (Go). Not marked: Claude Code's Datadog intakes (shared multi-tenant hosts projects may need), .NET's telemetry (no host in Microsoft's docs). - Tests: TestParseQuiet, TestQuietHosts, TestQuietOnlyWhenNoRuleAllows, learn/log/rules tests, network_rules.txtar, e2e network check for api3.cursor.sh. Co-Authored-By: Claude Opus 5.5 <[email protected]>
181 lines
8.1 KiB
Plaintext
181 lines
8.1 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, learn, 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'
|
|
# Only devvm's own policies mark a host quiet: in a file of the user's,
|
|
# the line isn't a rule, and doctor says why.
|
|
exec sh -c 'echo "quiet metrics.test" >> "$GLOBAL"'
|
|
exec devvm network
|
|
stdout '^ quiet metrics\.test # not a rule, skipped \(line \d+\)$'
|
|
exec devvm network --json
|
|
stdout '"text": "quiet metrics\.test"'
|
|
! stdout '"quiet": \['
|
|
exec devvm doctor
|
|
stderr '^devvm: policy_quiet_not_own file=\S*/config/devvm/policy line=\d+ rule=quiet metrics\.test$'
|
|
! stderr 'policy_not_rule'
|
|
exec sh -c 'grep -v -e "metrics.test" "$GLOBAL" > "$WORK/g" && cat "$WORK/g" > "$GLOBAL"'
|
|
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
|