carlos / platform Public

media: the gate pins each container's command and refuses group 0

Controller rulings on the Task 4 concerns. ContainerDef gains EntryPoint
and Command; a new last check, command, refuses any revision whose
deadline or codec does not run exactly [EngineEntryPoint] with
[DeadlineCommand] or [CodecCommand] (/usr/local/bin/carlos-media
deadline|codec, the contract plan 3's image implements). Per-run values
travel as environment overrides, so no argument may vary.

The user check now also refuses a root group (65534:0, 65534:root, an
empty group). TestRunRequestNamesNoCommand pins RunRequest's fields,
since RunTask overrides can replace a command and the gate reads only
the revision.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 566c685361bd2f92817d7579ea0a04efcf5f0386 parent 74641f9
2 files changed, +145 −7
  • internal/media/gate.go +50 −7
  • internal/media/gate_test.go +95 −0
diff --git a/internal/media/gate.go b/internal/media/gate.go
index c993cb108..79aa55435 100644
--- a/internal/media/gate.go
+++ b/internal/media/gate.go
@@ -3,11 +3,32 @@ package media
import (
"errors"
"math"
+ "slices"
"strconv"
"strings"
"time"
)
+// What the engine's two containers run (spec §5.5, plan 3 Task 1). The
+// image's one binary is EngineEntryPoint; its first argument picks the
+// role. A task definition sets both explicitly on each container, entry
+// point exactly [EngineEntryPoint] and command exactly [DeadlineCommand]
+// or [CodecCommand], and the gate refuses anything else, including an
+// entry point left to the image's default (the gate cannot see the
+// image's config, only its digest).
+//
+// This is the contract plan 3 implements: cmd/carlos-media installed at
+// /usr/local/bin/carlos-media, dispatching "deadline" and "codec" with no
+// further arguments. Every per-run value reaches the containers as an
+// environment variable in the run's container overrides (DeadlineEnv and
+// ExpiryEnv on deadline, PayloadEnv on codec), never as an argument, so
+// no argument varies per run and the command is compared whole.
+const (
+ EngineEntryPoint = "/usr/local/bin/carlos-media"
+ DeadlineCommand = "deadline"
+ CodecCommand = "codec"
+)
+
// TaskDefinition is what the refusal gate reads of one ECS task
// definition revision (spec §5.5). Plan 3's adapter fills it from
// DescribeTaskDefinition and caches the verdict per revision ARN.
@@ -26,13 +47,16 @@ type TaskDefinition struct {
// linuxParameters.capabilities.drop holds ALL and add is empty, and
// Volumes is every volume the container can reach, which is each mount
// point's source volume plus those of any container its volumesFrom
-// names. StopTimeout is nil when the definition sets none.
+// names. StopTimeout is nil when the definition sets none. EntryPoint and
+// Command are the definition's entryPoint and command as written, nil
+// when unset.
type ContainerDef struct {
Name, Image, User string
Essential, ReadOnlyRoot, DropsAll bool
StopTimeout *int
DependsOn []Dependency
Volumes []string
+ EntryPoint, Command []string
}
// Dependency is one dependsOn entry: the container waited for and the
@@ -60,6 +84,7 @@ var gateChecks = []gateCheck{
{"read_only", gateReadOnly},
{"capabilities", gateCapabilities},
{"arm64", gateARM64},
+ {"command", gateCommand},
}
// CheckTaskDefinition is the refusal gate (spec §5.5, astra R6-1): nil
@@ -73,8 +98,10 @@ var gateChecks = []gateCheck{
// else; deadline on nothing), stop_timeout (both exactly 30 s, the stop
// grace), task_role (none), pid_mode (none), shared_volume (no volume
// reachable from both), image (one image for both, pinned by digest),
-// user (both set and not root), read_only (both), capabilities (both
-// drop ALL), arm64.
+// user (both set, neither user nor group root), read_only (both),
+// capabilities (both drop ALL), arm64, command (each container runs
+// exactly its role: EngineEntryPoint with DeadlineCommand or
+// CodecCommand).
func CheckTaskDefinition(td TaskDefinition) error {
deadline, codec, ok := gateContainers(td.Containers)
if !ok {
@@ -164,11 +191,18 @@ func gateUser(_ TaskDefinition, d, c ContainerDef) bool {
return notRoot(d.User) && notRoot(c.User)
}
-// notRoot answers whether a container's user field is set and names a
-// user other than root. A numeric user is parsed as the runtime parses
-// it, so 00 and +0 are root too, and one outside 1..2^31-1 is refused.
+// notRoot answers whether a container's user field is set and names
+// neither the root user nor the root group: "user" or "user:group", each
+// part set, not root and not id 0.
func notRoot(user string) bool {
- name, _, _ := strings.Cut(user, ":")
+ name, group, hasGroup := strings.Cut(user, ":")
+ return notRootID(name) && (!hasGroup || notRootID(group) && !strings.Contains(group, ":"))
+}
+
+// notRootID answers whether one part of a user field is set and is not
+// root. A numeric id is parsed as the runtime parses it, so 00 and +0 are
+// 0 too, and one outside 1..2^31-1 is refused.
+func notRootID(name string) bool {
if name == "" || name == "root" {
return false
}
@@ -191,3 +225,12 @@ func gateCapabilities(_ TaskDefinition, d, c ContainerDef) bool {
}
func gateARM64(td TaskDefinition, _, _ ContainerDef) bool { return td.CPUArchitecture == "ARM64" }
+
+// gateCommand: each container runs its own role of the engine binary
+// and nothing else. A revision that points deadline at another role, or
+// at any argument list that might not exit, would loosen the bound.
+func gateCommand(_ TaskDefinition, d, c ContainerDef) bool {
+ entry := []string{EngineEntryPoint}
+ return slices.Equal(d.EntryPoint, entry) && slices.Equal(d.Command, []string{DeadlineCommand}) &&
+ slices.Equal(c.EntryPoint, entry) && slices.Equal(c.Command, []string{CodecCommand})
+}
diff --git a/internal/media/gate_test.go b/internal/media/gate_test.go
index 6b998f53a..2208929ee 100644
--- a/internal/media/gate_test.go
+++ b/internal/media/gate_test.go
@@ -2,6 +2,7 @@ package media
import (
"errors"
+ "reflect"
"testing"
)
@@ -24,6 +25,8 @@ func intendedTaskDefinition() TaskDefinition {
Name: ContainerDeadline, Image: tdImage, User: "65534:65534",
Essential: true, ReadOnlyRoot: true, DropsAll: true,
StopTimeout: thirty(),
+ EntryPoint: []string{"/usr/local/bin/carlos-media"},
+ Command: []string{"deadline"},
},
{
Name: ContainerCodec, Image: tdImage, User: "65534:65534",
@@ -31,6 +34,8 @@ func intendedTaskDefinition() TaskDefinition {
StopTimeout: thirty(),
DependsOn: []Dependency{{Container: ContainerDeadline, Condition: "START"}},
Volumes: []string{"scratch"},
+ EntryPoint: []string{"/usr/local/bin/carlos-media"},
+ Command: []string{"codec"},
},
},
}
@@ -223,6 +228,24 @@ func TestCheckTaskDefinition(t *testing.T) {
{"codec user beyond int64", func(t *testing.T, td *TaskDefinition) {
container(t, td, ContainerCodec).User = "99999999999999999999"
}, "user"},
+ {"codec group 0", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).User = "65534:0"
+ }, "user"},
+ {"deadline group 0", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).User = "65534:0"
+ }, "user"},
+ {"codec group root", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).User = "65534:root"
+ }, "user"},
+ {"codec group 00", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).User = "65534:00"
+ }, "user"},
+ {"codec group empty", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).User = "65534:"
+ }, "user"},
+ {"codec group with a second colon", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).User = "65534:65534:0"
+ }, "user"},
{"codec user unset", func(t *testing.T, td *TaskDefinition) {
container(t, td, ContainerCodec).User = ""
}, "user"},
@@ -253,6 +276,48 @@ func TestCheckTaskDefinition(t *testing.T) {
{"no architecture", func(t *testing.T, td *TaskDefinition) {
td.CPUArchitecture = ""
}, "arm64"},
+
+ // command
+ {"deadline runs the codec", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).Command = []string{"codec"}
+ }, "command"},
+ {"deadline runs a drill that never exits", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).Command = []string{"drill", "hostile-timer"}
+ }, "command"},
+ {"deadline with an extra argument", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).Command = []string{"deadline", "3000"}
+ }, "command"},
+ {"deadline with no command", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).Command = nil
+ }, "command"},
+ {"deadline with another entry point", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).EntryPoint = []string{"/bin/sh", "-c"}
+ }, "command"},
+ {"deadline with the image's default entry point", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).EntryPoint = nil
+ }, "command"},
+ {"deadline with the entry point carrying the role", func(t *testing.T, td *TaskDefinition) {
+ d := container(t, td, ContainerDeadline)
+ d.EntryPoint, d.Command = []string{"/usr/local/bin/carlos-media", "deadline"}, nil
+ }, "command"},
+ {"deadline with an extra entry point argument", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).EntryPoint = []string{"/usr/local/bin/carlos-media", "codec"}
+ }, "command"},
+ {"codec with an extra entry point argument", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).EntryPoint = []string{"/usr/local/bin/carlos-media", "selftest"}
+ }, "command"},
+ {"codec runs selftest", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).Command = []string{"selftest"}
+ }, "command"},
+ {"codec with an extra argument", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).Command = []string{"codec", "--debug"}
+ }, "command"},
+ {"codec with another entry point", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).EntryPoint = []string{"/usr/bin/ffmpeg"}
+ }, "command"},
+ {"codec with the image's default entry point", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerCodec).EntryPoint = nil
+ }, "command"},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
@@ -294,6 +359,9 @@ func TestCheckTaskDefinitionOrder(t *testing.T) {
{"read_only", func(t *testing.T, td *TaskDefinition) { container(t, td, ContainerCodec).ReadOnlyRoot = false }},
{"capabilities", func(t *testing.T, td *TaskDefinition) { container(t, td, ContainerCodec).DropsAll = false }},
{"arm64", func(t *testing.T, td *TaskDefinition) { td.CPUArchitecture = "X86_64" }},
+ {"command", func(t *testing.T, td *TaskDefinition) {
+ container(t, td, ContainerDeadline).Command = []string{"codec"}
+ }},
}
td := intendedTaskDefinition()
for i := len(steps) - 1; i >= 0; i-- {
@@ -304,3 +372,30 @@ func TestCheckTaskDefinitionOrder(t *testing.T) {
}
}
}
+
+// TestEngineCommandConstants pins the contract plan 3's image and module
+// implement (cmd/carlos-media at /usr/local/bin/carlos-media, roles
+// "deadline" and "codec"), so a change to them is a change to both.
+func TestEngineCommandConstants(t *testing.T) {
+ if EngineEntryPoint != "/usr/local/bin/carlos-media" || DeadlineCommand != "deadline" || CodecCommand != "codec" {
+ t.Fatalf("engine command contract changed: %q %q %q", EngineEntryPoint, DeadlineCommand, CodecCommand)
+ }
+}
+
+// TestRunRequestNamesNoCommand: RunTask's container overrides can
+// replace a container's command (not its entry point), which the gate
+// cannot see because it reads the revision, not the run. The console
+// builds every override from RunRequest (plan 3's adapter Run, pinned by
+// its TestRunTaskInput), so RunRequest carries no command: a new field
+// here fails this test and has to be weighed against the gate.
+func TestRunRequestNamesNoCommand(t *testing.T) {
+ want := []string{"Execution", "Class", "Payload", "DeadlineS", "GrantExpiry", "EphemeralGiB"}
+ rt := reflect.TypeOf(RunRequest{})
+ var got []string
+ for i := 0; i < rt.NumField(); i++ {
+ got = append(got, rt.Field(i).Name)
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Fatalf("RunRequest fields = %v, want %v: an override field must not change what the containers run", got, want)
+ }
+}