carlos / platform Public

carlos-media: embed TLS roots; image build and selftest prove them

Branch review round 1, P1-B (Fable). Invariant: the engine works end
to end as built. The pinned Debian base has no /etc/ssl, no locked
package provides a bundle and maintainer scripts never run, so on the
first real job the source GET and every PUT would fail x509
verification, retry, and end unreadable.

cmd/carlos-media imports golang.org/x/crypto/x509roots/fallback
(Mozilla's roots, used only when the system has none; go.mod gains
the module). mediaimage refuses a binary whose Go build record does
not link it. selftest's first case, tls-roots, verifies a real S3
chain from Certificate Transparency at a fixed time against the
binary's own roots, offline, so R2's selftest on Fargate proves them.
A child process with no system roots at all verifies the chain; a
handler test sends a GET and a PUT to an httptest TLS store through
the production client, with roots loaded from SSL_CERT_FILE, and an
untrusted store gets no request.

The binary grows 196,608 bytes (126,924 gzipped); the image's
compressed layers total 209,554,907 bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev da8d4c307012d3abf478a0146bd75ae1449bee7a parent 64761e6
16 files changed, +526 −9
  • cmd/carlos-media/main.go +9 −0
  • cmd/carlos-media/tlsroots_test.go +52 −0
  • cmd/mediaimage/build.go +31 −0
  • cmd/mediaimage/mediaimage_test.go +48 −1
  • deploy/media-image/README.md +1 −1
  • docs/superpowers/notes/media-conversion-copy-deck.md +3 −1
  • go.mod +1 −0
  • go.sum +2 −0
  • internal/mediahandler/handler.go +5 −0
  • internal/mediahandler/s3test_test.go +6 −1
  • internal/mediahandler/selftest.go +7 −2
  • internal/mediahandler/selftest_s3_chain.pem +76 −0
  • internal/mediahandler/selftest_test.go +5 −3
  • internal/mediahandler/selftesttls.go +91 −0
  • internal/mediahandler/selftesttls_test.go +53 −0
  • internal/mediahandler/tls_test.go +136 −0
