| 1 | package runner |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "crypto/sha256" |
| 6 | "encoding/hex" |
| 7 | "errors" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/release" |
| 10 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 11 | "amadan.net/oficina/equipo/internal/runnerproto" |
| 12 | ) |
| 13 | |
| 14 | // ownerRoute: this runner's own person, in owner mode, confined, untainted. |
| 15 | func ownerRoute(person, runner string, s runnerproto.Selection) bool { |
| 16 | return s.Isolation.Mode == "owner mode" && s.Isolation.Status == "confined" && !s.Isolation.RunnerTainted && s.Person != "" && s.Person == person && s.RunnerID != "" && s.RunnerID == runner |
| 17 | } |
| 18 | |
| 19 | // ownerConnectionReport: an owner-mode connection is available only when the |
| 20 | // installed programs verify and the coordinator policy builds and preflights. |
| 21 | func ownerConnectionReport(ctx context.Context, b AccountBinding, m release.Manifest, installed bool, construct func(string) (provider.Launch, func() error, error), preflight func(provider.Launch) error) (runnerproto.ConnectionReport, error) { |
| 22 | homeHash := sha256.Sum256([]byte(b.ProviderHome)) |
| 23 | report := runnerproto.ConnectionReport{OwnerMode: true, AccountLabel: b.Label, LocalID: b.LocalID, Provider: b.Provider, Family: b.Family, Model: b.Model, Kind: b.Kind, ProviderVersion: b.ExpectedIdentity.ProviderVersion, LauncherVersion: m.LauncherVersion, BwrapVersion: m.BwrapVersion, PolicyVersion: m.PolicyVersion, ProviderVersionSource: "direct-cli", UnavailableReason: "capability_unverified", IsolationConfigHash: runnerproto.EventHash(b), Routing: runnerproto.ConnectionRouting{BindingID: b.ID, AccountID: b.AccountID, CredentialHomeHash: hex.EncodeToString(homeHash[:])}} |
| 24 | if !installed { |
| 25 | report.UnavailableReason = "binary_verification_failed" |
| 26 | return report, nil |
| 27 | } |
| 28 | if err := ctx.Err(); err != nil { |
| 29 | return report, err |
| 30 | } |
| 31 | launch, cleanup, err := construct("coordinate") |
| 32 | if err == nil { |
| 33 | report.IsolationConfigHash = launch.Policy.Hash |
| 34 | if err = preflight(launch); err == nil { |
| 35 | report.Available, report.ReadIsolation, report.UnavailableReason = true, true, "" |
| 36 | report.Routing.ObservedAccountID = b.AccountID |
| 37 | report.Routing.AccountPinned, report.Routing.NoFailover, report.Routing.TimelineRecovery, report.Routing.ProcessOwnership = true, true, true, true |
| 38 | } |
| 39 | } |
| 40 | if cleanup != nil { |
| 41 | if e := cleanup(); e != nil { |
| 42 | return report, e |
| 43 | } |
| 44 | } |
| 45 | if errors.Is(err, provider.ErrLoginRequired) { |
| 46 | report.UnavailableReason = "account.sign_in_again" |
| 47 | } else if err != nil { |
| 48 | report.UnavailableReason = "preflight_failed" |
| 49 | } |
| 50 | return report, nil |
| 51 | } |
| 52 | |