@smthrs/platform-node 0.0.0-stage → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +211 -0
- package/LICENSE +21 -0
- package/README.md +165 -2
- package/bin/darwin-arm64/smithers-jj-export +0 -0
- package/bin/darwin-x64/smithers-jj-export +0 -0
- package/bin/linux-arm64/smithers-jj-export +0 -0
- package/bin/linux-x64/smithers-jj-export +4 -0
- package/bin/win32-x64/smithers-jj-export.exe +0 -0
- package/dist/cjs/AtomicFileSystem.d.ts +147 -0
- package/dist/cjs/AtomicFileSystem.d.ts.map +1 -0
- package/dist/cjs/AtomicFileSystem.js +234 -0
- package/dist/cjs/AtomicFileSystem.js.map +7 -0
- package/dist/cjs/EgressHttpClient.d.ts +106 -0
- package/dist/cjs/EgressHttpClient.d.ts.map +1 -0
- package/dist/cjs/EgressHttpClient.js +202 -0
- package/dist/cjs/EgressHttpClient.js.map +7 -0
- package/dist/cjs/HostLiveness.d.ts +81 -0
- package/dist/cjs/HostLiveness.d.ts.map +1 -0
- package/dist/cjs/HostLiveness.js +49 -0
- package/dist/cjs/HostLiveness.js.map +7 -0
- package/dist/cjs/NodeHost.d.ts +145 -0
- package/dist/cjs/NodeHost.d.ts.map +1 -0
- package/dist/cjs/NodeHost.js +128 -0
- package/dist/cjs/NodeHost.js.map +7 -0
- package/dist/cjs/ProcessConfinement.d.ts +61 -0
- package/dist/cjs/ProcessConfinement.d.ts.map +1 -0
- package/dist/cjs/ProcessConfinement.js +287 -0
- package/dist/cjs/ProcessConfinement.js.map +7 -0
- package/dist/cjs/ProcessReaper.d.ts +457 -0
- package/dist/cjs/ProcessReaper.d.ts.map +1 -0
- package/dist/cjs/ProcessReaper.js +349 -0
- package/dist/cjs/ProcessReaper.js.map +7 -0
- package/dist/cjs/ProcessSandbox.d.ts +377 -0
- package/dist/cjs/ProcessSandbox.d.ts.map +1 -0
- package/dist/cjs/ProcessSandbox.js +759 -0
- package/dist/cjs/ProcessSandbox.js.map +7 -0
- package/dist/cjs/ScopedProcess.d.ts +65 -0
- package/dist/cjs/ScopedProcess.d.ts.map +1 -0
- package/dist/cjs/ScopedProcess.js +87 -0
- package/dist/cjs/ScopedProcess.js.map +7 -0
- package/dist/cjs/index.d.ts +38 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/AtomicFileSystemExecutable.d.ts +61 -0
- package/dist/cjs/internal/AtomicFileSystemExecutable.d.ts.map +1 -0
- package/dist/cjs/internal/AtomicFileSystemExecutable.js +250 -0
- package/dist/cjs/internal/AtomicFileSystemExecutable.js.map +7 -0
- package/dist/cjs/internal/AtomicFileSystemProtocol.d.ts +78 -0
- package/dist/cjs/internal/AtomicFileSystemProtocol.d.ts.map +1 -0
- package/dist/cjs/internal/AtomicFileSystemProtocol.js +382 -0
- package/dist/cjs/internal/AtomicFileSystemProtocol.js.map +7 -0
- package/dist/cjs/internal/AtomicFileSystemTransport.d.ts +44 -0
- package/dist/cjs/internal/AtomicFileSystemTransport.d.ts.map +1 -0
- package/dist/cjs/internal/AtomicFileSystemTransport.js +197 -0
- package/dist/cjs/internal/AtomicFileSystemTransport.js.map +7 -0
- package/dist/cjs/internal/AtomicHelperError.d.ts +35 -0
- package/dist/cjs/internal/AtomicHelperError.d.ts.map +1 -0
- package/dist/cjs/internal/AtomicHelperError.js +45 -0
- package/dist/cjs/internal/AtomicHelperError.js.map +7 -0
- package/dist/cjs/internal/AtomicHelperFault.d.ts +59 -0
- package/dist/cjs/internal/AtomicHelperFault.d.ts.map +1 -0
- package/dist/cjs/internal/AtomicHelperFault.js +66 -0
- package/dist/cjs/internal/AtomicHelperFault.js.map +7 -0
- package/dist/cjs/internal/PipedProcess.d.ts +35 -0
- package/dist/cjs/internal/PipedProcess.d.ts.map +1 -0
- package/dist/cjs/internal/PipedProcess.js +309 -0
- package/dist/cjs/internal/PipedProcess.js.map +7 -0
- package/dist/cjs/internal/ProcSnapshot.d.ts +85 -0
- package/dist/cjs/internal/ProcSnapshot.d.ts.map +1 -0
- package/dist/cjs/internal/ProcSnapshot.js +123 -0
- package/dist/cjs/internal/ProcSnapshot.js.map +7 -0
- package/dist/cjs/internal/ProcessCleanup.d.ts +64 -0
- package/dist/cjs/internal/ProcessCleanup.d.ts.map +1 -0
- package/dist/cjs/internal/ProcessCleanup.js +62 -0
- package/dist/cjs/internal/ProcessCleanup.js.map +7 -0
- package/dist/cjs/internal/ProcessCleanupPolicyError.d.ts +30 -0
- package/dist/cjs/internal/ProcessCleanupPolicyError.d.ts.map +1 -0
- package/dist/cjs/internal/ProcessCleanupPolicyError.js +33 -0
- package/dist/cjs/internal/ProcessCleanupPolicyError.js.map +7 -0
- package/dist/cjs/internal/ProcessFault.d.ts +63 -0
- package/dist/cjs/internal/ProcessFault.d.ts.map +1 -0
- package/dist/cjs/internal/ProcessFault.js +63 -0
- package/dist/cjs/internal/ProcessFault.js.map +7 -0
- package/dist/cjs/internal/ProcessSupervisor.d.ts +141 -0
- package/dist/cjs/internal/ProcessSupervisor.d.ts.map +1 -0
- package/dist/cjs/internal/ProcessSupervisor.js +682 -0
- package/dist/cjs/internal/ProcessSupervisor.js.map +7 -0
- package/dist/cjs/internal/SupervisorProgram.d.ts +9 -0
- package/dist/cjs/internal/SupervisorProgram.d.ts.map +1 -0
- package/dist/cjs/internal/SupervisorProgram.js +306 -0
- package/dist/cjs/internal/SupervisorProgram.js.map +7 -0
- package/dist/cjs/internal/WindowsProcessJob.d.ts +39 -0
- package/dist/cjs/internal/WindowsProcessJob.d.ts.map +1 -0
- package/dist/cjs/internal/WindowsProcessJob.js +113 -0
- package/dist/cjs/internal/WindowsProcessJob.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/AtomicFileSystem.d.ts +147 -0
- package/dist/esm/AtomicFileSystem.d.ts.map +1 -0
- package/dist/esm/AtomicFileSystem.js +290 -0
- package/dist/esm/AtomicFileSystem.js.map +1 -0
- package/dist/esm/EgressHttpClient.d.ts +106 -0
- package/dist/esm/EgressHttpClient.d.ts.map +1 -0
- package/dist/esm/EgressHttpClient.js +259 -0
- package/dist/esm/EgressHttpClient.js.map +1 -0
- package/dist/esm/HostLiveness.d.ts +81 -0
- package/dist/esm/HostLiveness.d.ts.map +1 -0
- package/dist/esm/HostLiveness.js +68 -0
- package/dist/esm/HostLiveness.js.map +1 -0
- package/dist/esm/NodeHost.d.ts +145 -0
- package/dist/esm/NodeHost.d.ts.map +1 -0
- package/dist/esm/NodeHost.js +162 -0
- package/dist/esm/NodeHost.js.map +1 -0
- package/dist/esm/ProcessConfinement.d.ts +61 -0
- package/dist/esm/ProcessConfinement.d.ts.map +1 -0
- package/dist/esm/ProcessConfinement.js +311 -0
- package/dist/esm/ProcessConfinement.js.map +1 -0
- package/dist/esm/ProcessReaper.d.ts +457 -0
- package/dist/esm/ProcessReaper.d.ts.map +1 -0
- package/dist/esm/ProcessReaper.js +711 -0
- package/dist/esm/ProcessReaper.js.map +1 -0
- package/dist/esm/ProcessSandbox.d.ts +377 -0
- package/dist/esm/ProcessSandbox.d.ts.map +1 -0
- package/dist/esm/ProcessSandbox.js +1014 -0
- package/dist/esm/ProcessSandbox.js.map +1 -0
- package/dist/esm/ScopedProcess.d.ts +65 -0
- package/dist/esm/ScopedProcess.d.ts.map +1 -0
- package/dist/esm/ScopedProcess.js +66 -0
- package/dist/esm/ScopedProcess.js.map +1 -0
- package/dist/esm/index.d.ts +38 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +38 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/AtomicFileSystemExecutable.d.ts +61 -0
- package/dist/esm/internal/AtomicFileSystemExecutable.d.ts.map +1 -0
- package/dist/esm/internal/AtomicFileSystemExecutable.js +350 -0
- package/dist/esm/internal/AtomicFileSystemExecutable.js.map +1 -0
- package/dist/esm/internal/AtomicFileSystemProtocol.d.ts +78 -0
- package/dist/esm/internal/AtomicFileSystemProtocol.d.ts.map +1 -0
- package/dist/esm/internal/AtomicFileSystemProtocol.js +412 -0
- package/dist/esm/internal/AtomicFileSystemProtocol.js.map +1 -0
- package/dist/esm/internal/AtomicFileSystemTransport.d.ts +44 -0
- package/dist/esm/internal/AtomicFileSystemTransport.d.ts.map +1 -0
- package/dist/esm/internal/AtomicFileSystemTransport.js +242 -0
- package/dist/esm/internal/AtomicFileSystemTransport.js.map +1 -0
- package/dist/esm/internal/AtomicHelperError.d.ts +35 -0
- package/dist/esm/internal/AtomicHelperError.d.ts.map +1 -0
- package/dist/esm/internal/AtomicHelperError.js +39 -0
- package/dist/esm/internal/AtomicHelperError.js.map +1 -0
- package/dist/esm/internal/AtomicHelperFault.d.ts +59 -0
- package/dist/esm/internal/AtomicHelperFault.d.ts.map +1 -0
- package/dist/esm/internal/AtomicHelperFault.js +66 -0
- package/dist/esm/internal/AtomicHelperFault.js.map +1 -0
- package/dist/esm/internal/PipedProcess.d.ts +35 -0
- package/dist/esm/internal/PipedProcess.d.ts.map +1 -0
- package/dist/esm/internal/PipedProcess.js +321 -0
- package/dist/esm/internal/PipedProcess.js.map +1 -0
- package/dist/esm/internal/ProcSnapshot.d.ts +85 -0
- package/dist/esm/internal/ProcSnapshot.d.ts.map +1 -0
- package/dist/esm/internal/ProcSnapshot.js +188 -0
- package/dist/esm/internal/ProcSnapshot.js.map +1 -0
- package/dist/esm/internal/ProcessCleanup.d.ts +64 -0
- package/dist/esm/internal/ProcessCleanup.d.ts.map +1 -0
- package/dist/esm/internal/ProcessCleanup.js +45 -0
- package/dist/esm/internal/ProcessCleanup.js.map +1 -0
- package/dist/esm/internal/ProcessCleanupPolicyError.d.ts +30 -0
- package/dist/esm/internal/ProcessCleanupPolicyError.d.ts.map +1 -0
- package/dist/esm/internal/ProcessCleanupPolicyError.js +25 -0
- package/dist/esm/internal/ProcessCleanupPolicyError.js.map +1 -0
- package/dist/esm/internal/ProcessFault.d.ts +63 -0
- package/dist/esm/internal/ProcessFault.d.ts.map +1 -0
- package/dist/esm/internal/ProcessFault.js +64 -0
- package/dist/esm/internal/ProcessFault.js.map +1 -0
- package/dist/esm/internal/ProcessSupervisor.d.ts +141 -0
- package/dist/esm/internal/ProcessSupervisor.d.ts.map +1 -0
- package/dist/esm/internal/ProcessSupervisor.js +682 -0
- package/dist/esm/internal/ProcessSupervisor.js.map +1 -0
- package/dist/esm/internal/SupervisorProgram.d.ts +9 -0
- package/dist/esm/internal/SupervisorProgram.d.ts.map +1 -0
- package/dist/esm/internal/SupervisorProgram.js +290 -0
- package/dist/esm/internal/SupervisorProgram.js.map +1 -0
- package/dist/esm/internal/WindowsProcessJob.d.ts +39 -0
- package/dist/esm/internal/WindowsProcessJob.d.ts.map +1 -0
- package/dist/esm/internal/WindowsProcessJob.js +115 -0
- package/dist/esm/internal/WindowsProcessJob.js.map +1 -0
- package/dist/vendor/adapters.json +1757 -0
- package/dist/vendor/chunk-2Y7WC4KU.js +109 -0
- package/dist/vendor/chunk-3GR5VZ2M.js +118 -0
- package/dist/vendor/chunk-42QKY6T6.js +40 -0
- package/dist/vendor/chunk-54RLBMTZ.js +61 -0
- package/dist/vendor/chunk-5ZMHBXIK.js +55 -0
- package/dist/vendor/chunk-6ME2W7TF.js +28 -0
- package/dist/vendor/chunk-AMQKOQNT.js +34 -0
- package/dist/vendor/chunk-B3FZ67QU.js +59 -0
- package/dist/vendor/chunk-BKTBUBQY.js +437 -0
- package/dist/vendor/chunk-DS7GF46S.js +34 -0
- package/dist/vendor/chunk-DVOAHXPG.js +104 -0
- package/dist/vendor/chunk-DWSHTSVX.js +229 -0
- package/dist/vendor/chunk-EGBNVEEW.js +14 -0
- package/dist/vendor/chunk-EZWY45HP.js +18 -0
- package/dist/vendor/chunk-FNZOJHSV.js +71 -0
- package/dist/vendor/chunk-GXCHI7BM.js +131 -0
- package/dist/vendor/chunk-IIJ52ZU6.js +20 -0
- package/dist/vendor/chunk-J7A4CZDO.js +92 -0
- package/dist/vendor/chunk-JG5TTWPT.js +85 -0
- package/dist/vendor/chunk-JJ24ARBQ.js +394 -0
- package/dist/vendor/chunk-KOZMM5PZ.js +426 -0
- package/dist/vendor/chunk-KUUXSID7.js +18 -0
- package/dist/vendor/chunk-LEUPYT3Q.js +36 -0
- package/dist/vendor/chunk-M32LDTW7.js +18 -0
- package/dist/vendor/chunk-M7CLUILA.js +0 -0
- package/dist/vendor/chunk-MBSKBQ5D.js +21 -0
- package/dist/vendor/chunk-MLKGABMK.js +9 -0
- package/dist/vendor/chunk-NBVRTDTV.js +129 -0
- package/dist/vendor/chunk-OXNGN5H7.js +81 -0
- package/dist/vendor/chunk-QPLDT6A6.js +564 -0
- package/dist/vendor/chunk-QYBKAIA6.js +18 -0
- package/dist/vendor/chunk-RO2R4MJH.js +62 -0
- package/dist/vendor/chunk-SIR62W3Y.js +398 -0
- package/dist/vendor/chunk-TFIKFFSC.js +26 -0
- package/dist/vendor/chunk-TXKLEBBL.js +143 -0
- package/dist/vendor/chunk-UFH5UUZK.js +48 -0
- package/dist/vendor/chunk-VANKHF46.js +96 -0
- package/dist/vendor/chunk-VZBDV3TV.js +18 -0
- package/dist/vendor/chunk-XDKNKFBW.js +22 -0
- package/dist/vendor/chunk-XH4U3JSV.js +249 -0
- package/dist/vendor/chunk-Y35ZAO5U.js +53 -0
- package/dist/vendor/chunk-ZJMRMY57.js +0 -0
- package/dist/vendor/cjs/node/NodeChildProcessSpawner.d.ts +7 -0
- package/dist/vendor/cjs/node/NodeChildProcessSpawner.js +1 -0
- package/dist/vendor/cjs/node/NodeClusterHttp.d.ts +63 -0
- package/dist/vendor/cjs/node/NodeClusterHttp.js +1 -0
- package/dist/vendor/cjs/node/NodeClusterSocket.d.ts +79 -0
- package/dist/vendor/cjs/node/NodeClusterSocket.js +1 -0
- package/dist/vendor/cjs/node/NodeCrypto.d.ts +10 -0
- package/dist/vendor/cjs/node/NodeCrypto.js +1 -0
- package/dist/vendor/cjs/node/NodeFileSystem.d.ts +10 -0
- package/dist/vendor/cjs/node/NodeFileSystem.js +1 -0
- package/dist/vendor/cjs/node/NodeHttpClient.d.ts +179 -0
- package/dist/vendor/cjs/node/NodeHttpClient.js +1 -0
- package/dist/vendor/cjs/node/NodeHttpIncomingMessage.d.ts +62 -0
- package/dist/vendor/cjs/node/NodeHttpIncomingMessage.js +1 -0
- package/dist/vendor/cjs/node/NodeHttpPlatform.d.ts +36 -0
- package/dist/vendor/cjs/node/NodeHttpPlatform.js +1 -0
- package/dist/vendor/cjs/node/NodeHttpServer.d.ts +120 -0
- package/dist/vendor/cjs/node/NodeHttpServer.js +1 -0
- package/dist/vendor/cjs/node/NodeHttpServerRequest.d.ts +29 -0
- package/dist/vendor/cjs/node/NodeHttpServerRequest.js +1 -0
- package/dist/vendor/cjs/node/NodeMultipart.d.ts +46 -0
- package/dist/vendor/cjs/node/NodeMultipart.js +1 -0
- package/dist/vendor/cjs/node/NodeMultipartParser.d.ts +97 -0
- package/dist/vendor/cjs/node/NodeMultipartParser.js +1 -0
- package/dist/vendor/cjs/node/NodePath.d.ts +27 -0
- package/dist/vendor/cjs/node/NodePath.js +1 -0
- package/dist/vendor/cjs/node/NodeRedis.d.ts +74 -0
- package/dist/vendor/cjs/node/NodeRedis.js +1 -0
- package/dist/vendor/cjs/node/NodeRuntime.d.ts +85 -0
- package/dist/vendor/cjs/node/NodeRuntime.js +1 -0
- package/dist/vendor/cjs/node/NodeServices.d.ts +34 -0
- package/dist/vendor/cjs/node/NodeServices.js +1 -0
- package/dist/vendor/cjs/node/NodeSink.d.ts +8 -0
- package/dist/vendor/cjs/node/NodeSink.js +1 -0
- package/dist/vendor/cjs/node/NodeSocket.d.ts +38 -0
- package/dist/vendor/cjs/node/NodeSocket.js +1 -0
- package/dist/vendor/cjs/node/NodeSocketServer.d.ts +8 -0
- package/dist/vendor/cjs/node/NodeSocketServer.js +1 -0
- package/dist/vendor/cjs/node/NodeStdio.d.ts +11 -0
- package/dist/vendor/cjs/node/NodeStdio.js +1 -0
- package/dist/vendor/cjs/node/NodeStream.d.ts +8 -0
- package/dist/vendor/cjs/node/NodeStream.js +1 -0
- package/dist/vendor/cjs/node/NodeTerminal.d.ts +21 -0
- package/dist/vendor/cjs/node/NodeTerminal.js +1 -0
- package/dist/vendor/cjs/node/NodeWorker.d.ts +22 -0
- package/dist/vendor/cjs/node/NodeWorker.js +1 -0
- package/dist/vendor/cjs/node/NodeWorkerRunner.d.ts +12 -0
- package/dist/vendor/cjs/node/NodeWorkerRunner.js +1 -0
- package/dist/vendor/cjs/node/Undici.d.ts +28 -0
- package/dist/vendor/cjs/node/Undici.js +1 -0
- package/dist/vendor/cjs/node/index.d.ts +100 -0
- package/dist/vendor/cjs/node/index.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeChildProcessSpawner.d.ts +57 -0
- package/dist/vendor/cjs/node-shared/NodeChildProcessSpawner.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeClusterSocket.d.ts +22 -0
- package/dist/vendor/cjs/node-shared/NodeClusterSocket.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeCrypto.d.ts +27 -0
- package/dist/vendor/cjs/node-shared/NodeCrypto.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeFileSystem.d.ts +11 -0
- package/dist/vendor/cjs/node-shared/NodeFileSystem.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeHttpCompression.d.ts +36 -0
- package/dist/vendor/cjs/node-shared/NodeHttpCompression.js +1 -0
- package/dist/vendor/cjs/node-shared/NodePath.d.ts +27 -0
- package/dist/vendor/cjs/node-shared/NodePath.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeRuntime.d.ts +47 -0
- package/dist/vendor/cjs/node-shared/NodeRuntime.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeSink.d.ts +69 -0
- package/dist/vendor/cjs/node-shared/NodeSink.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeSocket.d.ts +134 -0
- package/dist/vendor/cjs/node-shared/NodeSocket.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeSocketServer.d.ts +80 -0
- package/dist/vendor/cjs/node-shared/NodeSocketServer.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeStdio.d.ts +12 -0
- package/dist/vendor/cjs/node-shared/NodeStdio.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeStream.d.ts +179 -0
- package/dist/vendor/cjs/node-shared/NodeStream.js +1 -0
- package/dist/vendor/cjs/node-shared/NodeTerminal.d.ts +22 -0
- package/dist/vendor/cjs/node-shared/NodeTerminal.js +1 -0
- package/dist/vendor/cjs/node-shared/index.d.ts +56 -0
- package/dist/vendor/cjs/node-shared/index.js +1 -0
- package/dist/vendor/cjs/node-shared/internal/nodeChildProcessSpawner.d.ts +4 -0
- package/dist/vendor/cjs/node-shared/internal/nodeChildProcessSpawner.js +1 -0
- package/dist/vendor/cjs/node-shared/internal/utils.d.ts +2 -0
- package/dist/vendor/cjs/node-shared/internal/utils.js +1 -0
- package/dist/vendor/cjs/package.json +1 -0
- package/dist/vendor/cjs/platform-node-shared.d.ts +56 -0
- package/dist/vendor/cjs/platform-node-shared.js +1 -0
- package/dist/vendor/cjs/platform-node.d.ts +100 -0
- package/dist/vendor/cjs/platform-node.js +1 -0
- package/dist/vendor/node/LICENSE +21 -0
- package/dist/vendor/node/NodeChildProcessSpawner.d.ts +7 -0
- package/dist/vendor/node/NodeChildProcessSpawner.js +14 -0
- package/dist/vendor/node/NodeClusterHttp.d.ts +63 -0
- package/dist/vendor/node/NodeClusterHttp.js +43 -0
- package/dist/vendor/node/NodeClusterSocket.d.ts +79 -0
- package/dist/vendor/node/NodeClusterSocket.js +30 -0
- package/dist/vendor/node/NodeCrypto.d.ts +10 -0
- package/dist/vendor/node/NodeCrypto.js +8 -0
- package/dist/vendor/node/NodeFileSystem.d.ts +10 -0
- package/dist/vendor/node/NodeFileSystem.js +9 -0
- package/dist/vendor/node/NodeHttpClient.d.ts +179 -0
- package/dist/vendor/node/NodeHttpClient.js +46 -0
- package/dist/vendor/node/NodeHttpIncomingMessage.d.ts +62 -0
- package/dist/vendor/node/NodeHttpIncomingMessage.js +10 -0
- package/dist/vendor/node/NodeHttpPlatform.d.ts +36 -0
- package/dist/vendor/node/NodeHttpPlatform.js +16 -0
- package/dist/vendor/node/NodeHttpServer.d.ts +120 -0
- package/dist/vendor/node/NodeHttpServer.js +46 -0
- package/dist/vendor/node/NodeHttpServerRequest.d.ts +29 -0
- package/dist/vendor/node/NodeHttpServerRequest.js +9 -0
- package/dist/vendor/node/NodeMultipart.d.ts +46 -0
- package/dist/vendor/node/NodeMultipart.js +15 -0
- package/dist/vendor/node/NodeMultipartParser.d.ts +97 -0
- package/dist/vendor/node/NodeMultipartParser.js +11 -0
- package/dist/vendor/node/NodePath.d.ts +27 -0
- package/dist/vendor/node/NodePath.js +12 -0
- package/dist/vendor/node/NodeRedis.d.ts +74 -0
- package/dist/vendor/node/NodeRedis.js +11 -0
- package/dist/vendor/node/NodeRuntime.d.ts +85 -0
- package/dist/vendor/node/NodeRuntime.js +8 -0
- package/dist/vendor/node/NodeServices.d.ts +34 -0
- package/dist/vendor/node/NodeServices.js +23 -0
- package/dist/vendor/node/NodeSink.d.ts +8 -0
- package/dist/vendor/node/NodeSink.js +12 -0
- package/dist/vendor/node/NodeSocket.d.ts +38 -0
- package/dist/vendor/node/NodeSocket.js +31 -0
- package/dist/vendor/node/NodeSocketServer.d.ts +8 -0
- package/dist/vendor/node/NodeSocketServer.js +21 -0
- package/dist/vendor/node/NodeStdio.d.ts +11 -0
- package/dist/vendor/node/NodeStdio.js +10 -0
- package/dist/vendor/node/NodeStream.d.ts +8 -0
- package/dist/vendor/node/NodeStream.js +27 -0
- package/dist/vendor/node/NodeTerminal.d.ts +21 -0
- package/dist/vendor/node/NodeTerminal.js +10 -0
- package/dist/vendor/node/NodeWorker.d.ts +22 -0
- package/dist/vendor/node/NodeWorker.js +9 -0
- package/dist/vendor/node/NodeWorkerRunner.d.ts +12 -0
- package/dist/vendor/node/NodeWorkerRunner.js +7 -0
- package/dist/vendor/node/Undici.d.ts +28 -0
- package/dist/vendor/node/Undici.js +9 -0
- package/dist/vendor/node/index.d.ts +100 -0
- package/dist/vendor/node/index.js +115 -0
- package/dist/vendor/node-shared/LICENSE +21 -0
- package/dist/vendor/node-shared/NodeChildProcessSpawner.d.ts +57 -0
- package/dist/vendor/node-shared/NodeChildProcessSpawner.js +13 -0
- package/dist/vendor/node-shared/NodeClusterSocket.d.ts +22 -0
- package/dist/vendor/node-shared/NodeClusterSocket.js +11 -0
- package/dist/vendor/node-shared/NodeCrypto.d.ts +27 -0
- package/dist/vendor/node-shared/NodeCrypto.js +9 -0
- package/dist/vendor/node-shared/NodeFileSystem.d.ts +11 -0
- package/dist/vendor/node-shared/NodeFileSystem.js +8 -0
- package/dist/vendor/node-shared/NodeHttpCompression.d.ts +36 -0
- package/dist/vendor/node-shared/NodeHttpCompression.js +13 -0
- package/dist/vendor/node-shared/NodePath.d.ts +27 -0
- package/dist/vendor/node-shared/NodePath.js +11 -0
- package/dist/vendor/node-shared/NodeRuntime.d.ts +47 -0
- package/dist/vendor/node-shared/NodeRuntime.js +7 -0
- package/dist/vendor/node-shared/NodeSink.d.ts +69 -0
- package/dist/vendor/node-shared/NodeSink.js +11 -0
- package/dist/vendor/node-shared/NodeSocket.d.ts +134 -0
- package/dist/vendor/node-shared/NodeSocket.js +23 -0
- package/dist/vendor/node-shared/NodeSocketServer.d.ts +80 -0
- package/dist/vendor/node-shared/NodeSocketServer.js +20 -0
- package/dist/vendor/node-shared/NodeStdio.d.ts +12 -0
- package/dist/vendor/node-shared/NodeStdio.js +9 -0
- package/dist/vendor/node-shared/NodeStream.d.ts +179 -0
- package/dist/vendor/node-shared/NodeStream.js +26 -0
- package/dist/vendor/node-shared/NodeTerminal.d.ts +22 -0
- package/dist/vendor/node-shared/NodeTerminal.js +9 -0
- package/dist/vendor/node-shared/index.d.ts +56 -0
- package/dist/vendor/node-shared/index.js +58 -0
- package/dist/vendor/node-shared/internal/nodeChildProcessSpawner.d.ts +4 -0
- package/dist/vendor/node-shared/internal/nodeChildProcessSpawner.js +7 -0
- package/dist/vendor/node-shared/internal/utils.d.ts +2 -0
- package/dist/vendor/node-shared/internal/utils.js +7 -0
- package/dist/vendor/platform-node-shared.d.ts +56 -0
- package/dist/vendor/platform-node-shared.js +58 -0
- package/dist/vendor/platform-node.d.ts +100 -0
- package/dist/vendor/platform-node.js +115 -0
- package/docs/README.md +129 -0
- package/docs/api.md +552 -0
- package/docs/concepts/descriptor-relative-filesystem.md +181 -0
- package/docs/concepts/host-bundle.md +125 -0
- package/docs/concepts/process-containment.md +182 -0
- package/docs/guides/answer-run-ownership.md +87 -0
- package/docs/guides/configure-the-filesystem-helper.md +152 -0
- package/docs/guides/contain-child-processes.md +139 -0
- package/docs/guides/match-files-with-glob.md +151 -0
- package/docs/installation.md +204 -0
- package/docs/quickstart.md +147 -0
- package/docs/troubleshooting.md +130 -0
- package/package.json +202 -3
- package/src/AtomicFileSystem.ts +415 -0
- package/src/EgressHttpClient.ts +327 -0
- package/src/HostLiveness.ts +103 -0
- package/src/NodeHost.ts +253 -0
- package/src/ProcessConfinement.ts +356 -0
- package/src/ProcessReaper.ts +951 -0
- package/src/ProcessSandbox.ts +1273 -0
- package/src/ScopedProcess.ts +123 -0
- package/src/index.ts +44 -0
- package/src/internal/AtomicFileSystemExecutable.ts +379 -0
- package/src/internal/AtomicFileSystemProtocol.ts +502 -0
- package/src/internal/AtomicFileSystemTransport.ts +272 -0
- package/src/internal/AtomicHelperError.ts +50 -0
- package/src/internal/AtomicHelperFault.ts +84 -0
- package/src/internal/PipedProcess.ts +357 -0
- package/src/internal/ProcSnapshot.ts +193 -0
- package/src/internal/ProcessCleanup.ts +99 -0
- package/src/internal/ProcessCleanupPolicyError.ts +30 -0
- package/src/internal/ProcessFault.ts +82 -0
- package/src/internal/ProcessSupervisor.ts +801 -0
- package/src/internal/SupervisorProgram.ts +289 -0
- package/src/internal/WindowsProcessJob.ts +114 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aggregate Node.js Host bundle.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the `NodeHost` service union and a single `layer` that
|
|
5
|
+
* provides the closed Host surface backed by Node: `@effect/platform-node`'s
|
|
6
|
+
* filesystem, child-process spawner, Undici `HttpClient`, native `Path`,
|
|
7
|
+
* and the Node `Jj` adapter from its own package. Use the layer when a Node
|
|
8
|
+
* program wants every host capability from one place; use the individual
|
|
9
|
+
* modules when a program should only be able to reach part of the host. The
|
|
10
|
+
* bundle also supplies native `ProcessConfinement` for the kernel spawner.
|
|
11
|
+
*
|
|
12
|
+
* There is no Node HTTP module either: outgoing requests are Effect's
|
|
13
|
+
* `HttpClient`, and `@effect/platform-node` already ships the Undici-backed
|
|
14
|
+
* implementation. Undici follows no redirect unless a redirect interceptor is
|
|
15
|
+
* installed, so every hop stays visible to `@smthrs/kernel`'s decorator.
|
|
16
|
+
*
|
|
17
|
+
* There is no Node shell module: running a command is Effect's
|
|
18
|
+
* `ChildProcessSpawner`, and `@effect/platform-node` already ships the
|
|
19
|
+
* implementation.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.1.0
|
|
22
|
+
*/
|
|
23
|
+
import * as NodeChildProcessSpawner from "../vendor/node/NodeChildProcessSpawner.js";
|
|
24
|
+
import * as NodeCrypto from "../vendor/node/NodeCrypto.js";
|
|
25
|
+
import * as NodeFileSystem from "../vendor/node/NodeFileSystem.js";
|
|
26
|
+
import * as NodeHttpClient from "../vendor/node/NodeHttpClient.js";
|
|
27
|
+
import * as NodePath from "../vendor/node/NodePath.js";
|
|
28
|
+
import * as NodeJj from "@smthrs/jj/node/NodeJj";
|
|
29
|
+
import * as Layer from "effect/Layer";
|
|
30
|
+
import * as Schema from "effect/Schema";
|
|
31
|
+
import { isAbsolute } from "node:path";
|
|
32
|
+
import * as AtomicFileSystem from "./AtomicFileSystem.js";
|
|
33
|
+
import * as EgressHttpClient from "./EgressHttpClient.js";
|
|
34
|
+
import * as ProcessConfinement from "./ProcessConfinement.js";
|
|
35
|
+
import * as ProcessReaper from "./ProcessReaper.js";
|
|
36
|
+
/**
|
|
37
|
+
* The Node platform modules Effect ships, re-exported so a program that wants
|
|
38
|
+
* only part of the host has one place to reach for them. `NodeJj` belongs to
|
|
39
|
+
* `@smthrs/jj`; import it from there.
|
|
40
|
+
*
|
|
41
|
+
* `NodeCrypto` is here for a different reason than the rest. `Crypto` is not a
|
|
42
|
+
* Host service — it carries no host authority the kernel could attenuate, so
|
|
43
|
+
* it is not in {@link NodeHost} and not in the closed list — but every durable
|
|
44
|
+
* composition needs one, and a program that already depends on this package
|
|
45
|
+
* for its host should not have to add a second dependency for the digest.
|
|
46
|
+
*
|
|
47
|
+
* @category re-exports
|
|
48
|
+
* @since 0.1.0
|
|
49
|
+
*/
|
|
50
|
+
export { AtomicFileSystem, EgressHttpClient, NodeChildProcessSpawner, NodeCrypto, NodeFileSystem, NodeHttpClient, ProcessReaper };
|
|
51
|
+
/**
|
|
52
|
+
* The `HttpClient` every bundle below installs: Undici through the egress
|
|
53
|
+
* proxy this process's environment names, and a direct Undici pool when it
|
|
54
|
+
* names none.
|
|
55
|
+
*
|
|
56
|
+
* `NodeHttpClient.layerUndici` is the direct pool unconditionally. It is still
|
|
57
|
+
* re-exported above for a program composing its own services, but a bundle
|
|
58
|
+
* that spans a whole host has to work inside a sandbox whose only way out is a
|
|
59
|
+
* proxy, so the bundles read the environment. See {@link EgressHttpClient}.
|
|
60
|
+
*/
|
|
61
|
+
const httpClient = EgressHttpClient.layer(process.env);
|
|
62
|
+
/**
|
|
63
|
+
* Invalid repository-root configuration, refused before layer construction.
|
|
64
|
+
* @category errors
|
|
65
|
+
* @since 1.0.0-rc.0
|
|
66
|
+
*/
|
|
67
|
+
export class NodeHostError extends Schema.TaggedError()("@smthrs/platform-node/NodeHostError", {
|
|
68
|
+
code: Schema.Literal("invalid_repository_root"),
|
|
69
|
+
message: Schema.String
|
|
70
|
+
}) {
|
|
71
|
+
name = "NodeHostError";
|
|
72
|
+
}
|
|
73
|
+
const absoluteRoot = (root) => {
|
|
74
|
+
if (isAbsolute(root))
|
|
75
|
+
return root;
|
|
76
|
+
throw new NodeHostError({
|
|
77
|
+
code: "invalid_repository_root",
|
|
78
|
+
message: `NodeHost requires an absolute repository root, got ${JSON.stringify(Array.from(root).slice(0, 64).join(""))}`
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Stable implementation identities for the raw bundle's five Host slots.
|
|
83
|
+
* Contained POSIX factories replace its spawner with {@link ProcessReaper.layerSpawner}.
|
|
84
|
+
* @category models
|
|
85
|
+
* @since 1.0.0-rc.0
|
|
86
|
+
*/
|
|
87
|
+
export const implementationIds = {
|
|
88
|
+
"effect/FileSystem": "@smthrs/platform-node/AtomicFileSystem",
|
|
89
|
+
"effect/Path": "@effect/platform-node/NodePath",
|
|
90
|
+
"effect/process/ChildProcessSpawner": "@effect/platform-node/NodeChildProcessSpawner",
|
|
91
|
+
"@smthrs/jj/Jj": "@smthrs/jj/node/NodeJj",
|
|
92
|
+
"effect/HttpClient": "@smthrs/platform-node/EgressHttpClient"
|
|
93
|
+
};
|
|
94
|
+
/** The two services `NodeChildProcessSpawner` resolves paths and files with. */
|
|
95
|
+
const platform = Layer.mergeAll(AtomicFileSystem.layer, NodePath.layer);
|
|
96
|
+
/** The reaper half of {@link ContainedOptions}. */
|
|
97
|
+
const reaping = (options) => ({
|
|
98
|
+
ownerPid: options?.ownerPid,
|
|
99
|
+
system: options?.system
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* Provides the default Node implementations for the whole closed Host surface.
|
|
103
|
+
*
|
|
104
|
+
* @category layers
|
|
105
|
+
* @since 0.1.0
|
|
106
|
+
*/
|
|
107
|
+
export const layer = Layer.mergeAll(ProcessConfinement.layer(), platform, Layer.provide(NodeChildProcessSpawner.layer, platform), httpClient, NodeJj.layer);
|
|
108
|
+
/**
|
|
109
|
+
* Provides the Node host with `Jj` bound to one absolute repository root.
|
|
110
|
+
*
|
|
111
|
+
* @category layers
|
|
112
|
+
* @since 1.0.0
|
|
113
|
+
*/
|
|
114
|
+
export const layerAt = (repositoryRoot) => Layer.mergeAll(ProcessConfinement.layer(), platform, Layer.provide(NodeChildProcessSpawner.layer, platform), httpClient, NodeJj.layerAt(absoluteRoot(repositoryRoot)));
|
|
115
|
+
/**
|
|
116
|
+
* Provides the Node host with process containment turned on.
|
|
117
|
+
*
|
|
118
|
+
* The difference from {@link layer} is what happens to a spawned process when
|
|
119
|
+
* its run stops. Under {@link layer} a child is signalled when its scope
|
|
120
|
+
* closes and then waited for, forever if it ignores `SIGTERM`, and a host that
|
|
121
|
+
* dies without closing its scopes abandons every child it started. This layer
|
|
122
|
+
* gives each child an escalation deadline and records it in the
|
|
123
|
+
* `ProcessLedger`, then sweeps the records a previous incarnation of the same
|
|
124
|
+
* host left behind before it hands the host over
|
|
125
|
+
* ({@link ProcessReaper.reap}).
|
|
126
|
+
*
|
|
127
|
+
* jj is contained here too: `layerContained` builds the `Jj` service over the
|
|
128
|
+
* same spawner rather than letting it start its own children, so a `jj`
|
|
129
|
+
* invocation a crashed host left running is a record the next incarnation
|
|
130
|
+
* reaps like any other.
|
|
131
|
+
*
|
|
132
|
+
* The ledger is a requirement rather than a default because the durable half
|
|
133
|
+
* of containment is only as good as the journal underneath it:
|
|
134
|
+
* `ProcessLedger.layer` inherits a crashed incarnation's processes,
|
|
135
|
+
* `ProcessLedger.layerMemory` contains this incarnation and nothing more, and
|
|
136
|
+
* the choice belongs to the program that knows which it has.
|
|
137
|
+
*
|
|
138
|
+
* @category layers
|
|
139
|
+
* @since 0.1.0
|
|
140
|
+
*/
|
|
141
|
+
export const layerContained = (options) => {
|
|
142
|
+
const spawner = Layer.provide(ProcessReaper.layerSpawner({ graceMs: options?.graceMs }), Layer.provide(NodeChildProcessSpawner.layer, platform));
|
|
143
|
+
return Layer.mergeAll(ProcessConfinement.layer(), platform, httpClient,
|
|
144
|
+
// jj goes through the CONTAINED spawner here, not around it. `NodeJj.layer`
|
|
145
|
+
// spawns its own children, which is right for a host that has no spawner
|
|
146
|
+
// to offer, but under containment it would mean a `jj` that leads no
|
|
147
|
+
// recorded process group, appears in no ledger, and survives the
|
|
148
|
+
// incarnation that started it.
|
|
149
|
+
Layer.provideMerge(NodeJj.layerSpawner, spawner)).pipe(Layer.provideMerge(ProcessReaper.layer(reaping(options))));
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Provides the contained Node host with `Jj` bound to one absolute repository
|
|
153
|
+
* root.
|
|
154
|
+
*
|
|
155
|
+
* @category layers
|
|
156
|
+
* @since 1.0.0
|
|
157
|
+
*/
|
|
158
|
+
export const layerContainedAt = (repositoryRoot, options) => {
|
|
159
|
+
const spawner = Layer.provide(ProcessReaper.layerSpawner({ graceMs: options?.graceMs }), Layer.provide(NodeChildProcessSpawner.layer, platform));
|
|
160
|
+
return Layer.mergeAll(ProcessConfinement.layer(), platform, httpClient, Layer.provideMerge(NodeJj.layerSpawnerAt(absoluteRoot(repositoryRoot)), spawner)).pipe(Layer.provideMerge(ProcessReaper.layer(reaping(options))));
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=NodeHost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeHost.js","sourceRoot":"","sources":["../../src/NodeHost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,uBAAuB,MAAM,+CAA+C,CAAA;AACxF,OAAO,KAAK,UAAU,MAAM,kCAAkC,CAAA;AAC9D,OAAO,KAAK,cAAc,MAAM,sCAAsC,CAAA;AACtE,OAAO,KAAK,cAAc,MAAM,sCAAsC,CAAA;AACtE,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAA;AAE1D,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAKhD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;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AA;IACD,OAAO,KAAK,CAAC,QAAQ,CACnB,kBAAkB,CAAC,KAAK,EAAE,EAC1B,QAAQ,EACR,UAAU;IACV,4EAA4E;IAC5E,yEAAyE;IACzE,qEAAqE;IACrE,iEAAiE;IACjE,+BAA+B;IAC/B,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,CACjD,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,cAAsB,EACtB,OAA0B,EACmC,EAAE;IAC/D,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAC3B,aAAa,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EACzD,KAAK,CAAC,OAAO,CAAC,uBAAuB,CAAC,KAAK,EAAE,QAAQ,CAAC,CACvD,CAAA;IACD,OAAO,KAAK,CAAC,QAAQ,CACnB,kBAAkB,CAAC,KAAK,EAAE,EAC1B,QAAQ,EACR,UAAU,EACV,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,CACjF,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC,CAAA","sourcesContent":["/**\n * Aggregate Node.js Host bundle.\n *\n * This module defines the `NodeHost` service union and a single `layer` that\n * provides the closed Host surface backed by Node: `@effect/platform-node`'s\n * filesystem, child-process spawner, Undici `HttpClient`, native `Path`,\n * and the Node `Jj` adapter from its own package. Use the layer when a Node\n * program wants every host capability from one place; use the individual\n * modules when a program should only be able to reach part of the host. The\n * bundle also supplies native `ProcessConfinement` for the kernel spawner.\n *\n * There is no Node HTTP module either: outgoing requests are Effect's\n * `HttpClient`, and `@effect/platform-node` already ships the Undici-backed\n * implementation. Undici follows no redirect unless a redirect interceptor is\n * installed, so every hop stays visible to `@smthrs/kernel`'s decorator.\n *\n * There is no Node shell module: running a command is Effect's\n * `ChildProcessSpawner`, and `@effect/platform-node` already ships the\n * implementation.\n *\n * @since 0.1.0\n */\n\nimport * as NodeChildProcessSpawner from \"@effect/platform-node/NodeChildProcessSpawner\"\nimport * as NodeCrypto from \"@effect/platform-node/NodeCrypto\"\nimport * as NodeFileSystem from \"@effect/platform-node/NodeFileSystem\"\nimport * as NodeHttpClient from \"@effect/platform-node/NodeHttpClient\"\nimport * as NodePath from \"@effect/platform-node/NodePath\"\nimport type { Jj, JjError } from \"@smthrs/jj\"\nimport * as NodeJj from \"@smthrs/jj/node/NodeJj\"\nimport type { HostServiceIds } from \"@smthrs/kernel/HostServices\"\nimport type * as KernelProcessConfinement from \"@smthrs/kernel/ProcessConfinement\"\nimport type * as ProcessLedger from \"@smthrs/kernel/ProcessLedger\"\nimport type { FileSystem } from \"effect/FileSystem\"\nimport * as Layer from \"effect/Layer\"\nimport type * as Path from \"effect/Path\"\nimport * as Schema from \"effect/Schema\"\nimport type { HttpClient } from \"effect/unstable/http/HttpClient\"\nimport type { ChildProcessSpawner } from \"effect/unstable/process/ChildProcessSpawner\"\nimport { isAbsolute } from \"node:path\"\nimport * as AtomicFileSystem from \"./AtomicFileSystem.ts\"\nimport * as EgressHttpClient from \"./EgressHttpClient.ts\"\nimport * as ProcessConfinement from \"./ProcessConfinement.ts\"\nimport * as ProcessReaper from \"./ProcessReaper.ts\"\n\n/**\n * The Node platform modules Effect ships, re-exported so a program that wants\n * only part of the host has one place to reach for them. `NodeJj` belongs to\n * `@smthrs/jj`; import it from there.\n *\n * `NodeCrypto` is here for a different reason than the rest. `Crypto` is not a\n * Host service — it carries no host authority the kernel could attenuate, so\n * it is not in {@link NodeHost} and not in the closed list — but every durable\n * composition needs one, and a program that already depends on this package\n * for its host should not have to add a second dependency for the digest.\n *\n * @category re-exports\n * @since 0.1.0\n */\nexport {\n AtomicFileSystem,\n EgressHttpClient,\n NodeChildProcessSpawner,\n NodeCrypto,\n NodeFileSystem,\n NodeHttpClient,\n ProcessReaper\n}\n\n/**\n * The `HttpClient` every bundle below installs: Undici through the egress\n * proxy this process's environment names, and a direct Undici pool when it\n * names none.\n *\n * `NodeHttpClient.layerUndici` is the direct pool unconditionally. It is still\n * re-exported above for a program composing its own services, but a bundle\n * that spans a whole host has to work inside a sandbox whose only way out is a\n * proxy, so the bundles read the environment. See {@link EgressHttpClient}.\n */\nconst httpClient = EgressHttpClient.layer(process.env)\n\n/**\n * The union of host services provided by the Node host layer.\n *\n * @category models\n * @since 0.1.0\n */\nexport type NodeHost =\n | FileSystem\n | Path.Path\n | ChildProcessSpawner\n | Jj\n | HttpClient\n | KernelProcessConfinement.ProcessConfinement\n\n/**\n * Invalid repository-root configuration, refused before layer construction.\n * @category errors\n * @since 1.0.0-rc.0\n */\nexport class NodeHostError extends Schema.TaggedError<NodeHostError>()(\"@smthrs/platform-node/NodeHostError\", {\n code: Schema.Literal(\"invalid_repository_root\"),\n message: Schema.String\n}) {\n override readonly name = \"NodeHostError\"\n}\n\nconst absoluteRoot = (root: string): string => {\n if (isAbsolute(root)) return root\n throw new NodeHostError({\n code: \"invalid_repository_root\",\n message: `NodeHost requires an absolute repository root, got ${\n JSON.stringify(Array.from(root).slice(0, 64).join(\"\"))\n }`\n })\n}\n\n/**\n * Stable implementation identities for the raw bundle's five Host slots.\n * Contained POSIX factories replace its spawner with {@link ProcessReaper.layerSpawner}.\n * @category models\n * @since 1.0.0-rc.0\n */\nexport const implementationIds: Readonly<Record<(typeof HostServiceIds)[number], string>> = {\n \"effect/FileSystem\": \"@smthrs/platform-node/AtomicFileSystem\",\n \"effect/Path\": \"@effect/platform-node/NodePath\",\n \"effect/process/ChildProcessSpawner\": \"@effect/platform-node/NodeChildProcessSpawner\",\n \"@smthrs/jj/Jj\": \"@smthrs/jj/node/NodeJj\",\n \"effect/HttpClient\": \"@smthrs/platform-node/EgressHttpClient\"\n}\n\n/** The two services `NodeChildProcessSpawner` resolves paths and files with. */\nconst platform = Layer.mergeAll(AtomicFileSystem.layer, NodePath.layer)\n\n/**\n * What a caller may configure about a contained Node host.\n *\n * `platform` is deliberately absent. `ContainedSpawner.Options` declares it so a\n * caller that supplies its own spawner can describe one, but this native host\n * detaches by `process.platform` whatever a record claims. A caller-supplied\n * `\"win32\"` on a POSIX host would therefore\n * record `pgid: null` for a child that really does lead a group, and\n * {@link ProcessReaper.reap} would retire that record as `no-group` and leave\n * the orphan running forever — a durable lie rather than a compile error.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport type ContainedOptions = ProcessReaper.SpawnerOptions & ProcessReaper.Options\n\n/** The reaper half of {@link ContainedOptions}. */\nconst reaping = (options?: ContainedOptions): ProcessReaper.Options => ({\n ownerPid: options?.ownerPid,\n system: options?.system\n})\n\n/**\n * Provides the default Node implementations for the whole closed Host surface.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer: Layer.Layer<NodeHost, JjError> = Layer.mergeAll(\n ProcessConfinement.layer(),\n platform,\n Layer.provide(NodeChildProcessSpawner.layer, platform),\n httpClient,\n NodeJj.layer\n)\n\n/**\n * Provides the Node host with `Jj` bound to one absolute repository root.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerAt = (repositoryRoot: string): Layer.Layer<NodeHost, JjError> =>\n Layer.mergeAll(\n ProcessConfinement.layer(),\n platform,\n Layer.provide(NodeChildProcessSpawner.layer, platform),\n httpClient,\n NodeJj.layerAt(absoluteRoot(repositoryRoot))\n )\n\n/**\n * Provides the Node host with process containment turned on.\n *\n * The difference from {@link layer} is what happens to a spawned process when\n * its run stops. Under {@link layer} a child is signalled when its scope\n * closes and then waited for, forever if it ignores `SIGTERM`, and a host that\n * dies without closing its scopes abandons every child it started. This layer\n * gives each child an escalation deadline and records it in the\n * `ProcessLedger`, then sweeps the records a previous incarnation of the same\n * host left behind before it hands the host over\n * ({@link ProcessReaper.reap}).\n *\n * jj is contained here too: `layerContained` builds the `Jj` service over the\n * same spawner rather than letting it start its own children, so a `jj`\n * invocation a crashed host left running is a record the next incarnation\n * reaps like any other.\n *\n * The ledger is a requirement rather than a default because the durable half\n * of containment is only as good as the journal underneath it:\n * `ProcessLedger.layer` inherits a crashed incarnation's processes,\n * `ProcessLedger.layerMemory` contains this incarnation and nothing more, and\n * the choice belongs to the program that knows which it has.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerContained = (\n options?: ContainedOptions\n): Layer.Layer<NodeHost, JjError, ProcessLedger.ProcessLedger> => {\n const spawner = Layer.provide(\n ProcessReaper.layerSpawner({ graceMs: options?.graceMs }),\n Layer.provide(NodeChildProcessSpawner.layer, platform)\n )\n return Layer.mergeAll(\n ProcessConfinement.layer(),\n platform,\n httpClient,\n // jj goes through the CONTAINED spawner here, not around it. `NodeJj.layer`\n // spawns its own children, which is right for a host that has no spawner\n // to offer, but under containment it would mean a `jj` that leads no\n // recorded process group, appears in no ledger, and survives the\n // incarnation that started it.\n Layer.provideMerge(NodeJj.layerSpawner, spawner)\n ).pipe(Layer.provideMerge(ProcessReaper.layer(reaping(options))))\n}\n\n/**\n * Provides the contained Node host with `Jj` bound to one absolute repository\n * root.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerContainedAt = (\n repositoryRoot: string,\n options?: ContainedOptions\n): Layer.Layer<NodeHost, JjError, ProcessLedger.ProcessLedger> => {\n const spawner = Layer.provide(\n ProcessReaper.layerSpawner({ graceMs: options?.graceMs }),\n Layer.provide(NodeChildProcessSpawner.layer, platform)\n )\n return Layer.mergeAll(\n ProcessConfinement.layer(),\n platform,\n httpClient,\n Layer.provideMerge(NodeJj.layerSpawnerAt(absoluteRoot(repositoryRoot)), spawner)\n ).pipe(Layer.provideMerge(ProcessReaper.layer(reaping(options))))\n}\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kernel's `ProcessConfinement` seam, filled with this host's native
|
|
3
|
+
* sandbox: bubblewrap on Linux, seatbelt on macOS.
|
|
4
|
+
*
|
|
5
|
+
* `@smthrs/kernel`'s `ChildProcessSpawner.layer` hands every stage that passed
|
|
6
|
+
* its `proc:spawn` check to the confinement in its context, together with the
|
|
7
|
+
* `ProcessConfinement.Profile` the grants in force admit. This module turns
|
|
8
|
+
* that profile into a {@link ProcessSandbox.Request}, plans it against the
|
|
9
|
+
* workspace, and wraps the stage's argv in the mechanism the host has, so an
|
|
10
|
+
* approved `bash` can write only where an `fs:write` grant says and reach the
|
|
11
|
+
* network only when a `net:*` grant says. A stage that asked for the platform
|
|
12
|
+
* shell is spelled out as `/bin/sh -c <line>` first: wrapping a `shell: true`
|
|
13
|
+
* command line would otherwise leave its redirections and pipes to a shell
|
|
14
|
+
* outside the sandbox.
|
|
15
|
+
*
|
|
16
|
+
* A host with no mechanism is the one decision this module leaves to its
|
|
17
|
+
* caller: {@link Options.unavailable} either refuses the spawn, so nothing
|
|
18
|
+
* runs that the profile would not have confined, or runs it unconfined with
|
|
19
|
+
* a warning, the way every host did before this seam existed. A write set
|
|
20
|
+
* the mechanism cannot enforce safely, a symbolic link below the workspace
|
|
21
|
+
* root, is always refused.
|
|
22
|
+
*
|
|
23
|
+
* @since 1.0.0-rc.1
|
|
24
|
+
*/
|
|
25
|
+
import * as KernelProcessConfinement from "@smthrs/kernel/ProcessConfinement";
|
|
26
|
+
import * as Layer from "effect/Layer";
|
|
27
|
+
import * as ProcessSandbox from "./ProcessSandbox.ts";
|
|
28
|
+
/**
|
|
29
|
+
* How the confinement is built.
|
|
30
|
+
*
|
|
31
|
+
* @category models
|
|
32
|
+
* @since 1.0.0-rc.1
|
|
33
|
+
*/
|
|
34
|
+
export interface Options {
|
|
35
|
+
/**
|
|
36
|
+
* What happens when this host has no mechanism to enforce a profile with.
|
|
37
|
+
* `"refuse"` fails the spawn, so a command never runs with more than the
|
|
38
|
+
* profile allows; `"unconfined"` runs it as given and logs a
|
|
39
|
+
* warning naming what the host lacks.
|
|
40
|
+
*/
|
|
41
|
+
readonly unavailable?: "refuse" | "unconfined" | undefined;
|
|
42
|
+
/** The host facts mechanism selection reads; defaults to the real host. */
|
|
43
|
+
readonly host?: ProcessSandbox.Host | undefined;
|
|
44
|
+
/** Where each run's private temporary directory is created; defaults to the OS temporary directory. */
|
|
45
|
+
readonly temporaryDirectory?: string | undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Builds the native confinement.
|
|
49
|
+
*
|
|
50
|
+
* @category constructors
|
|
51
|
+
* @since 1.0.0-rc.1
|
|
52
|
+
*/
|
|
53
|
+
export declare const make: (options?: Options) => KernelProcessConfinement.Service;
|
|
54
|
+
/**
|
|
55
|
+
* Provides the native confinement.
|
|
56
|
+
*
|
|
57
|
+
* @category layers
|
|
58
|
+
* @since 1.0.0-rc.1
|
|
59
|
+
*/
|
|
60
|
+
export declare const layer: (options?: Options) => Layer.Layer<KernelProcessConfinement.ProcessConfinement>;
|
|
61
|
+
//# sourceMappingURL=ProcessConfinement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessConfinement.d.ts","sourceRoot":"","sources":["../../src/ProcessConfinement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,wBAAwB,MAAM,mCAAmC,CAAA;AAE7E,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAOrC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAA;IAC1D,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,IAAI,GAAG,SAAS,CAAA;IAC/C,uGAAuG;IACvG,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACjD;AA0FD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,UAAS,OAAY,KAAG,wBAAwB,CAAC,OAoMrE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,UAAS,OAAY,KAAG,KAAK,CAAC,KAAK,CAAC,wBAAwB,CAAC,kBAAkB,CAC1B,CAAA"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kernel's `ProcessConfinement` seam, filled with this host's native
|
|
3
|
+
* sandbox: bubblewrap on Linux, seatbelt on macOS.
|
|
4
|
+
*
|
|
5
|
+
* `@smthrs/kernel`'s `ChildProcessSpawner.layer` hands every stage that passed
|
|
6
|
+
* its `proc:spawn` check to the confinement in its context, together with the
|
|
7
|
+
* `ProcessConfinement.Profile` the grants in force admit. This module turns
|
|
8
|
+
* that profile into a {@link ProcessSandbox.Request}, plans it against the
|
|
9
|
+
* workspace, and wraps the stage's argv in the mechanism the host has, so an
|
|
10
|
+
* approved `bash` can write only where an `fs:write` grant says and reach the
|
|
11
|
+
* network only when a `net:*` grant says. A stage that asked for the platform
|
|
12
|
+
* shell is spelled out as `/bin/sh -c <line>` first: wrapping a `shell: true`
|
|
13
|
+
* command line would otherwise leave its redirections and pipes to a shell
|
|
14
|
+
* outside the sandbox.
|
|
15
|
+
*
|
|
16
|
+
* A host with no mechanism is the one decision this module leaves to its
|
|
17
|
+
* caller: {@link Options.unavailable} either refuses the spawn, so nothing
|
|
18
|
+
* runs that the profile would not have confined, or runs it unconfined with
|
|
19
|
+
* a warning, the way every host did before this seam existed. A write set
|
|
20
|
+
* the mechanism cannot enforce safely, a symbolic link below the workspace
|
|
21
|
+
* root, is always refused.
|
|
22
|
+
*
|
|
23
|
+
* @since 1.0.0-rc.1
|
|
24
|
+
*/
|
|
25
|
+
import * as KernelProcessConfinement from "@smthrs/kernel/ProcessConfinement";
|
|
26
|
+
import * as Effect from "effect/Effect";
|
|
27
|
+
import * as Layer from "effect/Layer";
|
|
28
|
+
import * as PlatformError from "effect/PlatformError";
|
|
29
|
+
import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
30
|
+
import * as NodeFs from "node:fs";
|
|
31
|
+
import * as NodeOs from "node:os";
|
|
32
|
+
import * as NodePath from "node:path";
|
|
33
|
+
import * as ProcessSandbox from "./ProcessSandbox.js";
|
|
34
|
+
const shellLine = (command) => [command.command, ...command.args].join(" ");
|
|
35
|
+
/**
|
|
36
|
+
* The argv a stage executes, with a shell request made explicit.
|
|
37
|
+
*
|
|
38
|
+
* Node runs a `shell: true` stage as `/bin/sh -c <line>` on POSIX, and a
|
|
39
|
+
* string shell as `<shell> -c <line>`; the wrapper needs that program to be
|
|
40
|
+
* the one it confines, so the shell becomes the argv's first token and the
|
|
41
|
+
* spawned stage no longer asks for one.
|
|
42
|
+
*/
|
|
43
|
+
const argvOf = (command) => {
|
|
44
|
+
const shell = command.options.shell;
|
|
45
|
+
if (shell === undefined || shell === false)
|
|
46
|
+
return [command.command, ...command.args];
|
|
47
|
+
return [shell === true ? "/bin/sh" : shell, "-c", shellLine(command)];
|
|
48
|
+
};
|
|
49
|
+
const failure = (tag, command, description, cause) => PlatformError.systemError({
|
|
50
|
+
_tag: tag,
|
|
51
|
+
module: "ProcessConfinement",
|
|
52
|
+
method: "confine",
|
|
53
|
+
pathOrDescriptor: shellLine(command),
|
|
54
|
+
description,
|
|
55
|
+
cause
|
|
56
|
+
});
|
|
57
|
+
const messageOf = (cause) => ProcessSandbox.isUnenforceable(cause)
|
|
58
|
+
? cause.message
|
|
59
|
+
: cause instanceof Error
|
|
60
|
+
? cause.message
|
|
61
|
+
: String(cause);
|
|
62
|
+
/** Classic BPF for seccomp_data: deny host Unix sockets and io_uring, preserving stream socketpair.
|
|
63
|
+
* Closed networking additionally denies every IP socket family.
|
|
64
|
+
* Wrong ABI and x32 syscall encodings fail closed rather than bypassing socket(). */
|
|
65
|
+
const networkFilter = (architecture, network) => {
|
|
66
|
+
const abi = architecture === "x64"
|
|
67
|
+
? { audit: 0xc000003e, socket: 41, socketpair: 53 }
|
|
68
|
+
: architecture === "arm64"
|
|
69
|
+
? { audit: 0xc00000b7, socket: 198, socketpair: 199 }
|
|
70
|
+
: undefined;
|
|
71
|
+
if (abi === undefined)
|
|
72
|
+
throw new Error(`native-network seccomp is unavailable on ${architecture}`);
|
|
73
|
+
const instructions = [
|
|
74
|
+
[0x20, 0, 0, 4], // load audit architecture
|
|
75
|
+
[0x15, 1, 0, abi.audit],
|
|
76
|
+
[0x06, 0, 0, 0x80000000], // kill unsupported ABI
|
|
77
|
+
[0x20, 0, 0, 0], // load syscall number
|
|
78
|
+
[0x35, 0, 1, 0x40000000],
|
|
79
|
+
[0x06, 0, 0, 0x80000000], // kill x32 / invalid high syscall numbers
|
|
80
|
+
[0x15, 0, 1, 425], // io_uring_setup on both supported ABIs
|
|
81
|
+
[0x06, 0, 0, 0x00050001], // io_uring can otherwise create sockets without socket()
|
|
82
|
+
[0x15, 0, 6, abi.socketpair],
|
|
83
|
+
[0x20, 0, 0, 16], // socketpair domain
|
|
84
|
+
[0x15, 0, 4, 1], // AF_UNIX
|
|
85
|
+
[0x20, 0, 0, 24], // socketpair type, low 32 bits of args[1]
|
|
86
|
+
[0x54, 0, 0, 0xf], // strip SOCK_NONBLOCK and SOCK_CLOEXEC
|
|
87
|
+
[0x15, 1, 0, 1], // only SOCK_STREAM; Linux aliases SOCK_RAW to datagram operations
|
|
88
|
+
[0x06, 0, 0, 0x00050001],
|
|
89
|
+
[0x20, 0, 0, 0] // reload syscall number before the socket() policy
|
|
90
|
+
];
|
|
91
|
+
if (network === "none") {
|
|
92
|
+
instructions.push([0x15, 0, 1, abi.socket], [0x06, 0, 0, 0x00050001]); // EPERM for every socket family
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
instructions.push([0x15, 0, 3, abi.socket], [0x20, 0, 0, 16], // socket domain, low 32 bits of args[0]
|
|
96
|
+
[0x15, 0, 1, 1], // AF_UNIX; IP families remain available
|
|
97
|
+
[0x06, 0, 0, 0x00050001]);
|
|
98
|
+
}
|
|
99
|
+
instructions.push([0x06, 0, 0, 0x7fff0000]); // SECCOMP_RET_ALLOW
|
|
100
|
+
const bytes = new Uint8Array(instructions.length * 8);
|
|
101
|
+
const view = new DataView(bytes.buffer);
|
|
102
|
+
for (const [index, [code, jt, jf, value]] of instructions.entries()) {
|
|
103
|
+
view.setUint16(index * 8, code, true);
|
|
104
|
+
view.setUint8(index * 8 + 2, jt);
|
|
105
|
+
view.setUint8(index * 8 + 3, jf);
|
|
106
|
+
view.setUint32(index * 8 + 4, value, true);
|
|
107
|
+
}
|
|
108
|
+
return bytes;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Builds the native confinement.
|
|
112
|
+
*
|
|
113
|
+
* @category constructors
|
|
114
|
+
* @since 1.0.0-rc.1
|
|
115
|
+
*/
|
|
116
|
+
export const make = (options = {}) => {
|
|
117
|
+
const hostFacts = options.host ?? ProcessSandbox.host();
|
|
118
|
+
const temporaryRoot = options.temporaryDirectory ?? NodeOs.tmpdir();
|
|
119
|
+
const unavailable = options.unavailable ?? "refuse";
|
|
120
|
+
const confine = Effect.fn("ProcessConfinement.confine")(function* (command, profile) {
|
|
121
|
+
const request = {
|
|
122
|
+
network: profile.network,
|
|
123
|
+
unixSockets: false,
|
|
124
|
+
strict: true,
|
|
125
|
+
reads: profile.reads,
|
|
126
|
+
writes: profile.writes,
|
|
127
|
+
readOnly: profile.readOnly
|
|
128
|
+
};
|
|
129
|
+
const selected = ProcessSandbox.select(request, hostFacts);
|
|
130
|
+
if (ProcessSandbox.isUnenforceable(selected)) {
|
|
131
|
+
if (unavailable === "refuse") {
|
|
132
|
+
return yield* failure("NotFound", command, `${selected.message} This host refuses to spawn unconfined.`, selected);
|
|
133
|
+
}
|
|
134
|
+
yield* Effect.logWarning(`${selected.message} Running unconfined.`);
|
|
135
|
+
return command;
|
|
136
|
+
}
|
|
137
|
+
// The stage's directory is absolute: the kernel spawner roots it first.
|
|
138
|
+
const cwd = command.options.cwd ?? profile.workspaceRoot;
|
|
139
|
+
const within = (root, path) => {
|
|
140
|
+
const relative = NodePath.relative(root, path);
|
|
141
|
+
return relative !== ".." && !relative.startsWith(`..${NodePath.sep}`) && !NodePath.isAbsolute(relative);
|
|
142
|
+
};
|
|
143
|
+
if (!within(profile.workspaceRoot, cwd)) {
|
|
144
|
+
return yield* failure("PermissionDenied", command, "command directory is outside the workspace", undefined);
|
|
145
|
+
}
|
|
146
|
+
// A lexical workspace path can enter an unrelated host directory through
|
|
147
|
+
// a symlink. Check the real directory before granting or preparing a run.
|
|
148
|
+
const canonical = yield* Effect.try({
|
|
149
|
+
try: () => {
|
|
150
|
+
const root = NodeFs.realpathSync(profile.workspaceRoot);
|
|
151
|
+
const directory = NodeFs.realpathSync(cwd);
|
|
152
|
+
if (!within(root, directory))
|
|
153
|
+
throw new Error("command directory is outside the workspace");
|
|
154
|
+
for (const relative of profile.reads) {
|
|
155
|
+
const lexical = NodePath.resolve(root, relative);
|
|
156
|
+
if (!within(root, lexical))
|
|
157
|
+
continue;
|
|
158
|
+
// A read bind follows its source symlink. Refuse a grant that would
|
|
159
|
+
// therefore mount unrelated host bytes inside the workspace.
|
|
160
|
+
if (NodeFs.existsSync(lexical)) {
|
|
161
|
+
const real = NodeFs.realpathSync(lexical);
|
|
162
|
+
if (!within(root, real))
|
|
163
|
+
throw new Error("read grant resolves outside the workspace");
|
|
164
|
+
if (real !== lexical)
|
|
165
|
+
throw new Error("read grant is a symbolic link");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return { root, cwd: directory };
|
|
169
|
+
},
|
|
170
|
+
catch: (cause) => failure("PermissionDenied", command, messageOf(cause), cause)
|
|
171
|
+
});
|
|
172
|
+
// The private tmp lives as long as the spawn's scope, however preparation
|
|
173
|
+
// ends; the declared write directories are created so the mechanism has
|
|
174
|
+
// something to bind, which the grant that opened them already permits.
|
|
175
|
+
const allocatedTmp = yield* Effect.acquireRelease(Effect.try({
|
|
176
|
+
try: () => NodeFs.mkdtempSync(NodePath.join(temporaryRoot, "smithers-confinement-")),
|
|
177
|
+
catch: (cause) => failure("Unknown", command, `could not prepare the confinement: ${messageOf(cause)}`, cause)
|
|
178
|
+
}), (directory) => Effect.sync(() => {
|
|
179
|
+
try {
|
|
180
|
+
NodeFs.rmSync(directory, { recursive: true, force: true });
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Cleanup is best-effort when the host refuses directory removal.
|
|
184
|
+
}
|
|
185
|
+
}));
|
|
186
|
+
const tmp = yield* Effect.try({
|
|
187
|
+
try: () => NodeFs.realpathSync(allocatedTmp),
|
|
188
|
+
catch: (cause) => failure("Unknown", command, `could not prepare the confinement: ${messageOf(cause)}`, cause)
|
|
189
|
+
});
|
|
190
|
+
const planned = yield* Effect.try({
|
|
191
|
+
try: () => ProcessSandbox.plan(request, { workspaceRoot: canonical.root, cwd: canonical.cwd, tmp }, hostFacts),
|
|
192
|
+
catch: (cause) => failure("Unknown", command, `could not plan the confinement: ${messageOf(cause)}`, cause)
|
|
193
|
+
});
|
|
194
|
+
if (ProcessSandbox.isUnenforceable(planned)) {
|
|
195
|
+
return yield* failure("PermissionDenied", command, planned.message, planned);
|
|
196
|
+
}
|
|
197
|
+
// Build outputs may grant their parent directory. An agent grant must
|
|
198
|
+
// never inherit that widening when a requested tree is already a file.
|
|
199
|
+
const exactWrites = profile.writes.map((relative) => NodePath.resolve(planned.workspaceRoot, relative));
|
|
200
|
+
if (planned.writes.some((write) => !exactWrites.includes(write))) {
|
|
201
|
+
return yield* failure("PermissionDenied", command, "write grant is not a directory tree", undefined);
|
|
202
|
+
}
|
|
203
|
+
// A workspace link does not grant authority to its target on the host.
|
|
204
|
+
const confinement = { ...planned, externalReads: [] };
|
|
205
|
+
yield* Effect.try({
|
|
206
|
+
try: () => {
|
|
207
|
+
ProcessSandbox.validateWrites(confinement, hostFacts);
|
|
208
|
+
NodeFs.mkdirSync(NodePath.join(tmp, "home"), { recursive: true });
|
|
209
|
+
NodeFs.mkdirSync(NodePath.join(tmp, "cache"), { recursive: true });
|
|
210
|
+
for (const write of planned.writes)
|
|
211
|
+
NodeFs.mkdirSync(write, { recursive: true });
|
|
212
|
+
},
|
|
213
|
+
catch: (cause) => failure("Unknown", command, `could not prepare the confinement: ${messageOf(cause)}`, cause)
|
|
214
|
+
});
|
|
215
|
+
// Only the target receives its requested environment. Dynamic-loader and
|
|
216
|
+
// other startup variables must never configure the host sandbox launcher.
|
|
217
|
+
const targetEnvironment = {};
|
|
218
|
+
const inherited = command.options.env === undefined || command.options.extendEnv === true;
|
|
219
|
+
for (const [name, value] of Object.entries(inherited ? process.env : {})) {
|
|
220
|
+
// Bash exports functions as names such as BASH_FUNC_which%%. These
|
|
221
|
+
// ambient entries cannot be exported by the portable inner launcher.
|
|
222
|
+
if (typeof value === "string" && /^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
223
|
+
targetEnvironment[name] = value;
|
|
224
|
+
}
|
|
225
|
+
for (const [name, value] of Object.entries(command.options.env ?? {})) {
|
|
226
|
+
if (typeof value === "string")
|
|
227
|
+
targetEnvironment[name] = value;
|
|
228
|
+
else
|
|
229
|
+
delete targetEnvironment[name];
|
|
230
|
+
}
|
|
231
|
+
const privateEnvironment = ProcessSandbox.environment(confinement);
|
|
232
|
+
const script = yield* Effect.try({
|
|
233
|
+
try: () => {
|
|
234
|
+
const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
235
|
+
const exports = [];
|
|
236
|
+
for (const [name, value] of Object.entries({ ...targetEnvironment, ...privateEnvironment })) {
|
|
237
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
238
|
+
throw new Error("environment variable name is not portable");
|
|
239
|
+
if (value.includes("\0"))
|
|
240
|
+
throw new Error("environment variable contains a null byte");
|
|
241
|
+
exports.push(`export ${name}=${quote(value)}`);
|
|
242
|
+
}
|
|
243
|
+
const file = NodePath.join(tmp, "environment.sh");
|
|
244
|
+
// Values stay off argv and journal receipts; the script is private,
|
|
245
|
+
// removed with the scope, and interpreted only inside confinement.
|
|
246
|
+
NodeFs.writeFileSync(file, [
|
|
247
|
+
"#!/bin/sh",
|
|
248
|
+
"unset ENV BASH_ENV CDPATH PWD OLDPWD SHLVL _",
|
|
249
|
+
...exports,
|
|
250
|
+
"exec \"$@\"",
|
|
251
|
+
""
|
|
252
|
+
].join("\n"), { flag: "wx", mode: 0o600 });
|
|
253
|
+
return file;
|
|
254
|
+
},
|
|
255
|
+
catch: (cause) => failure("PermissionDenied", command, messageOf(cause), cause)
|
|
256
|
+
});
|
|
257
|
+
// Resolve the actual program before wrapping it in the environment shell.
|
|
258
|
+
// Otherwise the sandbox sees only /usr/bin/env and omits a native helper
|
|
259
|
+
// installed outside its ordinary runtime paths.
|
|
260
|
+
const originalArgv = argvOf(command);
|
|
261
|
+
const launch = ProcessSandbox.launcher(originalArgv[0], targetEnvironment.PATH, [...confinement.reads, ...confinement.writes, ...confinement.externalReads], confinement.workspaceRoot, hostFacts);
|
|
262
|
+
const targetArgv = ["/usr/bin/env", "-i", "/bin/sh", script, launch.program, ...originalArgv.slice(1)];
|
|
263
|
+
const wrapped = yield* Effect.try({
|
|
264
|
+
try: () => ProcessSandbox.wrap({ ...confinement, externalReads: [...confinement.externalReads, ...launch.reads, script] }, targetArgv, targetEnvironment, hostFacts),
|
|
265
|
+
catch: (cause) => failure("Unknown", command, `could not render the confinement: ${messageOf(cause)}`, cause)
|
|
266
|
+
});
|
|
267
|
+
let [executable, ...args] = wrapped.argv;
|
|
268
|
+
if (selected._tag === "bubblewrap") {
|
|
269
|
+
const filter = yield* Effect.try({
|
|
270
|
+
try: () => {
|
|
271
|
+
const file = NodePath.join(tmp, "network.seccomp");
|
|
272
|
+
NodeFs.writeFileSync(file, networkFilter(process.arch, profile.network), { flag: "wx", mode: 0o600 });
|
|
273
|
+
return file;
|
|
274
|
+
},
|
|
275
|
+
catch: (cause) => failure("PermissionDenied", command, messageOf(cause), cause)
|
|
276
|
+
});
|
|
277
|
+
let fd = 3;
|
|
278
|
+
while (command.options.additionalFds?.[`fd${fd}`] !== undefined)
|
|
279
|
+
fd++;
|
|
280
|
+
// A regular file avoids a filter-input pipe whose early closure can
|
|
281
|
+
// surface as an unhandled ECONNRESET before bwrap reports its refusal.
|
|
282
|
+
args = [
|
|
283
|
+
"-c",
|
|
284
|
+
`exec ${fd}<"$1"; shift; exec "$@"`,
|
|
285
|
+
"smithers-seccomp",
|
|
286
|
+
filter,
|
|
287
|
+
executable,
|
|
288
|
+
"--seccomp",
|
|
289
|
+
String(fd),
|
|
290
|
+
...args
|
|
291
|
+
];
|
|
292
|
+
executable = "/bin/sh";
|
|
293
|
+
}
|
|
294
|
+
return ChildProcess.make(executable, args, {
|
|
295
|
+
...command.options,
|
|
296
|
+
cwd: canonical.cwd,
|
|
297
|
+
shell: false,
|
|
298
|
+
env: { PATH: "/usr/bin:/bin:/usr/sbin:/sbin", LANG: "C", ...privateEnvironment },
|
|
299
|
+
extendEnv: false
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
return KernelProcessConfinement.ProcessConfinement.of({ confine });
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Provides the native confinement.
|
|
306
|
+
*
|
|
307
|
+
* @category layers
|
|
308
|
+
* @since 1.0.0-rc.1
|
|
309
|
+
*/
|
|
310
|
+
export const layer = (options = {}) => Layer.succeed(KernelProcessConfinement.ProcessConfinement)(make(options));
|
|
311
|
+
//# sourceMappingURL=ProcessConfinement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessConfinement.js","sourceRoot":"","sources":["../../src/ProcessConfinement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,wBAAwB,MAAM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;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,UAAmB,EAAE,EAA4D,EAAE,CACvG,KAAK,CAAC,OAAO,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA","sourcesContent":["/**\n * The kernel's `ProcessConfinement` seam, filled with this host's native\n * sandbox: bubblewrap on Linux, seatbelt on macOS.\n *\n * `@smthrs/kernel`'s `ChildProcessSpawner.layer` hands every stage that passed\n * its `proc:spawn` check to the confinement in its context, together with the\n * `ProcessConfinement.Profile` the grants in force admit. This module turns\n * that profile into a {@link ProcessSandbox.Request}, plans it against the\n * workspace, and wraps the stage's argv in the mechanism the host has, so an\n * approved `bash` can write only where an `fs:write` grant says and reach the\n * network only when a `net:*` grant says. A stage that asked for the platform\n * shell is spelled out as `/bin/sh -c <line>` first: wrapping a `shell: true`\n * command line would otherwise leave its redirections and pipes to a shell\n * outside the sandbox.\n *\n * A host with no mechanism is the one decision this module leaves to its\n * caller: {@link Options.unavailable} either refuses the spawn, so nothing\n * runs that the profile would not have confined, or runs it unconfined with\n * a warning, the way every host did before this seam existed. A write set\n * the mechanism cannot enforce safely, a symbolic link below the workspace\n * root, is always refused.\n *\n * @since 1.0.0-rc.1\n */\n\nimport * as KernelProcessConfinement from \"@smthrs/kernel/ProcessConfinement\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport * as PlatformError from \"effect/PlatformError\"\nimport type * as Scope from \"effect/Scope\"\nimport * as ChildProcess from \"effect/unstable/process/ChildProcess\"\nimport * as NodeFs from \"node:fs\"\nimport * as NodeOs from \"node:os\"\nimport * as NodePath from \"node:path\"\nimport * as ProcessSandbox from \"./ProcessSandbox.ts\"\n\n/**\n * How the confinement is built.\n *\n * @category models\n * @since 1.0.0-rc.1\n */\nexport interface Options {\n /**\n * What happens when this host has no mechanism to enforce a profile with.\n * `\"refuse\"` fails the spawn, so a command never runs with more than the\n * profile allows; `\"unconfined\"` runs it as given and logs a\n * warning naming what the host lacks.\n */\n readonly unavailable?: \"refuse\" | \"unconfined\" | undefined\n /** The host facts mechanism selection reads; defaults to the real host. */\n readonly host?: ProcessSandbox.Host | undefined\n /** Where each run's private temporary directory is created; defaults to the OS temporary directory. */\n readonly temporaryDirectory?: string | undefined\n}\n\nconst shellLine = (command: ChildProcess.StandardCommand): string => [command.command, ...command.args].join(\" \")\n\n/**\n * The argv a stage executes, with a shell request made explicit.\n *\n * Node runs a `shell: true` stage as `/bin/sh -c <line>` on POSIX, and a\n * string shell as `<shell> -c <line>`; the wrapper needs that program to be\n * the one it confines, so the shell becomes the argv's first token and the\n * spawned stage no longer asks for one.\n */\nconst argvOf = (command: ChildProcess.StandardCommand): ReadonlyArray<string> => {\n const shell = command.options.shell\n if (shell === undefined || shell === false) return [command.command, ...command.args]\n return [shell === true ? \"/bin/sh\" : shell, \"-c\", shellLine(command)]\n}\n\nconst failure = (\n tag: \"NotFound\" | \"PermissionDenied\" | \"Unknown\",\n command: ChildProcess.StandardCommand,\n description: string,\n cause: unknown\n): PlatformError.PlatformError =>\n PlatformError.systemError({\n _tag: tag,\n module: \"ProcessConfinement\",\n method: \"confine\",\n pathOrDescriptor: shellLine(command),\n description,\n cause\n })\n\nconst messageOf = (cause: unknown): string =>\n ProcessSandbox.isUnenforceable(cause)\n ? cause.message\n : cause instanceof Error\n ? cause.message\n : String(cause)\n\n/** Classic BPF for seccomp_data: deny host Unix sockets and io_uring, preserving stream socketpair.\n * Closed networking additionally denies every IP socket family.\n * Wrong ABI and x32 syscall encodings fail closed rather than bypassing socket(). */\nconst networkFilter = (architecture: string, network: \"none\" | \"open\"): Uint8Array => {\n const abi = architecture === \"x64\"\n ? { audit: 0xc000003e, socket: 41, socketpair: 53 }\n : architecture === \"arm64\"\n ? { audit: 0xc00000b7, socket: 198, socketpair: 199 }\n : undefined\n if (abi === undefined) throw new Error(`native-network seccomp is unavailable on ${architecture}`)\n const instructions: Array<readonly [number, number, number, number]> = [\n [0x20, 0, 0, 4], // load audit architecture\n [0x15, 1, 0, abi.audit],\n [0x06, 0, 0, 0x80000000], // kill unsupported ABI\n [0x20, 0, 0, 0], // load syscall number\n [0x35, 0, 1, 0x40000000],\n [0x06, 0, 0, 0x80000000], // kill x32 / invalid high syscall numbers\n [0x15, 0, 1, 425], // io_uring_setup on both supported ABIs\n [0x06, 0, 0, 0x00050001], // io_uring can otherwise create sockets without socket()\n [0x15, 0, 6, abi.socketpair],\n [0x20, 0, 0, 16], // socketpair domain\n [0x15, 0, 4, 1], // AF_UNIX\n [0x20, 0, 0, 24], // socketpair type, low 32 bits of args[1]\n [0x54, 0, 0, 0xf], // strip SOCK_NONBLOCK and SOCK_CLOEXEC\n [0x15, 1, 0, 1], // only SOCK_STREAM; Linux aliases SOCK_RAW to datagram operations\n [0x06, 0, 0, 0x00050001],\n [0x20, 0, 0, 0] // reload syscall number before the socket() policy\n ]\n if (network === \"none\") {\n instructions.push([0x15, 0, 1, abi.socket], [0x06, 0, 0, 0x00050001]) // EPERM for every socket family\n } else {\n instructions.push(\n [0x15, 0, 3, abi.socket],\n [0x20, 0, 0, 16], // socket domain, low 32 bits of args[0]\n [0x15, 0, 1, 1], // AF_UNIX; IP families remain available\n [0x06, 0, 0, 0x00050001]\n )\n }\n instructions.push([0x06, 0, 0, 0x7fff0000]) // SECCOMP_RET_ALLOW\n const bytes = new Uint8Array(instructions.length * 8)\n const view = new DataView(bytes.buffer)\n for (const [index, [code, jt, jf, value]] of instructions.entries()) {\n view.setUint16(index * 8, code, true)\n view.setUint8(index * 8 + 2, jt)\n view.setUint8(index * 8 + 3, jf)\n view.setUint32(index * 8 + 4, value, true)\n }\n return bytes\n}\n\n/**\n * Builds the native confinement.\n *\n * @category constructors\n * @since 1.0.0-rc.1\n */\nexport const make = (options: Options = {}): KernelProcessConfinement.Service => {\n const hostFacts = options.host ?? ProcessSandbox.host()\n const temporaryRoot = options.temporaryDirectory ?? NodeOs.tmpdir()\n const unavailable = options.unavailable ?? \"refuse\"\n const confine = Effect.fn(\"ProcessConfinement.confine\")(function*(\n command: ChildProcess.StandardCommand,\n profile: KernelProcessConfinement.Profile\n ): Effect.fn.Return<ChildProcess.StandardCommand, PlatformError.PlatformError, Scope.Scope> {\n const request: ProcessSandbox.Request = {\n network: profile.network,\n unixSockets: false,\n strict: true,\n reads: profile.reads,\n writes: profile.writes,\n readOnly: profile.readOnly\n }\n const selected = ProcessSandbox.select(request, hostFacts)\n if (ProcessSandbox.isUnenforceable(selected)) {\n if (unavailable === \"refuse\") {\n return yield* failure(\n \"NotFound\",\n command,\n `${selected.message} This host refuses to spawn unconfined.`,\n selected\n )\n }\n yield* Effect.logWarning(`${selected.message} Running unconfined.`)\n return command\n }\n // The stage's directory is absolute: the kernel spawner roots it first.\n const cwd = command.options.cwd ?? profile.workspaceRoot\n const within = (root: string, path: string): boolean => {\n const relative = NodePath.relative(root, path)\n return relative !== \"..\" && !relative.startsWith(`..${NodePath.sep}`) && !NodePath.isAbsolute(relative)\n }\n if (!within(profile.workspaceRoot, cwd)) {\n return yield* failure(\"PermissionDenied\", command, \"command directory is outside the workspace\", undefined)\n }\n // A lexical workspace path can enter an unrelated host directory through\n // a symlink. Check the real directory before granting or preparing a run.\n const canonical = yield* Effect.try({\n try: () => {\n const root = NodeFs.realpathSync(profile.workspaceRoot)\n const directory = NodeFs.realpathSync(cwd)\n if (!within(root, directory)) throw new Error(\"command directory is outside the workspace\")\n for (const relative of profile.reads) {\n const lexical = NodePath.resolve(root, relative)\n if (!within(root, lexical)) continue\n // A read bind follows its source symlink. Refuse a grant that would\n // therefore mount unrelated host bytes inside the workspace.\n if (NodeFs.existsSync(lexical)) {\n const real = NodeFs.realpathSync(lexical)\n if (!within(root, real)) throw new Error(\"read grant resolves outside the workspace\")\n if (real !== lexical) throw new Error(\"read grant is a symbolic link\")\n }\n }\n return { root, cwd: directory }\n },\n catch: (cause) => failure(\"PermissionDenied\", command, messageOf(cause), cause)\n })\n // The private tmp lives as long as the spawn's scope, however preparation\n // ends; the declared write directories are created so the mechanism has\n // something to bind, which the grant that opened them already permits.\n const allocatedTmp = yield* Effect.acquireRelease(\n Effect.try({\n try: () => NodeFs.mkdtempSync(NodePath.join(temporaryRoot, \"smithers-confinement-\")),\n catch: (cause) => failure(\"Unknown\", command, `could not prepare the confinement: ${messageOf(cause)}`, cause)\n }),\n (directory) =>\n Effect.sync(() => {\n try {\n NodeFs.rmSync(directory, { recursive: true, force: true })\n } catch {\n // Cleanup is best-effort when the host refuses directory removal.\n }\n })\n )\n const tmp = yield* Effect.try({\n try: () => NodeFs.realpathSync(allocatedTmp),\n catch: (cause) => failure(\"Unknown\", command, `could not prepare the confinement: ${messageOf(cause)}`, cause)\n })\n const planned = yield* Effect.try({\n try: () => ProcessSandbox.plan(request, { workspaceRoot: canonical.root, cwd: canonical.cwd, tmp }, hostFacts),\n catch: (cause) => failure(\"Unknown\", command, `could not plan the confinement: ${messageOf(cause)}`, cause)\n })\n if (ProcessSandbox.isUnenforceable(planned)) {\n return yield* failure(\"PermissionDenied\", command, planned.message, planned)\n }\n // Build outputs may grant their parent directory. An agent grant must\n // never inherit that widening when a requested tree is already a file.\n const exactWrites = profile.writes.map((relative) => NodePath.resolve(planned.workspaceRoot, relative))\n if (planned.writes.some((write) => !exactWrites.includes(write))) {\n return yield* failure(\"PermissionDenied\", command, \"write grant is not a directory tree\", undefined)\n }\n // A workspace link does not grant authority to its target on the host.\n const confinement: ProcessSandbox.Plan = { ...planned, externalReads: [] }\n yield* Effect.try({\n try: () => {\n ProcessSandbox.validateWrites(confinement, hostFacts)\n NodeFs.mkdirSync(NodePath.join(tmp, \"home\"), { recursive: true })\n NodeFs.mkdirSync(NodePath.join(tmp, \"cache\"), { recursive: true })\n for (const write of planned.writes) NodeFs.mkdirSync(write, { recursive: true })\n },\n catch: (cause) => failure(\"Unknown\", command, `could not prepare the confinement: ${messageOf(cause)}`, cause)\n })\n // Only the target receives its requested environment. Dynamic-loader and\n // other startup variables must never configure the host sandbox launcher.\n const targetEnvironment: Record<string, string> = {}\n const inherited = command.options.env === undefined || command.options.extendEnv === true\n for (const [name, value] of Object.entries(inherited ? process.env : {})) {\n // Bash exports functions as names such as BASH_FUNC_which%%. These\n // ambient entries cannot be exported by the portable inner launcher.\n if (typeof value === \"string\" && /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) targetEnvironment[name] = value\n }\n for (const [name, value] of Object.entries(command.options.env ?? {})) {\n if (typeof value === \"string\") targetEnvironment[name] = value\n else delete targetEnvironment[name]\n }\n const privateEnvironment = ProcessSandbox.environment(confinement)\n const script = yield* Effect.try({\n try: () => {\n const quote = (value: string): string => `'${value.replaceAll(\"'\", \"'\\\\''\")}'`\n const exports: Array<string> = []\n for (const [name, value] of Object.entries({ ...targetEnvironment, ...privateEnvironment })) {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(\"environment variable name is not portable\")\n if (value.includes(\"\\0\")) throw new Error(\"environment variable contains a null byte\")\n exports.push(`export ${name}=${quote(value)}`)\n }\n const file = NodePath.join(tmp, \"environment.sh\")\n // Values stay off argv and journal receipts; the script is private,\n // removed with the scope, and interpreted only inside confinement.\n NodeFs.writeFileSync(\n file,\n [\n \"#!/bin/sh\",\n \"unset ENV BASH_ENV CDPATH PWD OLDPWD SHLVL _\",\n ...exports,\n \"exec \\\"$@\\\"\",\n \"\"\n ].join(\"\\n\"),\n { flag: \"wx\", mode: 0o600 }\n )\n return file\n },\n catch: (cause) => failure(\"PermissionDenied\", command, messageOf(cause), cause)\n })\n // Resolve the actual program before wrapping it in the environment shell.\n // Otherwise the sandbox sees only /usr/bin/env and omits a native helper\n // installed outside its ordinary runtime paths.\n const originalArgv = argvOf(command)\n const launch = ProcessSandbox.launcher(\n originalArgv[0]!, targetEnvironment.PATH,\n [...confinement.reads, ...confinement.writes, ...confinement.externalReads],\n confinement.workspaceRoot, hostFacts\n )\n const targetArgv = [\"/usr/bin/env\", \"-i\", \"/bin/sh\", script, launch.program, ...originalArgv.slice(1)]\n const wrapped = yield* Effect.try({\n try: () =>\n ProcessSandbox.wrap({ ...confinement, externalReads: [...confinement.externalReads, ...launch.reads, script] }, targetArgv, targetEnvironment, hostFacts),\n catch: (cause) => failure(\"Unknown\", command, `could not render the confinement: ${messageOf(cause)}`, cause)\n })\n let [executable, ...args] = wrapped.argv\n if (selected._tag === \"bubblewrap\") {\n const filter = yield* Effect.try({\n try: () => {\n const file = NodePath.join(tmp, \"network.seccomp\")\n NodeFs.writeFileSync(file, networkFilter(process.arch, profile.network), { flag: \"wx\", mode: 0o600 })\n return file\n },\n catch: (cause) => failure(\"PermissionDenied\", command, messageOf(cause), cause)\n })\n let fd = 3\n while (command.options.additionalFds?.[`fd${fd}`] !== undefined) fd++\n // A regular file avoids a filter-input pipe whose early closure can\n // surface as an unhandled ECONNRESET before bwrap reports its refusal.\n args = [\n \"-c\",\n `exec ${fd}<\"$1\"; shift; exec \"$@\"`,\n \"smithers-seccomp\",\n filter,\n executable!,\n \"--seccomp\",\n String(fd),\n ...args\n ]\n executable = \"/bin/sh\"\n }\n return ChildProcess.make(executable!, args, {\n ...command.options,\n cwd: canonical.cwd,\n shell: false,\n env: { PATH: \"/usr/bin:/bin:/usr/sbin:/sbin\", LANG: \"C\", ...privateEnvironment },\n extendEnv: false\n })\n })\n return KernelProcessConfinement.ProcessConfinement.of({ confine })\n}\n\n/**\n * Provides the native confinement.\n *\n * @category layers\n * @since 1.0.0-rc.1\n */\nexport const layer = (options: Options = {}): Layer.Layer<KernelProcessConfinement.ProcessConfinement> =>\n Layer.succeed(KernelProcessConfinement.ProcessConfinement)(make(options))\n"]}
|