Files
devvm/internal/cli/proxy.go
T
w3cjandClaude Opus 5.5 f71adb5a04 refactor: devvm's own files stay in the binary
assets.FS is the only copy of devvm's own files: nothing writes them to
~/.local/share/devvm/assets/<hash> any more, so an edit on disk can't
widen running proxies' allowlists or change a --from base its key
doesn't describe.

- Proxy: -builtin-policy NAME,... names policies in IO.FS (cli's _proxy
  passes assets.FS; proxy stays stdlib-only). Built-ins are parsed once
  at start (readBuiltins), ahead of -policy's files in the union, never
  re-read; a missing one, or one with a line that isn't a rule, refuses
  to start. -policy carries only the user's files.
- netpolicy: PolicyFiles(d, assets, vm, img) becomes Policies(d, vm, img)
  (builtin, files); Proxy.PolicyFiles and AssetsInUse go. .proxy.policy
  records both lists, a line each, for the restart check. ReadRules takes
  built-ins from an fs.FS; RuleFile.Builtin.
- devvm network: built-ins labelled "# devvm: layers/base.policy";
  --json entries carry "builtin": NAME or "file": PATH ("version": 1).
- Lima: createArgs ends in "-" and create() feeds base.yaml on stdin;
  convert writes oci/ and, with company CAs, guest/ca.sh into its own
  temp folder beside vm/ (writeScripts, state.WriteFile), mounted
  read-only and deleted by the existing cleanup. Lima.assets() goes.
- Deleted: internal/state/assets.go and its test (WriteAssets,
  StaleAssets, AssetsHash), paths.Dirs.Assets, gc's stale-assets plan
  and the gc_assets/deleted_assets messages, space's devvm's files row.
- Tests: proxy built-ins (order, not re-read, missing/invalid refuse,
  Main refuses before listening), Policies, the restart check on either
  list, ReadRules/WriteRules labels, JSON shape, createArgs and create's
  stdin, writeScripts' files and modes; CLI scripts check
  $XDG_DATA_HOME/devvm/assets never appears after up, build and --from,
  base.yaml on create's input (the limactl stub keeps it), the
  conversion's mounts and script paths in its temp folder.
- Docs: design (One binary), install, overview, space, images (gc),
  internals network, images and lima, safety/network, proxy README,
  the network command's Long and its CLI page; AGENTS.md rule.
- Coverage baselines (darwin) raised: cli 88.2, netpolicy 87.2,
  proxy 88.2, state 91.8. Dirs' method cap lowered to 41.

Image keys are unchanged: they already hash the embedded files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-02 17:29:06 -07:00

40 lines
1.3 KiB
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/w3cj/devvm/assets"
"github.com/w3cj/devvm/internal/msg"
"github.com/w3cj/devvm/internal/proxy"
"github.com/w3cj/devvm/internal/secrets"
"github.com/w3cj/devvm/internal/ui"
)
// newProxyCmd is devvm _proxy: one VM's network policy proxy, and the
// one-shot modes devvm runs it in (-init-ca, -login, -redact). Hidden: it's
// not for users. Its flags are the proxy's own (one dash or two), parsed by
// proxy.Main; its event log and log lines are data, written to devvm's
// stdout and stderr. Its built-in policies (-builtin-policy) come from
// devvm's own files in the binary.
func newProxyCmd(u *ui.UI) *cobra.Command {
return &cobra.Command{
Use: "_proxy [flags]",
Short: "Run a VM's network policy proxy",
Hidden: true,
DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {
err := proxy.Main(args, proxy.IO{
Stdin: cmd.InOrStdin(),
Stdout: u.Stdout(),
Stderr: u.Stderr(),
Kept: func(agent string, names []string) { secrets.LoginKept(u.Warn, agent, names) },
FS: assets.FS, // the built-in policies, read from the binary
})
if err != nil {
u.Die(msg.ProxyFailed(err.Error()).Because(err))
}
return nil
},
}
}