diff --git a/cmd/carlos-media/main.go b/cmd/carlos-media/main.go
index 240c76fac..0222f69cf 100644
--- a/cmd/carlos-media/main.go
+++ b/cmd/carlos-media/main.go
@@ -26,6 +26,15 @@ import (
"syscall"
"time"
+ // The engine image is a Debian base with no CA bundle, and its
+ // packages' maintainer scripts never run, so the task has no system
+ // roots: every transfer to S3 would fail x509 verification. This
+ // embeds Mozilla's roots, which Go uses only when the system has none
+ // (branch review round 1, P1-B). mediaimage refuses a carlos-media
+ // that does not link it (checkTLSRoots), and selftest verifies a real
+ // S3 chain against the roots the binary ends up with.
+ _ "golang.org/x/crypto/x509roots/fallback"
+
"github.com/carlosframework/platform/internal/media"
"github.com/carlosframework/platform/internal/mediahandler"
"github.com/carlosframework/platform/internal/version"
diff --git a/cmd/carlos-media/tlsroots_test.go b/cmd/carlos-media/tlsroots_test.go
new file mode 100644
index 000000000..8f2db0a9d
--- /dev/null
+++ b/cmd/carlos-media/tlsroots_test.go
@@ -0,0 +1,52 @@
+package main
+
+import (
+ "bytes"
+ "context"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/mediahandler"
+)
+
+// rootsChildEnv marks the re-executed test binary that runs
+// TestTLSRootsWithNoSystemRoots' check.
+const rootsChildEnv = "CARLOS_MEDIA_TEST_ROOTS_CHILD"
+
+// TestTLSRootsWithNoSystemRoots (branch review round 1, P1-B): the engine
+// image has no CA bundle. With Go finding no system roots at all
+// (SSL_CERT_FILE names nothing, SSL_CERT_DIR an empty directory), this
+// package's binary still verifies a real S3 chain: its roots are the ones
+// it embeds. selftest's tls-roots case is the same check, run on Fargate.
+func TestTLSRootsWithNoSystemRoots(t *testing.T) {
+ if os.Getenv(rootsChildEnv) != "" {
+ var out bytes.Buffer
+ if err := mediahandler.SelftestTLS(&out); err != nil {
+ t.Fatalf("with no system roots: %s", out.String())
+ }
+ return
+ }
+ dir := t.TempDir()
+ none := filepath.Join(dir, "no-certs")
+ if err := os.Mkdir(none, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
+ defer cancel()
+ cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestTLSRootsWithNoSystemRoots$", "-test.count=1", "-test.v")
+ var env []string
+ for _, kv := range os.Environ() {
+ if !strings.HasPrefix(kv, "SSL_CERT_") && !strings.HasPrefix(kv, "GODEBUG=") {
+ env = append(env, kv)
+ }
+ }
+ cmd.Env = append(env, rootsChildEnv+"=1", "SSL_CERT_FILE="+filepath.Join(dir, "absent.pem"), "SSL_CERT_DIR="+none)
+ out, err := cmd.CombinedOutput()
+ if err != nil || !strings.Contains(string(out), "--- PASS: TestTLSRootsWithNoSystemRoots") {
+ t.Fatalf("the binary's own roots do not verify S3's chain: %v\n%s", err, out)
+ }
+}
diff --git a/cmd/mediaimage/build.go b/cmd/mediaimage/build.go
index cbce6b1fd..f539f63d2 100644
--- a/cmd/mediaimage/build.go
+++ b/cmd/mediaimage/build.go
@@ -40,6 +40,8 @@ var (
errPrivilegedMode = errors.New("setuid or setgid path in the image")
// errToolchain is an image built with another Go than releases use.
errToolchain = errors.New("wrong Go toolchain")
+ // errNoTLSRoots is a carlos-media that embeds no TLS roots.
+ errNoTLSRoots = errors.New("carlos-media embeds no TLS roots")
)
const (
@@ -94,6 +96,32 @@ func checkToolchain(binary string) error {
return nil
}
+// tlsRootsModule embeds Mozilla's roots in carlos-media (its blank import
+// of the package of the same path). The image has no CA bundle: the base
+// has no /etc/ssl and the packages' maintainer scripts never run here, so
+// without it no transfer to S3 would verify (branch review round 1, P1-B).
+const tlsRootsModule = "golang.org/x/crypto/x509roots/fallback"
+
+// binaryRoots reads whether a binary embeds TLS roots. The fixtures'
+// binaries are hand-made ELFs with no Go build record, so tests replace it;
+// TestCarlosMediaEmbedsTLSRoots holds the real one to real binaries.
+var binaryRoots = binaryEmbedsRoots
+
+// binaryEmbedsRoots is nil when file's Go build record lists
+// tlsRootsModule among the modules it links, else errNoTLSRoots.
+func binaryEmbedsRoots(file string) error {
+ info, err := buildinfo.ReadFile(file)
+ if err != nil {
+ return fmt.Errorf("%w: %s names no Go build record: %w", errNoTLSRoots, file, err)
+ }
+ for _, d := range info.Deps {
+ if d.Path == tlsRootsModule {
+ return nil
+ }
+ }
+ return fmt.Errorf("%w: %s does not link %s, and the image has no CA bundle, so no transfer to S3 would verify", errNoTLSRoots, file, tlsRootsModule)
+}
+
// libraryDirs is the arm64 loader's default search path on Debian.
var libraryDirs = []string{"lib/aarch64-linux-gnu", "usr/lib/aarch64-linux-gnu", "lib", "usr/lib"}
@@ -149,6 +177,9 @@ func buildImage(ctx context.Context, o buildOptions) (media.ImageInfo, error) {
if err := checkToolchain(o.Binary); err != nil {
return media.ImageInfo{}, err
}
+ if err := binaryRoots(o.Binary); err != nil {
+ return media.ImageInfo{}, err
+ }
ref, err := parseImageRef(lock.Base)
if err != nil {
return media.ImageInfo{}, err
diff --git a/cmd/mediaimage/mediaimage_test.go b/cmd/mediaimage/mediaimage_test.go
index 152d7095f..7bed360d2 100644
--- a/cmd/mediaimage/mediaimage_test.go
+++ b/cmd/mediaimage/mediaimage_test.go
@@ -6,6 +6,7 @@ import (
"compress/gzip"
"crypto"
"crypto/sha256"
+ "debug/buildinfo"
"debug/elf"
"encoding/base64"
"encoding/binary"
@@ -42,10 +43,11 @@ const testCreated = "2026-11-16T10:00:00Z"
// The fixtures' carlos-media is a hand-made ELF with no Go build record,
// and this test binary may run on any Go. TestBuildEnforcesTheReleaseToolchain
-// puts the real checks back.
+// and TestBuildRefusesABinaryWithNoTLSRoots put the real checks back.
func init() {
toolchain.tool = func() string { return releaseGoVersion }
toolchain.binary = func(string) (string, error) { return releaseGoVersion, nil }
+ binaryRoots = func(string) error { return nil }
}
// fx is one entry of a fixture tar.
@@ -1564,6 +1566,51 @@ func TestBuildEnforcesTheReleaseToolchain(t *testing.T) {
}
}
+// TestBuildRefusesABinaryWithNoTLSRoots (branch review round 1, P1-B):
+// the image has no CA bundle, so a carlos-media that embeds no roots could
+// verify no transfer; the build stops before writing anything.
+func TestBuildRefusesABinaryWithNoTLSRoots(t *testing.T) {
+ f := newFixture(t)
+ f.write(t)
+ t.Cleanup(func() { binaryRoots = func(string) error { return nil } })
+ binaryRoots = binaryEmbedsRoots
+ if _, err := buildImage(t.Context(), f.options()); !errors.Is(err, errNoTLSRoots) {
+ t.Fatalf("a binary with no Go build record = %v, want errNoTLSRoots", err)
+ }
+ if _, err := os.Stat(f.out); !os.IsNotExist(err) {
+ t.Fatalf("a refused build left %s: %v", f.out, err)
+ }
+}
+
+// TestCarlosMediaEmbedsTLSRoots reads real binaries built for the engine
+// (linux/arm64, as make media-image-binary builds carlos-media):
+// carlos-media is accepted; rootfswitness, which links another module
+// (golang.org/x/sys) and no roots, is refused.
+func TestCarlosMediaEmbedsTLSRoots(t *testing.T) {
+ if testing.Short() {
+ t.Skip("skipped in -short: it cross-compiles two commands")
+ }
+ build := func(pkg string) string {
+ out := filepath.Join(t.TempDir(), filepath.Base(pkg))
+ cmd := exec.Command("go", "build", "-o", out, pkg)
+ cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=arm64", "CGO_ENABLED=0")
+ if log, err := cmd.CombinedOutput(); err != nil {
+ t.Fatalf("build %s: %v\n%s", pkg, err, log)
+ }
+ return out
+ }
+ if err := binaryEmbedsRoots(build("../carlos-media")); err != nil {
+ t.Fatalf("carlos-media: %v", err)
+ }
+ other := build("../rootfswitness")
+ if info, err := buildinfo.ReadFile(other); err != nil || len(info.Deps) == 0 {
+ t.Fatalf("rootfswitness lists no module, so refusing it proves nothing: %v", err)
+ }
+ if err := binaryEmbedsRoots(other); !errors.Is(err, errNoTLSRoots) {
+ t.Fatalf("a binary with no roots = %v, want errNoTLSRoots", err)
+ }
+}
+
func TestBinaryGoVersionReadsARealBinary(t *testing.T) {
self, err := os.Executable()
if err != nil {
diff --git a/deploy/media-image/README.md b/deploy/media-image/README.md
index 10ba68f2d..1d6b70768 100644
--- a/deploy/media-image/README.md
+++ b/deploy/media-image/README.md
@@ -1,6 +1,6 @@
# The media engine image
-This is the arm64 container image that converts video and audio. It holds Debian 13’s slim base image, Debian’s ffmpeg with the libraries it needs, and the `carlos-media` binary. `debs.lock` pins every package by version and sha256, and it pins the base image by digest. Nothing in the image is setuid or setgid.
+This is the arm64 container image that converts video and audio. It holds Debian 13’s slim base image, Debian’s ffmpeg with the libraries it needs, and the `carlos-media` binary. `debs.lock` pins every package by version and sha256, and it pins the base image by digest. Nothing in the image is setuid or setgid. The base has no certificate bundle, so `carlos-media` carries its own TLS roots, and the build refuses a binary that doesn’t.
`cmd/mediaimage` assembles the image directly, with no container runtime. The same commit and lock give the same image digest.
diff --git a/docs/superpowers/notes/media-conversion-copy-deck.md b/docs/superpowers/notes/media-conversion-copy-deck.md
index 55c88c08f..c2a3b3b21 100644
--- a/docs/superpowers/notes/media-conversion-copy-deck.md
+++ b/docs/superpowers/notes/media-conversion-copy-deck.md
@@ -618,6 +618,7 @@ Operator-facing text from `cmd/mediaimage`, which builds and pushes the engine i
| `image.release.refused` | `unauthenticated release: ` then one of `not one clearsigned message`, `text after the signature`, `a signature does not match`, `no good signature from a Debian archive key`, `gpgv wrote no signed content`, `not one release stanza`, `the SHA256 list is damaged`, `Date: %s`, `Valid-Until: %s`, `the release is %q, want %q`, `%s is dated after the snapshot`, `%s had expired at the snapshot`, `%s does not list %s` (pending Luna pass; plan 3 Task 8) |
| `image.release.index` | `sha256 mismatch: %s %s is not the file its release names` (pending Luna pass; plan 3 Task 8) |
| `image.privileged` | `setuid or setgid path in the image: %s`, the paths joined by `, ` (pending Luna pass; plan 3 Task 8) |
+| `image.tls_roots` | `carlos-media embeds no TLS roots: %s does not link golang.org/x/crypto/x509roots/fallback, and the image has no CA bundle, so no transfer to S3 would verify`; `carlos-media embeds no TLS roots: %s names no Go build record: %s` (pending Luna pass; branch review round 1) |
| `image.toolchain` | `wrong Go toolchain: mediaimage runs on %s, releases use %s`; `wrong Go toolchain: %s was built with %s, releases use %s`; `wrong Go toolchain: %s names no Go version: %s` (pending Luna pass; plan 3 Task 8) |
| `image.location` | `the registry pointed outside itself: %s://%s`; `the registry pointed outside itself: an upload answer has no Location`; `the registry pointed outside itself: an upload Location does not parse`; `the registry pointed outside itself: more than %d redirects` (pending Luna pass; plan 3 Task 8) |
| `image.push.refused` | `push refused: CARLOS_REGISTRY_PASSWORD is not set`; `push refused: --tag must be a release tag`; `push refused: --repo must be <registry>/<repo>`; `push refused: the layout holds %d manifests` (pending Luna pass; plan 3 Task 8) |
@@ -637,10 +638,11 @@ or an output's name: never a credential, a URL or a header. `%s` and
| Key | Text |
|---|---|
| `engine.selftest.usage` | `usage: carlos-media selftest <video\|audio>` (pending Luna pass; plan 3 Task 7) |
-| `engine.selftest.pass` | `PASS %s` (pending Luna pass; plan 3 Task 7). `%s` is a case: `video-1080p`, `video-portrait-rotated`, `video-pq-4k`, `video-location-tag`, `audio-voice-webm-live`, `audio-silent-wav`, `audio-mp3-cover-art` |
+| `engine.selftest.pass` | `PASS %s` (pending Luna pass; plan 3 Task 7). `%s` is a case: `tls-roots` (first in both selftests; branch review round 1), `video-1080p`, `video-portrait-rotated`, `video-pq-4k`, `video-location-tag`, `audio-voice-webm-live`, `audio-silent-wav`, `audio-mp3-cover-art` |
| `engine.selftest.fail` | `FAIL %s: %s` (pending Luna pass; plan 3 Task 7). A case and one of `engine.selftest.reason.*` |
| `engine.selftest.no_scratch` | `FAIL selftest: no directory in the scratch: %s`, `FAIL selftest: no local store: %s` (pending Luna pass; plan 3 Task 7). The system's error number's text |
| `engine.selftest.reason.*` | `no case directory: %s`; `ffmpeg could not make the source: %s`; `the source cannot be read: %s`; `the source does not sniff: %s`; `the source does not probe: %s`; `no payload: %s`; `the conversion exited %d`; `the handler broke the presigned contract: %s` (`a request the store did not sign` or `a signed header missing or changed`); `the result is not a success result`; `converted %d ms of a %d ms source`; `%s: stored %d bytes, the result says %d`; `%s does not read as a fragmented MP4: %s`; `%s: no playlist: %s`; `%s is not the playlist of %s`; `the result gives %s as %dx%d, want %dx%d`; `poster.jpg is not a JPEG`; `poster.jpg is %dx%d, want %dx%d`; `video.mp4 does not probe: %s`; `video.mp4 is %s %dx%d (rotation %d, SAR %d:%d), want h264 %dx%d` (fix 1: as encoded, never scaled first); `peaks.json does not hold %d peaks`; `peaks.json has a peak outside 0 to 255`; `a silent source has a peak of %d`; `every peak is 0`; `the source does not measure: %s`; `audio.mp4 does not measure: %s`; `audio.mp4's true peak is %.1f dBTP, over %.1f`; `audio.mp4 is %.1f LUFS, louder than %.0f LUFS`; `audio.mp4's loudness range is %.1f LU, the source's %.1f`; `a log line carries the source's metadata`; `%s carries the source's metadata` (pending Luna pass; plan 3 Task 7). Each `%s` after a colon is a job code, a system error number's text or one of the meter's fixed reasons |
+| `engine.selftest.reason.tls` | `tls-roots`'s reasons: `no root this binary trusts signs S3's certificate`; `S3's certificate does not verify`; `the embedded S3 chain does not parse` (pending Luna pass; branch review round 1) |
| `engine.selftest.measured` | `%s: source %.1f LUFS, %.1f dBTP, LRA %.1f LU; audio.mp4 %.1f LUFS, %.1f dBTP, LRA %.1f LU` (pending Luna pass; plan 3 Task 7). On stderr, the voice case only |
| `engine.loudness.reason.lra` | `the ebur128 summary's LRA is not a number`, `the ebur128 summary has no LRA` (pending Luna pass; plan 3 Task 7) |
| `engine.drill.usage` | `usage: carlos-media drill <creds\|dns\|net <address>…\|endpoints\|endpoints-verdict <A> <B> <C>\|hostile-timer\|fill-scratch\|many-files\|bad-outputs>` (pending Luna pass; plan 3 Task 7) |
diff --git a/go.mod b/go.mod
index 2ee19db4b..ec89b2262 100644
--- a/go.mod
+++ b/go.mod
@@ -29,6 +29,7 @@ require (
github.com/pion/turn/v4 v4.1.4
github.com/superfly/ltx v0.5.1
golang.org/x/crypto v0.58.0
+ golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
golang.org/x/net v0.62.0
golang.org/x/sys v0.49.0
modernc.org/sqlite v1.55.0
diff --git a/go.sum b/go.sum
index da48d34e6..795d715bc 100644
--- a/go.sum
+++ b/go.sum
@@ -232,6 +232,8 @@ golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54=
golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w=
+golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e h1:G2pNJMnWEb60ip90TMo++m9fpt+d3YIZa0er3buPKRo=
+golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e/go.mod h1:MEIPiCnxvQEjA4astfaKItNwEVZA5Ki+3+nyGbJ5N18=
golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
diff --git a/internal/mediahandler/handler.go b/internal/mediahandler/handler.go
index 4e51a1b4a..e03863ba9 100644
--- a/internal/mediahandler/handler.go
+++ b/internal/mediahandler/handler.go
@@ -13,6 +13,7 @@ package mediahandler
import (
"bytes"
"context"
+ "crypto/x509"
"encoding/json"
"errors"
"fmt"
@@ -82,6 +83,10 @@ type Config struct {
// diskFull reports whether the scratch's file system is full; nil
// is scratchFull. Tests replace it.
diskFull func(dir string) bool
+ // tlsRoots are the roots selftest's tls-roots case verifies against;
+ // nil is the process's own, as every transfer uses. Tests set them
+ // so the case does not depend on the machine's roots.
+ tlsRoots *x509.CertPool
}
// withDefaults fills every unset field.
diff --git a/internal/mediahandler/s3test_test.go b/internal/mediahandler/s3test_test.go
index 3588dc1f4..fb493eee2 100644
--- a/internal/mediahandler/s3test_test.go
+++ b/internal/mediahandler/s3test_test.go
@@ -159,8 +159,13 @@ type s3Server struct {
// newS3 starts a server whose grant expires an hour after clock's now.
func newS3(t *testing.T, clock *testClock) *s3Server {
+ return newS3On(t, clock, httptest.NewServer)
+}
+
+// newS3On is newS3 started by start: httptest.NewTLSServer for HTTPS.
+func newS3On(t *testing.T, clock *testClock, start func(http.Handler) *httptest.Server) *s3Server {
s := &s3Server{t: t, clock: clock, expiry: clock.Now().Add(time.Hour), objects: map[string]*s3Object{}, transfers: map[string]s3Transfer{}, Stalled: make(chan struct{}), Held: make(chan struct{})}
- s.srv = httptest.NewServer(http.HandlerFunc(s.serve))
+ s.srv = start(http.HandlerFunc(s.serve))
t.Cleanup(s.srv.Close)
return s
}
diff --git a/internal/mediahandler/selftest.go b/internal/mediahandler/selftest.go
index 908942263..f4802a477 100644
--- a/internal/mediahandler/selftest.go
+++ b/internal/mediahandler/selftest.go
@@ -121,6 +121,12 @@ func Selftest(ctx context.Context, cfg Config, kind string, w io.Writer) error {
if !ok {
return errors.New("selftest: unknown kind")
}
+ // The roots first: a binary that cannot verify S3 converts nothing,
+ // whatever its ffmpeg does.
+ failed := 0
+ if selftestTLS(w, cfg.tlsRoots) != nil {
+ failed++
+ }
cfg = cfg.withDefaults()
dir, err := os.MkdirTemp(cfg.Scratch, "selftest-")
if err != nil {
@@ -135,7 +141,6 @@ func Selftest(ctx context.Context, cfg Config, kind string, w io.Writer) error {
return err
}
defer store.Close()
- failed := 0
for _, c := range cases {
caseDir := filepath.Join(dir, c.name)
err := runSelftestCase(ctx, cfg, store, caseDir, c)
@@ -150,7 +155,7 @@ func Selftest(ctx context.Context, cfg Config, kind string, w io.Writer) error {
fmt.Fprintf(w, "PASS %s\n", c.name)
}
if failed > 0 {
- return fmt.Errorf("selftest: %d of %d cases failed", failed, len(cases))
+ return fmt.Errorf("selftest: %d of %d cases failed", failed, len(cases)+1)
}
return nil
}
diff --git a/internal/mediahandler/selftest_s3_chain.pem b/internal/mediahandler/selftest_s3_chain.pem
new file mode 100644
index 000000000..c989e7497
--- /dev/null
+++ b/internal/mediahandler/selftest_s3_chain.pem
@@ -0,0 +1,76 @@
+# A real S3 certificate chain for carlos-media selftest's tls-roots case
+# (internal/mediahandler/selftesttls.go): the leaf for *.s3.ap-south-1.amazonaws.com
+# as Certificate Transparency logged it (crt.sh id 29458616774), then its
+# issuer, Amazon RSA 2048 M01 (crt.sh id 7406820095). Public certificates only.
+-----BEGIN CERTIFICATE-----
+MIIIETCCBvmgAwIBAgIQA3YKZ2fEoEs6UvaMVA3WEzANBgkqhkiG9w0BAQsFADA8
+MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRwwGgYDVQQDExNBbWF6b24g
+UlNBIDIwNDggTTAxMB4XDTI2MDkxNDAwMDAwMFoXDTI3MDMzMDIzNTk1OVowKDEm
+MCQGA1UEAwwdKi5zMy5hcC1zb3V0aC0xLmFtYXpvbmF3cy5jb20wggEiMA0GCSqG
+SIb3DQEBAQUAA4IBDwAwggEKAoIBAQCPi09estKYxV923UAoO9NIJZyK/lmpWRyU
+sO6CVS3FOpkHPipl4cgN5lXExizJZGPCc66sHsDcjNLcEGT90YucsXYB4fMMfVHK
+bKwoYVUY/Ez5MCXwZB38vS/BQDViepBF65MNVxRHwJCBnltrrEMigzkFYNOeSK7q
+UMUP8aH9X8Qk2UF71b+KGlT/G3d1rLMKtH1r+yc36ZWizRh4w+d5/c1UIpvYnB4U
+3OGBxKJQ5GNrqngIfxhlyan5RPJMnD6Daqvpujuwo2EPuc7Ib40Ba8P8IHrYmVe/
+Pzui6GHeVWvSyTszq9+pUzqI3lfXdJG3VJeXLVefDwcY29RvzxiVAgMBAAGjggUh
+MIIFHTAfBgNVHSMEGDAWgBSBuA5jiokSGOX6OztQlZ/m5ZAThTAdBgNVHQ4EFgQU
+4wd9tFSmZH56rB7RpKMvXChEaUEwggJZBgNVHREEggJQMIICTIIdKi5zMy5hcC1z
+b3V0aC0xLmFtYXpvbmF3cy5jb22CEiouczMuYW1hem9uYXdzLmNvbYImczMtZGVw
+cmVjYX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kEUDeK/pZwTXv4KqPK0G50fOHOQAd8j21p0cMBgbG
+kfMHVwLU7b0XwZCav0h1ogdPMN1KakK1DT0VwA/+hFvGPJnMV1Kx2G4S1ZaSk0uU
+5QfoiYIIano01J5k4T2HapKQmmOhS/iPtuo00wW+IMLeBuKMn3OLn005hcrOGTad
+hcmeyfhQP7Z+iKHvyoQGi1C0ClymHETx/chhQGDyYSWqB/THwnN15AwLQo0E5V9E
+SJlbe4mBlqeInUsNYugExNf+tOiybcrswBy8OFsd34XOW3rjSUtsuafd9AWySa3h
+xRRrwszrzX/WWGm6wyB+f7C4
+-----END CERTIFICATE-----
diff --git a/internal/mediahandler/selftest_test.go b/internal/mediahandler/selftest_test.go
index f59046fa3..974ef9455 100644
--- a/internal/mediahandler/selftest_test.go
+++ b/internal/mediahandler/selftest_test.go
@@ -23,12 +23,13 @@ func TestSelftestReal(t *testing.T) {
t.Run(kind, func(t *testing.T) {
cfg := real
cfg.Scratch = t.TempDir()
+ cfg.tlsRoots = selftestIssuerRoots(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
var out bytes.Buffer
err := Selftest(ctx, cfg, kind, &out)
t.Logf("%s", out.String())
- if err != nil || strings.Count(out.String(), "PASS ") != len(selftestCases[kind]) {
+ if err != nil || strings.Count(out.String(), "PASS ") != len(selftestCases[kind])+1 {
t.Fatalf("Selftest(%s): %v\n%s", kind, err, out.String())
}
})
@@ -41,16 +42,17 @@ func TestSelftestReal(t *testing.T) {
func TestSelftestFailsEachCase(t *testing.T) {
needChildren(t)
cfg, _ := fakeConfig(t, "fail")
+ cfg.tlsRoots = selftestIssuerRoots(t)
var out bytes.Buffer
if err := Selftest(context.Background(), cfg, SelftestAudio, &out); err == nil {
t.Fatal("Selftest passed on a failing ffmpeg")
}
lines := strings.Split(strings.TrimSpace(out.String()), "\n")
- if len(lines) != len(selftestCases[SelftestAudio]) {
+ if len(lines) != 1+len(selftestCases[SelftestAudio]) || lines[0] != "PASS tls-roots" {
t.Fatalf("%d lines\n%s", len(lines), out.String())
}
for i, c := range selftestCases[SelftestAudio] {
- if lines[i] != "FAIL "+c.name+": ffmpeg could not make the source: unreadable" {
+ if lines[i+1] != "FAIL "+c.name+": ffmpeg could not make the source: unreadable" {
t.Errorf("line %q", lines[i])
}
}
diff --git a/internal/mediahandler/selftesttls.go b/internal/mediahandler/selftesttls.go
new file mode 100644
index 000000000..50903de06
--- /dev/null
+++ b/internal/mediahandler/selftesttls.go
@@ -0,0 +1,91 @@
+package mediahandler
+
+import (
+ "crypto/x509"
+ _ "embed"
+ "encoding/pem"
+ "errors"
+ "fmt"
+ "io"
+ "time"
+)
+
+// The engine image has no CA bundle, so carlos-media embeds roots of its
+// own (cmd/carlos-media's x509roots/fallback import, branch review round
+// 1, P1-B). selftest's first case proves the roots the binary ends up
+// with verify a real S3 certificate, offline: R2 runs it on Fargate before
+// any tenant's file is converted, where a missing root would otherwise
+// show only as every job failing unreadable.
+
+// selftestS3Chain is a real S3 leaf and its issuing intermediate, as
+// Certificate Transparency logged them (the file names both).
+//
+//go:embed selftest_s3_chain.pem
+var selftestS3Chain []byte
+
+// selftestTLSHost is a name the leaf covers, and selftestTLSTime a moment
+// inside its validity (2026-09-14 to 2027-03-30), so the check never
+// depends on today's date or reaches the network.
+const selftestTLSHost = "s3.ap-south-1.amazonaws.com"
+
+var selftestTLSTime = time.Date(2026, 12, 1, 0, 0, 0, 0, time.UTC)
+
+// selftestTLSCase is the case's name on its PASS or FAIL line.
+const selftestTLSCase = "tls-roots"
+
+// SelftestTLS verifies selftestS3Chain against the process's roots (the
+// system's when it has any, else the ones the binary embeds) and prints
+// "PASS tls-roots" or "FAIL tls-roots: <reason>" to w. The reason is fixed
+// words: a certificate's own text is never printed.
+func SelftestTLS(w io.Writer) error { return selftestTLS(w, nil) }
+
+// selftestTLS is SelftestTLS against roots, nil being the process's own.
+func selftestTLS(w io.Writer, roots *x509.CertPool) error {
+ err := verifySelftestChain(selftestS3Chain, roots)
+ if err != nil {
+ // engine.selftest.fail (pending Luna pass).
+ fmt.Fprintf(w, "FAIL %s: %v\n", selftestTLSCase, err)
+ return err
+ }
+ // engine.selftest.pass (pending Luna pass).
+ fmt.Fprintf(w, "PASS %s\n", selftestTLSCase)
+ return nil
+}
+
+// verifySelftestChain verifies chain's first certificate, with the rest
+// as intermediates, for selftestTLSHost at selftestTLSTime against roots,
+// nil being the process's own. Its errors are engine.selftest.reason.tls
+// rows.
+func verifySelftestChain(chain []byte, roots *x509.CertPool) error {
+ var certs []*x509.Certificate
+ for rest := chain; ; {
+ var block *pem.Block
+ block, rest = pem.Decode(rest)
+ if block == nil {
+ break
+ }
+ c, err := x509.ParseCertificate(block.Bytes)
+ if err != nil {
+ return errors.New("the embedded S3 chain does not parse")
+ }
+ certs = append(certs, c)
+ }
+ if len(certs) < 2 {
+ return errors.New("the embedded S3 chain does not parse")
+ }
+ inter := x509.NewCertPool()
+ for _, c := range certs[1:] {
+ inter.AddCert(c)
+ }
+ _, err := certs[0].Verify(x509.VerifyOptions{
+ DNSName: selftestTLSHost, Intermediates: inter, Roots: roots, CurrentTime: selftestTLSTime,
+ })
+ var unknown x509.UnknownAuthorityError
+ switch {
+ case err == nil:
+ return nil
+ case errors.As(err, &unknown):
+ return errors.New("no root this binary trusts signs S3's certificate")
+ }
+ return errors.New("S3's certificate does not verify")
+}
diff --git a/internal/mediahandler/selftesttls_test.go b/internal/mediahandler/selftesttls_test.go
new file mode 100644
index 000000000..85059687b
--- /dev/null
+++ b/internal/mediahandler/selftesttls_test.go
@@ -0,0 +1,53 @@
+package mediahandler
+
+import (
+ "bytes"
+ "crypto/x509"
+ "encoding/pem"
+ "testing"
+)
+
+// selftestIssuerRoots is a pool holding only the embedded chain's issuer,
+// so the tls-roots case passes whatever roots this machine has.
+func selftestIssuerRoots(t testing.TB) *x509.CertPool {
+ t.Helper()
+ rest := selftestS3Chain
+ var last *x509.Certificate
+ for {
+ var block *pem.Block
+ if block, rest = pem.Decode(rest); block == nil {
+ break
+ }
+ c, err := x509.ParseCertificate(block.Bytes)
+ if err != nil {
+ t.Fatal(err)
+ }
+ last = c
+ }
+ pool := x509.NewCertPool()
+ pool.AddCert(last)
+ return pool
+}
+
+// TestSelftestChainVerifies: the embedded chain is a leaf for the host
+// and its issuer, valid at the fixed time, and the case reports which of
+// its fixed reasons applies.
+func TestSelftestChainVerifies(t *testing.T) {
+ if err := verifySelftestChain(selftestS3Chain, selftestIssuerRoots(t)); err != nil {
+ t.Fatalf("the chain under its own issuer: %v", err)
+ }
+ if err := verifySelftestChain(selftestS3Chain, x509.NewCertPool()); err == nil || err.Error() != "no root this binary trusts signs S3's certificate" {
+ t.Fatalf("no roots at all: %v", err)
+ }
+ if err := verifySelftestChain([]byte("not a chain"), nil); err == nil || err.Error() != "the embedded S3 chain does not parse" {
+ t.Fatalf("garbage: %v", err)
+ }
+ var out bytes.Buffer
+ if err := selftestTLS(&out, x509.NewCertPool()); err == nil || out.String() != "FAIL tls-roots: no root this binary trusts signs S3's certificate\n" {
+ t.Fatalf("selftestTLS with no roots: %v %q", err, out.String())
+ }
+ out.Reset()
+ if err := selftestTLS(&out, selftestIssuerRoots(t)); err != nil || out.String() != "PASS tls-roots\n" {
+ t.Fatalf("selftestTLS: %v %q", err, out.String())
+ }
+}
diff --git a/internal/mediahandler/tls_test.go b/internal/mediahandler/tls_test.go
new file mode 100644
index 000000000..4bd175252
--- /dev/null
+++ b/internal/mediahandler/tls_test.go
@@ -0,0 +1,136 @@
+package mediahandler
+
+import (
+ "bytes"
+ "context"
+ "crypto/ecdsa"
+ "crypto/elliptic"
+ "crypto/rand"
+ "crypto/x509"
+ "crypto/x509/pkix"
+ "encoding/pem"
+ "math/big"
+ "net"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/media"
+)
+
+// tlsChildEnv names the mode a re-executed test binary runs
+// TestTransfersVerifyTLSWithTheProductionClient's child in.
+const tlsChildEnv = "MEDIA_TEST_TLS_CHILD"
+
+// TestTransfersVerifyTLSWithTheProductionClient (branch review round 1,
+// P1-B): the source GET and an output PUT reach an HTTPS store through
+// the client production builds (Config.HTTP nil), which verifies the
+// store's certificate against the process's roots exactly as the engine
+// gets them: Go loads them once, from SSL_CERT_FILE and SSL_CERT_DIR
+// here, in a fresh process that has made no TLS connection before. A
+// store whose certificate no root signs gets no request at all.
+func TestTransfersVerifyTLSWithTheProductionClient(t *testing.T) {
+ if mode := os.Getenv(tlsChildEnv); mode != "" {
+ tlsChild(t, mode)
+ return
+ }
+ for _, mode := range []string{"trusted", "untrusted"} {
+ t.Run(mode, func(t *testing.T) {
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ defer cancel()
+ cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestTransfersVerifyTLSWithTheProductionClient$", "-test.count=1", "-test.v")
+ cmd.Env = append(os.Environ(), tlsChildEnv+"="+mode)
+ out, err := cmd.CombinedOutput()
+ if err != nil || !strings.Contains(string(out), "--- PASS: TestTransfersVerifyTLSWithTheProductionClient") {
+ t.Fatalf("child %s: %v\n%s", mode, err, out)
+ }
+ })
+ }
+}
+
+// tlsChild is the child's half: an HTTPS store, the roots Go will load,
+// then one download and one upload with the production client.
+func tlsChild(t *testing.T, mode string) {
+ h := newHarness(t)
+ h.s = newS3On(t, h.clock, httptest.NewTLSServer)
+ root := h.s.srv.Certificate()
+ if mode == "untrusted" {
+ root = selfSigned(t)
+ }
+ dir := t.TempDir()
+ rootsFile := filepath.Join(dir, "roots.pem")
+ if err := os.WriteFile(rootsFile, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: root.Raw}), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ none := filepath.Join(dir, "no-certs")
+ if err := os.Mkdir(none, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ // Before any TLS in this process: Go reads both once, at its first
+ // verification, as it does in the engine's task.
+ t.Setenv("SSL_CERT_FILE", rootsFile)
+ t.Setenv("SSL_CERT_DIR", none)
+
+ cfg := h.cfg
+ cfg.HTTP = nil // production's client: defaultHTTPClient
+ data := bytes.Repeat([]byte("source over https "), 4096)
+ p := h.s.payload(t, media.PresetVideo720p, data, 8*mib)
+ if !strings.HasPrefix(p.Transfers.Source.URL, "https://") {
+ t.Fatalf("the source is not on HTTPS: %s", p.Transfers.Source.URL)
+ }
+ dst := filepath.Join(dir, "source")
+ err := Download(context.Background(), cfg, p, dst)
+ if mode == "untrusted" {
+ if err == nil {
+ t.Fatal("a store whose certificate no root signs served the source")
+ }
+ if n := len(h.s.Requests()); n != 0 {
+ t.Fatalf("%d requests reached a store whose certificate no root signs", n)
+ }
+ return
+ }
+ if err != nil {
+ t.Fatalf("download over HTTPS: %v; logs %q", err, h.Logs())
+ }
+ if got, err := os.ReadFile(dst); err != nil || !bytes.Equal(got, data) {
+ t.Fatalf("downloaded %d bytes, %v", len(got), err)
+ }
+ out := filepath.Join(dir, "video.mp4")
+ if err := os.WriteFile(out, []byte("an output over https"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := Upload(context.Background(), cfg, p, p.Transfers.Outputs[0], out); err != nil {
+ t.Fatalf("upload over HTTPS: %v; logs %q", err, h.Logs())
+ }
+ if got, _ := h.s.Object(outPrefix + "video.mp4"); string(got) != "an output over https" {
+ t.Fatalf("stored output %q", got)
+ }
+}
+
+// selfSigned is a certificate for 127.0.0.1 no store here is served with.
+func selfSigned(t *testing.T) *x509.Certificate {
+ t.Helper()
+ key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+ tmpl := &x509.Certificate{
+ SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "another store"},
+ NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(time.Hour),
+ IPAddresses: []net.IP{net.ParseIP("127.0.0.1")}, IsCA: true, BasicConstraintsValid: true,
+ KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageDigitalSignature,
+ }
+ der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ c, err := x509.ParseCertificate(der)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return c
+}