Repository navigation
fix(runtime-services): keep native MariaDB socket path within sun_path - #2587
Merged
Merged
Conversation
A long TMPDIR (e.g. Homeboy's per-run directory) pushed <root>/storage/runtime/server.sock past the 108-byte Unix-domain socket limit, so mariadbd exited before readiness and discovery reported the generic bounded-filesystem-unavailable. Select the owned-root base by projected socket length: prefer the canonical os.tmpdir(), fall back to the canonical /tmp, and otherwise fail before allocation with NativeMariaDbSocketPathError. The mkdtemp 0700 root and the realpath/lstat ownership proofs are unchanged for whichever base is chosen. The final socket path is asserted again, and the cause is surfaced as diagnostic.cause.code and readiness reason "socket-path-too-long" without leaking private paths. Fixes #2586
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2586
Problem
The native MariaDB server socket is created at
<mkdtemp root under realpath(tmpdir())>/storage/runtime/server.sock, which is theTMPDIRlength plus 54 bytes. Homeboy's per-runTMPDIRis 120 bytes, so the socket path is far pastsun_path(108 bytes on Linux, 104 on macOS).mariadbdexits before readiness, and the probe reported onlybounded-filesystem-unavailable.Fix
The root's base directory is now chosen by the length of the socket path it would produce. I moved the whole owned root instead of only the socket dir. Splitting the socket dir out would mean a second private root with its own lifecycle and cleanup, and it would also take the socket out of the bounded FUSE image the docs describe.
selectNativeMariaDbRootBase()takes candidates in order: the canonicalos.tmpdir()first, then the canonical/tmp. It returns the first one whose projected socket path is at mostNATIVE_MARIADB_SOCKET_PATH_LIMIT_BYTES(100 bytes, below both platform limits). Length is measured on therealpath, so a short symlink alias to a long directory can't get through.NativeMariaDbSocketPathError(reason: "socket-path-too-long") before any root is allocated.mkdtemp()changes.chmod 0700, therealpath === resolvecanonical check, the lstat directory/non-symlink proof, device/inode capture,assertOwnedNativeRoot,ownedNativePathcontainment and verified removal all run unchanged. Using/tmpis no weaker than usingTMPDIR:mkdtempcreates a random-suffixed directory that only the caller owns, and the existing proofs are what ensure ownership.<root>/datadir.ext4) and its mount (<root>/storage) move together with the root. The mount source, mountpoint and mountinfo checks are unchanged.assertNativeMariaDbSocketPath()beforemariadbdis started.diagnostic.cause = { code: "socket-path-too-long", message }, andnativeMariaDbHostReadiness()returnsreason: "socket-path-too-long". That covers both the direct-failure path and the retained-cleanup path. The messages give byte counts only, because evidence must not contain private absolute paths.RuntimeServiceDependencies.nativeRootBases(default[os.tmpdir(), "/tmp"]).docs/native-mariadb-runtime-service.mdis updated.Tests
New unit tests in
tests/native-mariadb-runtime-service.test.ts(fake binaries):TMPDIRis used unchanged; a longTMPDIRfalls back to the short base; a short symlink alias to a long dir is rejected on its canonical length; missing candidates are skipped; all-too-long raisesNativeMariaDbSocketPathErrorwith byte counts and no paths.[long, short]bases: it is ready; every--socket=path is under the short base and at most 100 bytes; the fallback root is a canonical, non-symlink0700dir; nothing is allocated under the long base; the root is removed on release.[long]only: it fails asprovision-failedwithcause.code: "socket-path-too-long"; no paths appear in the evidence; no root is allocated.[long]gives{ status: "unavailable", reason: "socket-path-too-long" }, and[long, short]givesready.Before the fix, the new tests fail against the old source.
tests/native-mariadb-runtime-service.integration.test.tsnow acceptssocket-path-too-longas a stable fail-closed reason.Results:
npm run test:runtime-services: passes.npm run check(build, types, fast contracts; 329 commands): passes.End-to-end (real MariaDB 10.11.14 + fuse2fs, uid 1000)
Run after
npm run build, withTMPDIR=/var/lib/datamachine/workspace/.homeboy/runtime/tmp/homeboy-run-df70bf63-6e8d-4494-a0e6-27a2706a628d-1794495483671992580(120 bytes):bounded-filesystem-unavailable, and provisioning failed withNative MariaDB exited before readiness.ready, andprovisionRuntimeServices(...)returnsDB_HOST=127.0.0.1/DB_PORTwithreadiness: "ready"and RSS 58 MiB. Release completes, and nowp-codebox-mariadb-*roots or FUSE mounts are left behind.TMPDIRand the default one.TMPDIRit was run withnode --import tsxbecause thetsxCLI's own IPC pipe hits the samesun_pathlimit.AI assistance
This PR was written by an AI agent (Claude) via Extra Chill Bot. That covers the investigation, the fix, the tests and this description. I reproduced the bug and ran the end-to-end verification above on a real host.