跳到主要内容

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

浏览文件

guest_probe_darwin_arm64.go

48 行 · 2.4 KB历史下载
1//go:build darwin && arm64 && cgo && !no_vz
2
3package maclogin
4
5import (
6 "context"
7 "os/exec"
8
9 "al.essio.dev/pkg/shellescape"
10 "github.com/sylvinus/agent-vm/internal/guestos"
11)
12
13// Read authorization state from the installed, root-owned executable. The
14// ordinary GUI user's writable socket and shell startup files are not trusted
15// to identify a destination for an administrator password.
16func guestGUIProbeCommand(ctx context.Context, profile, administrator, user string, arguments ...string) (*exec.Cmd, error) {
17 args, err := guestos.MacOSSSHArgs(profile, administrator)
18 if err != nil {
19 return nil, err
20 }
21 rootScript := `set -eu
22app='/Applications/Cage Guest Window.app'
23for file in "$app" "$app/Contents" "$app/Contents/MacOS" "$app/Contents/MacOS/CageGuestWindow"; do
24 test ! -L "$file" && test "$(/usr/bin/stat -f %u "$file")" = 0 || exit 72
25 mode=$(/usr/bin/stat -f %Lp "$file")
26 test "$((0$mode & 022))" = 0 || exit 72
27done
28/usr/bin/codesign --verify --strict -R '=identifier "dev.cage.GuestClaudeWindow"' "$app" || exit 72
29uid=$(/usr/bin/id -u ` + shellescape.Quote(user) + `)
30test "$(/usr/bin/stat -f %u /dev/console)" = "$uid" || exit 73
31exec /bin/launchctl asuser "$uid" /usr/bin/sudo -Hu ` + shellescape.Quote(user) + ` /usr/bin/env -i HOME=` + shellescape.Quote("/Users/"+user) + ` PATH=/usr/bin:/bin ` +
32 shellescape.QuoteCommand(append([]string{"/Applications/Cage Guest Window.app/Contents/MacOS/CageGuestWindow"}, arguments...))
33 // An askpass helper keeps SSH stdin available to the probe. Its private
34 // script contains only the existing credential's path, and is removed when
35 // this invocation ends. Credentials remain inside the guest.
36 loginScript := `set -eu
37umask 077
38probe_dir=$(/usr/bin/mktemp -d ` + shellescape.Quote("/Users/"+administrator+"/.cage-probe.XXXXXXXX") + `)
39trap '/bin/rm -f "$probe_dir/askpass"; /bin/rmdir "$probe_dir"' EXIT
40trap 'exit 1' HUP INT TERM
41/usr/bin/printf '%s\n' '#!/bin/sh' ` + shellescape.Quote("exec /bin/cat "+shellescape.Quote("/Users/"+administrator+"/password")) + ` > "$probe_dir/askpass"
42/bin/chmod 700 "$probe_dir/askpass"
43SUDO_ASKPASS="$probe_dir/askpass" /usr/bin/sudo -A -p '' /bin/sh -c ` + shellescape.Quote(rootScript)
44 command := "exec /bin/sh -c " + shellescape.Quote(loginScript)
45 cmd := exec.CommandContext(ctx, "/usr/bin/ssh", append(args, "-T", "cage-macos", "--", command)...)
46 cmd.Env = []string{"PATH=/usr/bin:/bin", "LC_ALL=C"}
47 return cmd, nil
48}