carlos / platform Public

Devbox mode on macOS (#488): launchd socket, LOCAL_PEERCRED, env file

On a Mac, launchd binds the tailnet address :443 as root and hands the
listening socket to carlos devbox serve, which runs as its own user
(internal/launchd, no cgo). The registrar identifies callers with
LOCAL_PEERCRED. serve --env-file reads a private KEY=VALUE file, refusing
open modes, other owners, ACLs (internal/fileacl) and FIFOs, because a
LaunchDaemon plist is world-readable. infra/devbox gains the plist and a
macOS runbook section.

Reviews: Astra whole-branch (xhigh), 1 P1 and 2 P2, all fixed and
re-reviewed clean. Darwin tests passed on a real Mac. Census approved by
Astra on #280. Copy DBX-C58..C93 approved by Paul. Not released.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from devbox-macos into main.
claude agent, operated by paul@keymail.dev 90c4d3aaeeac668193f938ba6f628b88ebf7eae1 parent 11c8c86
34 files changed, +1,912 −26
  • approved_devbox_copy_test.go +6 −4
  • devbox_cli.go +143 −15
  • devbox_cli_test.go +331 −0
  • devbox_envfile.go +118 −0
  • devbox_envfile_darwin_test.go +40 −0
  • devbox_envfile_other.go +12 −0
  • devbox_envfile_unix.go +27 −0
  • devbox_plist_test.go +196 −0
  • docs/superpowers/notes/census-proposal-devbox-macos.md +29 −0
  • docs/superpowers/plans/2026-10-30-devbox-mode-copy.md +52 −0
  • docs/superpowers/plans/2026-10-31-devbox-macos.md +101 −0
  • infra/devbox/README.md +89 −0
  • infra/devbox/com.carlosframework.devbox.plist +68 −0
  • internal/devbox/peer_darwin.go +48 −0
  • internal/devbox/peer_darwin_test.go +54 −0
  • internal/devbox/peer_other.go +4 −3
  • internal/edge/devbox.go +69 −4
  • internal/edge/devbox_test.go +103 −0
  • internal/fileacl/fileacl.go +15 −0
  • internal/fileacl/fileacl_darwin.go +76 −0
  • internal/fileacl/fileacl_darwin_amd64.s +19 −0
  • internal/fileacl/fileacl_darwin_arm64.s +19 −0
  • internal/fileacl/fileacl_darwin_test.go +40 −0
  • internal/fileacl/fileacl_other.go +8 −0
  • internal/fileacl/fileacl_other_test.go +24 −0
  • internal/launchd/activate_darwin.go +82 −0
  • internal/launchd/activate_darwin_amd64.s +15 −0
  • internal/launchd/activate_darwin_arm64.s +15 −0
  • internal/launchd/activate_darwin_test.go +34 −0
  • internal/launchd/activate_other.go +14 −0
  • internal/launchd/activate_other_test.go +15 −0
  • internal/launchd/launchd.go +21 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-devbox-macos.tsv +24 −0

CI passed — run details

diff --git a/approved_devbox_copy_test.go b/approved_devbox_copy_test.go
index f68c56056..37bb82f55 100644
--- a/approved_devbox_copy_test.go
+++ b/approved_devbox_copy_test.go
@@ -13,7 +13,7 @@ import (
// checked with its helpers, so "applied" means the same thing in every gate:
//
// - TestDevboxCopyRecordIsComplete: the deck names exactly DBX-C1 to
-// DBX-C52;
+// DBX-C93;
// - TestDevboxBuiltCopyIsApproved: an id in devboxCopyBuilt is an approved
// row (a string reaches code only after Paul has approved it);
// - TestDevboxBuiltCopyIsApplied: a built row's text is in the file it
@@ -23,10 +23,10 @@ const devboxCopyRecordPath = "docs/superpowers/plans/2026-10-30-devbox-mode-copy
var devboxCopyIDPattern = regexp.MustCompile(`^DBX-C[1-9][0-9]*$`)
-// devboxCopyIDs is the deck's inventory: DBX-C1 to DBX-C57, pinned.
+// devboxCopyIDs is the deck's inventory: DBX-C1 to DBX-C93, pinned.
var devboxCopyIDs = func() []string {
- ids := make([]string, 0, 57)
- for i := 1; i <= 57; i++ {
+ ids := make([]string, 0, 93)
+ for i := 1; i <= 93; i++ {
ids = append(ids, "DBX-C"+strconv.Itoa(i))
}
return ids
@@ -36,6 +36,8 @@ var devboxCopyIDs = func() []string {
// The task that writes a row's text adds its id here in the same commit.
var devboxCopyBuilt = []string{
"DBX-C1", "DBX-C2", "DBX-C3", "DBX-C4", "DBX-C5", "DBX-C6", "DBX-C7", "DBX-C8", "DBX-C9", "DBX-C10", "DBX-C11", "DBX-C12", "DBX-C13", "DBX-C14", "DBX-C15", "DBX-C16", "DBX-C17", "DBX-C18", "DBX-C19", "DBX-C20", "DBX-C21", "DBX-C22", "DBX-C23", "DBX-C24", "DBX-C25", "DBX-C26", "DBX-C27", "DBX-C28", "DBX-C29", "DBX-C30", "DBX-C31", "DBX-C32", "DBX-C33", "DBX-C34", "DBX-C35", "DBX-C36", "DBX-C37", "DBX-C38", "DBX-C39", "DBX-C40", "DBX-C41", "DBX-C42", "DBX-C43", "DBX-C44", "DBX-C45", "DBX-C46", "DBX-C47", "DBX-C48", "DBX-C49", "DBX-C50", "DBX-C51", "DBX-C52", "DBX-C53", "DBX-C54", "DBX-C55", "DBX-C56", "DBX-C57",
+ // macOS (#488)
+ "DBX-C58", "DBX-C59", "DBX-C60", "DBX-C61", "DBX-C62", "DBX-C63", "DBX-C64", "DBX-C65", "DBX-C66", "DBX-C67", "DBX-C68", "DBX-C69", "DBX-C70", "DBX-C71", "DBX-C72", "DBX-C73", "DBX-C74", "DBX-C75", "DBX-C76", "DBX-C77", "DBX-C78", "DBX-C79", "DBX-C80", "DBX-C81", "DBX-C82", "DBX-C83", "DBX-C84", "DBX-C85", "DBX-C86", "DBX-C87", "DBX-C88", "DBX-C89", "DBX-C90", "DBX-C91", "DBX-C92", "DBX-C93",
}
func mustParseDevboxRecord(t *testing.T) []copyRow {
diff --git a/devbox_cli.go b/devbox_cli.go
index 0d6f6065e..529796fa4 100644
--- a/devbox_cli.go
+++ b/devbox_cli.go
@@ -26,6 +26,7 @@ import (
"os/signal"
"os/user"
"path/filepath"
+ "runtime"
"slices"
"strconv"
"strings"
@@ -35,6 +36,7 @@ import (
"github.com/carlosframework/platform/internal/devbox"
"github.com/carlosframework/platform/internal/edge"
+ "github.com/carlosframework/platform/internal/launchd"
"github.com/carlosframework/platform/internal/registry"
)
@@ -63,6 +65,51 @@ const (
devboxInternal = "the devbox service could not finish that. try again, or tell whoever runs this devbox" // DBX-C54
)
+// serve's rows (macOS plan #488).
+const (
+ devboxUsageServe = "usage: carlos devbox serve [--env-file <env file>]" // DBX-C58
+ devboxHelpServe = "serve runs the devbox service. its systemd unit or launchd daemon starts it, and nobody else needs to" // DBX-C59
+ devboxHelpEnvFile = "a file of KEY=VALUE lines to read before serving. blank lines and lines starting with # are skipped, and values are taken as written, with no quotes. a setting in the file replaces one already in the environment. the file must belong to this account, and only this account may read or change it" // DBX-C60
+)
+
+func devboxEnvUnreadable(file string) string {
+ return fmt.Sprintf("could not read the environment file %s. check that it exists and that this account can read it", file) // DBX-C61
+}
+func devboxEnvOpen(file string) string {
+ return fmt.Sprintf("other accounts can read or change the environment file %s. make it private with: chmod 600 %s", file, file) // DBX-C62
+}
+func devboxEnvOwner(file string) string {
+ return fmt.Sprintf("the environment file %s belongs to another account. it must belong to the account the service runs as", file) // DBX-C63
+}
+func devboxEnvACL(file string) string {
+ return fmt.Sprintf("the environment file %s has an access control list, which can let other accounts read or change it. remove it with: chmod -N %s", file, file) // DBX-C93
+}
+func devboxEnvBadLine(line int, file string) string {
+ return fmt.Sprintf("line %d of %s is not KEY=VALUE, where KEY is letters, digits and underscores and does not start with a digit. each line must be a setting, a comment starting with #, or blank", line, file) // DBX-C64
+}
+func devboxEnvDuplicate(key, file string, first, second int) string {
+ return fmt.Sprintf("%s is set twice in %s, on lines %d and %d. keep one", key, file, first, second) // DBX-C65
+}
+
+// The launchd socket's rows.
+const (
+ devboxLaunchdNotManaged = "CARLOS_DEVBOX_LAUNCHD_SOCKET is set, but launchd did not start this process, so there is no socket to take. start the service with launchctl, or unset CARLOS_DEVBOX_LAUNCHD_SOCKET to run it by hand" // DBX-C66
+ devboxLaunchdUnsupported = "CARLOS_DEVBOX_LAUNCHD_SOCKET is set, but only macOS hands over sockets this way. unset it, and the service binds CARLOS_DEVBOX_LISTEN itself" // DBX-C69
+)
+
+func devboxLaunchdNoSocket(name string) string {
+ return fmt.Sprintf("launchd has no socket called %s for this service. the Sockets entry in the plist and CARLOS_DEVBOX_LAUNCHD_SOCKET must use the same name", name) // DBX-C67
+}
+func devboxLaunchdTooMany(count int, name string) string {
+ return fmt.Sprintf("launchd handed over %d sockets called %s, and the service serves on exactly one. set SockFamily to IPv4 in the plist", count, name) // DBX-C68
+}
+func devboxLaunchdEveryInterface(addr string) string {
+ return fmt.Sprintf("launchd's socket listens on every interface, %s. set SockNodeName in the plist to the tailnet address in CARLOS_DEVBOX_LISTEN", addr) // DBX-C70
+}
+func devboxLaunchdWrongAddr(addr, want string) string {
+ return fmt.Sprintf("launchd's socket listens on %s, but CARLOS_DEVBOX_LISTEN is %s. make SockNodeName and SockServiceName in the plist match it", addr, want) // DBX-C71
+}
+
// The rows with placeholders, one format each.
func devboxPrinted(url string) string { return url } // DBX-C11
func devboxRemoved(url string) string { return fmt.Sprintf("removed %s", url) } // DBX-C12
@@ -104,8 +151,24 @@ func devboxInUse(name string) string {
return fmt.Sprintf("%s is already in use on this devbox. pick another name", name) // DBX-C53
}
-// devboxDefaultSocket is where the unit's RuntimeDirectory puts the socket.
-const devboxDefaultSocket = "/run/carlos-devbox/devbox.sock"
+// devboxDefaultSocket is where the service puts the registrar socket: the
+// systemd unit's RuntimeDirectory on Linux, and on macOS the folder the
+// runbook creates, since /var/run there is root's alone.
+func devboxDefaultSocket(goos string) string {
+ if goos == "darwin" {
+ return "/usr/local/var/run/carlos-devbox/devbox.sock"
+ }
+ return "/run/carlos-devbox/devbox.sock"
+}
+
+// devboxSocketPath is the registrar socket: CARLOS_DEVBOX_SOCKET, or this
+// OS's default.
+func devboxSocketPath() string {
+ if sock := strings.TrimSpace(os.Getenv("CARLOS_DEVBOX_SOCKET")); sock != "" {
+ return sock
+ }
+ return devboxDefaultSocket(runtime.GOOS)
+}
// devboxSpoolCap is the total the folder spool may hold.
const devboxSpoolCap = 5 << 30
@@ -124,16 +187,12 @@ type devboxCLI struct {
}
func newDevboxCLI(stdout, stderr io.Writer) *devboxCLI {
- sock := strings.TrimSpace(os.Getenv("CARLOS_DEVBOX_SOCKET"))
- if sock == "" {
- sock = devboxDefaultSocket
- }
- return &devboxCLI{stdout: stdout, stderr: stderr, socket: sock, branch: gitCurrentBranch, now: time.Now}
+ return &devboxCLI{stdout: stdout, stderr: stderr, socket: devboxSocketPath(), branch: gitCurrentBranch, now: time.Now}
}
func runDevbox(args []string) {
if len(args) > 0 && args[0] == "serve" {
- if err := runDevboxServe(args[1:]); err != nil {
+ if err := runDevboxServe(args[1:]); err != nil && !errors.Is(err, flag.ErrHelp) {
log.Fatal(err)
}
return
@@ -528,8 +587,21 @@ func (c *devboxCLI) call(method, path, contentType string, body []byte, rc refus
// link record under CARLOS_DATA_DIR, and serves the edge and the registrar
// until SIGTERM or SIGINT, or until either fails.
func runDevboxServe(args []string) error {
- if len(args) > 0 {
- return fmt.Errorf("devbox serve: takes no arguments, got %q", args)
+ fs := flag.NewFlagSet("devbox serve", flag.ContinueOnError)
+ fs.Usage = flagUsage(fs, devboxUsageServe+"\n"+devboxHelpServe)
+ envFile := fs.String("env-file", "", devboxHelpEnvFile)
+ if err := fs.Parse(args); err != nil {
+ return err
+ }
+ if fs.NArg() > 0 {
+ return fmt.Errorf("devbox serve: takes no arguments, got %q", fs.Args())
+ }
+ // The file first, so that everything below reads the environment the
+ // service is meant to have.
+ if *envFile != "" {
+ if err := loadDevboxEnvFile(*envFile, os.Geteuid()); err != nil {
+ return err
+ }
}
listen := strings.TrimSpace(os.Getenv("CARLOS_DEVBOX_LISTEN"))
domain := strings.ToLower(strings.TrimSpace(os.Getenv("CARLOS_DEVBOX_DOMAIN")))
@@ -549,6 +621,24 @@ func runDevboxServe(args []string) error {
}) {
return fmt.Errorf("devbox serve: CARLOS_DEVBOX_DOMAIN %s is not in CARLOS_WILDCARD_DOMAINS", domain)
}
+ // On macOS launchd binds port 443 and hands the socket over; the plist
+ // names its Sockets entry here. It is held to CARLOS_DEVBOX_LISTEN
+ // before anything else starts.
+ var given net.Listener
+ if name := strings.TrimSpace(os.Getenv("CARLOS_DEVBOX_LAUNCHD_SOCKET")); name != "" {
+ ln, err := devboxLaunchdListener(name, launchd.Listeners)
+ if err != nil {
+ return err
+ }
+ if err := edge.CheckDevboxListener(ln, listen); err != nil {
+ ln.Close()
+ return devboxListenerRefusal(err)
+ }
+ // ServeDevbox closes it once it has it; this is for a failure on
+ // the way there.
+ defer ln.Close()
+ given = ln
+ }
// The unit's StateDirectory makes it; this is for a run outside one.
if err := os.MkdirAll(dataDir, 0o700); err != nil {
return fmt.Errorf("devbox serve: %w", err)
@@ -571,15 +661,53 @@ func runDevboxServe(args []string) error {
SpoolCap: devboxSpoolCap,
LookupUser: lookupUsername,
}
- cfg := edge.DevboxConfig{Registry: reg, ListenAddr: listen, CertDir: filepath.Join(dataDir, "certs"), SpoolRoot: spool}
+ cfg := edge.DevboxConfig{Registry: reg, ListenAddr: listen, Listener: given, CertDir: filepath.Join(dataDir, "certs"), SpoolRoot: spool}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, os.Interrupt)
defer stop()
- sock := strings.TrimSpace(os.Getenv("CARLOS_DEVBOX_SOCKET"))
- if sock == "" {
- sock = devboxDefaultSocket
+ return serveDevboxParts(ctx, devboxSocketPath(), r, func(ctx context.Context) error {
+ return devboxListenerRefusal(edge.ServeDevbox(ctx, cfg))
+ })
+}
+
+// devboxLaunchdListener takes the one listening socket launchd opened for
+// the plist's Sockets entry called name, refusing in the deck's words what
+// it cannot serve on. take is launchd.Listeners (a test replaces it).
+func devboxLaunchdListener(name string, take func(string) ([]net.Listener, error)) (net.Listener, error) {
+ lns, err := take(name)
+ switch {
+ case errors.Is(err, errors.ErrUnsupported):
+ return nil, errors.New(devboxLaunchdUnsupported)
+ case errors.Is(err, launchd.ErrNotManaged):
+ return nil, errors.New(devboxLaunchdNotManaged)
+ case errors.Is(err, launchd.ErrNoSocket):
+ return nil, errors.New(devboxLaunchdNoSocket(name))
+ case err != nil:
+ return nil, fmt.Errorf("devbox serve: %w", err)
+ }
+ switch len(lns) {
+ case 0:
+ return nil, errors.New(devboxLaunchdNoSocket(name))
+ case 1:
+ return lns[0], nil
+ }
+ for _, ln := range lns {
+ ln.Close()
+ }
+ return nil, errors.New(devboxLaunchdTooMany(len(lns), name))
+}
+
+// devboxListenerRefusal words the edge's refusal of launchd's socket for a
+// person; any other error is returned as it is.
+func devboxListenerRefusal(err error) error {
+ var le *edge.DevboxListenerError
+ if !errors.As(err, &le) {
+ return err
+ }
+ if le.Unspecified {
+ return errors.New(devboxLaunchdEveryInterface(le.Addr))
}
- return serveDevboxParts(ctx, sock, r, func(ctx context.Context) error { return edge.ServeDevbox(ctx, cfg) })
+ return errors.New(devboxLaunchdWrongAddr(le.Addr, le.Want))
}
// lookupUsername is the account name for uid, or "" when this machine has
diff --git a/devbox_cli_test.go b/devbox_cli_test.go
index 8121996cf..d0b3f241c 100644
--- a/devbox_cli_test.go
+++ b/devbox_cli_test.go
@@ -12,18 +12,23 @@ import (
"bytes"
"context"
"encoding/json"
+ "errors"
"fmt"
"net"
"net/http"
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strings"
"sync"
+ "syscall"
"testing"
"time"
"github.com/carlosframework/platform/internal/devbox"
+ "github.com/carlosframework/platform/internal/edge"
+ "github.com/carlosframework/platform/internal/launchd"
"github.com/carlosframework/platform/internal/registry"
)
@@ -489,3 +494,329 @@ func TestDevboxServeStopsBothOnError(t *testing.T) {
t.Fatal("the edge was not stopped")
}
}
+
+// ---- serve --env-file (macOS plan #488 Task 2) ------------------------------
+
+// writeDevboxEnvFile writes body to a fresh file with mode perm.
+func writeDevboxEnvFile(t *testing.T, body string, perm os.FileMode) string {
+ t.Helper()
+ p := filepath.Join(t.TempDir(), "env")
+ if err := os.WriteFile(p, []byte(body), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ // WriteFile's mode is cut by the umask; Chmod is not.
+ if err := os.Chmod(p, perm); err != nil {
+ t.Fatal(err)
+ }
+ return p
+}
+
+// A 0600 file owned by this user sets its variables, over any already in
+// the environment, before serve reads its config.
+func TestDevboxServeEnvFileLoads(t *testing.T) {
+ for _, k := range []string{"DBX_TEST_A", "DBX_TEST_B", "DBX_TEST_C"} {
+ t.Setenv(k, "") // restored after the test
+ }
+ t.Setenv("DBX_TEST_B", "from the environment")
+ p := writeDevboxEnvFile(t, "# a comment\n\nDBX_TEST_A=one\n DBX_TEST_B=two=2 # not a comment\r\n\t# indented comment\nDBX_TEST_C=\n", 0o600)
+ if err := loadDevboxEnvFile(p, os.Geteuid()); err != nil {
+ t.Fatalf("load = %v", err)
+ }
+ for k, want := range map[string]string{"DBX_TEST_A": "one", "DBX_TEST_B": "two=2 # not a comment", "DBX_TEST_C": ""} {
+ if got := os.Getenv(k); got != want {
+ t.Errorf("%s = %q, want %q", k, got, want)
+ }
+ }
+
+ // Through serve itself: the file's domain is what serve checks against
+ // CARLOS_WILDCARD_DOMAINS, so the file was read before the config.
+ for _, k := range []string{"CARLOS_DEVBOX_LISTEN", "CARLOS_DEVBOX_DOMAIN", "CARLOS_DATA_DIR", "CARLOS_WILDCARD_DOMAINS", "CARLOS_DEVBOX_LAUNCHD_SOCKET"} {
+ t.Setenv(k, "")
+ }
+ t.Setenv("CARLOS_WILDCARD_DOMAINS", "other.example.com")
+ data := filepath.Join(t.TempDir(), "data")
+ p = writeDevboxEnvFile(t, "CARLOS_DEVBOX_LISTEN=127.0.0.1:8443\nCARLOS_DEVBOX_DOMAIN=from-file.example.com\nCARLOS_DATA_DIR="+data+"\n", 0o600)
+ err := runDevboxServe([]string{"--env-file", p})
+ if err == nil || !strings.Contains(err.Error(), "from-file.example.com is not in CARLOS_WILDCARD_DOMAINS") {
+ t.Fatalf("serve = %v, want the file's domain refused", err)
+ }
+ if _, err := os.Stat(data); err == nil {
+ t.Fatal("serve made the data dir before refusing its config")
+ }
+}
+
+// Values are kept exactly as written after the first '=': trailing spaces
+// and whitespace-only values survive. Only a CRLF file's \r is dropped, and
+// blank and comment lines are told apart by their first non-space byte.
+func TestDevboxServeEnvFileKeepsValues(t *testing.T) {
+ for _, k := range []string{"DBX_TEST_A", "DBX_TEST_B", "DBX_TEST_C", "DBX_TEST_D", "DBX_TEST_E"} {
+ t.Setenv(k, "")
+ }
+ body := "DBX_TEST_A=abc \n" + // trailing spaces
+ "DBX_TEST_B= \n" + // whitespace only
+ "DBX_TEST_C= lead\ttab\t\r\n" + // CRLF; the tab before it stays
+ " \t\r\n" + // a blank line, CRLF
+ " # a comment = with an equals sign\r\n" +
+ "\tDBX_TEST_D=x # y\n" +
+ "DBX_TEST_E=no newline at the end "
+ p := writeDevboxEnvFile(t, body, 0o600)
+ if err := loadDevboxEnvFile(p, os.Geteuid()); err != nil {
+ t.Fatalf("load = %v", err)
+ }
+ for k, want := range map[string]string{
+ "DBX_TEST_A": "abc ",
+ "DBX_TEST_B": " ",
+ "DBX_TEST_C": " lead\ttab\t",
+ "DBX_TEST_D": "x # y",
+ "DBX_TEST_E": "no newline at the end ",
+ } {
+ if got := os.Getenv(k); got != want {
+ t.Errorf("%s = %q, want %q", k, got, want)
+ }
+ }
+}
+
+// A FIFO, named directly or through a symlink, is refused at once: the
+// open does not wait for a writer that never comes.
+func TestDevboxServeEnvFileRefusesFIFO(t *testing.T) {
+ dir := t.TempDir()
+ fifo := filepath.Join(dir, "fifo")
+ if err := syscall.Mkfifo(fifo, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ link := filepath.Join(dir, "link")
+ if err := os.Symlink(fifo, link); err != nil {
+ t.Fatal(err)
+ }
+ for _, p := range []string{fifo, link} {
+ done := make(chan error, 1)
+ go func() { done <- loadDevboxEnvFile(p, os.Geteuid()) }()
+ select {
+ case err := <-done:
+ want := "could not read the environment file " + p + ". check that it exists and that this account can read it\n"
+ if err == nil || !strings.HasPrefix(err.Error(), want) {
+ t.Errorf("%s: load = %v, want %q then the system's words", p, err, want)
+ }
+ case <-time.After(5 * time.Second):
+ t.Fatalf("%s: load is still waiting on the FIFO", p)
+ }
+ }
+}
+
+// A symlink to a proper env file is followed: the checks are on the file
+// it names.
+func TestDevboxServeEnvFileFollowsSymlink(t *testing.T) {
+ p := writeDevboxEnvFile(t, "DBX_TEST_A=one\n", 0o600)
+ link := filepath.Join(t.TempDir(), "env")
+ if err := os.Symlink(p, link); err != nil {
+ t.Fatal(err)
+ }
+ t.Setenv("DBX_TEST_A", "")
+ if err := loadDevboxEnvFile(link, os.Geteuid()); err != nil || os.Getenv("DBX_TEST_A") != "one" {
+ t.Fatalf("load via symlink = %v (DBX_TEST_A %q)", err, os.Getenv("DBX_TEST_A"))
+ }
+}
+
+func TestDevboxServeEnvFileRefusesOpenMode(t *testing.T) {
+ for _, perm := range []os.FileMode{0o640, 0o604, 0o620, 0o602, 0o601, 0o660} {
+ p := writeDevboxEnvFile(t, "DBX_TEST_A=one\n", perm)
+ t.Setenv("DBX_TEST_A", "")
+ err := loadDevboxEnvFile(p, os.Geteuid())
+ want := "other accounts can read or change the environment file " + p + ". make it private with: chmod 600 " + p
+ if err == nil || err.Error() != want {
+ t.Errorf("mode %o: load = %v, want %q", perm, err, want)
+ }
+ if os.Getenv("DBX_TEST_A") != "" {
+ t.Errorf("mode %o: a refused file set its variables", perm)
+ }
+ }
+ // 0400 is private too.
+ if err := loadDevboxEnvFile(writeDevboxEnvFile(t, "DBX_TEST_A=one\n", 0o400), os.Geteuid()); err != nil {
+ t.Errorf("mode 0400: load = %v", err)
+ }
+}
+
+func TestDevboxServeEnvFileRefusesOtherOwner(t *testing.T) {
+ p := writeDevboxEnvFile(t, "DBX_TEST_A=one\n", 0o600)
+ t.Setenv("DBX_TEST_A", "")
+ err := loadDevboxEnvFile(p, os.Geteuid()+1)
+ want := "the environment file " + p + " belongs to another account. it must belong to the account the service runs as"
+ if err == nil || err.Error() != want {
+ t.Fatalf("load = %v, want %q", err, want)
+ }
+ if os.Getenv("DBX_TEST_A") != "" {
+ t.Fatal("a refused file set its variables")
+ }
+}
+
+func TestDevboxServeEnvFileRefusesUnreadable(t *testing.T) {
+ p := filepath.Join(t.TempDir(), "missing")
+ err := loadDevboxEnvFile(p, os.Geteuid())
+ want := "could not read the environment file " + p + ". check that it exists and that this account can read it"
+ if err == nil || !strings.HasPrefix(err.Error(), want+"\n") || !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("load = %v, want %q then the system's words", err, want)
+ }
+}
+
+func TestDevboxServeEnvFileRefusesBadLine(t *testing.T) {
+ for _, tc := range []struct {
+ body string
+ line int
+ }{
+ {"DBX_TEST_A=one\nAKIASECRETWITHNOEQUALS\n", 2},
+ {"=value\n", 1},
+ {"# ok\nexport DBX_TEST_A=one\n", 2},
+ {"DBX_TEST_A =one\n", 1},
+ {"1DBX=one\n", 1},
+ {"DBX-TEST=one\n", 1},
+ } {
+ p := writeDevboxEnvFile(t, tc.body, 0o600)
+ t.Setenv("DBX_TEST_A", "")
+ err := loadDevboxEnvFile(p, os.Geteuid())
+ want := fmt.Sprintf("line %d of %s is not KEY=VALUE, where KEY is letters, digits and underscores and does not start with a digit. each line must be a setting, a comment starting with #, or blank", tc.line, p)
+ if err == nil || err.Error() != want {
+ t.Errorf("%q: load = %v, want %q", tc.body, err, want)
+ }
+ if strings.Contains(fmt.Sprint(err), "AKIA") || strings.Contains(fmt.Sprint(err), "value") {
+ t.Errorf("%q: the refusal repeats the file's contents: %v", tc.body, err)
+ }
+ if os.Getenv("DBX_TEST_A") != "" {
+ t.Errorf("%q: a refused file set its variables", tc.body)
+ }
+ }
+}
+
+func TestDevboxServeEnvFileRefusesDuplicate(t *testing.T) {
+ p := writeDevboxEnvFile(t, "DBX_TEST_A=one\n# x\nDBX_TEST_B=b\nDBX_TEST_A=two\n", 0o600)
+ t.Setenv("DBX_TEST_A", "")
+ t.Setenv("DBX_TEST_B", "")
+ err := loadDevboxEnvFile(p, os.Geteuid())
+ want := "DBX_TEST_A is set twice in " + p + ", on lines 1 and 4. keep one"
+ if err == nil || err.Error() != want {
+ t.Fatalf("load = %v, want %q", err, want)
+ }
+ if os.Getenv("DBX_TEST_A") != "" || os.Getenv("DBX_TEST_B") != "" {
+ t.Fatal("a refused file set its variables")
+ }
+}
+
+func TestDevboxDefaultSocketPath(t *testing.T) {
+ if got := devboxDefaultSocket("darwin"); got != "/usr/local/var/run/carlos-devbox/devbox.sock" {
+ t.Errorf("darwin = %q", got)
+ }
+ if got := devboxDefaultSocket("linux"); got != "/run/carlos-devbox/devbox.sock" {
+ t.Errorf("linux = %q", got)
+ }
+ t.Setenv("CARLOS_DEVBOX_SOCKET", "")
+ if got := devboxSocketPath(); got != devboxDefaultSocket(runtime.GOOS) {
+ t.Errorf("unset = %q", got)
+ }
+ t.Setenv("CARLOS_DEVBOX_SOCKET", " /tmp/x.sock ")
+ if got := devboxSocketPath(); got != "/tmp/x.sock" {
+ t.Errorf("override = %q", got)
+ }
+}
+
+// ---- serve on launchd's socket (macOS plan #488 Task 3) ---------------------
+
+// closeCounter is a listener that counts its Close calls.
+type closeCounter struct {
+ net.Listener
+ closed int
+}
+
+func (c *closeCounter) Close() error { c.closed++; return nil }
+
+func TestDevboxServeLaunchdRefusals(t *testing.T) {
+ refused := func(err error) func(string) ([]net.Listener, error) {
+ return func(string) ([]net.Listener, error) { return nil, err }
+ }
+ for _, c := range []struct {
+ name string
+ take func(string) ([]net.Listener, error)
+ want string
+ }{
+ {"not macOS", refused(errors.ErrUnsupported),
+ "CARLOS_DEVBOX_LAUNCHD_SOCKET is set, but only macOS hands over sockets this way. unset it, and the service binds CARLOS_DEVBOX_LISTEN itself"},
+ {"not started by launchd", refused(fmt.Errorf("%w (%w)", launchd.ErrNotManaged, syscall.ESRCH)),
+ "CARLOS_DEVBOX_LAUNCHD_SOCKET is set, but launchd did not start this process, so there is no socket to take. start the service with launchctl, or unset CARLOS_DEVBOX_LAUNCHD_SOCKET to run it by hand"},
+ {"no such socket", refused(fmt.Errorf("%w: x", launchd.ErrNoSocket)),
+ "launchd has no socket called Listeners for this service. the Sockets entry in the plist and CARLOS_DEVBOX_LAUNCHD_SOCKET must use the same name"},
+ {"none handed over", refused(nil),
+ "launchd has no socket called Listeners for this service. the Sockets entry in the plist and CARLOS_DEVBOX_LAUNCHD_SOCKET must use the same name"},
+ } {
+ ln, err := devboxLaunchdListener("Listeners", c.take)
+ if ln != nil || err == nil || err.Error() != c.want {
+ t.Errorf("%s: = %v, %v, want %q", c.name, ln, err, c.want)
+ }
+ }
+
+ // Two sockets (an IPv4 and an IPv6 one): refused, and both closed.
+ a, b := &closeCounter{}, &closeCounter{}
+ ln, err := devboxLaunchdListener("Listeners", func(string) ([]net.Listener, error) { return []net.Listener{a, b}, nil })
+ want := "launchd handed over 2 sockets called Listeners, and the service serves on exactly one. set SockFamily to IPv4 in the plist"
+ if ln != nil || err == nil || err.Error() != want {
+ t.Errorf("two sockets: = %v, %v, want %q", ln, err, want)
+ }
+ if a.closed != 1 || b.closed != 1 {
+ t.Errorf("two sockets: closed %d and %d times, want once each", a.closed, b.closed)
+ }
+
+ // One socket is the listener.
+ one := &closeCounter{}
+ ln, err = devboxLaunchdListener("Listeners", func(name string) ([]net.Listener, error) {
+ if name != "Listeners" {
+ t.Errorf("asked launchd for %q", name)
+ }
+ return []net.Listener{one}, nil
+ })
+ if err != nil || ln != one || one.closed != 0 {
+ t.Errorf("one socket: = %v, %v (closed %d)", ln, err, one.closed)
+ }
+
+ // The real thing, on Linux.
+ if _, err := devboxLaunchdListener("Listeners", launchd.Listeners); err == nil || !strings.HasPrefix(err.Error(), "CARLOS_DEVBOX_LAUNCHD_SOCKET is set, but only macOS") {
+ t.Errorf("launchd.Listeners on linux: %v", err)
+ }
+}
+
+func TestDevboxServeListenerRefusals(t *testing.T) {
+ for _, c := range []struct {
+ err error
+ want string
+ }{
+ {&edge.DevboxListenerError{Addr: "0.0.0.0:443", Want: "100.64.0.10:443", Unspecified: true},
+ "launchd's socket listens on every interface, 0.0.0.0:443. set SockNodeName in the plist to the tailnet address in CARLOS_DEVBOX_LISTEN"},
+ {fmt.Errorf("wrapped: %w", &edge.DevboxListenerError{Addr: "100.64.0.11:443", Want: "100.64.0.10:443"}),
+ "launchd's socket listens on 100.64.0.11:443, but CARLOS_DEVBOX_LISTEN is 100.64.0.10:443. make SockNodeName and SockServiceName in the plist match it"},
+ } {
+ if got := devboxListenerRefusal(c.err); got == nil || got.Error() != c.want {
+ t.Errorf("%v: = %v, want %q", c.err, got, c.want)
+ }
+ }
+ other := errors.New("edge broke")
+ if got := devboxListenerRefusal(other); got != other {
+ t.Errorf("another error = %v, want it unchanged", got)
+ }
+ if devboxListenerRefusal(nil) != nil {
+ t.Error("nil became an error")
+ }
+}
+
+// serve with CARLOS_DEVBOX_LAUNCHD_SOCKET set on Linux stops with the deck's
+// words, before it makes anything.
+func TestDevboxServeLaunchdSocketOnLinux(t *testing.T) {
+ data := filepath.Join(t.TempDir(), "data")
+ t.Setenv("CARLOS_DEVBOX_LISTEN", "127.0.0.1:8443")
+ t.Setenv("CARLOS_DEVBOX_DOMAIN", "devbox.example.com")
+ t.Setenv("CARLOS_WILDCARD_DOMAINS", "devbox.example.com")
+ t.Setenv("CARLOS_DATA_DIR", data)
+ t.Setenv("CARLOS_DEVBOX_LAUNCHD_SOCKET", "Listeners")
+ err := runDevboxServe(nil)
+ if err == nil || !strings.HasPrefix(err.Error(), "CARLOS_DEVBOX_LAUNCHD_SOCKET is set, but only macOS") {
+ t.Fatalf("serve = %v", err)
+ }
+ if _, err := os.Stat(data); err == nil {
+ t.Fatal("serve made the data dir before refusing")
+ }
+}
diff --git a/devbox_envfile.go b/devbox_envfile.go
new file mode 100644
index 000000000..4ff672e84
--- /dev/null
+++ b/devbox_envfile.go
@@ -0,0 +1,118 @@
+package main
+
+// carlos devbox serve --env-file: the service's settings, read by the
+// service itself. On macOS launchd would pass them from the plist, and every
+// account can read a plist, so the DNS credential lives in a file only the
+// service user can open (macOS plan #488). Linux's unit uses systemd's
+// EnvironmentFile and does not need this, but it works there too.
+//
+// The rules: the file belongs to the user the service runs as, and no other
+// account may read or change it, by its mode or (on macOS) by an ACL; every line is KEY=VALUE, a # comment or
+// blank (judged by its first byte that is not a space or tab); a key
+// appears once; a value is everything after the first '=' exactly as
+// written, less a CRLF file's \r; and a setting in the file replaces one
+// already in the environment. Nothing is set unless the whole file passes. No
+// refusal repeats a value, or any part of a line that is not a setting.
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "os"
+ "strings"
+
+ "github.com/carlosframework/platform/internal/fileacl"
+)
+
+// devboxEnvFileMax bounds the read: an environment file is a few lines.
+const devboxEnvFileMax = 1 << 20
+
+// loadDevboxEnvFile reads path and sets each of its settings in this
+// process's environment. euid is the user the file must belong to (the
+// caller passes os.Geteuid(); a test passes another).
+func loadDevboxEnvFile(path string, euid int) error {
+ f, err := openDevboxEnvFile(path)
+ if err != nil {
+ return errors.Join(errors.New(devboxEnvUnreadable(path)), err)
+ }
+ defer f.Close()
+ // The checks are on the file that was opened, not on the path again.
+ fi, err := f.Stat()
+ if err != nil {
+ return errors.Join(errors.New(devboxEnvUnreadable(path)), err)
+ }
+ if !fi.Mode().IsRegular() {
+ return errors.Join(errors.New(devboxEnvUnreadable(path)), fmt.Errorf("%s is not a regular file", path))
+ }
+ if uid, ok := fileOwner(fi); !ok || uid != euid {
+ return errors.New(devboxEnvOwner(path))
+ }
+ if fi.Mode().Perm()&0o077 != 0 {
+ return errors.New(devboxEnvOpen(path))
+ }
+ // On macOS an ACL can grant another account access that the mode
+ // does not show, so a file with one is refused (fileacl reports none
+ // on Linux, where the mode check already bounds a POSIX ACL). A
+ // failure to read the ACL refuses too.
+ if acl, err := fileacl.Extended(f); err != nil {
+ return errors.Join(errors.New(devboxEnvUnreadable(path)), err)
+ } else if acl {
+ return errors.New(devboxEnvACL(path))
+ }
+ raw, err := io.ReadAll(io.LimitReader(f, devboxEnvFileMax+1))
+ if err != nil {
+ return errors.Join(errors.New(devboxEnvUnreadable(path)), err)
+ }
+ if len(raw) > devboxEnvFileMax {
+ return errors.Join(errors.New(devboxEnvUnreadable(path)), fmt.Errorf("%s is over %d bytes", path, devboxEnvFileMax))
+ }
+
+ type setting struct {
+ key, value string
+ }
+ var settings []setting
+ seen := map[string]int{}
+ for i, line := range strings.Split(string(raw), "\n") {
+ n := i + 1
+ // A CRLF file's \r is the line ending, not part of the value.
+ // Everything else after the first '=' is the value as written,
+ // spaces and all.
+ line = strings.TrimSuffix(line, "\r")
+ lead := strings.TrimLeft(line, " \t")
+ if lead == "" || strings.HasPrefix(lead, "#") {
+ continue
+ }
+ key, value, ok := strings.Cut(lead, "=")
+ if !ok || !devboxEnvKey(key) {
+ return errors.New(devboxEnvBadLine(n, path))
+ }
+ if first, dup := seen[key]; dup {
+ return errors.New(devboxEnvDuplicate(key, path, first, n))
+ }
+ seen[key] = n
+ settings = append(settings, setting{key, value})
+ }
+ for _, s := range settings {
+ if err := os.Setenv(s.key, s.value); err != nil {
+ // The key passed devboxEnvKey, so only a value the OS refuses
+ // (a NUL byte) gets here; say which line, not what it holds.
+ return fmt.Errorf("devbox serve: %s line %d: the value cannot be set in the environment", path, seen[s.key])
+ }
+ }
+ return nil
+}
+
+// devboxEnvKey reports whether k is a variable name: letters, digits and
+// underscores, not starting with a digit.
+func devboxEnvKey(k string) bool {
+ if k == "" || (k[0] >= '0' && k[0] <= '9') {
+ return false
+ }
+ for i := 0; i < len(k); i++ {
+ c := k[i]
+ if !(c == '_' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9') {
+ return false
+ }
+ }
+ return true
+}
diff --git a/devbox_envfile_darwin_test.go b/devbox_envfile_darwin_test.go
new file mode 100644
index 000000000..2cd3c1891
--- /dev/null
+++ b/devbox_envfile_darwin_test.go
@@ -0,0 +1,40 @@
+//go:build darwin
+
+package main
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+ "testing"
+)
+
+// A 0600 file with an ACL entry granting another account access is
+// refused, and sets nothing; once chmod -N removes the ACL it loads.
+func TestDevboxServeEnvFileRefusesACL(t *testing.T) {
+ p := filepath.Join(t.TempDir(), "env")
+ if err := os.WriteFile(p, []byte("DBX_TEST_A=one\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chmod(p, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if out, err := exec.Command("/bin/chmod", "+a", "everyone allow read,write", p).CombinedOutput(); err != nil {
+ t.Fatalf("chmod +a: %v: %s", err, out)
+ }
+ t.Setenv("DBX_TEST_A", "")
+ err := loadDevboxEnvFile(p, os.Geteuid())
+ want := "the environment file " + p + " has an access control list, which can let other accounts read or change it. remove it with: chmod -N " + p
+ if err == nil || err.Error() != want {
+ t.Fatalf("load = %v, want %q", err, want)
+ }
+ if os.Getenv("DBX_TEST_A") != "" {
+ t.Fatal("a refused file set its variables")
+ }
+ if out, err := exec.Command("/bin/chmod", "-N", p).CombinedOutput(); err != nil {
+ t.Fatalf("chmod -N: %v: %s", err, out)
+ }
+ if err := loadDevboxEnvFile(p, os.Geteuid()); err != nil || os.Getenv("DBX_TEST_A") != "one" {
+ t.Fatalf("load without the ACL = %v (DBX_TEST_A %q)", err, os.Getenv("DBX_TEST_A"))
+ }
+}
diff --git a/devbox_envfile_other.go b/devbox_envfile_other.go
new file mode 100644
index 000000000..a6defb38a
--- /dev/null
+++ b/devbox_envfile_other.go
@@ -0,0 +1,12 @@
+//go:build !unix
+
+package main
+
+import "os"
+
+// openDevboxEnvFile is a plain open here: there are no FIFOs to wait on.
+func openDevboxEnvFile(path string) (*os.File, error) { return os.Open(path) }
+
+// fileOwner has no uid to report here, so no environment file passes the
+// owner check: devbox serve runs only on Linux and macOS.
+func fileOwner(fi os.FileInfo) (int, bool) { return 0, false }
diff --git a/devbox_envfile_unix.go b/devbox_envfile_unix.go
new file mode 100644
index 000000000..ed2d4cb32
--- /dev/null
+++ b/devbox_envfile_unix.go
@@ -0,0 +1,27 @@
+//go:build unix
+
+package main
+
+import (
+ "os"
+ "syscall"
+)
+
+// openDevboxEnvFile opens path without blocking: a FIFO with no writer
+// would otherwise hold the open forever, before the regular-file check on
+// the opened file could refuse it. O_NONBLOCK changes nothing for reading
+// a regular file. A symlink is followed on purpose (no O_NOFOLLOW): an env
+// file kept elsewhere and linked into place is legitimate, and every check
+// is on the file the open reached, never on the path.
+func openDevboxEnvFile(path string) (*os.File, error) {
+ return os.OpenFile(path, os.O_RDONLY|syscall.O_NONBLOCK, 0)
+}
+
+// fileOwner is the uid that owns the file fi describes.
+func fileOwner(fi os.FileInfo) (int, bool) {
+ st, ok := fi.Sys().(*syscall.Stat_t)
+ if !ok {
+ return 0, false
+ }
+ return int(st.Uid), true
+}
diff --git a/devbox_plist_test.go b/devbox_plist_test.go
new file mode 100644
index 000000000..77630eb4e
--- /dev/null
+++ b/devbox_plist_test.go
@@ -0,0 +1,196 @@
+package main
+
+// The macOS LaunchDaemon (infra/devbox/com.carlosframework.devbox.plist,
+// macOS plan #488 Task 4). plutil does not run on Linux, so this reads the
+// plist as XML with encoding/xml, builds its values, and checks each key
+// the plan sets. launchd binds the socket as root; the service runs as its
+// own user and reads its secrets from the env file, so the plist, which
+// every account can read, carries none.
+
+import (
+ "bytes"
+ "encoding/xml"
+ "errors"
+ "fmt"
+ "io"
+ "os"
+ "reflect"
+ "strings"
+ "testing"
+)
+
+const devboxPlistPath = "infra/devbox/com.carlosframework.devbox.plist"
+
+// plistValue reads the value element start opened: a dict, an array, a
+// string, an integer (kept as its text) or true/false.
+func plistValue(d *xml.Decoder, start xml.StartElement) (any, error) {
+ switch start.Name.Local {
+ case "true", "false":
+ if err := d.Skip(); err != nil {
+ return nil, err
+ }
+ return start.Name.Local == "true", nil
+ case "string", "integer", "key":
+ var s string
+ if err := d.DecodeElement(&s, &start); err != nil {
+ return nil, err
+ }
+ return s, nil
+ case "array":
+ var out []any
+ for {
+ tok, err := d.Token()
+ if err != nil {
+ return nil, err
+ }
+ switch t := tok.(type) {
+ case xml.StartElement:
+ v, err := plistValue(d, t)
+ if err != nil {
+ return nil, err
+ }
+ out = append(out, v)
+ case xml.EndElement:
+ return out, nil
+ }
+ }
+ case "dict":
+ out := map[string]any{}
+ key := ""
+ for {
+ tok, err := d.Token()
+ if err != nil {
+ return nil, err
+ }
+ switch t := tok.(type) {
+ case xml.StartElement:
+ v, err := plistValue(d, t)
+ if err != nil {
+ return nil, err
+ }
+ if t.Name.Local == "key" {
+ if key != "" {
+ return nil, fmt.Errorf("key %q has no value", key)
+ }
+ key = v.(string)
+ if _, dup := out[key]; dup {
+ return nil, fmt.Errorf("key %q twice", key)
+ }
+ continue
+ }
+ if key == "" {
+ return nil, fmt.Errorf("a <%s> with no key", t.Name.Local)
+ }
+ out[key], key = v, ""
+ case xml.EndElement:
+ if key != "" {
+ return nil, fmt.Errorf("key %q has no value", key)
+ }
+ return out, nil
+ }
+ }
+ }
+ return nil, fmt.Errorf("unexpected <%s>", start.Name.Local)
+}
+
+// parsePlist reads a whole plist document: <plist version="1.0"> holding
+// one value, and nothing after it.
+func parsePlist(raw []byte) (any, error) {
+ d := xml.NewDecoder(bytes.NewReader(raw))
+ var top any
+ inPlist := false
+ for {
+ tok, err := d.Token()
+ if errors.Is(err, io.EOF) {
+ if top == nil {
+ return nil, errors.New("no <plist> value")
+ }
+ return top, nil
+ }
+ if err != nil {
+ return nil, err
+ }
+ t, ok := tok.(xml.StartElement)
+ if !ok {
+ continue
+ }
+ if !inPlist {
+ if t.Name.Local != "plist" {
+ return nil, fmt.Errorf("the root is <%s>, not <plist>", t.Name.Local)
+ }
+ inPlist = true
+ continue
+ }
+ if top != nil {
+ return nil, fmt.Errorf("a second value, <%s>", t.Name.Local)
+ }
+ if top, err = plistValue(d, t); err != nil {
+ return nil, err
+ }
+ }
+}
+
+func TestDevboxPlistIsWellFormed(t *testing.T) {
+ raw, err := os.ReadFile(devboxPlistPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if strings.Contains(string(raw), "AWS_") {
+ t.Fatal("the plist names an AWS_ variable; every account can read it, so secrets go in the env file")
+ }
+ top, err := parsePlist(raw)
+ if err != nil {
+ t.Fatalf("%s: %v", devboxPlistPath, err)
+ }
+ got, ok := top.(map[string]any)
+ if !ok {
+ t.Fatalf("the plist's value is %T, want a dict", top)
+ }
+ want := map[string]any{
+ "Label": "com.carlosframework.devbox",
+ "ProgramArguments": []any{"/usr/local/bin/carlos", "devbox", "serve", "--env-file", "/usr/local/etc/carlos-devbox/env"},
+ "UserName": "_carlos-devbox",
+ "GroupName": "_carlos-devbox",
+ "Sockets": map[string]any{
+ "Listeners": map[string]any{
+ "SockNodeName": "100.64.0.10",
+ "SockServiceName": "443",
+ "SockType": "stream",
+ "SockFamily": "IPv4",
+ },
+ },
+ "RunAtLoad": true,
+ "KeepAlive": true,
+ "StandardOutPath": "/usr/local/var/log/carlos-devbox.log",
+ "StandardErrorPath": "/usr/local/var/log/carlos-devbox.log",
+ "EnvironmentVariables": map[string]any{"CARLOS_DEVBOX_LAUNCHD_SOCKET": "Listeners"},
+ }
+ if !reflect.DeepEqual(got, want) {
+ for k := range want {
+ if !reflect.DeepEqual(got[k], want[k]) {
+ t.Errorf("%s = %#v, want %#v", k, got[k], want[k])
+ }
+ }
+ for k := range got {
+ if _, ok := want[k]; !ok {
+ t.Errorf("unexpected key %s = %#v", k, got[k])
+ }
+ }
+ }
+}
+
+// The reader itself refuses what plutil would.
+func TestDevboxPlistReaderRefuses(t *testing.T) {
+ for _, bad := range []string{
+ `<plist version="1.0"><dict><key>A</key></dict></plist>`,
+ `<plist version="1.0"><dict><key>A</key><string>x</string><key>A</key><string>y</string></dict></plist>`,
+ `<plist version="1.0"><dict><string>x</string></dict></plist>`,
+ `<plist version="1.0"><dict><key>A</key><string>x</string></plist>`,
+ `<dict></dict>`,
+ `<plist version="1.0"><dict></dict><dict></dict></plist>`,
+ } {
+ if _, err := parsePlist([]byte(bad)); err == nil {
+ t.Errorf("parsePlist(%q) = nil error", bad)
+ }
+ }
+}
diff --git a/docs/superpowers/notes/census-proposal-devbox-macos.md b/docs/superpowers/notes/census-proposal-devbox-macos.md
new file mode 100644
index 000000000..44609a2e0
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-devbox-macos.md
@@ -0,0 +1,29 @@
+# Census approval: devbox-macos
+
+Ruling `census-ruling-devbox-macos`. The independent reviewer approves or rejects every change below, 7 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `devbox_cli.go` `runDevboxServe` | body | unchanged (3) | devbox on macOS (#488): serve now parses flags; --env-file PATH loads the service user's own env file (loadDevboxEnvFile) before reading the same environment as before; with CARLOS_DEVBOX_LAUNCHD_SOCKET set it takes launchd's listening socket (launchd.Listeners, macOS only; elsewhere it refuses) and holds it to CARLOS_DEVBOX_LISTEN (edge.CheckDevboxListener) before making anything; the socket path comes from devboxSocketPath (CARLOS_DEVBOX_SOCKET, or the OS default). Runs as the unprivileged service user (carlos-devbox on Linux, _carlos-devbox on macOS), never root; no new read beyond the env file named on its own command line |
+
+Envelopes re-pinned: `.`, `infra/devbox`, `internal/edge`, `internal/fileacl`, `internal/launchd`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `devbox_cli.go` `runDevboxServe`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-devbox-mode;basis=new: carlos devbox serve, run by the carlos-devbox unit as the unprivileged carlos-devbox user, reads its config from the environment (CARLOS_DEVBOX_LISTEN, CARLOS_DEVBOX_DOMAIN, CARLOS_DATA_DIR, CARLOS_WILDCARD_DOMAINS, CARLOS_DEVBOX_SOCKET) and opens registry.db and links.json under its own StateDirectory. Not root
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `devbox_envfile.go:loadDevboxEnvFile`: reads +file:ReadAll, +file:Stat; written legacy, accepted-legacy, frozen
+- new `devbox_envfile_unix.go:openDevboxEnvFile`: reads +file:OpenFile; written legacy, accepted-legacy, frozen
+- new `infra/devbox/com.carlosframework.devbox.plist:external`: reads +file:external; written legacy, accepted-legacy, frozen
+- new `internal/fileacl/fileacl_darwin_amd64.s:external`: reads +file:external; written legacy, accepted-legacy, frozen
+- new `internal/fileacl/fileacl_darwin_arm64.s:external`: reads +file:external; written legacy, accepted-legacy, frozen
+- new `internal/launchd/activate_darwin_amd64.s:external`: reads +file:external; written legacy, accepted-legacy, frozen
+- new `internal/launchd/activate_darwin_arm64.s:external`: reads +file:external; written legacy, accepted-legacy, frozen
+
+Seal: `c86929d08b9b2038fa103d1c7311ab2958e7100e92dc550d36daeb364affd029` → `67b54b219f990c3dcfe32c6ffb11a80a4ca3898aec060fe9f4450e21098af714`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-devbox-macos.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/plans/2026-10-30-devbox-mode-copy.md b/docs/superpowers/plans/2026-10-30-devbox-mode-copy.md
index 5986d4884..4b15cb952 100644
--- a/docs/superpowers/plans/2026-10-30-devbox-mode-copy.md
+++ b/docs/superpowers/plans/2026-10-30-devbox-mode-copy.md
@@ -123,3 +123,55 @@ sit in code blocks under these sentences and are not copy.
| DBX-C55 | docs/site/cli.md | Publish a dev server or a folder as an HTTPS link on a shared devbox, for people on eg a tailnet. A live link follows your dev server on 127.0.0.1, so edits show up as you save. A folder link serves a copy of the folder, and sharing it again replaces the copy. | approved |
| DBX-C56 | docs/site/cli.md | If you work through an AI agent, run both the dev server and carlos devbox share outside the agent's sandbox. A dev server started inside the sandbox listens where the devbox cannot reach it, and the sandbox also stops the command from reaching the devbox service. | approved |
| DBX-C57 | infra/devbox/README.md | If you work through an AI agent, run both the dev server and carlos devbox share outside the agent's sandbox. A dev server started inside the sandbox listens where the devbox cannot reach it, and the sandbox also stops the command from reaching the devbox service. | approved |
+
+## macOS (#488): serve's environment file, the launchd socket and the runbook's macOS section
+
+Drafted 2026-10-31 for docs/superpowers/plans/2026-10-31-devbox-macos.md.
+`carlos devbox serve` prints these when it stops. The runbook rows are one
+sentence or heading each; commands, paths and the plist sit in code blocks
+under them and are not copy.
+
+More placeholders: `<env file>` the environment file's path as given to
+`--env-file`; `<line>` a line number in that file; `<key>` a variable's
+name, such as `CARLOS_DATA_DIR`; `<socket name>` the name of a socket in the
+plist's `Sockets` entry, such as `Listeners`; `<count>` a number;
+`<address>` an IP address and port, such as `100.64.0.10:443`.
+
+| id | file | text | status |
+|---|---|---|---|
+| DBX-C58 | devbox_cli.go | usage: carlos devbox serve [--env-file <env file>] | approved |
+| DBX-C59 | devbox_cli.go | serve runs the devbox service. its systemd unit or launchd daemon starts it, and nobody else needs to | approved |
+| DBX-C60 | devbox_cli.go | a file of KEY=VALUE lines to read before serving. blank lines and lines starting with # are skipped, and values are taken as written, with no quotes. a setting in the file replaces one already in the environment. the file must belong to this account, and only this account may read or change it | approved |
+| DBX-C61 | devbox_cli.go | could not read the environment file <env file>. check that it exists and that this account can read it | approved |
+| DBX-C62 | devbox_cli.go | other accounts can read or change the environment file <env file>. make it private with: chmod 600 <env file> | approved |
+| DBX-C63 | devbox_cli.go | the environment file <env file> belongs to another account. it must belong to the account the service runs as | approved |
+| DBX-C64 | devbox_cli.go | line <line> of <env file> is not KEY=VALUE, where KEY is letters, digits and underscores and does not start with a digit. each line must be a setting, a comment starting with #, or blank | approved |
+| DBX-C65 | devbox_cli.go | <key> is set twice in <env file>, on lines <line> and <line>. keep one | approved |
+| DBX-C66 | devbox_cli.go | CARLOS_DEVBOX_LAUNCHD_SOCKET is set, but launchd did not start this process, so there is no socket to take. start the service with launchctl, or unset CARLOS_DEVBOX_LAUNCHD_SOCKET to run it by hand | approved |
+| DBX-C67 | devbox_cli.go | launchd has no socket called <socket name> for this service. the Sockets entry in the plist and CARLOS_DEVBOX_LAUNCHD_SOCKET must use the same name | approved |
+| DBX-C68 | devbox_cli.go | launchd handed over <count> sockets called <socket name>, and the service serves on exactly one. set SockFamily to IPv4 in the plist | approved |
+| DBX-C69 | devbox_cli.go | CARLOS_DEVBOX_LAUNCHD_SOCKET is set, but only macOS hands over sockets this way. unset it, and the service binds CARLOS_DEVBOX_LISTEN itself | approved |
+| DBX-C70 | devbox_cli.go | launchd's socket listens on every interface, <address>. set SockNodeName in the plist to the tailnet address in CARLOS_DEVBOX_LISTEN | approved |
+| DBX-C71 | devbox_cli.go | launchd's socket listens on <address>, but CARLOS_DEVBOX_LISTEN is <address>. make SockNodeName and SockServiceName in the plist match it | approved |
+| DBX-C72 | infra/devbox/README.md | ## Install on macOS, once, as root | approved |
+| DBX-C73 | infra/devbox/README.md | On a Mac, launchd binds port 443 on the tailnet address as root and hands the open socket to the service. | approved |
+| DBX-C74 | infra/devbox/README.md | The service runs as its own user, so no carlos process runs as root. | approved |
+| DBX-C75 | infra/devbox/README.md | Follow these steps instead of the Linux ones above. | approved |
+| DBX-C76 | infra/devbox/README.md | Create the service user and its group, both called _carlos-devbox. | approved |
+| DBX-C77 | infra/devbox/README.md | It is a hidden account with no login and no home folder. | approved |
+| DBX-C78 | infra/devbox/README.md | Give both the same ID, a number below 500 that no user or group has yet. | approved |
+| DBX-C79 | infra/devbox/README.md | The commands below use 451. | approved |
+| DBX-C80 | infra/devbox/README.md | Create the service's folders: one for its data, private to the service user, and one for the registrar socket, which every account can reach. | approved |
+| DBX-C81 | infra/devbox/README.md | Create the log file as well, owned by the service user. | approved |
+| DBX-C82 | infra/devbox/README.md | Write the environment file, private to the service user. | approved |
+| DBX-C83 | infra/devbox/README.md | It holds this Mac's tailnet address, the devbox domain, the data folder and the AWS key for the certificate challenge record. | approved |
+| DBX-C84 | infra/devbox/README.md | The service reads this file itself, because every account can read a plist. | approved |
+| DBX-C85 | infra/devbox/README.md | Install the carlos binary and the plist. | approved |
+| DBX-C86 | infra/devbox/README.md | In the plist, replace 100.64.0.10 with this Mac's tailnet address, the same one as in CARLOS_DEVBOX_LISTEN. | approved |
+| DBX-C87 | infra/devbox/README.md | The service refuses to start if launchd hands it a socket on any other address. | approved |
+| DBX-C88 | infra/devbox/README.md | Create the IAM user, key and policy as in the Linux steps above, then load the service. | approved |
+| DBX-C89 | infra/devbox/README.md | If the tailnet is not up when launchd loads the service, launchd cannot bind the address. | approved |
+| DBX-C90 | infra/devbox/README.md | Once the tailnet is up, start the service again. | approved |
+| DBX-C91 | infra/devbox/README.md | Then add the DNS record and run the checks below. | approved |
+| DBX-C92 | infra/devbox/README.md | On a Mac, use lsof instead of ss to see what is listening, and read the log file instead of journalctl. | approved |
+| DBX-C93 | devbox_cli.go | the environment file <env file> has an access control list, which can let other accounts read or change it. remove it with: chmod -N <env file> | approved |
diff --git a/docs/superpowers/plans/2026-10-31-devbox-macos.md b/docs/superpowers/plans/2026-10-31-devbox-macos.md
new file mode 100644
index 000000000..8fd228dd0
--- /dev/null
+++ b/docs/superpowers/plans/2026-10-31-devbox-macos.md
@@ -0,0 +1,101 @@
+# Devbox mode on macOS (#488) Implementation Plan
+
+> **For agentic workers:** steps use checkbox (`- [ ]`) syntax. One implementer builds Tasks 2–4 in order; the controller runs Task 1's copy review with Paul and the reviews.
+
+**Goal:** `carlos devbox` runs on a macOS devbox (the second shared devbox) exactly as on Linux: owned, tailnet-only `https://<name>.<devbox domain>` links on port 443, with nothing of ours running as root.
+
+**Architecture:** launchd (root) binds `<tailnet-ip>:443` from a `Sockets` entry in a LaunchDaemon plist, and hands the listening socket to `carlos devbox serve`, which runs as its own user (Paul's ruling, 2026-10-31: "launchd socket", over bind-then-drop, pf, or a port in URLs). The registrar identifies callers with `LOCAL_PEERCRED` instead of `SO_PEERCRED`. A LaunchDaemon plist is world-readable, so the DNS credential comes from an env file that `serve` reads itself (`--env-file`, mode 0600, owned by the service user).
+
+**Spec:** docs/superpowers/specs/2026-10-30-devbox-mode-design.md (devbox mode; its anti-goals all hold on macOS) and amadan #488. Evidence: on the macOS devbox, binding `100.76.110.54:443` as an ordinary user fails with EACCES (Doc's test, 2026-10-31).
+
+## Global Constraints
+
+- Nothing of ours runs as root. launchd does the bind; `carlos devbox serve` never calls setuid or checks euid.
+- Listen only on the configured tailnet address. A launchd-passed listener whose local address is unspecified (0.0.0.0, ::) or not the configured `CARLOS_DEVBOX_LISTEN` address is refused, the same as a self-bound one.
+- Peer identity fails closed: no uid, no identity. Every request on such a connection is refused (`bad-request`).
+- No cgo. CI cross-builds darwin with CGO_ENABLED=0. Call libSystem with the x/sys/unix pattern (`//go:cgo_import_dynamic` plus an assembly trampoline plus `syscall_syscall`), in `_darwin` files only.
+- Linux behaviour and Linux files are unchanged, apart from `--env-file`, which works on both.
+- User-facing strings come only from the approved copy deck (DBX-C58 onwards, appended to docs/superpowers/plans/2026-10-30-devbox-mode-copy.md). No em dashes. Neutral names (devbox.example.com, 100.64.0.10).
+- Tests that can only run on darwin are `//go:build darwin`. The gate is `GOOS=darwin go vet` and test compilation (`GOOS=darwin go test -c` per package) on DOCS-T1, plus whatever runs on linux.
+
+## Review Focus
+
+1. **A launchd listener on the wrong address** (unspecified, or not `CARLOS_DEVBOX_LISTEN`): refused before serving. Test in Task 3.
+2. **An env file readable by group or other, or owned by someone else:** refused, with the deck's message naming the path. Test in Task 2.
+3. **An env file line that isn't `KEY=VALUE`, has a duplicate key, or tries to override something already in the environment:** refused, or the rule is stated. The ruling: the file wins and duplicates are refused. Test in Task 2.
+4. **`launch_activate_socket` returning ESRCH, because the service wasn't started by launchd** (someone runs `serve` by hand on a Mac without `--listen`): a clear error, not a hang. Test in Task 3 (darwin).
+5. **A peer uid of 0 from LOCAL_PEERCRED:** treated like any other uid. Root can own links, the same as on Linux. No special case.
+
+---
+
+### Task 1: Copy (controller and Paul)
+
+Draft rows DBX-C58+ for:
+- the `--env-file` flag help;
+- the env-file refusals (unreadable, too open, wrong owner, bad line, duplicate key);
+- the "not started by launchd" serve error;
+- the runbook's macOS section: create the service user (`sysadminctl` or `dscl`), install the binary and plist, the env file, the launchd socket, `launchctl bootstrap`, the DNS and IAM steps, and the smoke checklist pointer.
+
+Run copy review with Paul, apply his edits verbatim, and bump the deck gate's pinned inventory.
+
+### Task 2: `--env-file` and macOS defaults
+
+**Files:** devbox_cli.go and devbox_cli_test.go (root package).
+
+- [ ] Tests:
+ - `TestDevboxServeEnvFileLoads`: a 0600 file owned by the current user, with `KEY=VALUE` lines, blanks and `#` comments, sets those variables before serve reads its config.
+ - `TestDevboxServeEnvFileRefusesOpenMode`: 0640 and 0604 are refused with the deck's message.
+ - `TestDevboxServeEnvFileRefusesBadLine`: a line without `=`, and an empty key, are refused.
+ - `TestDevboxServeEnvFileRefusesDuplicate`.
+ - `TestDevboxDefaultSocketPath`: the default socket is `/usr/local/var/run/carlos-devbox/devbox.sock` on darwin and `/run/carlos-devbox/devbox.sock` elsewhere. Use a GOOS seam; `CARLOS_DEVBOX_SOCKET` still overrides.
+- [ ] Implement `--env-file PATH` on `carlos devbox serve` (both OSes). Owner checks use the file's uid against `os.Geteuid()`. Values are never logged.
+- [ ] Run `TMPDIR=/tmp/g go test -run 'TestDevbox' .`, and the copy gate.
+- [ ] Commit.
+
+### Task 3: launchd socket activation and the registrar on darwin
+
+**Files:**
+- `internal/devbox/peer_darwin.go`;
+- `peer_other.go` (build tag becomes `!linux && !darwin`);
+- `internal/edge/devbox.go` (`DevboxConfig.Listener net.Listener`);
+- new `internal/launchd/` (`activate_darwin.go`, `activate_darwin_amd64.s` and `activate_darwin_arm64.s` trampolines, `activate_other.go` stub);
+- `devbox_cli.go` (serve takes the launchd listener when `CARLOS_DEVBOX_LAUNCHD_SOCKET` names one).
+
+**Interfaces:**
+- `func launchd.Listeners(name string) ([]net.Listener, error)`. It calls `launch_activate_socket(name, &fds, &cnt)`, wraps each fd with `net.FileListener(os.NewFile(...))`, and frees the C array with libSystem `free`. On non-darwin it returns `errors.ErrUnsupported`.
+- `edge.DevboxConfig.Listener`: when non-nil, ServeDevbox serves TLS on it instead of binding. It validates `Listener.Addr()` against `ListenAddr` (same IP and port), and the address rule from Review Focus 1 applies.
+
+- [ ] Tests:
+ - linux: `TestDevboxUsesGivenListener` (serves on an injected 127.0.0.1 listener when `ListenAddr` matches it);
+ - linux: `TestDevboxRefusesListenerOnOtherAddr`, and an unspecified listener address;
+ - darwin-only: `TestPeerUIDDarwin` (a Unix socket pair attributes `os.Getuid()`);
+ - darwin-only: `TestLaunchdListenersOutsideLaunchd` (returns an error, does not hang).
+- [ ] Implement. `PeerUID` on darwin uses `unix.GetsockoptXucred(fd, unix.SOL_LOCAL, unix.LOCAL_PEERCRED)` and checks `Version == XUCRED_VERSION`.
+- [ ] Run the linux tests with `go test ./internal/edge -run TestDevbox` and `go test ./internal/devbox`. Then run `GOOS=darwin GOARCH=arm64 go vet ./internal/devbox ./internal/edge ./internal/launchd .`, the same for amd64, and `GOOS=darwin go test -c -o /dev/null` for `./internal/devbox` and `./internal/launchd`.
+- [ ] Commit.
+
+### Task 4: The plist and the runbook
+
+**Files:** `infra/devbox/com.carlosframework.devbox.plist`, and a macOS section in `infra/devbox/README.md` (prose from Task 1's approved rows).
+
+- [ ] The plist sets:
+ - `Label com.carlosframework.devbox`;
+ - `ProgramArguments`: `/usr/local/bin/carlos devbox serve --env-file /usr/local/etc/carlos-devbox/env`;
+ - `UserName` and `GroupName`: `_carlos-devbox`;
+ - `Sockets`: `Listeners`, with `SockNodeName` 100.64.0.10 (the placeholder the runbook replaces), `SockServiceName` 443, `SockType` stream and `SockFamily` IPv4;
+ - `RunAtLoad`, and `KeepAlive` true;
+ - stdout and stderr to `/usr/local/var/log/carlos-devbox.log`;
+ - `EnvironmentVariables`: `CARLOS_DEVBOX_LAUNCHD_SOCKET=Listeners` only, with no secrets.
+- [ ] The runbook's macOS steps:
+ 1. create the `_carlos-devbox` role user;
+ 2. create `/usr/local/var/carlos-devbox` (0700) and `/usr/local/var/run/carlos-devbox` (0755), owned by it;
+ 3. write `/usr/local/etc/carlos-devbox/env` (0600, owned by it) with `CARLOS_DATA_DIR=/usr/local/var/carlos-devbox`;
+ 4. install the plist in `/Library/LaunchDaemons` (root:wheel 0644);
+ 5. `launchctl bootstrap system ...`.
+ Also note: if the tailnet address isn't up when launchd loads, the bind fails; re-run with `launchctl kickstart -k system/com.carlosframework.devbox`.
+- [ ] `plutil -lint` can't run on Linux. Validate the plist as XML with Go's `encoding/xml` in a test (`TestDevboxPlistIsWellFormed`), and check that it carries no `AWS_` key.
+- [ ] Commit.
+
+## After the build
+
+Astra reviews the whole branch: peer identity, listener validation and env-file handling are security-relevant. Then the census (`make census-card` / `census-propose`; darwin files are outside its linux scope, but devbox_cli.go and internal/edge change), CI, and a merge on Paul's go. Install on the macOS devbox: DNS `*.tito-studio.dev.platform.tito.io` → 100.76.110.54, an IAM user scoped to its challenge record, and the runbook run by someone with admin on the Mac.
diff --git a/infra/devbox/README.md b/infra/devbox/README.md
index fa9671799..a8ffe7bd2 100644
--- a/infra/devbox/README.md
+++ b/infra/devbox/README.md
@@ -54,6 +54,95 @@ systemctl enable --now carlos-devbox
journalctl -u carlos-devbox -f
```
+## Install on macOS, once, as root
+
+On a Mac, launchd binds port 443 on the tailnet address as root and hands the open socket to the service. The service runs as its own user, so no carlos process runs as root. Follow these steps instead of the Linux ones above.
+
+Create the service user and its group, both called _carlos-devbox. It is a hidden account with no login and no home folder.
+
+Give both the same ID, a number below 500 that no user or group has yet. The commands below use 451.
+
+```sh
+dscl . -list /Users UniqueID | sort -n -k2
+dscl . -list /Groups PrimaryGroupID | sort -n -k2
+
+dscl . -create /Groups/_carlos-devbox
+dscl . -create /Groups/_carlos-devbox PrimaryGroupID 451
+dscl . -create /Groups/_carlos-devbox RealName "carlos devbox"
+dscl . -create /Users/_carlos-devbox
+dscl . -create /Users/_carlos-devbox UniqueID 451
+dscl . -create /Users/_carlos-devbox PrimaryGroupID 451
+dscl . -create /Users/_carlos-devbox RealName "carlos devbox"
+dscl . -create /Users/_carlos-devbox UserShell /usr/bin/false
+dscl . -create /Users/_carlos-devbox NFSHomeDirectory /var/empty
+dscl . -create /Users/_carlos-devbox Password '*'
+dscl . -create /Users/_carlos-devbox IsHidden 1
+```
+
+Create the service's folders: one for its data, private to the service user, and one for the registrar socket, which every account can reach. Create the log file as well, owned by the service user.
+
+```sh
+install -d -m 0700 -o _carlos-devbox -g _carlos-devbox /usr/local/var/carlos-devbox
+install -d -m 0755 -o _carlos-devbox -g _carlos-devbox /usr/local/var/run/carlos-devbox
+install -d -m 0755 /usr/local/var/log
+touch /usr/local/var/log/carlos-devbox.log
+chown _carlos-devbox:_carlos-devbox /usr/local/var/log/carlos-devbox.log
+chmod 0640 /usr/local/var/log/carlos-devbox.log
+```
+
+Write the environment file, private to the service user. It holds this Mac's tailnet address, the devbox domain, the data folder and the AWS key for the certificate challenge record. The service reads this file itself, because every account can read a plist.
+
+```sh
+install -d -m 0750 -o root -g _carlos-devbox /usr/local/etc/carlos-devbox
+touch /usr/local/etc/carlos-devbox/env
+chown _carlos-devbox:_carlos-devbox /usr/local/etc/carlos-devbox/env
+chmod 0600 /usr/local/etc/carlos-devbox/env
+"${EDITOR:-vi}" /usr/local/etc/carlos-devbox/env
+```
+
+```sh
+# /usr/local/etc/carlos-devbox/env
+CARLOS_DEVBOX_LISTEN=100.64.0.10:443
+CARLOS_DEVBOX_DOMAIN=devbox.example.com
+CARLOS_WILDCARD_DOMAINS=devbox.example.com
+CARLOS_DATA_DIR=/usr/local/var/carlos-devbox
+CARLOS_DNS_PROVIDER=route53
+AWS_ACCESS_KEY_ID=AKIA...
+AWS_SECRET_ACCESS_KEY=...
+```
+
+Install the carlos binary and the plist. In the plist, replace 100.64.0.10 with this Mac's tailnet address, the same one as in CARLOS_DEVBOX_LISTEN. The service refuses to start if launchd hands it a socket on any other address.
+
+```sh
+install -d -m 0755 /usr/local/bin
+install -m 0755 carlos /usr/local/bin/carlos
+install -m 0644 -o root -g wheel infra/devbox/com.carlosframework.devbox.plist \
+ /Library/LaunchDaemons/com.carlosframework.devbox.plist
+TAILNET_IP=100.64.0.10
+sed -i '' "s/100\.64\.0\.10/$TAILNET_IP/" /Library/LaunchDaemons/com.carlosframework.devbox.plist
+```
+
+Create the IAM user, key and policy as in the Linux steps above, then load the service.
+
+```sh
+launchctl bootstrap system /Library/LaunchDaemons/com.carlosframework.devbox.plist
+tail -f /usr/local/var/log/carlos-devbox.log
+```
+
+If the tailnet is not up when launchd loads the service, launchd cannot bind the address. Once the tailnet is up, start the service again.
+
+```sh
+launchctl kickstart -k system/com.carlosframework.devbox
+```
+
+Then add the DNS record and run the checks below. On a Mac, use lsof instead of ss to see what is listening, and read the log file instead of journalctl.
+
+```sh
+ls /usr/local/var/carlos-devbox/certs
+grep -i acme /usr/local/var/log/carlos-devbox.log
+lsof -nP -iTCP -sTCP:LISTEN | grep carlos
+```
+
## DNS
Add one A record, by hand, once: *.devbox.example.com pointing at this machine's tailnet IPv4 address.
diff --git a/infra/devbox/com.carlosframework.devbox.plist b/infra/devbox/com.carlosframework.devbox.plist
new file mode 100644
index 000000000..e0668ed9b
--- /dev/null
+++ b/infra/devbox/com.carlosframework.devbox.plist
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!--
+ Devbox mode on macOS (#488): the LaunchDaemon for `carlos devbox serve`.
+ launchd, as root, binds the tailnet address on port 443 (Sockets) and
+ starts the service as _carlos-devbox, which takes that socket
+ (CARLOS_DEVBOX_LAUNCHD_SOCKET names the entry). Nothing of ours runs as
+ root. Install: infra/devbox/README.md, "Install on macOS".
+
+ Every account can read this file, so it holds no secret. The settings
+ and the DNS credential are in the env file, mode 0600, which the service
+ reads itself (its env-file flag, below).
+
+ Replace 100.64.0.10 with this Mac's tailnet address, the same one as
+ CARLOS_DEVBOX_LISTEN in the env file: the service refuses a socket on any
+ other address.
+-->
+<plist version="1.0">
+<dict>
+ <key>Label</key>
+ <string>com.carlosframework.devbox</string>
+
+ <key>ProgramArguments</key>
+ <array>
+ <string>/usr/local/bin/carlos</string>
+ <string>devbox</string>
+ <string>serve</string>
+ <string>--env-file</string>
+ <string>/usr/local/etc/carlos-devbox/env</string>
+ </array>
+
+ <key>UserName</key>
+ <string>_carlos-devbox</string>
+ <key>GroupName</key>
+ <string>_carlos-devbox</string>
+
+ <key>Sockets</key>
+ <dict>
+ <key>Listeners</key>
+ <dict>
+ <key>SockNodeName</key>
+ <string>100.64.0.10</string>
+ <key>SockServiceName</key>
+ <string>443</string>
+ <key>SockType</key>
+ <string>stream</string>
+ <key>SockFamily</key>
+ <string>IPv4</string>
+ </dict>
+ </dict>
+
+ <key>EnvironmentVariables</key>
+ <dict>
+ <key>CARLOS_DEVBOX_LAUNCHD_SOCKET</key>
+ <string>Listeners</string>
+ </dict>
+
+ <key>RunAtLoad</key>
+ <true/>
+ <key>KeepAlive</key>
+ <true/>
+
+ <key>StandardOutPath</key>
+ <string>/usr/local/var/log/carlos-devbox.log</string>
+ <key>StandardErrorPath</key>
+ <string>/usr/local/var/log/carlos-devbox.log</string>
+</dict>
+</plist>
diff --git a/internal/devbox/peer_darwin.go b/internal/devbox/peer_darwin.go
new file mode 100644
index 000000000..b6be12f36
--- /dev/null
+++ b/internal/devbox/peer_darwin.go
@@ -0,0 +1,48 @@
+//go:build darwin
+
+package devbox
+
+import (
+ "errors"
+ "fmt"
+ "net"
+
+ "golang.org/x/sys/unix"
+)
+
+// xucredVersion is XUCRED_VERSION from <sys/ucred.h>, the only layout of
+// struct xucred the kernel writes. x/sys/unix does not export it.
+const xucredVersion = 0
+
+// PeerUID returns the uid of the process at the other end of a Unix socket,
+// as the kernel recorded it at connect time (LOCAL_PEERCRED, macOS's
+// SO_PEERCRED). Any other kind of connection, or credentials in a layout
+// this code does not know, is an error: no uid, no identity. Uid 0 is a uid
+// like any other.
+func PeerUID(c net.Conn) (uint32, error) {
+ uc, ok := c.(*net.UnixConn)
+ if !ok {
+ return 0, errors.New("devbox: not a unix connection")
+ }
+ raw, err := uc.SyscallConn()
+ if err != nil {
+ return 0, err
+ }
+ var cred *unix.Xucred
+ var cerr error
+ if err := raw.Control(func(fd uintptr) {
+ cred, cerr = unix.GetsockoptXucred(int(fd), unix.SOL_LOCAL, unix.LOCAL_PEERCRED)
+ }); err != nil {
+ return 0, err
+ }
+ if cerr != nil {
+ return 0, cerr
+ }
+ if cred == nil {
+ return 0, errors.New("devbox: no peer credentials")
+ }
+ if cred.Version != xucredVersion {
+ return 0, fmt.Errorf("devbox: peer credentials in xucred version %d, want %d", cred.Version, xucredVersion)
+ }
+ return cred.Uid, nil
+}
diff --git a/internal/devbox/peer_darwin_test.go b/internal/devbox/peer_darwin_test.go
new file mode 100644
index 000000000..7e0b3f412
--- /dev/null
+++ b/internal/devbox/peer_darwin_test.go
@@ -0,0 +1,54 @@
+//go:build darwin
+
+package devbox
+
+import (
+ "net"
+ "os"
+ "testing"
+
+ "golang.org/x/sys/unix"
+)
+
+// A Unix socket pair made by this process: LOCAL_PEERCRED attributes the
+// other end to this process's uid. A TCP connection has no peer uid.
+func TestPeerUIDDarwin(t *testing.T) {
+ fds, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ conns := make([]net.Conn, 2)
+ for i, fd := range fds {
+ f := os.NewFile(uintptr(fd), "pair")
+ c, err := net.FileConn(f) // dups fd
+ f.Close()
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { c.Close() })
+ conns[i] = c
+ }
+ for _, c := range conns {
+ uid, err := PeerUID(c)
+ if err != nil {
+ t.Fatalf("PeerUID = %v", err)
+ }
+ if uid != uint32(os.Getuid()) {
+ t.Fatalf("PeerUID = %d, want %d", uid, os.Getuid())
+ }
+ }
+
+ ln, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer ln.Close()
+ c, err := net.Dial("tcp", ln.Addr().String())
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer c.Close()
+ if _, err := PeerUID(c); err == nil {
+ t.Fatal("PeerUID on a TCP connection = nil error, want a refusal")
+ }
+}
diff --git a/internal/devbox/peer_other.go b/internal/devbox/peer_other.go
index 5f36c4f9f..5698a0f40 100644
--- a/internal/devbox/peer_other.go
+++ b/internal/devbox/peer_other.go
@@ -1,4 +1,4 @@
-//go:build !linux
+//go:build !linux && !darwin
package devbox
@@ -7,8 +7,9 @@ import (
"net"
)
-// PeerUID is Linux only: elsewhere there is no SO_PEERCRED, so no caller has
-// an identity and the registrar refuses every request.
+// PeerUID is Linux and macOS only: elsewhere there is no SO_PEERCRED or
+// LOCAL_PEERCRED, so no caller has an identity and the registrar refuses
+// every request.
func PeerUID(c net.Conn) (uint32, error) {
return 0, errors.ErrUnsupported
}
diff --git a/internal/edge/devbox.go b/internal/edge/devbox.go
index 4d1605e9c..b85c7c1c4 100644
--- a/internal/edge/devbox.go
+++ b/internal/edge/devbox.go
@@ -40,6 +40,57 @@ type DevboxConfig struct {
ListenAddr string // host:port; host must be a specific IP
CertDir string // autocert.DirCache for the wildcard + ACME account key
SpoolRoot string // passed to WithLocalStatic
+ // Listener, when set, is served on instead of binding ListenAddr: on
+ // macOS launchd binds port 443 and hands the socket over (#488). It
+ // must be on ListenAddr exactly (CheckDevboxListener). ServeDevbox
+ // owns it from the call on and closes it before returning.
+ Listener net.Listener
+}
+
+// DevboxListenerError is a listener handed to ServeDevbox that is not on
+// ListenAddr: Addr is where it listens and Want is ListenAddr. Unspecified
+// says it listens on every interface (0.0.0.0 or ::), which is never
+// served. The caller words it for a person.
+type DevboxListenerError struct {
+ Addr, Want string
+ Unspecified bool
+}
+
+func (e *DevboxListenerError) Error() string {
+ if e.Unspecified {
+ return fmt.Sprintf("edge: devbox: the given listener is on %s, which is every interface; want %s", e.Addr, e.Want)
+ }
+ return fmt.Sprintf("edge: devbox: the given listener is on %s, not on the listen address %s", e.Addr, e.Want)
+}
+
+// CheckDevboxListener refuses, with a *DevboxListenerError, a listener that
+// is not a TCP listener on exactly listenAddr (the same IP and port), or
+// that listens on every interface. A listenAddr ServeDevbox would refuse
+// is refused first, with that error.
+func CheckDevboxListener(ln net.Listener, listenAddr string) error {
+ if err := checkDevboxListenAddr(listenAddr); err != nil {
+ return err
+ }
+ addr := ln.Addr()
+ refused := &DevboxListenerError{Addr: addr.String(), Want: listenAddr}
+ tcp, ok := addr.(*net.TCPAddr)
+ if !ok {
+ return refused
+ }
+ got, ok := netip.AddrFromSlice(tcp.IP)
+ if !ok {
+ return refused
+ }
+ got = got.Unmap()
+ if got.IsUnspecified() {
+ refused.Unspecified = true
+ return refused
+ }
+ want, err := netip.ParseAddrPort(listenAddr)
+ if err != nil || want.Addr().Unmap() != got || int(want.Port()) != tcp.Port {
+ return refused
+ }
+ return nil
}
// ServeDevbox serves the registry's routes over HTTPS on cfg.ListenAddr with
@@ -69,12 +120,23 @@ type devboxSeams struct {
}
func serveDevbox(ctx context.Context, cfg DevboxConfig, seams devboxSeams) error {
+ // A given listener is ours to close whatever happens. Once the server
+ // has it, Shutdown or Close closes it first, and this Close is a no-op.
+ if cfg.Listener != nil {
+ defer cfg.Listener.Close()
+ }
// The address first, before anything is built: a devbox is reachable
// only on its tailnet address, and an empty or wildcard host would put
- // every route on the office LAN too.
+ // every route on the office LAN too. A given listener is held to the
+ // same address.
if err := checkDevboxListenAddr(cfg.ListenAddr); err != nil {
return err
}
+ if cfg.Listener != nil {
+ if err := CheckDevboxListener(cfg.Listener, cfg.ListenAddr); err != nil {
+ return err
+ }
+ }
if cfg.Registry == nil {
return errors.New("edge: devbox: no registry")
}
@@ -122,9 +184,12 @@ func serveDevbox(ctx context.Context, cfg DevboxConfig, seams devboxSeams) error
// behind. The address is never empty here, so listen's default never
// applies; it is the address again rather than ":https", which would be
// every interface.
- ln, err := listen("https", cfg.ListenAddr, cfg.ListenAddr)
- if err != nil {
- return err
+ ln := cfg.Listener
+ if ln == nil {
+ ln, err = listen("https", cfg.ListenAddr, cfg.ListenAddr)
+ if err != nil {
+ return err
+ }
}
if seams.bound != nil {
seams.bound(ln.Addr())
diff --git a/internal/edge/devbox_test.go b/internal/edge/devbox_test.go
index 9f26e8695..d4836891c 100644
--- a/internal/edge/devbox_test.go
+++ b/internal/edge/devbox_test.go
@@ -251,6 +251,14 @@ type devboxRun struct {
// run loop loads it and orders nothing), adds a service route
// slow.<parent> to heldAddr when it is set, and serves on 127.0.0.1:0.
func startDevbox(t *testing.T, heldAddr string, drainTimeout time.Duration) *devboxRun {
+ t.Helper()
+ return startDevboxOn(t, heldAddr, drainTimeout, nil)
+}
+
+// startDevboxOn is startDevbox serving on ln, a listener handed in as
+// launchd hands one over, when ln is not nil; ListenAddr is then ln's
+// address.
+func startDevboxOn(t *testing.T, heldAddr string, drainTimeout time.Duration, ln net.Listener) *devboxRun {
t.Helper()
certDir := t.TempDir()
cert, key := selfSignedWildcard(t, devboxParent, time.Now().Add(60*24*time.Hour))
@@ -274,6 +282,9 @@ func startDevbox(t *testing.T, heldAddr string, drainTimeout time.Duration) *dev
boundAddr := make(chan string, 1)
done := make(chan error, 1)
cfg := DevboxConfig{Registry: reg, ListenAddr: "127.0.0.1:0", CertDir: certDir, SpoolRoot: t.TempDir()}
+ if ln != nil {
+ cfg.ListenAddr, cfg.Listener = ln.Addr().String(), ln
+ }
seams := devboxSeams{
bound: func(a net.Addr) { boundAddr <- a.String() },
errorLog: log.New(errLog, "", 0),
@@ -486,3 +497,95 @@ func TestDevboxBindFailureIsAnError(t *testing.T) {
t.Fatalf("ServeDevbox on a held port = %v (ctx %v), want an immediate bind error", err, ctx.Err())
}
}
+
+// A listener handed in (launchd's, on macOS) is served on as it is: the
+// devbox does not bind ListenAddr itself, which would fail here because the
+// listener holds that very address. Cancelling closes it.
+func TestDevboxUsesGivenListener(t *testing.T) {
+ ca, requests := countingCA(t)
+ devboxEnv(t, ca.URL)
+ ln, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { ln.Close() })
+ run := startDevboxOn(t, "", 0, ln)
+ if run.addr != ln.Addr().String() {
+ t.Fatalf("served on %s, want the given listener's %s", run.addr, ln.Addr())
+ }
+ run.cancel()
+ select {
+ case err := <-run.done:
+ if err != nil {
+ t.Fatalf("ServeDevbox after cancel = %v", err)
+ }
+ case <-time.After(15 * time.Second):
+ t.Fatal("ServeDevbox did not return")
+ }
+ if _, err := ln.Accept(); err == nil {
+ t.Fatal("the given listener is still open after ServeDevbox returned")
+ }
+ if n := requests.Load(); n != 0 {
+ t.Fatalf("the CA saw %d request(s), want 0", n)
+ }
+}
+
+// fakeListener is a listener on any address, without binding it: binding
+// every interface in a test would put a port on the LAN.
+type fakeListener struct {
+ addr net.Addr
+ closed atomic.Bool
+}
+
+func (f *fakeListener) Accept() (net.Conn, error) { return nil, net.ErrClosed }
+func (f *fakeListener) Close() error { f.closed.Store(true); return nil }
+func (f *fakeListener) Addr() net.Addr { return f.addr }
+
+// A listener on any address but ListenAddr is refused before anything is
+// served or ordered, with a DevboxListenerError naming both addresses, and
+// closed. One on every interface is refused the same way, and says so.
+func TestDevboxRefusesListenerOnOtherAddr(t *testing.T) {
+ ca, requests := countingCA(t)
+ devboxEnv(t, ca.URL)
+ tcp := func(ip string, port int) net.Addr { return &net.TCPAddr{IP: net.ParseIP(ip), Port: port} }
+ for _, c := range []struct {
+ name string
+ ln net.Addr
+ listen string
+ unspecified bool
+ }{
+ {"other port", tcp("127.0.0.1", 8443), "127.0.0.1:443", false},
+ {"other ip", tcp("127.0.0.2", 443), "127.0.0.1:443", false},
+ {"ipv6 for ipv4", tcp("::1", 443), "127.0.0.1:443", false},
+ {"every interface", tcp("0.0.0.0", 443), "100.64.0.10:443", true},
+ {"every interface, ipv6", tcp("::", 443), "100.64.0.10:443", true},
+ {"not tcp", &net.UnixAddr{Name: "/tmp/x.sock", Net: "unix"}, "100.64.0.10:443", false},
+ } {
+ t.Run(c.name, func(t *testing.T) {
+ ln := &fakeListener{addr: c.ln}
+ cfg := DevboxConfig{Registry: openReg(t), ListenAddr: c.listen, Listener: ln, CertDir: t.TempDir(), SpoolRoot: t.TempDir()}
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ defer cancel()
+ err := ServeDevbox(ctx, cfg)
+ var le *DevboxListenerError
+ if !errors.As(err, &le) || ctx.Err() != nil {
+ t.Fatalf("ServeDevbox = %v (ctx %v), want an immediate DevboxListenerError", err, ctx.Err())
+ }
+ if le.Addr != c.ln.String() || le.Want != c.listen || le.Unspecified != c.unspecified {
+ t.Fatalf("error = %+v, want Addr %s, Want %s, Unspecified %v", *le, c.ln, c.listen, c.unspecified)
+ }
+ if err := CheckDevboxListener(ln, c.listen); !errors.As(err, &le) {
+ t.Fatalf("CheckDevboxListener = %v, want the same refusal", err)
+ }
+ if !ln.closed.Load() {
+ t.Fatal("the refused listener was not closed")
+ }
+ })
+ }
+ if err := CheckDevboxListener(&fakeListener{addr: tcp("100.64.0.10", 443)}, "100.64.0.10:443"); err != nil {
+ t.Fatalf("CheckDevboxListener on the right address = %v", err)
+ }
+ if n := requests.Load(); n != 0 {
+ t.Fatalf("the CA saw %d request(s), want 0", n)
+ }
+}
diff --git a/internal/fileacl/fileacl.go b/internal/fileacl/fileacl.go
new file mode 100644
index 000000000..7d408e2d7
--- /dev/null
+++ b/internal/fileacl/fileacl.go
@@ -0,0 +1,15 @@
+// Package fileacl reports whether an open file carries an extended access
+// control list: entries beyond its owner, group and other mode bits that can
+// grant another account access the mode does not show. On macOS an ACL is
+// evaluated before the mode bits, so a 0600 file can still be readable by
+// someone else (devbox mode's env file, #488).
+//
+// Linux is not covered and needs no cover for a mode check: with a POSIX
+// ACL, the group bits of st_mode are the ACL's mask, which bounds every
+// named user and group entry, so a mode with no group or other bits leaves
+// those entries no access. Elsewhere Extended reports none.
+//
+// There is no cgo. On darwin the package calls acl_get_fd(3),
+// acl_get_entry(3) and acl_free(3) in libSystem the way golang.org/x/sys/unix
+// calls libc, as internal/launchd does.
+package fileacl
diff --git a/internal/fileacl/fileacl_darwin.go b/internal/fileacl/fileacl_darwin.go
new file mode 100644
index 000000000..34ce570d3
--- /dev/null
+++ b/internal/fileacl/fileacl_darwin.go
@@ -0,0 +1,76 @@
+//go:build darwin
+
+package fileacl
+
+import (
+ "fmt"
+ "os"
+ "syscall"
+ "unsafe"
+)
+
+// From <sys/acl.h>.
+const aclFirstEntry = 0 // ACL_FIRST_ENTRY
+
+// Extended reports whether f carries an extended ACL with one or more
+// entries. It reads the open descriptor, never the path again. A file
+// system without ACLs has none. Any other failure is an error, so a caller
+// that refuses on error fails closed.
+func Extended(f *os.File) (bool, error) {
+ raw, err := f.SyscallConn()
+ if err != nil {
+ return false, err
+ }
+ var has bool
+ var cerr error
+ if err := raw.Control(func(fd uintptr) { has, cerr = extended(int(fd)) }); err != nil {
+ return false, err
+ }
+ return has, cerr
+}
+
+func extended(fd int) (bool, error) {
+ // acl_t acl_get_fd(int fd): NULL and errno when there is none.
+ acl, _, e := syscall_syscallPtr(libc_acl_get_fd_trampoline_addr, uintptr(fd), 0, 0)
+ if acl == 0 {
+ switch e {
+ case syscall.ENOENT, syscall.ENOTSUP, syscall.EOPNOTSUPP:
+ return false, nil // no extended ACL, or none possible here
+ }
+ return false, fmt.Errorf("fileacl: acl_get_fd: %w", e)
+ }
+ // int acl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p):
+ // 0 when there is a first entry. The entry points into acl and is
+ // not freed on its own.
+ var entry uintptr
+ r, _, e := syscall_syscall(libc_acl_get_entry_trampoline_addr, acl, aclFirstEntry, uintptr(unsafe.Pointer(&entry)))
+ // int acl_free(void *obj_p)
+ syscall_syscall(libc_acl_free_trampoline_addr, acl, 0, 0)
+ switch {
+ case int32(r) == 0:
+ return true, nil
+ case e == syscall.EINVAL:
+ return false, nil // an ACL with no entries
+ }
+ return false, fmt.Errorf("fileacl: acl_get_entry: %w", e)
+}
+
+// The syscall package's libc calls, marked for linkname use by x/sys/unix
+// (unix/syscall_darwin_libSystem.go). syscallPtr reports errno when r1 is 0
+// (a NULL pointer); syscall when r1 is -1.
+func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
+func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
+
+//go:linkname syscall_syscall syscall.syscall
+//go:linkname syscall_syscallPtr syscall.syscallPtr
+
+// The trampolines are in fileacl_darwin_$GOARCH.s.
+var (
+ libc_acl_get_fd_trampoline_addr uintptr
+ libc_acl_get_entry_trampoline_addr uintptr
+ libc_acl_free_trampoline_addr uintptr
+)
+
+//go:cgo_import_dynamic fileacl_libc_acl_get_fd acl_get_fd "/usr/lib/libSystem.B.dylib"
+//go:cgo_import_dynamic fileacl_libc_acl_get_entry acl_get_entry "/usr/lib/libSystem.B.dylib"
+//go:cgo_import_dynamic fileacl_libc_acl_free acl_free "/usr/lib/libSystem.B.dylib"
diff --git a/internal/fileacl/fileacl_darwin_amd64.s b/internal/fileacl/fileacl_darwin_amd64.s
new file mode 100644
index 000000000..05777366f
--- /dev/null
+++ b/internal/fileacl/fileacl_darwin_amd64.s
@@ -0,0 +1,19 @@
+// The libc trampolines for fileacl_darwin.go, in x/sys/unix's form
+// (unix/zsyscall_darwin_*.s), as internal/launchd has them.
+
+#include "textflag.h"
+
+TEXT libc_acl_get_fd_trampoline<>(SB),NOSPLIT,$0-0
+ JMP fileacl_libc_acl_get_fd(SB)
+GLOBL ·libc_acl_get_fd_trampoline_addr(SB), RODATA, $8
+DATA ·libc_acl_get_fd_trampoline_addr(SB)/8, $libc_acl_get_fd_trampoline<>(SB)
+
+TEXT libc_acl_get_entry_trampoline<>(SB),NOSPLIT,$0-0
+ JMP fileacl_libc_acl_get_entry(SB)
+GLOBL ·libc_acl_get_entry_trampoline_addr(SB), RODATA, $8
+DATA ·libc_acl_get_entry_trampoline_addr(SB)/8, $libc_acl_get_entry_trampoline<>(SB)
+
+TEXT libc_acl_free_trampoline<>(SB),NOSPLIT,$0-0
+ JMP fileacl_libc_acl_free(SB)
+GLOBL ·libc_acl_free_trampoline_addr(SB), RODATA, $8
+DATA ·libc_acl_free_trampoline_addr(SB)/8, $libc_acl_free_trampoline<>(SB)
diff --git a/internal/fileacl/fileacl_darwin_arm64.s b/internal/fileacl/fileacl_darwin_arm64.s
new file mode 100644
index 000000000..05777366f
--- /dev/null
+++ b/internal/fileacl/fileacl_darwin_arm64.s
@@ -0,0 +1,19 @@
+// The libc trampolines for fileacl_darwin.go, in x/sys/unix's form
+// (unix/zsyscall_darwin_*.s), as internal/launchd has them.
+
+#include "textflag.h"
+
+TEXT libc_acl_get_fd_trampoline<>(SB),NOSPLIT,$0-0
+ JMP fileacl_libc_acl_get_fd(SB)
+GLOBL ·libc_acl_get_fd_trampoline_addr(SB), RODATA, $8
+DATA ·libc_acl_get_fd_trampoline_addr(SB)/8, $libc_acl_get_fd_trampoline<>(SB)
+
+TEXT libc_acl_get_entry_trampoline<>(SB),NOSPLIT,$0-0
+ JMP fileacl_libc_acl_get_entry(SB)
+GLOBL ·libc_acl_get_entry_trampoline_addr(SB), RODATA, $8
+DATA ·libc_acl_get_entry_trampoline_addr(SB)/8, $libc_acl_get_entry_trampoline<>(SB)
+
+TEXT libc_acl_free_trampoline<>(SB),NOSPLIT,$0-0
+ JMP fileacl_libc_acl_free(SB)
+GLOBL ·libc_acl_free_trampoline_addr(SB), RODATA, $8
+DATA ·libc_acl_free_trampoline_addr(SB)/8, $libc_acl_free_trampoline<>(SB)
diff --git a/internal/fileacl/fileacl_darwin_test.go b/internal/fileacl/fileacl_darwin_test.go
new file mode 100644
index 000000000..130d5e013
--- /dev/null
+++ b/internal/fileacl/fileacl_darwin_test.go
@@ -0,0 +1,40 @@
+//go:build darwin
+
+package fileacl
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+ "testing"
+)
+
+// A 0600 file has no ACL until chmod +a gives it one, which grants another
+// account read and write that the mode does not show; chmod -N removes it.
+func TestExtendedDarwin(t *testing.T) {
+ p := filepath.Join(t.TempDir(), "env")
+ if err := os.WriteFile(p, []byte("A=1\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ check := func(want bool) {
+ t.Helper()
+ f, err := os.Open(p)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ got, err := Extended(f)
+ if err != nil || got != want {
+ t.Fatalf("Extended = %v, %v, want %v", got, err, want)
+ }
+ }
+ check(false)
+ if out, err := exec.Command("/bin/chmod", "+a", "everyone allow read,write", p).CombinedOutput(); err != nil {
+ t.Fatalf("chmod +a: %v: %s", err, out)
+ }
+ check(true)
+ if out, err := exec.Command("/bin/chmod", "-N", p).CombinedOutput(); err != nil {
+ t.Fatalf("chmod -N: %v: %s", err, out)
+ }
+ check(false)
+}
diff --git a/internal/fileacl/fileacl_other.go b/internal/fileacl/fileacl_other.go
new file mode 100644
index 000000000..baf5b5502
--- /dev/null
+++ b/internal/fileacl/fileacl_other.go
@@ -0,0 +1,8 @@
+//go:build !darwin
+
+package fileacl
+
+import "os"
+
+// Extended reports no ACL: see the package comment.
+func Extended(f *os.File) (bool, error) { return false, nil }
diff --git a/internal/fileacl/fileacl_other_test.go b/internal/fileacl/fileacl_other_test.go
new file mode 100644
index 000000000..a73373249
--- /dev/null
+++ b/internal/fileacl/fileacl_other_test.go
@@ -0,0 +1,24 @@
+//go:build !darwin
+
+package fileacl
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+func TestExtendedElsewhereReportsNone(t *testing.T) {
+ p := filepath.Join(t.TempDir(), "f")
+ if err := os.WriteFile(p, nil, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ f, err := os.Open(p)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ if got, err := Extended(f); got || err != nil {
+ t.Fatalf("Extended = %v, %v", got, err)
+ }
+}
diff --git a/internal/launchd/activate_darwin.go b/internal/launchd/activate_darwin.go
new file mode 100644
index 000000000..33c3d4bde
--- /dev/null
+++ b/internal/launchd/activate_darwin.go
@@ -0,0 +1,82 @@
+//go:build darwin
+
+package launchd
+
+import (
+ "errors"
+ "fmt"
+ "net"
+ "os"
+ "syscall"
+ "unsafe"
+)
+
+// Listeners returns the listening sockets launchd opened for the plist's
+// Sockets entry called name. It may be called once per name: launchd
+// answers a second call with EALREADY. Each listener is a dup of launchd's
+// descriptor, which is closed, as is the array launchd allocated for them.
+func Listeners(name string) ([]net.Listener, error) {
+ cname, err := syscall.BytePtrFromString(name)
+ if err != nil {
+ return nil, fmt.Errorf("launchd: socket name %q: %w", name, err)
+ }
+ // int launch_activate_socket(const char *name, int **fds, size_t *cnt);
+ // It returns 0 or an errno value; it does not set errno.
+ var fds *int32
+ var cnt uintptr
+ r1, _, _ := syscall_syscall(libc_launch_activate_socket_trampoline_addr,
+ uintptr(unsafe.Pointer(cname)), uintptr(unsafe.Pointer(&fds)), uintptr(unsafe.Pointer(&cnt)))
+ if code := syscall.Errno(int32(r1)); code != 0 {
+ switch code {
+ case syscall.ESRCH:
+ return nil, fmt.Errorf("%w (%w)", ErrNotManaged, code)
+ case syscall.ENOENT:
+ return nil, fmt.Errorf("%w: %q (%w)", ErrNoSocket, name, code)
+ }
+ return nil, fmt.Errorf("launchd: launch_activate_socket %q: %w", name, code)
+ }
+ if fds == nil {
+ return nil, nil
+ }
+ raw := make([]int32, cnt)
+ copy(raw, unsafe.Slice(fds, cnt))
+ syscall_syscall(libc_free_trampoline_addr, uintptr(unsafe.Pointer(fds)), 0, 0)
+
+ var out []net.Listener
+ var errs []error
+ for _, fd := range raw {
+ f := os.NewFile(uintptr(fd), "launchd:"+name)
+ ln, err := net.FileListener(f) // dups the descriptor
+ f.Close()
+ if err != nil {
+ errs = append(errs, err)
+ continue
+ }
+ out = append(out, ln)
+ }
+ if len(errs) > 0 {
+ for _, ln := range out {
+ ln.Close()
+ }
+ return nil, fmt.Errorf("launchd: socket %q: %w", name, errors.Join(errs...))
+ }
+ return out, nil
+}
+
+// syscall_syscall is the syscall package's libc call (syscall.syscall),
+// which enters and leaves the scheduler's syscall state around fn. The
+// syscall package marks it for linkname use by x/sys/unix, which reaches it
+// exactly this way (unix/syscall_darwin_libSystem.go).
+func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
+
+//go:linkname syscall_syscall syscall.syscall
+
+// The trampolines are in activate_darwin_$GOARCH.s; each jumps to the libc
+// symbol its directive below imports.
+var (
+ libc_launch_activate_socket_trampoline_addr uintptr
+ libc_free_trampoline_addr uintptr
+)
+
+//go:cgo_import_dynamic launchd_libc_launch_activate_socket launch_activate_socket "/usr/lib/libSystem.B.dylib"
+//go:cgo_import_dynamic launchd_libc_free free "/usr/lib/libSystem.B.dylib"
diff --git a/internal/launchd/activate_darwin_amd64.s b/internal/launchd/activate_darwin_amd64.s
new file mode 100644
index 000000000..fc98fc817
--- /dev/null
+++ b/internal/launchd/activate_darwin_amd64.s
@@ -0,0 +1,15 @@
+// The libc trampolines for activate_darwin.go, in x/sys/unix's form
+// (unix/zsyscall_darwin_*.s): a jump to the dynamically imported symbol,
+// and a read-only word holding the trampoline's address for Go to call.
+
+#include "textflag.h"
+
+TEXT libc_launch_activate_socket_trampoline<>(SB),NOSPLIT,$0-0
+ JMP launchd_libc_launch_activate_socket(SB)
+GLOBL ·libc_launch_activate_socket_trampoline_addr(SB), RODATA, $8
+DATA ·libc_launch_activate_socket_trampoline_addr(SB)/8, $libc_launch_activate_socket_trampoline<>(SB)
+
+TEXT libc_free_trampoline<>(SB),NOSPLIT,$0-0
+ JMP launchd_libc_free(SB)
+GLOBL ·libc_free_trampoline_addr(SB), RODATA, $8
+DATA ·libc_free_trampoline_addr(SB)/8, $libc_free_trampoline<>(SB)
diff --git a/internal/launchd/activate_darwin_arm64.s b/internal/launchd/activate_darwin_arm64.s
new file mode 100644
index 000000000..fc98fc817
--- /dev/null
+++ b/internal/launchd/activate_darwin_arm64.s
@@ -0,0 +1,15 @@
+// The libc trampolines for activate_darwin.go, in x/sys/unix's form
+// (unix/zsyscall_darwin_*.s): a jump to the dynamically imported symbol,
+// and a read-only word holding the trampoline's address for Go to call.
+
+#include "textflag.h"
+
+TEXT libc_launch_activate_socket_trampoline<>(SB),NOSPLIT,$0-0
+ JMP launchd_libc_launch_activate_socket(SB)
+GLOBL ·libc_launch_activate_socket_trampoline_addr(SB), RODATA, $8
+DATA ·libc_launch_activate_socket_trampoline_addr(SB)/8, $libc_launch_activate_socket_trampoline<>(SB)
+
+TEXT libc_free_trampoline<>(SB),NOSPLIT,$0-0
+ JMP launchd_libc_free(SB)
+GLOBL ·libc_free_trampoline_addr(SB), RODATA, $8
+DATA ·libc_free_trampoline_addr(SB)/8, $libc_free_trampoline<>(SB)
diff --git a/internal/launchd/activate_darwin_test.go b/internal/launchd/activate_darwin_test.go
new file mode 100644
index 000000000..c078611f7
--- /dev/null
+++ b/internal/launchd/activate_darwin_test.go
@@ -0,0 +1,34 @@
+//go:build darwin
+
+package launchd
+
+import (
+ "errors"
+ "testing"
+ "time"
+)
+
+// go test is not a launchd job, so there is no socket to take: Listeners
+// says so at once, and does not wait on launchd.
+func TestLaunchdListenersOutsideLaunchd(t *testing.T) {
+ done := make(chan error, 1)
+ go func() {
+ lns, err := Listeners("Listeners")
+ for _, ln := range lns {
+ ln.Close()
+ }
+ if err == nil {
+ err = errors.New("no error")
+ }
+ done <- err
+ }()
+ select {
+ case err := <-done:
+ if !errors.Is(err, ErrNotManaged) && !errors.Is(err, ErrNoSocket) {
+ t.Fatalf("Listeners outside launchd = %v, want ErrNotManaged (or ErrNoSocket)", err)
+ }
+ t.Logf("Listeners outside launchd: %v", err)
+ case <-time.After(10 * time.Second):
+ t.Fatal("Listeners outside launchd did not return")
+ }
+}
diff --git a/internal/launchd/activate_other.go b/internal/launchd/activate_other.go
new file mode 100644
index 000000000..6f0ef65a7
--- /dev/null
+++ b/internal/launchd/activate_other.go
@@ -0,0 +1,14 @@
+//go:build !darwin
+
+package launchd
+
+import (
+ "errors"
+ "net"
+)
+
+// Listeners is macOS only: elsewhere there is no launchd to hand over a
+// socket.
+func Listeners(name string) ([]net.Listener, error) {
+ return nil, errors.ErrUnsupported
+}
diff --git a/internal/launchd/activate_other_test.go b/internal/launchd/activate_other_test.go
new file mode 100644
index 000000000..4bf0d7fa8
--- /dev/null
+++ b/internal/launchd/activate_other_test.go
@@ -0,0 +1,15 @@
+//go:build !darwin
+
+package launchd
+
+import (
+ "errors"
+ "testing"
+)
+
+func TestLaunchdListenersUnsupported(t *testing.T) {
+ lns, err := Listeners("Listeners")
+ if !errors.Is(err, errors.ErrUnsupported) || lns != nil {
+ t.Fatalf("Listeners = %v, %v, want nil, ErrUnsupported", lns, err)
+ }
+}
diff --git a/internal/launchd/launchd.go b/internal/launchd/launchd.go
new file mode 100644
index 000000000..190228550
--- /dev/null
+++ b/internal/launchd/launchd.go
@@ -0,0 +1,21 @@
+// Package launchd takes the listening sockets launchd opened for this
+// process (a LaunchDaemon plist's Sockets entry), so a service can serve on a
+// port it may not bind itself. On macOS only port 443 needs it: launchd
+// binds as root, then starts the service as its own user (devbox mode on
+// macOS, #488).
+//
+// There is no cgo. On darwin the package calls launch_activate_socket(3)
+// and free(3) in libSystem the way golang.org/x/sys/unix calls libc: a
+// //go:cgo_import_dynamic for each symbol, an assembly trampoline that jumps
+// to it, and the syscall package's libc call path, reached by linkname.
+package launchd
+
+import "errors"
+
+var (
+ // ErrNotManaged: launchd did not start this process, so it holds no
+ // sockets for it (ESRCH).
+ ErrNotManaged = errors.New("launchd: this process was not started by launchd")
+ // ErrNoSocket: the job has no socket of that name (ENOENT).
+ ErrNoSocket = errors.New("launchd: no socket of that name for this job")
+)
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index e7721b280..2960b5a41 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -51,3 +51,4 @@ plan14-root-reads-fleet-alerts-1.tsv 8653544a508c745b01d4bbe2a89a3fb11f6da6b9ba6
plan14-root-reads-managed-fleets-1b.tsv 7570ca617863882780c1c5a7d04430b578a297ee4d72ca25acc1cdc5288ca283
plan14-root-reads-sponsor-existing-accounts.tsv 7570ca617863882780c1c5a7d04430b578a297ee4d72ca25acc1cdc5288ca283
plan14-root-reads-rootfs-apps-6.tsv c86929d08b9b2038fa103d1c7311ab2958e7100e92dc550d36daeb364affd029
+plan14-root-reads-devbox-macos.tsv 67b54b219f990c3dcfe32c6ffb11a80a4ca3898aec060fe9f4450e21098af714
diff --git a/internal/provision/testdata/plan14-root-reads-devbox-macos.tsv b/internal/provision/testdata/plan14-root-reads-devbox-macos.tsv
new file mode 100644
index 000000000..4f9637352
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-devbox-macos.tsv
@@ -0,0 +1,24 @@
+# Census overlay devbox-macos, written by census-propose (#369). census-ruling-devbox-macos, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-devbox-macos.md.
+# 1 body, 0 sites, 5 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 7 new dispositions: 0 reads re-frozen at their disposition with the claim, 7 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy afa5aecc1a5bd5ad74033708636757efaafe3d8f72b679d0064581207161caee devbox_cli.go runDevboxServe legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-mode;basis=new: carlos devbox serve, run by the carlos-devbox unit as the unprivileged carlos-devbox user, reads its config from the environment (CARLOS_DEVBOX_LISTEN, CARLOS_DEVBOX_DOMAIN, CARLOS_DATA_DIR, CARLOS_WILDCARD_DOMAINS, CARLOS_DEVBOX_SOCKET) and opens registry.db and links.json under its own StateDirectory. Not root;rev3=census-ruling-devbox-macos;basis=devbox on macOS (#488): serve now parses flags; --env-file PATH loads the service user's own env file (loadDevboxEnvFile) before reading the same environment as before; with CARLOS_DEVBOX_LAUNCHD_SOCKET set it takes launchd's listening socket (launchd.Listeners, macOS only; elsewhere it refuses) and holds it to CARLOS_DEVBOX_LISTEN (edge.CheckDevboxListener) before making anything; the socket path comes from devboxSocketPath (CARLOS_DEVBOX_SOCKET, or the OS default). Runs as the unprivileged service user (carlos-devbox on Linux, _carlos-devbox on macOS), never root; no new read beyond the env file named on its own command line data-literal@1086,data-literal@776,file:Open@2328 af97c614709d8403666d632eca5c15d20c905ab21e02064ab18ba2bb7a01cb30
+@legacy b8322b056054fcd65f2b37586ea7cf914add6f2941a653061bd27c00cf0ce77c devbox_envfile.go loadDevboxEnvFile legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): reads the --env-file named on carlos devbox serve's command line (the unit or plist, written by root at install), as the unprivileged service user. On the opened file: Stat for regular-file, owner == euid, mode & 077 == 0 and (darwin) no extended ACL, then ReadAll bounded to 1 MiB; every line must be KEY=VALUE, a comment or blank, no duplicate keys, nothing set unless all pass. Not root file:ReadAll@1113,file:Stat@274 252ac41ef1929f6859f2eed8aed3442d72c3364f33d91cfdbb6e8160018a5703
+@legacy fb4d89771bc46c1c18fa9cdc1974c91f08ff108cc1b0858e0f92f963d683530d devbox_envfile_unix.go openDevboxEnvFile legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): os.OpenFile(path, O_RDONLY|O_NONBLOCK) of the env file so a FIFO is refused instead of hanging; symlinks followed, every check is on the opened file. Called only by loadDevboxEnvFile, as the service user. Not root file:OpenFile@64 8a26179df81c92ba09042dd3f4a2bd7bbe05cd595b6ddb2810f9e08ed84711ca
+@legacy 66dc91dbb2550a4501a822dd65059877d338665e911bbeb44f90c3ad0c7d4913 infra/devbox/com.carlosframework.devbox.plist external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): the macOS LaunchDaemon. launchd (root) binds 100.64.0.10:443 (replaced at install with the tailnet IP) as Sockets/Listeners and runs /usr/local/bin/carlos devbox serve --env-file /usr/local/etc/carlos-devbox/env as UserName/GroupName _carlos-devbox. Its only environment is CARLOS_DEVBOX_LAUNCHD_SOCKET=Listeners; no secrets. Installed root:wheel 0644 by the runbook. macOS only; not read by anything on Linux file:external@0 1f1e35b36f33b13c5664bd67137fe38330a43b1c18427a1c5ddda4e0b9c38127
+@legacy b8ab4e084b2dfcd1ed51f5bf8d1add8fbbab8d4dfccda76d573e2f8a714e0b8a internal/fileacl/fileacl_darwin_amd64.s external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): darwin/amd64 libSystem trampolines (JMP to acl_get_fd, acl_get_entry, acl_free) in x/sys/unix's form; built only for darwin, so absent from the linux root binary file:external@0 1a635ddd767dcea2d62da4b1bcfcb6aadfef5f753d9d26922279830576f814cc
+@legacy 55b0f75e71a953c047b0e0bba18002f46c0d4e43121db019bd9566c4473a84f3 internal/fileacl/fileacl_darwin_arm64.s external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): darwin/arm64 libSystem trampolines (JMP to acl_get_fd, acl_get_entry, acl_free) in x/sys/unix's form; built only for darwin, so absent from the linux root binary file:external@0 1a635ddd767dcea2d62da4b1bcfcb6aadfef5f753d9d26922279830576f814cc
+@legacy 8e716fc612a5b130c9637d657ed9157058fea8ad3971d033863b94a7b37fc835 internal/launchd/activate_darwin_amd64.s external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): darwin/amd64 libSystem trampolines (JMP to launch_activate_socket, free) in x/sys/unix's form; built only for darwin, so absent from the linux root binary file:external@0 1027b2b693372a26fc14c404fd9fd31f780ce7727ee948dfc74336a5e181c05d
+@legacy 41d70fc3db920fa8b9000d59bb515e4960d103f7786cf4cc0868227542df0664 internal/launchd/activate_darwin_arm64.s external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): darwin/arm64 libSystem trampolines (JMP to launch_activate_socket, free) in x/sys/unix's form; built only for darwin, so absent from the linux root binary file:external@0 1027b2b693372a26fc14c404fd9fd31f780ce7727ee948dfc74336a5e181c05d
+devbox_cli.go runDevboxServe legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-mode;basis=new: carlos devbox serve, run by the carlos-devbox unit as the unprivileged carlos-devbox user, reads its config from the environment (CARLOS_DEVBOX_LISTEN, CARLOS_DEVBOX_DOMAIN, CARLOS_DATA_DIR, CARLOS_WILDCARD_DOMAINS, CARLOS_DEVBOX_SOCKET) and opens registry.db and links.json under its own StateDirectory. Not root;rev3=census-ruling-devbox-macos;basis=devbox on macOS (#488): serve now parses flags; --env-file PATH loads the service user's own env file (loadDevboxEnvFile) before reading the same environment as before; with CARLOS_DEVBOX_LAUNCHD_SOCKET set it takes launchd's listening socket (launchd.Listeners, macOS only; elsewhere it refuses) and holds it to CARLOS_DEVBOX_LISTEN (edge.CheckDevboxListener) before making anything; the socket path comes from devboxSocketPath (CARLOS_DEVBOX_SOCKET, or the OS default). Runs as the unprivileged service user (carlos-devbox on Linux, _carlos-devbox on macOS), never root; no new read beyond the env file named on its own command line data-literal@1086,data-literal@776,file:Open@2328 af97c614709d8403666d632eca5c15d20c905ab21e02064ab18ba2bb7a01cb30
+devbox_envfile.go loadDevboxEnvFile legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): reads the --env-file named on carlos devbox serve's command line (the unit or plist, written by root at install), as the unprivileged service user. On the opened file: Stat for regular-file, owner == euid, mode & 077 == 0 and (darwin) no extended ACL, then ReadAll bounded to 1 MiB; every line must be KEY=VALUE, a comment or blank, no duplicate keys, nothing set unless all pass. Not root file:ReadAll@1113,file:Stat@274 252ac41ef1929f6859f2eed8aed3442d72c3364f33d91cfdbb6e8160018a5703
+devbox_envfile_unix.go openDevboxEnvFile legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): os.OpenFile(path, O_RDONLY|O_NONBLOCK) of the env file so a FIFO is refused instead of hanging; symlinks followed, every check is on the opened file. Called only by loadDevboxEnvFile, as the service user. Not root file:OpenFile@64 8a26179df81c92ba09042dd3f4a2bd7bbe05cd595b6ddb2810f9e08ed84711ca
+infra/devbox/com.carlosframework.devbox.plist external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): the macOS LaunchDaemon. launchd (root) binds 100.64.0.10:443 (replaced at install with the tailnet IP) as Sockets/Listeners and runs /usr/local/bin/carlos devbox serve --env-file /usr/local/etc/carlos-devbox/env as UserName/GroupName _carlos-devbox. Its only environment is CARLOS_DEVBOX_LAUNCHD_SOCKET=Listeners; no secrets. Installed root:wheel 0644 by the runbook. macOS only; not read by anything on Linux file:external@0 1f1e35b36f33b13c5664bd67137fe38330a43b1c18427a1c5ddda4e0b9c38127
+internal/fileacl/fileacl_darwin_amd64.s external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): darwin/amd64 libSystem trampolines (JMP to acl_get_fd, acl_get_entry, acl_free) in x/sys/unix's form; built only for darwin, so absent from the linux root binary file:external@0 1a635ddd767dcea2d62da4b1bcfcb6aadfef5f753d9d26922279830576f814cc
+internal/fileacl/fileacl_darwin_arm64.s external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): darwin/arm64 libSystem trampolines (JMP to acl_get_fd, acl_get_entry, acl_free) in x/sys/unix's form; built only for darwin, so absent from the linux root binary file:external@0 1a635ddd767dcea2d62da4b1bcfcb6aadfef5f753d9d26922279830576f814cc
+internal/launchd/activate_darwin_amd64.s external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): darwin/amd64 libSystem trampolines (JMP to launch_activate_socket, free) in x/sys/unix's form; built only for darwin, so absent from the linux root binary file:external@0 1027b2b693372a26fc14c404fd9fd31f780ce7727ee948dfc74336a5e181c05d
+internal/launchd/activate_darwin_arm64.s external legacy accepted-legacy accepted-legacy;rev3=census-ruling-devbox-macos;basis=new (#488): darwin/arm64 libSystem trampolines (JMP to launch_activate_socket, free) in x/sys/unix's form; built only for darwin, so absent from the linux root binary file:external@0 1027b2b693372a26fc14c404fd9fd31f780ce7727ee948dfc74336a5e181c05d
+@coverage . c27e785adb2911421cd3c4a419b53128313be5cea7ec838c04f52e77fa02c00b
+@coverage infra/devbox 6004d4f104596fc9a9dd70a2f951b555913f5856b84979eb5992cbec39cd592d
+@coverage internal/edge 2c0e878b8066d3720e16e93cb14e9e360fc29d999ff8f61c9e2b35f477301b44
+@coverage internal/fileacl 0cc8a14e84bee6cb419f4d9b3fa3b644e59c14e58d8fbb94ad4aefb487e7a652
+@coverage internal/launchd 7dc9ec08bd27b46d2913aca093d094480ed434849e56c19998e068bba2346bb2