mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
A policy rule for a host name can narrow it to some of its requests: `api.github.com GET,HEAD /repos/` in a policy file, written by devvm network allow, deny and rm from --method and --path. Allows add up and a deny beats any allow, as for every rule, so narrowing a host that a rule allows whole, such as devvm's built-in GitHub, takes a deny: `devvm network deny api.github.com --method POST,PUT,PATCH,DELETE`, or `devvm network deny github.com --path '/*/*/git-receive-pack'`. An allow by method and path for a host already allowed whole warns that it narrows nothing and names the deny. The proxy decrypts such a host's HTTPS on :443 with the VM's CA, refuses its tunnels on other ports and without a CA, and judges every request on the connection, kept-alive HTTP/1.1 and HTTP/2 alike, every absolute-form one, and the shared Nix cache's own fetches. A connection's verdict and whether its requests are judged come from one read of the policy files. A blocked request gets 403 and a blocked event with its method and path; devvm network log shows it, and an allowed one's forward event names the rule that let it through. One matcher, internal/proxy/request.go, judges rules and secrets' bindings: methods from a closed list (RFC 9110's, PATCH, QUERY; never CONNECT); the methods a request names besides its own (every override-like header in any spelling, `_` for `-`, and the query's _method), each word judged, and while a rule narrows by method, a value that isn't exactly one method refused; path patterns with *, ** and a last / for everything below; and only a path in plain form. Allows and bindings match strictly, denies broadly: any case, every path that isn't plain, the prefix above a trailing /, and a last segment cut at its first dot (/admin.json, /admin.). A method devvm doesn't know isn't a rule, so a typo in a deny is a broken deny. Upgrades other than WebSocket and CONNECT inside a decrypted tunnel are refused for narrowed hosts. devvm secret set takes an optional --method (none for every method), and a secret's --path takes the same patterns, marked path_pattern in custom-secrets.json; a saved path with a * from before is refused rather than read as a wildcard. The bindings file stays version 1 while every binding reads alike to an older proxy, so devvm secret set and rm after an upgrade don't take a running older proxy's bindings away; a binding with methods or a pattern makes it version 2, which such a proxy refuses instead of putting a value in for every method, and writing one warns for each such VM. devvm network allow, deny and rm warn, naming the VM, when a rule by method and path changes while the VM's proxy runs from another devvm binary, or one devvm can't tell. A query with a ; or one Go can't read whole is refused while a rule narrows the host by method, and denies also match each segment with its trailing dots dropped. An allow that narrows nothing names the VMs, with -g by each VM's own allowlist, and says when it narrows only port 80's plain HTTP. - proxy: match, Methods, ParseMethods, PathOK, plainPath, matchPath, overrides, overrideLike, server.judgeRequest; parseRule/parseHostRule, CanonicalRule, NarrowRule, Narrowable, hostRules (rulesFor, verdict, byRequest, judge, unjudgeable), egress.checkHost, Allowlist.CoversWhole, trimDots; Binding.Methods, BindingListVersion 2 when needed (v1Binding); pathWithin and PathPrefixOK folded into match; the Nix cache judged - netpolicy: Rule(rule, deny, methods, path), NarrowedHost, sameRule, Proxy.Allowlist, Proxy.NarrowNotes, Proxy.OtherBinaries, BasePolicy, Proxy.SecretsWritten (after RefreshSecrets and devvm agent login --api-key's write); FormatEvent shows a blocked request's method and path and a forward's rule - secrets: Def/Secret/customJSON Methods, path_pattern, CheckMethods, CheckPath on proxy.PathOK - vm: RuleChange, PolicyChange(ctx, rules, RuleChange) - cli: --method and --path on network allow, deny and rm, --method on secret set, METHODS in devvm secret and "methods" in its --json - messages: bad_request_path (was bad_secret_path), bad_methods, rule_not_narrowable, rule_narrows, rule_narrows_nothing, rule_narrows_http_only, rule_narrows_unknown, proxy_other_binary, secrets_other_binary - tests: TestParseRuleNarrowed, TestMatchPath, TestDenyBypasses, TestAllowNarrowed, TestCoversWhole, TestForRequestMethods, TestInterceptRules and TestInterceptSecretMethods (HTTP/1.1 kept alive and HTTP/2), TestNarrowedNotDecrypted, TestNixCacheRulesByPath, FuzzDenyBypass (paths, methods, headers, _method), TestRule, TestNarrowedRules, TestOtherBinaries, TestRefreshSecretsOtherBinary, TestNarrowNotesUnreadable, TestDefine's path of /, TestReadBindings' versions, TestCustomsUnreadable's prefix path, network_narrow.txtar (narrows nothing), secret_custom.txtar's --method; on 0.1.0's frozen state: TestV010Bindings, TestV010ProxyConfig, TestV010Rules (0.1.0's TestParsePolicy and TestDecide, frozen), fixture_v010_network.txtar; e2e network: netRequestRules and the basic secret's --method GET,HEAD - docs: safety/network.md's Rules by method and path, the secrets' flags and an example, internals/network.md's Requests by method and path, the design note replacing the open-work entry, attack vectors, the commands page, internal/proxy/README.md, the CLI reference Co-Authored-By: Claude Opus 5.5 <[email protected]>
233 lines
8.7 KiB
Plaintext
233 lines
8.7 KiB
Plaintext
# devvm secret: the secrets kept on this machine, listed bare. The
|
|
# Keychain is the stub's on macOS (service DEVVM_SECRET_SERVICE), a file
|
|
# elsewhere. Every value here is fake.
|
|
exec devvm --help
|
|
stdout '^ secret '
|
|
! stdout '^ auth '
|
|
! stdout ' get '
|
|
! exec devvm auth claude
|
|
stderr '^devvm: no_command word=auth$'
|
|
|
|
# No command prints a secret's value: VMs' proxies look values up in
|
|
# their own process.
|
|
! exec devvm secret get github
|
|
stderr '^devvm: no_subcommand command=devvm secret commands=rm, set, unuse, use given=get$'
|
|
|
|
# A value saved where devvm keeps it is saved; the Keychain is asked
|
|
# for it by name, the value in no process's arguments.
|
|
exec devvm secret
|
|
stdout '^github +no +GH_TOKEN +Authorization +api\.github\.com, github\.com, codeload\.github\.com, raw\.githubusercontent\.com +- +- +-$'
|
|
stdout '^proxy +no +- +- +- +- +- +-$'
|
|
[darwin] stdin github0.token
|
|
[darwin] exec stub keychain-set github
|
|
[!darwin] mkdir $DATA/secrets
|
|
[!darwin] cp github0.token $DATA/secrets/github
|
|
stub_reset
|
|
exec devvm secret
|
|
stdout '^github +yes .* -$'
|
|
stdout '^claude +no +CLAUDE_CODE_OAUTH_TOKEN +Authorization +api\.anthropic\.com +- +- +-$'
|
|
[darwin] stub_calls
|
|
[darwin] stdout '^security find-generic-password -s devvm-test -a github -w$'
|
|
|
|
# A claude token in devvm's environment wins.
|
|
env CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-testfake
|
|
exec devvm secret
|
|
stdout '^NAME +SAVED +VARIABLE +HEADER +HOSTS +PATH +METHODS +USED BY$'
|
|
stdout '^claude +yes .* -$'
|
|
# --json: saved or not, its hosts, header and variable, never the token.
|
|
exec devvm secret --json
|
|
stdout '\A{\n "version": 1,\n "secrets": \[\n {\n "name": "claude",\n "saved": true,\n "used_by": \[\],\n "custom": false,\n "hosts": \[\n "api\.anthropic\.com"\n \],\n "header": "Authorization",\n "env": "CLAUDE_CODE_OAUTH_TOKEN",\n "prefix": "sk-ant-oat01-"\n },\n'
|
|
stdout '\n "name": "proxy",\n "saved": false,\n "used_by": \[\],\n "custom": false,\n "hosts": \[\]\n }\n'
|
|
! stdout testfake
|
|
env CLAUDE_CODE_OAUTH_TOKEN=
|
|
|
|
# Only devvm's own names and names of yours: never a path. A name of yours
|
|
# that isn't saved is no secret.
|
|
! exec devvm secret set ../../etc/passwd --stdin
|
|
stderr '^devvm: bad_secret_name given=\.\./\.\./etc/passwd most=40$'
|
|
stderr '^usage_help command=devvm secret set$'
|
|
! exec devvm secret rm ../x
|
|
stderr '^devvm: no_secret secret=\.\./x$'
|
|
stderr '^usage_help command=devvm secret rm$'
|
|
! exec devvm secret rm --force nope
|
|
stderr '^devvm: no_secret secret=nope$'
|
|
|
|
# --no-input never asks, and never reads an answer: the question fails,
|
|
# naming the flag that answers it. Nothing is saved: github keeps the token
|
|
# saved above.
|
|
stdin github.token
|
|
! exec devvm --no-input secret set github
|
|
stderr '^token_prompt$'
|
|
stderr '^devvm: no_input answer=--stdin$'
|
|
[darwin] exec stub keychain github
|
|
[darwin] stdout '\Aghp_testfake\n\z'
|
|
[!darwin] grep '^ghp_testfake$' $DATA/secrets/github
|
|
[darwin] env DEVVM_SECRET_SERVICE='x -a y'
|
|
[darwin] stdin claude.token
|
|
[darwin] ! exec devvm secret set claude --stdin
|
|
[darwin] stderr '^devvm: bad_secret_service$'
|
|
env DEVVM_SECRET_SERVICE=devvm-test
|
|
|
|
# set and rm; ls lists every secret, whether saved, and its VMs. A value
|
|
# goes in through stdin, never in a process's arguments.
|
|
stub_reset
|
|
stdin github.token
|
|
exec devvm secret set github --stdin
|
|
[darwin] stdout '^==> secret_saved_keychain secret=github$'
|
|
[!darwin] stdout '^==> secret_saved file=\S*/data/devvm/secrets/github secret=github$'
|
|
[darwin] exec stub keychain github
|
|
[darwin] stdout '\Aghp_testfake2\n\z'
|
|
[!darwin] grep '^ghp_testfake2$' $DATA/secrets/github
|
|
stub_calls
|
|
! stdout ghp_testfake2
|
|
[darwin] stdout '^security -i$'
|
|
[!darwin] exec sh -c 'stat -c %a "$DATA/secrets" "$DATA/secrets/github"'
|
|
[!darwin] stdout '^700\n600\n$'
|
|
exec devvm secret
|
|
stdout '^claude +no .* -$'
|
|
stdout '^github +yes .* -$'
|
|
! exec devvm secret rm github
|
|
stderr '^secret_rm_confirm name=github\ndevvm: no_input answer=--force$'
|
|
exec devvm secret rm --force github
|
|
stdout '^==> secret_removed secret=github$'
|
|
[darwin] ! exec stub keychain github
|
|
[!darwin] ! exists $DATA/secrets/github
|
|
! exec devvm secret rm --force github
|
|
stderr '^devvm: no_secret secret=github$'
|
|
|
|
# Tokens that are refused: nothing saved.
|
|
stdin empty.token
|
|
! exec devvm secret set github --stdin
|
|
stderr '^devvm: no_token$'
|
|
stdin quotes.token
|
|
! exec devvm secret set github --stdin
|
|
stderr '^devvm: token_quotes$'
|
|
stdin browser.token
|
|
! exec devvm secret set claude --stdin
|
|
stderr '^devvm: not_setup_token$'
|
|
stdin placeholder.token
|
|
! exec devvm secret set github --stdin
|
|
stderr '^devvm: token_is_placeholder$'
|
|
exec devvm secret
|
|
stdout '^claude +no .* -$'
|
|
stdout '^github +no .* -$'
|
|
|
|
# devvm secret set claude without a terminal or --stdin is refused,
|
|
# naming --stdin, and reads nothing.
|
|
stdin claude.token
|
|
! exec devvm secret set claude
|
|
stderr '^token_prompt\ndevvm: no_input answer=--stdin$'
|
|
exec devvm secret
|
|
stdout '^claude +no .* -$'
|
|
|
|
# With piped answers, the CLI tests' way to answer, its question reads
|
|
# a line instead, and shows nothing.
|
|
env DEVVM_PIPED_ANSWERS=1
|
|
stdin claude.token
|
|
exec devvm secret set claude
|
|
env DEVVM_PIPED_ANSWERS=
|
|
[darwin] stdout '^==> secret_saved_keychain secret=claude$'
|
|
! stderr .
|
|
[darwin] exec stub keychain claude
|
|
[darwin] stdout '\Ask-ant-oat01-testfake\n\z'
|
|
[!darwin] grep '^sk-ant-oat01-testfake$' $DATA/secrets/claude
|
|
! exec devvm secret set codex
|
|
stderr '^devvm: secret_name_taken given=codex$'
|
|
! exec devvm secret ls
|
|
stderr '^devvm: no_subcommand command=devvm secret commands=rm, set, unuse, use given=ls$'
|
|
|
|
# use and unuse bind a token to the folder's VM, an open one's too: its
|
|
# proxy has the VM's bindings, as every tier's does.
|
|
project off
|
|
! exec devvm secret use github
|
|
stderr '^devvm: no_vm dir=\S*/off$'
|
|
exec devvm --network open --no-git-protect
|
|
exec devvm secret use github
|
|
stdout '^==> secret_used secret=github vm=devvm-off-[0-9a-f]{14}$'
|
|
stderr '^devvm: no_github_token vm=devvm-off-[0-9a-f]{14}$'
|
|
vm_name OFF off
|
|
vm_state $OFF_dir/vm.json
|
|
stdout '^secrets.names=github$'
|
|
exec cat $OFF_dir/run/secrets.json
|
|
stdout '^\{"version":1,"bindings":\[\]\}$'
|
|
exec devvm secret
|
|
stdout '^github +no .* devvm-off-[0-9a-f]{14}$'
|
|
exec devvm secret --json
|
|
stdout '^ "name": "github",\n "saved": false,\n "used_by": \[\n "devvm-off-[0-9a-f]{14}"\n \],\n'
|
|
exec devvm secret unuse github
|
|
stdout '^==> secret_unused secret=github vm=devvm-off-[0-9a-f]{14}$'
|
|
! stderr .
|
|
vm_state $OFF_dir/vm.json
|
|
! stdout '^secrets.names=.'
|
|
! exec devvm secret unuse nope
|
|
stderr '^devvm: no_secret secret=nope$'
|
|
! exec devvm secret unuse NOPE
|
|
stderr '^devvm: no_secret secret=NOPE$'
|
|
! exec devvm secret use codex-key
|
|
stderr '^devvm: no_secret secret=codex-key$'
|
|
|
|
# The company proxy's password: saved as the others are, on stdin, and
|
|
# never a VM's.
|
|
stdin $WORK/proxy.password
|
|
exec devvm secret set proxy --stdin
|
|
[darwin] stdout '^==> secret_saved_keychain secret=proxy$'
|
|
[darwin] exec stub keychain proxy
|
|
[darwin] stdout '\Apa55 word\n\z'
|
|
[!darwin] grep '^pa55 word$' $DATA/secrets/proxy
|
|
exec devvm secret
|
|
stdout '^proxy +yes +- +- +- +- +- +-$'
|
|
! exec devvm secret use proxy
|
|
stderr '^devvm: secret_host_only secret=proxy$'
|
|
vm_state $OFF_dir/vm.json
|
|
! stdout '^secrets.names=.'
|
|
# Without --stdin and no terminal, it asks for a password.
|
|
stdin $WORK/proxy.password
|
|
! exec devvm --no-input secret set proxy
|
|
stderr '^password_prompt$'
|
|
stderr '^devvm: no_input answer=--stdin$'
|
|
exec devvm secret rm --force proxy
|
|
stdout '^==> secret_removed secret=proxy$'
|
|
|
|
# With network policy the VM's proxy gets the binding at once, and a
|
|
# token saved or removed later too; never the value.
|
|
project net
|
|
exec devvm --network allowlist --no-git-protect
|
|
vm_name NET net
|
|
exec cat $NET_dir/run/secrets.json
|
|
stdout '^\{"version":1,"bindings":\[\]\}$'
|
|
exec devvm secret use github
|
|
stderr '^devvm: no_github_token '
|
|
exec cat $NET_dir/run/secrets.json
|
|
stdout '^\{"version":1,"bindings":\[\]\}$'
|
|
stdin $WORK/github.token
|
|
exec devvm secret set github --stdin
|
|
exec cat $NET_dir/run/secrets.json
|
|
stdout '^\{"version":1,"bindings":\[\{"name":"github","kind":"secret","hosts":\["api.github.com","github.com","codeload.github.com","raw.githubusercontent.com"\],"header":"Authorization","placeholder":"devvm-proxy-managed-github-[0-9a-f]{32}"'
|
|
! stdout ghp_testfake2
|
|
exec cat $NET_dir/run/secrets.policy
|
|
stdout '^api.github.com:443$'
|
|
exec devvm secret unuse github
|
|
exec cat $NET_dir/run/secrets.json
|
|
stdout '^\{"version":1,"bindings":\[\]\}$'
|
|
exec devvm secret use github
|
|
exec devvm secret rm --force github
|
|
exec cat $NET_dir/run/secrets.json
|
|
stdout '^\{"version":1,"bindings":\[\]\}$'
|
|
|
|
-- github0.token --
|
|
ghp_testfake
|
|
-- github.token --
|
|
ghp_testfake2
|
|
-- claude.token --
|
|
sk-ant-oat01-testfake
|
|
-- empty.token --
|
|
|
|
-- quotes.token --
|
|
ghp_x" -A -T "
|
|
-- browser.token --
|
|
some-browser-code
|
|
-- placeholder.token --
|
|
devvm-proxy-managed-github-0123456789abcdef0123456789abcdef
|
|
-- proxy.password --
|
|
pa55 word
|