package runner import ( "context" "crypto/sha256" "encoding/hex" "errors" "amadan.net/oficina/equipo/internal/release" "amadan.net/oficina/equipo/internal/runner/provider" "amadan.net/oficina/equipo/internal/runnerproto" ) // ownerRoute: this runner's own person, in owner mode, confined, untainted. func ownerRoute(person, runner string, s runnerproto.Selection) bool { return s.Isolation.Mode == "owner mode" && s.Isolation.Status == "confined" && !s.Isolation.RunnerTainted && s.Person != "" && s.Person == person && s.RunnerID != "" && s.RunnerID == runner } // ownerConnectionReport: an owner-mode connection is available only when the // installed programs verify and the coordinator policy builds and preflights. 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) { homeHash := sha256.Sum256([]byte(b.ProviderHome)) 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[:])}} if !installed { report.UnavailableReason = "binary_verification_failed" return report, nil } if err := ctx.Err(); err != nil { return report, err } launch, cleanup, err := construct("coordinate") if err == nil { report.IsolationConfigHash = launch.Policy.Hash if err = preflight(launch); err == nil { report.Available, report.ReadIsolation, report.UnavailableReason = true, true, "" report.Routing.ObservedAccountID = b.AccountID report.Routing.AccountPinned, report.Routing.NoFailover, report.Routing.TimelineRecovery, report.Routing.ProcessOwnership = true, true, true, true } } if cleanup != nil { if e := cleanup(); e != nil { return report, e } } if errors.Is(err, provider.ErrLoginRequired) { report.UnavailableReason = "account.sign_in_again" } else if err != nil { report.UnavailableReason = "preflight_failed" } return report, nil }