mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
* test(pi): reproduce Windows private registration access failures Use NTFS DACL assertions instead of POSIX mode bits and verify that broadly accessible existing records cannot be read or silently reused. Keep the Unix mode assertion unchanged. * fix(pi): reclaim Windows locks and protect private registration state Anchor stale directories with delete sharing and delete the verified empty Windows directory by handle, keeping inode, lease and racing-owner guards. Create new registration directories with protected owner/SYSTEM DACLs and validate existing owner/access rules without changing their ACLs. Leave Unix permissions and directory-only removal unchanged. * test(pi): capture Windows lock identity before path replacement Windows Lstat lazily fetches file IDs by pathname. Snapshot the stale fixture through its anchored handle and add a matching-mtime replacement regression before first verification or release. * fix(pi): snapshot Windows lock IDs and accept privileged default owners Capture acquired lock identity through a handle before Windows can lazily resolve a replaced pathname. Elevated tokens can default file ownership to Administrators; permit privileged owners only alongside a verified current-user-only DACL. Refuse unsafe existing registration directories without modifying their ACLs or writing records. * docs(pi): record Windows acceptance and isolated regression workflow Document private Windows ACL requirements and refusal without permission rewrites. Add pinned devcontainer kit packaging, token-isolated full/basic acceptance, preserved UTF-8 logs and a reproducible UTM runbook. Preserve the original Unix permission assertion. * test(backup): isolate explicit agent backup from sync snapshots Sync automatically backs up target-local agents. Creating the fixture before sync makes the exact-one-backup assertion depend on both commands sharing a timestamp second. Create it after successful sync so the explicit backup is the only operation that snapshots it, without weakening the assertion.
87 lines
2.8 KiB
Go
87 lines
2.8 KiB
Go
package plugin
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func makePiRegistrationDir(path string) error {
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
|
|
return err
|
|
}
|
|
user, err := windows.GetCurrentProcessToken().GetTokenUser()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// The new directory is private from creation, before any raw entry is written.
|
|
// Never change an existing directory's ACL or its owner's permissions.
|
|
sd, err := windows.SecurityDescriptorFromString("O:" + user.User.Sid.String() + "D:P(A;OICI;FA;;;" + user.User.Sid.String() + ")(A;OICI;FA;;;SY)")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
name, err := windows.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
attrs := windows.SecurityAttributes{SecurityDescriptor: sd}
|
|
attrs.Length = uint32(unsafe.Sizeof(attrs))
|
|
if err := windows.CreateDirectory(name, &attrs); err != nil && err != windows.ERROR_ALREADY_EXISTS {
|
|
return err
|
|
}
|
|
return checkPiRegistrationPrivate(path)
|
|
}
|
|
|
|
func checkPiRegistrationPrivate(path string) error {
|
|
user, err := windows.GetCurrentProcessToken().GetTokenUser()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sd, err := windows.GetNamedSecurityInfo(path, windows.SE_FILE_OBJECT, windows.OWNER_SECURITY_INFORMATION|windows.DACL_SECURITY_INFORMATION)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
owner, _, err := sd.Owner()
|
|
// Elevated Windows tokens can default new files' owner to Administrators.
|
|
// These privileged owners still require an explicit current-user DACL below.
|
|
if err != nil || owner == nil || (!owner.Equals(user.User.Sid) && !owner.IsWellKnown(windows.WinLocalSystemSid) && !owner.IsWellKnown(windows.WinBuiltinAdministratorsSid)) {
|
|
return errors.New("Pi private state belongs to another Windows owner")
|
|
}
|
|
acl, _, err := sd.DACL()
|
|
if err != nil || acl == nil {
|
|
return errors.New("Pi private state has no verifiable Windows DACL")
|
|
}
|
|
ownerAccess := false
|
|
for i := uint32(0); i < uint32(acl.AceCount); i++ {
|
|
var ace *windows.ACCESS_ALLOWED_ACE
|
|
if err := windows.GetAce(acl, i, &ace); err != nil {
|
|
return err
|
|
}
|
|
if ace.Header.AceType == windows.ACCESS_DENIED_ACE_TYPE {
|
|
continue
|
|
}
|
|
if ace.Header.AceType != windows.ACCESS_ALLOWED_ACE_TYPE {
|
|
return errors.New("Pi private state has unsupported Windows access rules")
|
|
}
|
|
sid := (*windows.SID)(unsafe.Pointer(&ace.SidStart))
|
|
if sid.Equals(user.User.Sid) {
|
|
ownerAccess = ownerAccess || ace.Mask != 0
|
|
continue
|
|
}
|
|
// SYSTEM/administrators are privileged principals, like root on Unix.
|
|
if sid.IsWellKnown(windows.WinLocalSystemSid) || sid.IsWellKnown(windows.WinBuiltinAdministratorsSid) {
|
|
continue
|
|
}
|
|
if ace.Mask != 0 {
|
|
return errors.New("Pi private state grants access to other Windows users; preserve it and repair its ACL before retrying")
|
|
}
|
|
}
|
|
if !ownerAccess {
|
|
return errors.New("Pi private state does not grant its Windows owner access")
|
|
}
|
|
return nil
|
|
}
|