| 1 | package runnerproto |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | |
| 6 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 7 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 8 | ) |
| 9 | |
| 10 | type ProcessIdentity struct { |
| 11 | PID int `json:"pid"` |
| 12 | StartTicks uint64 `json:"start_ticks"` |
| 13 | BootID string `json:"boot_id"` |
| 14 | } |
| 15 | type ProcessOwner struct { |
| 16 | LocalOnly bool `json:"local_only"` |
| 17 | Attempt team.AttemptID `json:"attempt"` |
| 18 | Fence int64 `json:"fence"` |
| 19 | Marker string `json:"marker"` |
| 20 | AgentID string `json:"agent_id"` |
| 21 | Workspace provider.Workspace `json:"workspace"` |
| 22 | ExecutorGroups []ProcessIdentity `json:"executor_groups"` |
| 23 | } |
| 24 | type ProcessInventory struct { |
| 25 | Observed []ProcessIdentity `json:"observed"` |
| 26 | ExecutorGroups []ProcessIdentity `json:"executor_groups"` |
| 27 | Processes []ProcessIdentity `json:"processes"` |
| 28 | TerminalIDs []string `json:"terminal_ids"` |
| 29 | CoverageKnown bool `json:"coverage_known"` |
| 30 | BootID string `json:"boot_id"` |
| 31 | CheckedAt time.Time `json:"checked_at"` |
| 32 | } |
| 33 | type ContainmentProof struct { |
| 34 | Unstarted []NamespaceExit `json:"unstarted,omitempty"` |
| 35 | Namespaces []NamespaceExit `json:"namespaces,omitempty"` |
| 36 | CheckedAt time.Time `json:"checked_at,omitempty"` |
| 37 | // Zero identifies a historical proof without a version field. |
| 38 | Version int `json:"version,omitempty"` |
| 39 | Scope team.Scope `json:"scope"` |
| 40 | Handle team.Handle `json:"handle"` |
| 41 | Owner ProcessOwner `json:"owner"` |
| 42 | Inventory ProcessInventory `json:"inventory"` |
| 43 | Observed []ProcessIdentity `json:"observed"` |
| 44 | Empty bool `json:"empty"` |
| 45 | } |
| 46 | |
| 47 | type FreezeRequest struct { |
| 48 | ExpectedSymptom string `json:"expected_symptom"` |
| 49 | DefinitionHash string `json:"definition_hash"` |
| 50 | ReproductionHash string `json:"reproduction_hash"` |
| 51 | } |
| 52 | |
| 53 | // NamespaceExit binds an observed init exit to the durable launch identity. |
| 54 | type NamespaceExit struct { |
| 55 | ID string `json:"id"` |
| 56 | AttemptKey string `json:"attempt_key"` |
| 57 | BootID string `json:"boot_id"` |
| 58 | NamespaceID string `json:"namespace_id"` |
| 59 | ManifestHash string `json:"manifest_hash"` |
| 60 | HostPID int `json:"host_pid"` |
| 61 | StartTicks uint64 `json:"start_ticks"` |
| 62 | ExitCode int `json:"exit_code"` |
| 63 | Signal int `json:"signal"` |
| 64 | ObservedAt time.Time `json:"observed_at"` |
| 65 | } |
| 66 | type NamespaceContainmentProof struct { |
| 67 | Version int `json:"version"` |
| 68 | Scope team.Scope `json:"scope"` |
| 69 | Handle team.Handle `json:"handle"` |
| 70 | Namespaces []NamespaceExit `json:"namespaces"` |
| 71 | CheckedAt time.Time `json:"checked_at"` |
| 72 | } |
| 73 | |
| 74 | // NamespaceLaunch is authenticated runner evidence recorded before releasing init. |
| 75 | type NamespaceLaunch struct { |
| 76 | ID, AttemptKey, OwnerKey, BootID, NamespaceID, ManifestHash, PolicyHash string |
| 77 | HostPID int |
| 78 | StartTicks uint64 |
| 79 | } |
| 80 | |
| 81 | func (n NamespaceLaunch) Valid(owner string) bool { |
| 82 | return n.OwnerKey == owner && n.ID != "" && n.AttemptKey != "" && n.BootID != "" && n.NamespaceID != "" && len(n.ManifestHash) == 64 && len(n.PolicyHash) == 64 && n.HostPID > 0 && n.StartTicks > 0 |
| 83 | } |
| 84 | func (n NamespaceLaunch) Matches(x NamespaceExit) bool { |
| 85 | return n.ID == x.ID && n.AttemptKey == x.AttemptKey && n.BootID == x.BootID && n.NamespaceID == x.NamespaceID && n.ManifestHash == x.ManifestHash && n.HostPID == x.HostPID && n.StartTicks == x.StartTicks && !x.ObservedAt.IsZero() |
| 86 | } |
| 87 | |