跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

networkconfined.go

38 行 · 1.4 KB历史下载
1package vm
2
3import (
4 "errors"
5 "fmt"
6
7 "github.com/lima-vm/lima/v2/pkg/limatype"
8)
9
10// ErrNetworkOpen is returned by Start for a VM with a network besides its own
11// isolated one: the network policy (netguard) applies to the connections of
12// the VM's own netstack only.
13var ErrNetworkOpen = errors.New("agent-vm starts no VM with a network besides its own")
14
15// NetworkConfined fails when cfg gives the guest a network of Lima's `networks`
16// (a shared usernet, a socket, vzNAT, a vmnet one): its traffic does not go
17// through the netstack that the policy is applied to.
18func NetworkConfined(cfg *limatype.LimaYAML) error {
19 // Only these drivers attach the VM's NIC to our host-side netstack.
20 // WSL2 and HCS have separate host-managed networking, even with no
21 // explicit networks entry, so they cannot enforce the Cage egress gate.
22 if cfg.VMType != nil && *cfg.VMType != limatype.QEMU && *cfg.VMType != limatype.VZ {
23 return fmt.Errorf("%w: VM driver %q does not use the confined network", ErrNetworkOpen, *cfg.VMType)
24 }
25 for i, n := range cfg.Networks {
26 what := "a network"
27 switch {
28 case n.Lima != "":
29 what = fmt.Sprintf("the shared network %q", n.Lima)
30 case n.Socket != "":
31 what = fmt.Sprintf("the socket %q", n.Socket)
32 case n.VZNAT != nil && *n.VZNAT:
33 what = "vzNAT"
34 }
35 return fmt.Errorf("%w: networks[%d] is %s", ErrNetworkOpen, i, what)
36 }
37 return nil
38}