| 1 | package provider |
| 2 | |
| 3 | import ( |
| 4 | "crypto/sha256" |
| 5 | "encoding/hex" |
| 6 | "path/filepath" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | // IsolationTarget describes a synthetic marker verified on the host. It never |
| 11 | // carries marker bytes or a credential-file digest. |
| 12 | type IsolationTarget struct { |
| 13 | Name string `json:"name"` |
| 14 | HostPath string `json:"host_path"` |
| 15 | Path string `json:"path"` |
| 16 | SHA256 string `json:"sha256"` |
| 17 | } |
| 18 | |
| 19 | type IsolationResult struct { |
| 20 | Status string `json:"status,omitempty"` |
| 21 | Name string `json:"name"` |
| 22 | Operations map[string]string `json:"operations"` |
| 23 | Safe bool `json:"safe"` |
| 24 | } |
| 25 | |
| 26 | type IsolationReport struct { |
| 27 | ProbeNamespaceManifest string `json:"probe_namespace_manifest"` |
| 28 | Layer string `json:"layer"` |
| 29 | PolicyHash string `json:"policy_hash"` |
| 30 | NamespaceManifest string `json:"namespace_manifest"` |
| 31 | UID int `json:"uid"` |
| 32 | Targets []IsolationResult `json:"targets"` |
| 33 | SideDoors map[string]string `json:"side_doors"` |
| 34 | Safe bool `json:"safe"` |
| 35 | } |
| 36 | |
| 37 | // ProviderHomeTarget names the staged marker and its fixed aliases, never a source home. |
| 38 | func ProviderHomeTarget(name, path string) bool { |
| 39 | marker := filepath.Base(path) |
| 40 | random, err := hex.DecodeString(strings.TrimPrefix(marker, "equipo-read-")) |
| 41 | if err != nil || len(random) != 16 || marker != "equipo-read-"+hex.EncodeToString(random) { |
| 42 | return false |
| 43 | } |
| 44 | return map[string]string{ |
| 45 | "selected-home": "/home/runner/" + marker, |
| 46 | "proc-root": "/proc/1/root/home/runner/" + marker, |
| 47 | "self-root": "/proc/self/root/home/runner/" + marker, |
| 48 | "symlink": "/workspace/equipo-direct-sentinel-alias/" + marker, |
| 49 | }[name] == path |
| 50 | } |
| 51 | |
| 52 | // ManifestDigest is the lower-case hex SHA-256 the runner records for a |
| 53 | // policy manifest, a namespace manifest or a probe marker. |
| 54 | func ManifestDigest(raw []byte) string { |
| 55 | s := sha256.Sum256(raw) |
| 56 | return hex.EncodeToString(s[:]) |
| 57 | } |
| 58 | |