oficina / equipo Public

fix: identify runner configuration failures without exposing secrets

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 61d010feed6a388d623d7f8492e7f821aa7ed4f5 parent b79f0ab
9 files changed, +184 −20
  • cmd/equipo-runner/main.go +11 −6
  • cmd/equipo-runner/main_test.go +8 −0
  • docs/live-gate.md +42 −4
  • internal/equipo/copy.go +3 −0
  • internal/runner/config.go +17 −9
  • internal/runner/diagnostics.go +64 −0
  • internal/runner/enrol.go +4 −1
  • internal/runner/final_diagnostics_test.go +27 −0
  • internal/runner/runtime.go +8 −0
diff --git a/cmd/equipo-runner/main.go b/cmd/equipo-runner/main.go
index 6668f8ba..86946212 100644
--- a/cmd/equipo-runner/main.go
+++ b/cmd/equipo-runner/main.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
+ "fmt"
"io"
"os"
"os/signal"
@@ -16,16 +17,20 @@ import (
)
func run(ctx context.Context, args []string, input io.Reader, output, errorOutput io.Writer, getenv func(string) string) int {
- fail := func() int { _, _ = io.WriteString(errorOutput, equipo.CopyRunnerUnavailable+"\n"); return 1 }
+ fail := func(err error) int {
+ code, variable := runner.Diagnostic(err)
+ _, _ = fmt.Fprintf(errorOutput, equipo.CopyRunnerDiagnostic, code, variable)
+ return 1
+ }
if len(args) != 1 {
- return fail()
+ return fail(nil)
}
if args[0] == "version" {
if json.NewEncoder(output).Encode(struct {
Version string `json:"version"`
Manifest release.Manifest `json:"manifest"`
}{rastrillo.BuildVersion, release.BuildManifest()}) != nil {
- return fail()
+ return fail(nil)
}
return 0
}
@@ -37,11 +42,11 @@ func run(ctx context.Context, args []string, input io.Reader, output, errorOutpu
return 0
}
if args[0] != "run" && args[0] != "enrol" && args[0] != "preflight" && args[0] != "reset" {
- return fail()
+ return fail(nil)
}
cfg, err := runner.LoadConfig(getenv)
if err != nil {
- return fail()
+ return fail(err)
}
cfg.Copy = equipo.RunnerToolCopy()
switch args[0] {
@@ -59,7 +64,7 @@ func run(ctx context.Context, args []string, input io.Reader, output, errorOutpu
}
}
if err != nil && !errors.Is(err, context.Canceled) {
- return fail()
+ return fail(err)
}
return 0
}
diff --git a/cmd/equipo-runner/main_test.go b/cmd/equipo-runner/main_test.go
index c144f282..fd002ab3 100644
--- a/cmd/equipo-runner/main_test.go
+++ b/cmd/equipo-runner/main_test.go
@@ -28,3 +28,11 @@ func TestRunnerServiceVerbs(t *testing.T) {
t.Fatal("version unavailable")
}
}
+
+func TestRunnerDiagnosticIsCredentialFree(t *testing.T) {
+ var out, log bytes.Buffer
+ code := run(context.Background(), []string{"run"}, strings.NewReader(""), &out, &log, func(string) string { return "https://user:secret@example.com" })
+ if code != 1 || !strings.Contains(log.String(), "EQUIPO_ORIGIN") || !strings.Contains(log.String(), "runner.config.origin") || strings.Contains(log.String(), "secret") {
+ t.Fatal("missing or unsafe diagnostic", log.String())
+ }
+}
diff --git a/docs/live-gate.md b/docs/live-gate.md
index d148c73d..41425c6c 100644
--- a/docs/live-gate.md
+++ b/docs/live-gate.md
@@ -41,10 +41,8 @@ attempting acceptance. A failed or skipped test supplies no verified tuple.
5. Copy the versioned runner bundle to `~/.local/lib/equipo-runner/`. Put the
bundled service at `~/.config/systemd/user/equipo-runner.service`. Create
`~/.config/equipo-runner/runner.env` with mode 0600. Use absolute canonical
- paths for every path in `internal/runner/config.go`: runner state, Paseo
- home, Node, bridge, Amadan credential, account bindings, Codex, Go root and
- binary, workspace, scratch, Git and runner executable. Set the instance
- identity and observed Paseo server identity. The endpoint is loopback only.
+ paths from the runner environment table below. Set the instance identity
+ and observed Paseo server identity. The endpoint is loopback only.
State is mode 0700; credentials and bindings are mode 0600. Use disk-backed
scratch. Keep provider credentials out of workspaces.
6. Run the installed `equipo-runner enrol` yourself with that environment.
@@ -166,3 +164,43 @@ uncontained attempts remain. If it fails, keep the service stopped and resolve t
reported cause before trying again. Do not delete the journal or edit its block
flag. After a successful reset, restart the user service. New turns still require
fresh authority and timeline recovery.
+
+
+## Runner environment
+
+All these settings are required for run, enrol, preflight and reset. Examples use
+an operator account named runner. Replace its paths and the observed identities
+with your own values. Diagnostics print a reason code and variable name, never its
+value. `runner.config.path` means the path must be absolute and canonical;
+`runner.config.overlap` means it overlaps the private state directory.
+
+| Variable | Meaning | Example |
+| --- | --- | --- |
+| EQUIPO_ORIGIN | Instance origin, HTTPS except local loopback fixtures | https://equipo.example |
+| EQUIPO_INSTANCE_ID | Enrolled instance identity | equipo-team |
+| EQUIPO_RUNNER_STATE_DIR | Private journal, keys and credentials directory, mode 0700 | /home/runner/.local/state/equipo |
+| EQUIPO_PASEO_HOME | Existing Paseo daemon home | /home/runner/.paseo |
+| EQUIPO_PASEO_ENDPOINT | Loopback daemon host and port | 127.0.0.1:6773 |
+| EQUIPO_PASEO_SERVER_ID | Observed daemon identity | observed-server-id |
+| EQUIPO_NODE_PATH | Pinned Node executable | /home/runner/.local/bin/node |
+| EQUIPO_BRIDGE_PATH | Bridge from the versioned runner bundle | /home/runner/.local/lib/equipo-runner/paseo/bridge.mjs |
+| EQUIPO_ACCOUNT_BINDINGS_PATH | Private JSON account binding file, mode 0600 | /home/runner/.config/equipo-runner/bindings.json |
+| EQUIPO_AMADAN_CREDENTIAL_PATH | Private forge credential file, mode 0600 | /home/runner/.config/equipo-runner/forge.json |
+| EQUIPO_CODEX_PATH | Pinned Codex command sandbox executable | /home/runner/.local/bin/codex |
+| EQUIPO_GO_ROOT | Pinned Go installation | /home/runner/.local/go-dist |
+| EQUIPO_GO_BINARY | Go executable inside that installation | /home/runner/.local/go-dist/bin/go |
+| EQUIPO_WORKSPACE_ROOT | Disposable checkout directory outside private state | /home/runner/equipo-work |
+| EQUIPO_SCRATCH_ROOT | On-disk scratch directory outside private state | /home/runner/.cache/equipo-scratch |
+| EQUIPO_GIT_PATH | Git executable | /usr/bin/git |
+| EQUIPO_RUNNER_EXECUTABLE | Runner from the versioned bundle | /home/runner/.local/lib/equipo-runner/equipo-runner |
+
+The runner supplies the following variables to its children. Do not set them in
+runner.env or reuse values from a previous attempt.
+
+| Variable | Meaning | Example shape |
+| --- | --- | --- |
+| EQUIPO_TOOL_SOCKET | Private attempt tool socket | /private-attempt/tool.sock |
+| EQUIPO_TOOL_CAPABILITY_FILE | Private attempt capability file | /private-attempt/capability.json |
+| EQUIPO_ATTEMPT | Tool process attempt identifier | opaque-attempt-id |
+| EQUIPO_ATTEMPT_MARKER | Process ownership marker for an attempt | opaque-attempt-hash |
+| EQUIPO_COMMAND_MARKER | Process ownership marker for a check command | opaque-command-id |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index 95ee67bf..6a22dd4e 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -413,3 +413,6 @@ const CopyRunnerUnavailable = "The runner could not start. Check its local confi
// COPY REVIEW REQUIRED: Task 17 execution reconciliation diagnostic.
const CopyExecutionReconcile = "Execution recovery could not finish."
+
+// COPY REVIEW REQUIRED: credential-free runner diagnostic.
+const CopyRunnerDiagnostic = "Runner error %s at %s.\n"
diff --git a/internal/runner/config.go b/internal/runner/config.go
index 917ef82c..e3bc111b 100644
--- a/internal/runner/config.go
+++ b/internal/runner/config.go
@@ -31,25 +31,33 @@ func validOrigin(origin string) bool {
return err == nil && u.Host != "" && u.User == nil && u.Path == "" && u.RawQuery == "" && !u.ForceQuery && u.Fragment == "" && !strings.Contains(origin, "#") && (u.Scheme == "https" || (u.Scheme == "http" && u.Hostname() == "127.0.0.1"))
}
func (c Config) validate() error {
- if !validOrigin(c.Origin) || c.InstanceID == "" || c.PaseoServerID == "" {
- return paseo.ErrContract
+ if !validOrigin(c.Origin) {
+ return configIssue("runner.config.origin", "EQUIPO_ORIGIN", paseo.ErrContract)
+ }
+ for _, v := range []struct{ name, value string }{{"EQUIPO_INSTANCE_ID", c.InstanceID}, {"EQUIPO_PASEO_SERVER_ID", c.PaseoServerID}} {
+ if v.value == "" {
+ return configIssue("runner.config.missing", v.name, paseo.ErrContract)
+ }
}
host, port, err := net.SplitHostPort(c.PaseoEndpoint)
if err != nil || host != "127.0.0.1" || port == "" {
- return paseo.ErrContract
+ return configIssue("runner.config.endpoint", "EQUIPO_PASEO_ENDPOINT", paseo.ErrContract)
}
- for _, p := range []string{c.StateDir, c.PaseoHome, c.NodePath, c.BridgePath, c.AmadanCredentialPath, c.AccountBindingsPath, c.CodexPath, c.GoRoot, c.GoBinary, c.WorkspaceRoot, c.ScratchRoot, c.GitPath, c.Executable} {
- if !filepath.IsAbs(p) || filepath.Clean(p) != p || p == "/" {
- return paseo.ErrContract
+ for _, v := range []struct{ name, path string }{
+ {"EQUIPO_RUNNER_STATE_DIR", c.StateDir}, {"EQUIPO_PASEO_HOME", c.PaseoHome}, {"EQUIPO_NODE_PATH", c.NodePath}, {"EQUIPO_BRIDGE_PATH", c.BridgePath}, {"EQUIPO_AMADAN_CREDENTIAL_PATH", c.AmadanCredentialPath}, {"EQUIPO_ACCOUNT_BINDINGS_PATH", c.AccountBindingsPath}, {"EQUIPO_CODEX_PATH", c.CodexPath}, {"EQUIPO_GO_ROOT", c.GoRoot}, {"EQUIPO_GO_BINARY", c.GoBinary}, {"EQUIPO_WORKSPACE_ROOT", c.WorkspaceRoot}, {"EQUIPO_SCRATCH_ROOT", c.ScratchRoot}, {"EQUIPO_GIT_PATH", c.GitPath}, {"EQUIPO_RUNNER_EXECUTABLE", c.Executable},
+ } {
+ if !filepath.IsAbs(v.path) || filepath.Clean(v.path) != v.path || v.path == "/" {
+ return configIssue("runner.config.path", v.name, paseo.ErrContract)
}
}
- for _, p := range []string{c.WorkspaceRoot, c.ScratchRoot, c.PaseoHome} {
- if containsPath(c.StateDir, p) || containsPath(p, c.StateDir) {
- return paseo.ErrPolicy
+ for _, v := range []struct{ name, path string }{{"EQUIPO_WORKSPACE_ROOT", c.WorkspaceRoot}, {"EQUIPO_SCRATCH_ROOT", c.ScratchRoot}, {"EQUIPO_PASEO_HOME", c.PaseoHome}} {
+ if containsPath(c.StateDir, v.path) || containsPath(v.path, c.StateDir) {
+ return configIssue("runner.config.overlap", v.name, paseo.ErrPolicy)
}
}
return nil
}
+
func containsPath(root, path string) bool {
r, err := filepath.Rel(root, path)
return err == nil && (r == "." || r != ".." && !strings.HasPrefix(r, "../"))
diff --git a/internal/runner/diagnostics.go b/internal/runner/diagnostics.go
new file mode 100644
index 00000000..9252d36e
--- /dev/null
+++ b/internal/runner/diagnostics.go
@@ -0,0 +1,64 @@
+package runner
+
+import (
+ "amadan.net/oficina/equipo/internal/runner/paseo"
+ "context"
+ "errors"
+ "net"
+ "os"
+)
+
+type diagnosticError struct {
+ code, variable string
+ cause error
+}
+
+func (e *diagnosticError) Error() string { return e.code + ":" + e.variable }
+func (e *diagnosticError) Unwrap() error { return e.cause }
+func configIssue(code, variable string, cause error) error {
+ return &diagnosticError{code, variable, cause}
+}
+func diagnosticAt(err error, variable string) error {
+ if err == nil {
+ return nil
+ }
+ var known *diagnosticError
+ if errors.As(err, &known) {
+ return err
+ }
+ code, _ := Diagnostic(err)
+ return &diagnosticError{code, variable, err}
+}
+
+// Diagnostic returns only fixed codes and variable names, never error details.
+func Diagnostic(err error) (string, string) {
+ var known *diagnosticError
+ if errors.As(err, &known) {
+ return known.code, known.variable
+ }
+ var network net.Error
+ code := "runner.unavailable"
+ switch {
+ case err == nil:
+ code = "runner.command"
+ case errors.Is(err, os.ErrNotExist):
+ code = "runner.file_missing"
+ case errors.Is(err, os.ErrPermission):
+ code = "runner.file_permission"
+ case errors.Is(err, context.Canceled):
+ code = "runner.cancelled"
+ case errors.Is(err, context.DeadlineExceeded):
+ code = "runner.timeout"
+ case errors.As(err, &network):
+ code = "runner.network"
+ case errors.Is(err, paseo.ErrIdentity):
+ code = "runner.identity"
+ case errors.Is(err, paseo.ErrPolicy), errors.Is(err, paseo.ErrIsolation):
+ code = "runner.policy"
+ case errors.Is(err, paseo.ErrCapability), errors.Is(err, paseo.ErrContract):
+ code = "runner.contract"
+ case errors.Is(err, ErrJournal):
+ code = "runner.reconcile"
+ }
+ return code, "-"
+}
diff --git a/internal/runner/enrol.go b/internal/runner/enrol.go
index 8a618a94..8f7cd773 100644
--- a/internal/runner/enrol.go
+++ b/internal/runner/enrol.go
@@ -20,7 +20,9 @@ import (
func outboundClient() *http.Client {
return &http.Client{Timeout: 35 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
}
-func Enrol(ctx context.Context, c Config, output io.Writer) error {
+func Enrol(ctx context.Context, c Config, output io.Writer) (resultErr error) {
+ variable := "EQUIPO_RUNNER_STATE_DIR"
+ defer func() { resultErr = diagnosticAt(resultErr, variable) }()
if err := c.validate(); err != nil {
return err
}
@@ -81,6 +83,7 @@ func Enrol(ctx context.Context, c Config, output io.Writer) error {
if err != nil || len(key) != ed25519.PrivateKeySize {
return paseo.ErrIdentity
}
+ variable = "EQUIPO_ORIGIN"
client := outboundClient()
post := func(path string, in, out any) (int, error) {
raw, err := runnerproto.Marshal(in)
diff --git a/internal/runner/final_diagnostics_test.go b/internal/runner/final_diagnostics_test.go
new file mode 100644
index 00000000..e6b9eab4
--- /dev/null
+++ b/internal/runner/final_diagnostics_test.go
@@ -0,0 +1,27 @@
+package runner
+
+import (
+ "reflect"
+ "strings"
+ "testing"
+)
+
+func TestConfigDiagnosticNamesVariable(t *testing.T) {
+ vars := map[string]string{"Origin": "EQUIPO_ORIGIN", "InstanceID": "EQUIPO_INSTANCE_ID", "PaseoServerID": "EQUIPO_PASEO_SERVER_ID", "PaseoEndpoint": "EQUIPO_PASEO_ENDPOINT", "StateDir": "EQUIPO_RUNNER_STATE_DIR", "PaseoHome": "EQUIPO_PASEO_HOME", "NodePath": "EQUIPO_NODE_PATH", "BridgePath": "EQUIPO_BRIDGE_PATH", "AmadanCredentialPath": "EQUIPO_AMADAN_CREDENTIAL_PATH", "AccountBindingsPath": "EQUIPO_ACCOUNT_BINDINGS_PATH", "CodexPath": "EQUIPO_CODEX_PATH", "GoRoot": "EQUIPO_GO_ROOT", "GoBinary": "EQUIPO_GO_BINARY", "WorkspaceRoot": "EQUIPO_WORKSPACE_ROOT", "ScratchRoot": "EQUIPO_SCRATCH_ROOT", "GitPath": "EQUIPO_GIT_PATH", "Executable": "EQUIPO_RUNNER_EXECUTABLE"}
+ for field, want := range vars {
+ t.Run(field, func(t *testing.T) {
+ c := configFixture(t)
+ reflect.ValueOf(&c).Elem().FieldByName(field).SetString("")
+ code, variable := Diagnostic(c.validate())
+ if variable != want || !strings.HasPrefix(code, "runner.config.") {
+ t.Fatal("diagnostic lost variable", code, variable)
+ }
+ })
+ }
+ c := configFixture(t)
+ c.Origin = "https://user:secret@example.com"
+ code, variable := Diagnostic(c.validate())
+ if strings.Contains(code+variable, "secret") || variable != "EQUIPO_ORIGIN" {
+ t.Fatal("credential in diagnostic", code, variable)
+ }
+}
diff --git a/internal/runner/runtime.go b/internal/runner/runtime.go
index bd2b6f80..c16381cf 100644
--- a/internal/runner/runtime.go
+++ b/internal/runner/runtime.go
@@ -30,9 +30,11 @@ func openRuntime(ctx context.Context, c Config) (r *Runtime, err error) {
if err = c.validate(); err != nil {
return nil, err
}
+ variable := "EQUIPO_RUNNER_STATE_DIR"
r = &Runtime{cfg: c}
defer func() {
if err != nil {
+ err = diagnosticAt(err, variable)
r.Close()
}
}()
@@ -44,10 +46,12 @@ func openRuntime(ctx context.Context, c Config) (r *Runtime, err error) {
if err != nil {
return r, err
}
+ variable = "EQUIPO_ACCOUNT_BINDINGS_PATH"
bs, err := loadBindings(c.AccountBindingsPath)
if err != nil {
return r, err
}
+ variable = "EQUIPO_NODE_PATH"
if err = checkNode(ctx, c.NodePath); err != nil {
return r, err
}
@@ -56,14 +60,17 @@ func openRuntime(ctx context.Context, c Config) (r *Runtime, err error) {
return r, err
}
}
+ variable = "EQUIPO_CODEX_PATH"
r.sandbox, err = checks.NewCodexSandbox(ctx, checks.SandboxConfig{Binary: c.CodexPath, ScratchRoot: c.ScratchRoot, GoRoot: c.GoRoot, GoBinary: c.GoBinary, Protected: c.securityPaths(bs)})
if err != nil {
return r, err
}
+ variable = "EQUIPO_RUNNER_STATE_DIR"
r.journal, err = OpenJournal(ctx, filepath.Join(c.StateDir, "journal.db"))
if err != nil {
return r, err
}
+ variable = "EQUIPO_ORIGIN"
r.api, err = NewHTTPInstance(c.Origin+"/api/runner/v1", r.journal, credentials.Bearer)
if err != nil {
return r, err
@@ -75,6 +82,7 @@ func openRuntime(ctx context.Context, c Config) (r *Runtime, err error) {
for _, v := range release.BuildManifest().VerifiedIsolationTuples {
tuples = append(tuples, paseo.VerifiedTuple{Provider: v.Provider, ProviderVersion: v.ProviderVersion, PaseoVersion: v.PaseoVersion, ConfigHash: v.IsolationConfigHash})
}
+ variable = "EQUIPO_BRIDGE_PATH"
r.client, err = paseo.Start(ctx, paseo.Config{VerifyRouting: r.verifyRouting, VerifiedTuples: tuples, NodePath: c.NodePath, BridgePath: c.BridgePath, DaemonHome: c.PaseoHome, Endpoint: c.PaseoEndpoint, ServerID: c.PaseoServerID, RecordIntent: r.journal.RecordIntent, RecordCreationRefusal: r.journal.RecordCreationRefusal, InspectProcesses: r.coverage, AuthorizeUnconfined: r.authorizeUnconfined})
if err != nil {
return r, err