跳到主要内容

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

提交记录
修改internal/guestos/windows_host_enrollment_native_windows_test.go+19 −4看文件
@@ -34,9 +34,24 @@ func TestWindowsHostEnrollmentOrdinaryUser(t *testing.T) {
3434 t.Fatalf("build enrollment helper: %v\n%s", err, output)
3535 }
3636 }
37新增: runWindowsOrdinaryUserPowerShell(t, filepath.Join(root, "scripts", "guest-os", "windows-host-enrollment-smoke.ps1"), "-ManagerExecutable", manager)
38新增:}
39新增:
40新增:func TestWindowsUserToolACLOrdinaryUser(t *testing.T) {
41新增: script, err := filepath.Abs(filepath.Join("..", "..", "scripts", "guest-os", "windows-user-tools-acl.tests.ps1"))
42新增: if err != nil {
43新增: t.Fatal(err)
44新增: }
45新增: runWindowsOrdinaryUserPowerShell(t, script)
46新增:}
47新增:
48新增:func runWindowsOrdinaryUserPowerShell(t *testing.T, script string, arguments ...string) {
49新增: t.Helper()
50新增: ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
51新增: defer cancel()
3752 shell := filepath.Join(os.Getenv("SystemRoot"), "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
38删除: cmd := exec.CommandContext(ctx, shell, "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass",
39删除: "-File", filepath.Join(root, "scripts", "guest-os", "windows-host-enrollment-smoke.ps1"), "-ManagerExecutable", manager)
53新增: flags := append([]string{"-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", script}, arguments...)
54新增: cmd := exec.CommandContext(ctx, shell, flags...)
4055 if windows.GetCurrentProcessToken().IsElevated() {
4156 var token windows.Token
4257 if err := windows.OpenProcessToken(windows.CurrentProcess(), windows.TOKEN_DUPLICATE|windows.TOKEN_QUERY|windows.TOKEN_ASSIGN_PRIMARY|windows.TOKEN_ADJUST_DEFAULT, &token); err != nil {
@@ -85,11 +100,11 @@ func TestWindowsHostEnrollmentOrdinaryUser(t *testing.T) {
85100 defer ordinary.Close()
86101 }
87102 if ordinary.IsElevated() {
88删除: t.Fatal("the enrollment regression requires an unelevated token")
103新增: t.Fatal("the native regression requires an unelevated token")
89104 }
90105 cmd.SysProcAttr = &syscall.SysProcAttr{Token: syscall.Token(ordinary)}
91106 }
92107 if output, err := cmd.CombinedOutput(); err != nil {
93删除: t.Fatalf("ordinary-user enrollment: %v\n%s", err, output)
108新增: t.Fatalf("ordinary-user PowerShell %s: %v\n%s", filepath.Base(script), err, output)
94109 }
95110}
修改scripts/ci-windows-build.ps1+1 −1看文件
@@ -65,7 +65,7 @@ try {
6565 foreach ($test in @('windows-iso-setup.tests.ps1', 'windows-host-image.tests.ps1', 'new-windows-test-vm.tests.ps1')) {
6666 Invoke-BuildTool $windowsPowerShell @('-NoProfile', '-NonInteractive', '-File', "scripts/guest-os/$test")
6767 }
68删除: Invoke-BuildTool 'go' @('test', './internal/guestos', '-run', '^TestWindowsHostEnrollment', '-count=1')
68新增: Invoke-BuildTool 'go' @('test', './internal/guestos', '-run', '^TestWindows(HostEnrollment|UserToolACL)', '-count=1')
6969 if (-not $Release) {
7070 $windowsPowerShell = Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell/v1.0/powershell.exe'
7171 foreach ($test in @('install-guest-powershell.tests.ps1', 'windows-evaluation.tests.ps1')) {
修改scripts/guest-os/guest-clipboard-windows/install-ccs.ps1+17 −3看文件
@@ -20,14 +20,28 @@ function Assert-NoReparse([string]$Path) {
2020 while ($null -ne $item) { if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw 'A native CCS path is a reparse point.' }; if ($item -is [IO.FileInfo]) { $item=$item.Directory } else { $item=$item.Parent } }
2121}
2222function Protect-Path([string]$Path,[bool]$Directory) {
23删除: if ($Directory) { $acl=New-Object Security.AccessControl.DirectorySecurity } else { $acl=New-Object Security.AccessControl.FileSecurity }
24删除: $acl.SetOwner($user.User);$acl.SetAccessRuleProtection($true,$false)
23新增: $ownerSection = [Security.AccessControl.AccessControlSections]::Owner
24新增: $accessSection = [Security.AccessControl.AccessControlSections]::Access
25新增: if ($Directory) {
26新增: $existing = [Security.AccessControl.DirectorySecurity]::new($Path, $ownerSection)
27新增: $acl = New-Object Security.AccessControl.DirectorySecurity
28新增: } else {
29新增: $existing = [Security.AccessControl.FileSecurity]::new($Path, $ownerSection)
30新增: $acl = New-Object Security.AccessControl.FileSecurity
31新增: }
32新增: if ($existing.GetOwner([Security.Principal.SecurityIdentifier]) -ne $user.User) { throw 'The Cage tool path must already belong to the current GUI user.' }
33新增: $acl.SetAccessRuleProtection($true,$false)
2534 foreach ($sid in @($user.User,[Security.Principal.SecurityIdentifier]'S-1-5-18',[Security.Principal.SecurityIdentifier]'S-1-5-32-544')) {
2635 if ($Directory) { $rule=New-Object Security.AccessControl.FileSystemAccessRule($sid,'FullControl','ContainerInherit,ObjectInherit','None','Allow') }
2736 else { $rule=New-Object Security.AccessControl.FileSystemAccessRule($sid,'FullControl','Allow') }
2837 $acl.AddAccessRule($rule)
2938 }
30删除: Set-Acl -LiteralPath $Path -AclObject $acl
39新增: # Change only Access on a descriptor loaded without Audit. Set-Acl can
40新增: # request SeSecurityPrivilege when persisting a newly built descriptor.
41新增: $existing.SetSecurityDescriptorSddlForm($acl.GetSecurityDescriptorSddlForm($accessSection), $accessSection)
42新增: $item = Get-Item -LiteralPath $Path -Force
43新增: if ($PSVersionTable.PSEdition -eq 'Desktop') { $item.SetAccessControl($existing) }
44新增: else { [IO.FileSystemAclExtensions]::SetAccessControl($item, $existing) }
3145}
3246function PrivateDirectory([string]$Path) {
3347 $parent=[IO.DirectoryInfo]$Path
修改scripts/guest-os/guest-clipboard-windows/install-cli.ps1+17 −3看文件
@@ -24,14 +24,28 @@ function Assert-NoReparse([string]$Path) {
2424 }
2525}
2626function Protect-Path([string]$Path, [bool]$Directory) {
27删除: if ($Directory) { $acl = New-Object Security.AccessControl.DirectorySecurity } else { $acl = New-Object Security.AccessControl.FileSecurity }
28删除: $acl.SetOwner($user.User); $acl.SetAccessRuleProtection($true, $false)
27新增: $ownerSection = [Security.AccessControl.AccessControlSections]::Owner
28新增: $accessSection = [Security.AccessControl.AccessControlSections]::Access
29新增: if ($Directory) {
30新增: $existing = [Security.AccessControl.DirectorySecurity]::new($Path, $ownerSection)
31新增: $acl = New-Object Security.AccessControl.DirectorySecurity
32新增: } else {
33新增: $existing = [Security.AccessControl.FileSecurity]::new($Path, $ownerSection)
34新增: $acl = New-Object Security.AccessControl.FileSecurity
35新增: }
36新增: if ($existing.GetOwner([Security.Principal.SecurityIdentifier]) -ne $user.User) { throw 'The Cage tool path must already belong to the current GUI user.' }
37新增: $acl.SetAccessRuleProtection($true, $false)
2938 foreach ($sid in @($user.User, [Security.Principal.SecurityIdentifier]'S-1-5-18', [Security.Principal.SecurityIdentifier]'S-1-5-32-544')) {
3039 if ($Directory) { $rule = New-Object Security.AccessControl.FileSystemAccessRule($sid,'FullControl','ContainerInherit,ObjectInherit','None','Allow') }
3140 else { $rule = New-Object Security.AccessControl.FileSystemAccessRule($sid,'FullControl','Allow') }
3241 $acl.AddAccessRule($rule)
3342 }
34删除: Set-Acl -LiteralPath $Path -AclObject $acl
43新增: # Change only Access on a descriptor loaded without Audit. Set-Acl can
44新增: # request SeSecurityPrivilege when persisting a newly built descriptor.
45新增: $existing.SetSecurityDescriptorSddlForm($acl.GetSecurityDescriptorSddlForm($accessSection), $accessSection)
46新增: $item = Get-Item -LiteralPath $Path -Force
47新增: if ($PSVersionTable.PSEdition -eq 'Desktop') { $item.SetAccessControl($existing) }
48新增: else { [IO.FileSystemAclExtensions]::SetAccessControl($item, $existing) }
3549}
3650function New-PrivateDirectory([string]$Path) {
3751 $parent = [IO.DirectoryInfo]$Path
新增scripts/guest-os/windows-user-tools-acl.tests.ps1+81 −0看文件
@@ -0,0 +1,81 @@
1新增:#requires -Version 5.1
2新增:$ErrorActionPreference = 'Stop'
3新增:Set-StrictMode -Version Latest
4新增:$installers = @('install-cli.ps1', 'install-ccs.ps1')
5新增:$functions = @{}
6新增:foreach ($name in $installers) {
7新增: $errors = $null
8新增: $ast = [Management.Automation.Language.Parser]::ParseFile((Join-Path $PSScriptRoot ('guest-clipboard-windows/'+$name)), [ref]$null, [ref]$errors)
9新增: if ($errors.Count) { throw $errors[0] }
10新增: $protect = $ast.Find({ param($node) $node -is [Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq 'Protect-Path' }, $true)
11新增: $wideWrite = $protect.Find({
12新增: param($node)
13新增: ($node -is [Management.Automation.Language.CommandAst] -and $node.GetCommandName() -eq 'Set-Acl') -or
14新增: ($node -is [Management.Automation.Language.InvokeMemberExpressionAst] -and $node.Member.Value -in @('SetOwner','SetGroup','SetAuditRule','SetAuditRuleProtection'))
15新增: }, $true)
16新增: if ($wideWrite) { throw "$name must persist only DACL changes for the ordinary GUI user." }
17新增: $functions[$name] = $ast.FindAll({ param($node) $node -is [Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -in @('Assert-NoReparse','Protect-Path','New-PrivateDirectory','PrivateDirectory') }, $true)
18新增:}
19新增:if ([Environment]::OSVersion.Platform -ne 'Win32NT') {
20新增: Write-Output 'Parsed both installers and checked the DACL-only write contract. Native ACL fixtures require Windows.'
21新增: return
22新增:}
23新增:$user = [Security.Principal.WindowsIdentity]::GetCurrent()
24新增:if ([Security.Principal.WindowsPrincipal]::new($user).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Run the ACL fixtures as an ordinary user.' }
25新增:$privileges = & (Join-Path ([Environment]::SystemDirectory) 'whoami.exe') /priv /fo csv /nh | ConvertFrom-Csv -Header Name,Description,State
26新增:if ($LASTEXITCODE -ne 0 -or @($privileges | Where-Object Name -eq 'SeSecurityPrivilege').Count) { throw 'The ACL fixtures require a token without SeSecurityPrivilege.' }
27新增:$readSections = [Security.AccessControl.AccessControlSections]::Owner -bor [Security.AccessControl.AccessControlSections]::Group -bor [Security.AccessControl.AccessControlSections]::Access
28新增:function Read-TestSecurity([string]$Path, [bool]$Directory) {
29新增: if ($Directory) { return [Security.AccessControl.DirectorySecurity]::new($Path, $readSections) }
30新增: return [Security.AccessControl.FileSecurity]::new($Path, $readSections)
31新增:}
32新增:function Check-PrivateAccess($Before, $After, [bool]$Directory) {
33新增: $sidType = [Security.Principal.SecurityIdentifier]
34新增: if ($Before.GetOwner($sidType) -ne $After.GetOwner($sidType) -or $Before.GetGroup($sidType) -ne $After.GetGroup($sidType)) { throw 'Owner or group changed.' }
35新增: $expected = @($user.User.Value, 'S-1-5-18', 'S-1-5-32-544')
36新增: $rules = @($After.GetAccessRules($true, $true, $sidType))
37新增: if (!$After.AreAccessRulesProtected -or $rules.Count -ne 3) { throw 'The private DACL has the wrong protection or rule count.' }
38新增: if ((@($rules.IdentityReference.Value | Sort-Object) -join ',') -cne (@($expected | Sort-Object) -join ',')) { throw 'The private DACL has the wrong principals.' }
39新增: $inheritance = if ($Directory) { [Security.AccessControl.InheritanceFlags]'ContainerInherit,ObjectInherit' } else { [Security.AccessControl.InheritanceFlags]::None }
40新增: foreach ($rule in $rules) {
41新增: if ($rule.IsInherited -or $rule.FileSystemRights -ne [Security.AccessControl.FileSystemRights]::FullControl -or
42新增: $rule.AccessControlType -ne 'Allow' -or $rule.InheritanceFlags -ne $inheritance -or $rule.PropagationFlags -ne 'None') { throw 'The private DACL changed its access or inheritance contract.' }
43新增: }
44新增:}
45新增:$root = Join-Path ([IO.Path]::GetTempPath()) ('cage-user-tools-acl-'+[guid]::NewGuid().ToString('N'))
46新增:$null = [IO.Directory]::CreateDirectory($root)
47新增:try {
48新增: foreach ($name in $installers) {
49新增: foreach ($definition in $functions[$name]) { . ([scriptblock]::Create($definition.Extent.Text)) }
50新增: $directory = Join-Path $root ($name+' tools')
51新增: $null = [IO.Directory]::CreateDirectory($directory)
52新增: $before = Read-TestSecurity $directory $true
53新增: if ($name -eq 'install-cli.ps1') { New-PrivateDirectory $directory } else { PrivateDirectory $directory }
54新增: Check-PrivateAccess $before (Read-TestSecurity $directory $true) $true
55新增: # A fresh child inherits all three directory rules before its own
56新增: # explicit protection. Its content represents a retained install receipt.
57新增: $file = Join-Path $directory 'retained receipt.json'
58新增: [IO.File]::WriteAllText($file, 'existing fixture contents')
59新增: $before = Read-TestSecurity $file $false
60新增: $inherited = @($before.GetAccessRules($true, $true, [Security.Principal.SecurityIdentifier]))
61新增: if ($inherited.Count -ne 3 -or @($inherited | Where-Object { !$_.IsInherited }).Count) { throw 'New files did not inherit the protected directory rules.' }
62新增: Protect-Path $file $false
63新增: Check-PrivateAccess $before (Read-TestSecurity $file $false) $false
64新增: foreach ($entry in @(@($directory,$true), @($file,$false))) {
65新增: $before = Read-TestSecurity $entry[0] $entry[1]
66新增: Protect-Path $entry[0] $entry[1]
67新增: $after = Read-TestSecurity $entry[0] $entry[1]
68新增: if ($before.GetSecurityDescriptorSddlForm($readSections) -cne $after.GetSecurityDescriptorSddlForm($readSections)) { throw 'Retry changed existing security metadata.' }
69新增: $actualUser = $user
70新增: try {
71新增: $user = @{ User = [Security.Principal.SecurityIdentifier]::new('S-1-5-21-111-222-333-1001') }
72新增: try { Protect-Path $entry[0] $entry[1]; throw 'Wrong owner accepted' }
73新增: catch { if ($_.Exception.Message -notlike '*must already belong to the current GUI user*') { throw } }
74新增: } finally { $user = $actualUser }
75新增: $after = Read-TestSecurity $entry[0] $entry[1]
76新增: if ($before.GetSecurityDescriptorSddlForm($readSections) -cne $after.GetSecurityDescriptorSddlForm($readSections)) { throw 'Owner rejection changed security metadata.' }
77新增: }
78新增: if ([IO.File]::ReadAllText($file) -cne 'existing fixture contents') { throw 'Protection changed existing file contents.' }
79新增: }
80新增: Write-Output 'Passed ordinary-user CLI/CCS directory and file DACLs, inherited children, owner/group preservation, retries and owner rejection.'
81新增:} finally { [IO.Directory]::Delete($root, $true) }