carlos / platform Public

activator: the binary-launch guard covers strict starts and package-level initializers, and checks that each funnel's refusal refuses its own row

Plan 3 N1 round 2 (Astra READY AFTER FIXES, P2s 1-3): strictProc.Start,
cgroup.Prepared.Start and any Start taking an *exec.Cmd are funnel-only
primitives; var and const initializers are inspected like function
bodies; the refusal must be refuseRuntimeBinaryLaunch(<the funnel's route
parameter>) under err != nil, returning that error at once. One fixture
and one real-code mutation per item.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 70053b7401e20a64ab01044a357532e5ebc9fb41 parent e0da1ba
4 files changed, +269 −82
  • internal/activator/binary_launch_guard_test.go +195 −82
  • internal/activator/testdata/binary_launch_guard/pkgvar.go +14 −0
  • internal/activator/testdata/binary_launch_guard/refusals.go +32 −0
  • internal/activator/testdata/binary_launch_guard/strict.go +28 −0

CI failed — run details

Intent

Human

<task-notification> <task-id>ab8ab239784f5784b</task-id> <tool-use-id>toolu_015VNNYE6X4C5Wxyzvxoq61T</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/723ae101-0fd7-40c3-a758-6adf1597efb2/tasks/ab8ab239784f5784b.output</output-file> <status>completed</status> <summary>Agent "Plan 3 Task 5 implementer" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE Commit: 34ed6e72 rootfs apps plan 3: Task 5 round 3 P2, the layout guard recognises Pass methods by type, whatever the receiver's name Fix: the layout guard now recognises calls on any variable of type `Pass` or `*Pass`, not just one named `p`. That covers the method receiver, parameters, and locals declared with the type or built from a `Pass{}` literal. It applies to all three things the guard looks for: the risky journal and fence calls, the `exempt` check, and internal helper calls. One gap remains: a `Pass` that arrives some other way, such as a struct field or a function's return value, is still not recognised. Full type-checking would close that. Three new negative fixtures, each failing with its own message: - a `q *Pass` method calling `q.quiesce()` - `keptFence` called on a local `&amp;Pass{}` - `q.keep` called before `q.exempt` Mutation checks, both caught: - Matching only `p` again makes all three fixtures fail. - A `(q *Pass) sneak` calling `q.quiesce` in pass.go makes the guard fail on the real source. Tests: the invariant guards pass (internal/activator, internal/layout, root package) and vet is clean. Concerns: none. Task 5 closes. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-apps-3/.superpowers/sdd/2026-10-24-rootfs-apps-3-lifecycle/task-5-report.md (P2 note appended)</result> <usage><subagent_tokens>441153</subagent_tokens><tool_uses>4</tool_uses><duration_ms>67732</duration_ms></usage> </task-notification>

