| 1 | // Package denylist is the Mac runners spec §4.2 deny list: what no step |
| 2 | // on a Mac may read or write. It is a leaf (standard library only) so |
| 3 | // both the Mac worker (package mac, for its checks and Engineering |
| 4 | // profiles) and the native permission port (provider/claude, whose |
| 5 | // tests build darwin policies from it) share the one list, although mac |
| 6 | // itself imports provider/claude. |
| 7 | package denylist |
| 8 | |
| 9 | import ( |
| 10 | "path/filepath" |
| 11 | "slices" |
| 12 | ) |
| 13 | |
| 14 | // Paths are the places the §4.2 deny list protects on this machine. |
| 15 | type Paths struct { |
| 16 | // Home is the runner user's home (/Users/equipo-paul). |
| 17 | Home string |
| 18 | // StateDir holds the enrolment key, the steps and the relayed |
| 19 | // objects; AccountsRoot and SessionRoot the model sign-ins. |
| 20 | StateDir, AccountsRoot, SessionRoot string |
| 21 | // InstallDir is where the runner's binaries live (denied writes). |
| 22 | InstallDir string |
| 23 | // OtherHomes are every home under /Users but the runner user's. |
| 24 | OtherHomes []string |
| 25 | // UserTemp is the runner user's DARWIN_USER_TEMP_DIR, resolved and |
| 26 | // checked by UserTemp; "" when it was refused, and UserTempWhy says |
| 27 | // why. No checks profile is made without it: Xcode writes there |
| 28 | // whatever $TMPDIR says. |
| 29 | UserTemp, UserTempWhy string |
| 30 | // HomesUnknown: /Users could not be listed. Every profile then denies |
| 31 | // all of /Users, the runner's own home too, so no checks profile can |
| 32 | // be made (checks cannot run) rather than one that misses a home. |
| 33 | HomesUnknown bool |
| 34 | } |
| 35 | |
| 36 | // DenyList is §4.2: what no step may read or write. |
| 37 | func DenyList(p Paths) []string { |
| 38 | out := []string{p.StateDir, p.AccountsRoot, p.SessionRoot} |
| 39 | for _, rel := range []string{".ssh", ".aws", ".gnupg", ".config/op", "Library/Keychains"} { |
| 40 | out = append(out, filepath.Join(p.Home, rel)) |
| 41 | } |
| 42 | out = append(out, p.OtherHomes...) |
| 43 | if p.HomesUnknown { |
| 44 | out = append(out, "/Users") |
| 45 | } |
| 46 | out = append(out, "/Volumes") |
| 47 | result := []string{} |
| 48 | for _, path := range out { |
| 49 | if path != "" && !slices.Contains(result, path) { |
| 50 | result = append(result, path) |
| 51 | } |
| 52 | } |
| 53 | return result |
| 54 | } |
| 55 | |