diff --git a/internal/activator/binary_launch_guard_test.go b/internal/activator/binary_launch_guard_test.go
index 2c00dcba4..e8efdbdb4 100644
--- a/internal/activator/binary_launch_guard_test.go
+++ b/internal/activator/binary_launch_guard_test.go
@@ -5,13 +5,18 @@ package activator
// binary launch rejects a row with a runtime, and it does so in one place.
//
// The launch primitives are the cgroup manager's starts (Start,
-// StartGated, StartChild, StartChildGated), a process start on an exec.Cmd
-// (Start, Run, Output, CombinedOutput) and the raw process starts of os,
-// syscall and x/sys/unix. In this package's own code:
+// StartGated, StartChild, StartChildGated), a strict group's start
+// (cgroup.Prepared.Start, strictProc.Start, and any method named Start
+// that takes an *exec.Cmd), a process start on an exec.Cmd (Start, Run,
+// Output, CombinedOutput) and the raw process starts of os, syscall and
+// x/sys/unix. In this package's own code, function bodies and package-level
+// initializers alike (Astra N1 r2 P2 2):
//
-// - the cgroup manager's starts appear only in the launch funnels
-// (launchFunnels), and each funnel asks refuseRuntimeBinaryLaunch, and
-// returns on its refusal, before its first statement that names one;
+// - the cgroup and strict starts appear only in the launch funnels
+// (launchFunnels), and each funnel refuses before its first statement
+// that names one: `if err := refuseRuntimeBinaryLaunch(<its route
+// parameter>); err != nil { return ..., err }`, the condition, the
+// route and the propagation all checked (Astra N1 r2 P2 3);
// - an exec.Cmd is started directly only for systemctl (a literal
// "systemctl" command name), never for anything a row supplies;
// - an exec.Cmd naming anything but systemctl is only built inside a
@@ -52,7 +57,7 @@ const launchRefusal = "refuseRuntimeBinaryLaunch"
// launchPrimitives: package path -> the functions, or Type.Method names,
// that start a process.
var launchPrimitives = map[string][]string{
- "github.com/carlosframework/platform/internal/cgroup": {"Manager.Start", "Manager.StartGated", "Manager.StartChild", "Manager.StartChildGated"},
+ "github.com/carlosframework/platform/internal/cgroup": {"Manager.Start", "Manager.StartGated", "Manager.StartChild", "Manager.StartChildGated", "Prepared.Start"},
"os/exec": {"Cmd.Start", "Cmd.Run", "Cmd.Output", "Cmd.CombinedOutput"},
"os": {"StartProcess"},
"syscall": {"ForkExec", "Exec", "StartProcess"},
@@ -72,6 +77,17 @@ var launchGuardFixtures = map[string][]string{
"cmdstart.go": {"zzCmdStart: launch primitive exec.Cmd.Start on something other than systemctl", "zzCmdStart: exec.Command builds a process outside a launch funnel's build closure"},
"loosecmd.go": {"zzLooseCmd: exec.CommandContext builds a process outside a launch funnel's build closure"},
"funnels.go": {"zzLaunchFunnelLate: reaches a launch primitive before refuseRuntimeBinaryLaunch", "zzLaunchFunnelNone: reaches a launch primitive before refuseRuntimeBinaryLaunch"},
+ // Astra N1 round 2, P2 1: the strict starts.
+ "strict.go": {"zzStrictOutside: launch primitive activator.strictProc.Start outside the launch funnels",
+ "zzPreparedOutside: launch primitive cgroup.Prepared.Start outside the launch funnels",
+ "zzLaunchFunnelStrictLate: reaches a launch primitive before refuseRuntimeBinaryLaunch"},
+ // P2 2: package-level initializers.
+ "pkgvar.go": {"var zzLaunchVar: launch primitive exec.Cmd.Start on something other than systemctl",
+ "var zzStartChildValue: launch primitive cgroup.Manager.StartChildGated outside the launch funnels"},
+ // P2 3: a refusal that does not refuse the row being launched.
+ "refusals.go": {"zzLaunchFunnelInverted: reaches a launch primitive before refuseRuntimeBinaryLaunch",
+ "zzLaunchFunnelWrongRoute: reaches a launch primitive before refuseRuntimeBinaryLaunch",
+ "zzLaunchFunnelSwallowed: reaches a launch primitive before refuseRuntimeBinaryLaunch"},
}
var loadLaunchGuardPackage = sync.OnceValues(func() (*packages.Package, error) {
@@ -114,23 +130,30 @@ func packagesErr(pkgs []*packages.Package) error {
}
// launchPrimitiveName is obj's launch primitive name ("cgroup.Manager.Start",
-// "os.StartProcess"), or "".
+// "os.StartProcess", "activator.strictProc.Start"), or "". Besides the
+// listed names, any method named Start whose parameters include an
+// *exec.Cmd is a strict start, whatever its receiver (a named or an
+// anonymous interface, or a concrete type).
func launchPrimitiveName(obj types.Object) string {
fn, ok := obj.(*types.Func)
if !ok || fn.Pkg() == nil {
return ""
}
+ sig, _ := fn.Type().(*types.Signature)
name := fn.Name()
- if sig, ok := fn.Type().(*types.Signature); ok && sig.Recv() != nil {
+ if sig != nil && sig.Recv() != nil {
t := sig.Recv().Type()
if p, ok := t.(*types.Pointer); ok {
t = p.Elem()
}
- n, ok := t.(*types.Named)
- if !ok {
- return ""
+ recv := "(interface)"
+ if n, ok := t.(*types.Named); ok {
+ recv = n.Obj().Name()
+ }
+ name = recv + "." + name
+ if fn.Name() == "Start" && fn.Pkg().Path() != "os/exec" && takesExecCmd(sig) {
+ return fn.Pkg().Name() + "." + name
}
- name = n.Obj().Name() + "." + name
}
if !slices.Contains(launchPrimitives[fn.Pkg().Path()], name) {
return ""
@@ -138,6 +161,23 @@ func launchPrimitiveName(obj types.Object) string {
return fn.Pkg().Name() + "." + name
}
+func takesExecCmd(sig *types.Signature) bool {
+ for i := 0; i < sig.Params().Len(); i++ {
+ if types.TypeString(sig.Params().At(i).Type(), nil) == "*os/exec.Cmd" {
+ return true
+ }
+ }
+ return false
+}
+
+// funnelOnly reports whether primitive p may appear in a launch funnel:
+// the cgroup and strict starts. An exec.Cmd start is for systemctl alone,
+// and a raw start is never used.
+func funnelOnly(p string) bool {
+ return p != "" && !strings.HasPrefix(p, "exec.Cmd.") && !strings.HasPrefix(p, "os.") &&
+ !strings.HasPrefix(p, "syscall.") && !strings.HasPrefix(p, "unix.")
+}
+
// isExecCommand reports whether call is exec.Command or exec.CommandContext,
// and its command-name argument.
func isExecCommand(info *types.Info, call *ast.CallExpr) (string, ast.Expr, bool) {
@@ -185,100 +225,129 @@ func calleeName(info *types.Info, call *ast.CallExpr) string {
return ""
}
-// launchGuardProblems is every rule broken in f. isFunnel names a funnel.
+// launchGuardProblems is every rule broken in f: in each function body,
+// and in each package-level initializer (a function literal or a method
+// value stored in a var or const). isFunnel names a funnel.
func launchGuardProblems(info *types.Info, f *ast.File, isFunnel func(string) bool) []string {
var out []string
for _, decl := range f.Decls {
- fd, ok := decl.(*ast.FuncDecl)
- if !ok || fd.Body == nil {
- continue
+ switch d := decl.(type) {
+ case *ast.FuncDecl:
+ if d.Body == nil {
+ continue
+ }
+ funnel := isFunnel(d.Name.Name)
+ out = append(out, launchSiteProblems(info, d.Name.Name, d.Body, funnel)...)
+ if funnel {
+ if p := funnelOrderProblem(info, d); p != "" {
+ out = append(out, d.Name.Name+": "+p)
+ }
+ }
+ case *ast.GenDecl:
+ for _, spec := range d.Specs {
+ vs, ok := spec.(*ast.ValueSpec)
+ if !ok {
+ continue
+ }
+ for i, v := range vs.Values {
+ name := "var"
+ if i < len(vs.Names) {
+ name += " " + vs.Names[i].Name
+ }
+ out = append(out, launchSiteProblems(info, name, v, false)...)
+ }
+ }
}
- name := fd.Name.Name
- funnel := isFunnel(name)
- var stack []ast.Node
- ast.Inspect(fd.Body, func(n ast.Node) bool {
- if n == nil {
- stack = stack[:len(stack)-1]
+ }
+ return out
+}
+
+// launchSiteProblems is the launch-site rules over node, reported under
+// name; funnel says node is a launch funnel's body.
+func launchSiteProblems(info *types.Info, name string, node ast.Node, funnel bool) []string {
+ var out []string
+ var stack []ast.Node
+ ast.Inspect(node, func(n ast.Node) bool {
+ if n == nil {
+ stack = stack[:len(stack)-1]
+ return true
+ }
+ stack = append(stack, n)
+ switch x := n.(type) {
+ case *ast.Ident:
+ p := launchPrimitiveName(info.Uses[x])
+ if p == "" {
return true
}
- stack = append(stack, n)
- switch x := n.(type) {
- case *ast.Ident:
- p := launchPrimitiveName(info.Uses[x])
- if p == "" {
- return true
- }
- if strings.HasPrefix(p, "exec.Cmd.") {
- // x is the Sel of a selector; its receiver must be a
- // direct exec.Command("systemctl", ...).
- if len(stack) >= 2 {
- if sel, ok := stack[len(stack)-2].(*ast.SelectorExpr); ok && sel.Sel == x {
- if call, ok := sel.X.(*ast.CallExpr); ok {
- if _, arg, ok := isExecCommand(info, call); ok && isSystemctl(arg) {
- return true
- }
+ if strings.HasPrefix(p, "exec.Cmd.") {
+ // x is the Sel of a selector; its receiver must be a
+ // direct exec.Command("systemctl", ...).
+ if len(stack) >= 2 {
+ if sel, ok := stack[len(stack)-2].(*ast.SelectorExpr); ok && sel.Sel == x {
+ if call, ok := sel.X.(*ast.CallExpr); ok {
+ if _, arg, ok := isExecCommand(info, call); ok && isSystemctl(arg) {
+ return true
}
}
}
- out = append(out, name+": launch primitive "+p+" on something other than systemctl")
- return true
- }
- if !funnel || !strings.HasPrefix(p, "cgroup.") {
- out = append(out, name+": launch primitive "+p+" outside the launch funnels")
- }
- case *ast.CallExpr:
- fn, arg, ok := isExecCommand(info, x)
- if !ok || isSystemctl(arg) {
- return true
}
- // Inside a function literal that is an argument of a call
- // to a funnel or a wrapper?
- inside := false
- for i := len(stack) - 2; i >= 1 && !inside; i-- {
- lit, ok := stack[i].(*ast.FuncLit)
- if !ok {
- continue
- }
- if call, ok := stack[i-1].(*ast.CallExpr); ok && slices.Contains(launchFunnelCallers, calleeName(info, call)) && slices.ContainsFunc(call.Args, func(a ast.Expr) bool { return a == lit }) {
- inside = true
- }
+ out = append(out, name+": launch primitive "+p+" on something other than systemctl")
+ return true
+ }
+ if !funnel || !funnelOnly(p) {
+ out = append(out, name+": launch primitive "+p+" outside the launch funnels")
+ }
+ case *ast.CallExpr:
+ fn, arg, ok := isExecCommand(info, x)
+ if !ok || isSystemctl(arg) {
+ return true
+ }
+ // Inside a function literal that is an argument of a call
+ // to a funnel or a wrapper?
+ inside := false
+ for i := len(stack) - 2; i >= 1 && !inside; i-- {
+ lit, ok := stack[i].(*ast.FuncLit)
+ if !ok {
+ continue
}
- if !inside {
- out = append(out, name+": exec."+fn+" builds a process outside a launch funnel's build closure")
+ if call, ok := stack[i-1].(*ast.CallExpr); ok && slices.Contains(launchFunnelCallers, calleeName(info, call)) && slices.ContainsFunc(call.Args, func(a ast.Expr) bool { return a == lit }) {
+ inside = true
}
}
- return true
- })
- if funnel {
- if p := funnelOrderProblem(info, fd); p != "" {
- out = append(out, name+": "+p)
+ if !inside {
+ out = append(out, name+": exec."+fn+" builds a process outside a launch funnel's build closure")
}
}
- }
+ return true
+ })
return out
}
-// funnelOrderProblem checks that fd asks the refusal, and returns on it, in
-// a top-level statement before its first top-level statement naming a
-// launch primitive. A funnel that names none is reported too: a guard row
-// with nothing to guard is stale.
+// funnelOrderProblem checks that fd refuses (isRefusalStmt) in a
+// top-level statement before its first top-level statement naming a
+// funnel-only primitive. A funnel that names none is reported too: a guard
+// row with nothing to guard is stale.
func funnelOrderProblem(info *types.Info, fd *ast.FuncDecl) string {
+ route := routeParam(info, fd)
+ if route == nil {
+ return "has no registry.Route parameter to refuse"
+ }
refused := false
for _, st := range fd.Body.List {
- if !refused && isRefusalStmt(info, st) {
+ if !refused && isRefusalStmt(info, st, route) {
refused = true
continue
}
names := false
ast.Inspect(st, func(n ast.Node) bool {
- if id, ok := n.(*ast.Ident); ok && strings.HasPrefix(launchPrimitiveName(info.Uses[id]), "cgroup.") {
+ if id, ok := n.(*ast.Ident); ok && funnelOnly(launchPrimitiveName(info.Uses[id])) {
names = true
}
return !names
})
if names {
if !refused {
- return "reaches a launch primitive before " + launchRefusal
+ return "reaches a launch primitive before " + launchRefusal + " refuses its route"
}
return ""
}
@@ -286,23 +355,67 @@ func funnelOrderProblem(info *types.Info, fd *ast.FuncDecl) string {
return "names no launch primitive (a stale funnel row)"
}
-// isRefusalStmt: `if err := refuseRuntimeBinaryLaunch(...); err != nil {
-// return ... }`.
-func isRefusalStmt(info *types.Info, st ast.Stmt) bool {
+// routeParam is fd's registry.Route parameter: the row being launched.
+func routeParam(info *types.Info, fd *ast.FuncDecl) types.Object {
+ for _, field := range fd.Type.Params.List {
+ if types.TypeString(info.TypeOf(field.Type), nil) != "github.com/carlosframework/platform/internal/registry.Route" || len(field.Names) == 0 {
+ continue
+ }
+ return info.Defs[field.Names[0]]
+ }
+ return nil
+}
+
+// isRefusalStmt is exactly a refusal of route (Astra N1 r2 P2 3):
+//
+// if err := refuseRuntimeBinaryLaunch(route); err != nil {
+// return ..., err, ...
+// }
+//
+// The call's one argument is the funnel's own route parameter, the
+// condition is err != nil on the error the call returned, and the body's
+// first statement returns that same error.
+func isRefusalStmt(info *types.Info, st ast.Stmt, route types.Object) bool {
ifs, ok := st.(*ast.IfStmt)
if !ok || ifs.Init == nil || len(ifs.Body.List) == 0 {
return false
}
as, ok := ifs.Init.(*ast.AssignStmt)
- if !ok || len(as.Rhs) != 1 {
+ if !ok || as.Tok != token.DEFINE || len(as.Lhs) != 1 || len(as.Rhs) != 1 {
return false
}
+ errID, ok := as.Lhs[0].(*ast.Ident)
+ if !ok {
+ return false
+ }
+ errObj := info.Defs[errID]
call, ok := as.Rhs[0].(*ast.CallExpr)
- if !ok || calleeName(info, call) != launchRefusal {
+ if !ok || errObj == nil || calleeName(info, call) != launchRefusal || len(call.Args) != 1 {
+ return false
+ }
+ if arg, ok := call.Args[0].(*ast.Ident); !ok || info.Uses[arg] != route {
+ return false
+ }
+ cond, ok := ifs.Cond.(*ast.BinaryExpr)
+ if !ok || cond.Op != token.NEQ {
+ return false
+ }
+ x, xok := cond.X.(*ast.Ident)
+ y, yok := cond.Y.(*ast.Ident)
+ if !xok || !yok || info.Uses[x] != errObj {
+ return false
+ }
+ if _, isNil := info.Uses[y].(*types.Nil); !isNil {
+ return false
+ }
+ ret, ok := ifs.Body.List[0].(*ast.ReturnStmt)
+ if !ok {
return false
}
- _, ret := ifs.Body.List[len(ifs.Body.List)-1].(*ast.ReturnStmt)
- return ret
+ return slices.ContainsFunc(ret.Results, func(e ast.Expr) bool {
+ id, ok := e.(*ast.Ident)
+ return ok && info.Uses[id] == errObj
+ })
}
func TestBinaryLaunchesAskTheRuntimeFirst(t *testing.T) {
diff --git a/internal/activator/testdata/binary_launch_guard/pkgvar.go b/internal/activator/testdata/binary_launch_guard/pkgvar.go
new file mode 100644
index 000000000..93a1a2147
--- /dev/null
+++ b/internal/activator/testdata/binary_launch_guard/pkgvar.go
@@ -0,0 +1,14 @@
+// Launches hidden in package-level initializers (Astra N1 round 2, P2 2):
+// a function literal that starts a command, and a cgroup start stored as a
+// method expression.
+package activator
+
+import (
+ "os/exec"
+
+ "github.com/carlosframework/platform/internal/cgroup"
+)
+
+var zzLaunchVar = func(cmd *exec.Cmd) error { return cmd.Start() }
+
+var zzStartChildValue = (*cgroup.Manager).StartChildGated
diff --git a/internal/activator/testdata/binary_launch_guard/refusals.go b/internal/activator/testdata/binary_launch_guard/refusals.go
new file mode 100644
index 000000000..f7509a77e
--- /dev/null
+++ b/internal/activator/testdata/binary_launch_guard/refusals.go
@@ -0,0 +1,32 @@
+// Funnels whose "refusal" does not refuse the row being launched (Astra N1
+// round 2, P2 3): the condition inverted, another route checked, and the
+// error swallowed.
+package activator
+
+import (
+ "os/exec"
+
+ "github.com/carlosframework/platform/internal/cgroup"
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+func (b *ExecBackend) zzLaunchFunnelInverted(rt registry.Route, build func() *exec.Cmd) (*exec.Cmd, error) {
+ if err := refuseRuntimeBinaryLaunch(rt); err == nil {
+ return nil, err
+ }
+ return b.Cgroups.StartGated(rt.Host, cgroup.Limit{}, build, nil)
+}
+
+func (b *ExecBackend) zzLaunchFunnelWrongRoute(rt registry.Route, build func() *exec.Cmd) (*exec.Cmd, error) {
+ if err := refuseRuntimeBinaryLaunch(registry.Route{}); err != nil {
+ return nil, err
+ }
+ return b.Cgroups.StartGated(rt.Host, cgroup.Limit{}, build, nil)
+}
+
+func (b *ExecBackend) zzLaunchFunnelSwallowed(rt registry.Route, build func() *exec.Cmd) (*exec.Cmd, error) {
+ if err := refuseRuntimeBinaryLaunch(rt); err != nil {
+ return nil, nil
+ }
+ return b.Cgroups.StartGated(rt.Host, cgroup.Limit{}, build, nil)
+}
diff --git a/internal/activator/testdata/binary_launch_guard/strict.go b/internal/activator/testdata/binary_launch_guard/strict.go
new file mode 100644
index 000000000..80cc21653
--- /dev/null
+++ b/internal/activator/testdata/binary_launch_guard/strict.go
@@ -0,0 +1,28 @@
+// Strict-group starts outside a funnel, and a funnel that reaches one
+// before its refusal (Astra N1 round 2, P2 1).
+package activator
+
+import (
+ "os/exec"
+
+ "github.com/carlosframework/platform/internal/cgroup"
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+func zzStrictOutside(sp strictProc, cmd *exec.Cmd) error {
+ return sp.Start(cmd)
+}
+
+func zzPreparedOutside(p *cgroup.Prepared, cmd *exec.Cmd) error {
+ return p.Start(cmd)
+}
+
+func zzLaunchFunnelStrictLate(rt registry.Route, sp strictProc, cmd *exec.Cmd) error {
+ if err := sp.Start(cmd); err != nil {
+ return err
+ }
+ if err := refuseRuntimeBinaryLaunch(rt); err != nil {
+ return err
+ }
+ return nil
+}