@ai-ecoverse/slicc-kernel 1.196.17 → 1.196.19
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/README.md +8 -8
- package/dist/async-process.js +1 -1
- package/dist/cloudflare-sources.js +1 -1
- package/dist/cloudflare.js +353 -101
- package/dist/cloudflare.js.map +4 -4
- package/dist/kernel-worker.js +401 -149
- package/dist/kernel-worker.js.map +4 -4
- package/dist/meta.js.map +2 -2
- package/dist/node-process-worker.cjs +1 -1
- package/dist/node-process-worker.js +1 -1
- package/dist/node.js +351 -99
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +1 -1
- package/dist/types/fs/meta.d.ts +1 -0
- package/dist/types/fs/opfs.d.ts +12 -0
- package/dist/types/fs/private-rename.d.ts +25 -0
- package/dist/types/kernel/children.d.ts +1 -3
- package/dist/types/sudo.d.ts +5 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1133,7 +1133,7 @@ A lookup follows at most 40 symlinks, as Linux does: the 41st is `ELOOP`, for WA
|
|
|
1133
1133
|
|
|
1134
1134
|
OPFS renames use `FileSystemHandle.move()` when available. If a directory handle has no native move, the kernel coordinates with writers before copying the tree and deleting the source. Replacing an empty directory also uses this coordination. A shared-capable root without the locks needed for a copy returns `EBUSY` instead.
|
|
1135
1135
|
|
|
1136
|
-
|
|
1136
|
+
On a private root (no peer transport), an absent or explicitly unsupported native move falls back to a local copy. Before copying, the kernel drains operations on the source and destination trees. If a conflicting operation or write session remains open past a short grace period, the rename returns `EBUSY` without copying; finish the operation and retry. Later conflicting operations wait for the copy, with a bounded wait. A writer elsewhere on the root need not close. A local-folder mount commits writes under both operands before dispatch, so a shell can rename a directory while its descriptor remains open. A caller using the raw folder driver directly must close an overlapping uncommitted write session before retrying. This ordering is local to the kernel: it cannot coordinate writes from a native app or another tab that independently mounts the same local folder. The source is kept intact until every byte has been copied; a copy failure leaves an existing destination intact or removes a newly created one. On a root configured for peers, a rename that did not coordinate a copy still returns `EBUSY` instead of copying, even if no peer is currently visible. Other native failures report their own errno, such as `ENOENT` for a vanished source or `EACCES` for a denied move.
|
|
1137
1137
|
|
|
1138
1138
|
**FIFOs** (`mkfifo`, #896):
|
|
1139
1139
|
- **Creating one:** an Emscripten program's `mkfifo`/`mknod(S_IFIFO)` makes a FIFO node on the OPFS root (in `/tmp`, `/home` and the rest), owned by the caller, with mode `mode & ~umask`. `stat`, `ls -l` (`p`) and `test -p` show it as a FIFO, in Emscripten, WASI and JS programs. A WASIX program makes one through `slicc_fs.path_mkfifo` (see [File modes and the umask](#file-modes-and-the-umask); its libc uses it from wasix-sysroot -33), and `stat`s, `open`s, reads and writes one like any program. An existing name is `EEXIST`. tmpfs mounts (`/dev/shm`, a tmpfs `/tmp`) have FIFO nodes too, through the driver's `fifos` capability ([#907](https://github.com/ai-ecoverse/slicc-kernel/issues/907)). hostfs, `fsa` and media mounts have none, so `mkfifo` there is `EPERM`, and `EROFS` on a readonly path.
|
|
@@ -1390,7 +1390,7 @@ With `users: 'enforce'` the kernel checks every file call that reaches it agains
|
|
|
1390
1390
|
- **The layout:** with `users: 'report'` or `'enforce'`, the kernel gives its own paths an owner and a mode when they have no owner record yet: on a fresh root, and once on a root from before owners. These are `/` `0755`, `/root` `0700`, `/home` `0755`, `/etc` `0755`, `/etc/passwd` and `/etc/group` `0644`, `/usr` and `/usr/local` `0755`, `/node_modules` (or the `modules` option) and the system `PNPM_HOME` `0755`, all root's. A path that has a record keeps it, so an admin's `chmod 711 /home` or `chown cone /node_modules` lasts across restarts; a mounted path is left to its mount, and a path below a symlinked directory is stamped where it really is. Only a root that records owners is stamped: the OPFS root with its sidecar, which the page and the Node entry (in memory) both use; a custom root file system without owner records is left as it is. The directory for files removed while open, `/.slicc-unlinked`, is made root's `0700`. `/tmp` is the exception: it is set to `1777` at every start, and the first time owners are on for a root from before owners (and at every start after that until it has listed `/tmp` and succeeded for every entry), what is in it without an owner of its own is removed (as a boot empties `/tmp` on Linux; a file that is open is kept, a symlinked `/tmp` is left alone, and one `console.warn` line says how many entries went), since it would otherwise be root's, and a program that made it for its user, such as pnpm's lock directories, would find it isn't its own. Emscripten programs see `/` at `0755`, `/dev` at `0755`, `null`, `zero`, `full`, `random`, `urandom` and `tty` at `0666`, and `/dev/shm` at `1777`. With `users: 'off'` nothing is stamped. Paths the embedder makes (bios's `/opt` and `/var/lib/slicc`) are the embedder's to set. `/etc/sudoers` and `/etc/sudoers.d` are written when missing (see [Sudo](#sudo)).
|
|
1391
1391
|
- **Terminals:** a terminal from `openTerminal` belongs to its session's user, with group `tty` when `/etc/group` has one (the user's own group otherwise), mode `0620`; a pseudo-terminal's slave `/dev/pts/N` belongs to the uid and gid that opened `/dev/ptmx`, mode `0620`. Opening one by name (`/dev/ttyN`, `/dev/pts/N`, from every runtime) needs both `r` and `w`, so only its owner and root open it: the kernel's terminal descriptor always reads and writes, so the group's `w` bit (`write`, `wall` on Linux) does not let a group member open it. `/dev/tty` is the opener's own controlling terminal and is not checked, and descriptors a process inherited (across `sudo` or a `setresuid` too) keep working. Emscripten programs' `stat` of `/dev/ttyN` and `/dev/pts/N` shows the owner and mode. With `users: 'off'` terminals have no owner, as before.
|
|
1392
1392
|
- **A client's `fs`:** checked as the client's user; a page's client (root) passes.
|
|
1393
|
-
- **Removed files still open:** a process that holds a removed file may look it up (`stat`, `lstat`) under the hidden name the kernel gave it in `/.slicc-unlinked`, which is root's `0700`; every other process is refused there, so the kernel's own bookkeeping of held files raises no denials for their holders. The kernel tries twice to rename a held file into `/.slicc-unlinked`. If both attempts fail and the file is still present, removal returns `EBUSY` and the holder can keep reading the original file. These are two rename attempts, not two copy attempts:
|
|
1393
|
+
- **Removed files still open:** a process that holds a removed file may look it up (`stat`, `lstat`) under the hidden name the kernel gave it in `/.slicc-unlinked`, which is root's `0700`; every other process is refused there, so the kernel's own bookkeeping of held files raises no denials for their holders. The kernel tries twice to rename a held file into `/.slicc-unlinked`. If both attempts fail and the file is still present, removal returns `EBUSY` and the holder can keep reading the original file. These are two rename attempts, not two copy attempts: on a private root the kernel can copy a held file aside after draining writers, but on a shared-capable root neither attempt makes an uncoordinated copy ([#1218](https://github.com/ai-ecoverse/slicc-kernel/issues/1218)). Files of the same removal already moved aside are moved back. If one of those moves back fails too, that file stays in `/.slicc-unlinked`: its holder still reads it, but its name is gone although the removal reported `EBUSY`. That's a double failure, and rare.
|
|
1394
1394
|
|
|
1395
1395
|
`users: 'enforce'` is the default of `createKernel` and `createNodeKernel`; pass `'report'` to find what a program would be refused without refusing it, or `'off'` for kernels without owners. A `Launcher` made directly (see [What is in here](#what-is-in-here)) still defaults to `'off'`.
|
|
1396
1396
|
|
|
@@ -1404,7 +1404,7 @@ With `users: 'enforce'` the kernel checks every file call that reaches it agains
|
|
|
1404
1404
|
- **A line that doesn't parse is never dropped silently:** it is skipped, so it grants nothing, while the rest of the file still counts (as sudo's error recovery does), and every `sudo` and `sudo -l` says so on standard error before anything else. A caller with an effective uid of 0 gets one line per problem, with the file, the line number and what was expected: `sudo: /etc/sudoers.d/memory-handoff:1: line skipped: the SETENV: tag isn't supported: only NOPASSWD: and PASSWD: are`, or, for a line in neither form, `expected '[NOPASSWD] <user|%group|ALL> [(<target>)] [Cwd <dir>] [Stdin none] [ChainSha256 <sha256>] [RouteSha256 <sha256>] [Sha256 none|<file>=<sha256>…] Cmnd <command…|*>' or '<user|%group|ALL> ALL=[(<target>[,<target>…])] [NOPASSWD:] <command…|ALL>'`. A policy file that isn't root's, is a symlink, or is writable by group or others, and every file in a directory that is, is skipped the same way and reported as `sudo: <path> skipped: it must be root's, no symlink, and writable by root only`. Any other caller can't read the policy, so it gets only a count, without file names or anything from the lines: `sudo: 2 policy lines or files were skipped and grant nothing; ask an administrator to run sudo visudo -c`, and nothing when nothing was skipped. To check a line before installing it, run `visudo -c -f <file>` on your own copy, which reports it in full. Each problem is also logged once, in full, with `console.warn`.
|
|
1405
1405
|
- **`visudo -c`** is a command of the kernel itself, in `/usr/bin`, that checks the policy without running anything: `visudo -c -f <file>` (or `visudo -c <file>`, several allowed, `-` for standard input, shown as `stdin`) checks a file the caller can read, before it is installed, and prints `<file>: parsed OK` on standard output, or `visudo: <file>:<line>: <what was expected>` on standard error for each bad line, and exits with 1. `visudo -c` alone checks `/etc/sudoers` and the files in `/etc/sudoers.d` as `sudo` reads them, the ownership and mode included (`visudo: <path>: sudo skips it: …`), and needs an effective uid of 0, as reading those files does on Linux: `sudo visudo -c`. After the files, it prints the [timestamp values](#sudo-timestamps) on standard output: `Defaults timestamp_timeout=<minutes>, timestamp_type=<type>` for everyone (the kernel's 5 and `tty` where no line sets them), then each `Defaults:<user|%group>` line, as read, in the order they apply, so a later one wins; the first line ends with `, env_keep="<names>"` when the lines for everyone keep any variable (**The environment**, below); `-f` prints them only when the files have a `Defaults` line. `-q` prints nothing and only sets the status, `-s` is accepted (the check is always strict), and `visudo` without `-c` refuses to edit: write the file as root with mode `0440` (`install -m 0440 -o root -g root <file> /etc/sudoers.d/<name>`).
|
|
1406
1406
|
- **The embedders' recipe** puts cones in `sudo` (`groups: ['sudo']`) and scoops not, so a cone may ask for any command and a scoop for none.
|
|
1407
|
-
- **The command** is found once, on `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` for a bare name or against the caller's directory for a path, and its real path (symlinks resolved) is what runs and what the policy sees; the caller's `PATH` is never searched, as with sudo's `secure_path`, so a bare name doesn't find a user's own bin directory. The policy decides whether it runs, not who owns it: a command the caller can change runs as the target user when a line allows it. What the kernel adds is a binding to its contents. It looks at that file and every file that will really run for it (a catalog command's glue, module and imports module, and the `package.json` that defines it, a script and the interpreter its `#!` line or `binfmt` rule names, with the `package.json` that defines the rule). A file is omitted from the binding when it and every directory on its path are root-owned and not writable by group or others, and every symlink traversed, including links in a link target, is root-owned. Thus a root-only file behind root's own links counts like a direct path. Every other file is **user-writable**: its real path and sha256 go into the approval request (`userWritable`, below), and an `'always'` answer records them in its rule (`Sha256`). When the command starts, just before the kernel loads it, it hashes those files again; if one differs, is gone, or another user-writable file now runs for the command, nothing runs and `sudo` fails with `sudo: <
|
|
1407
|
+
- **The command** is found once, on `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` for a bare name or against the caller's directory for a path, and its real path (symlinks resolved) is what runs and what the policy sees; the caller's `PATH` is never searched, as with sudo's `secure_path`, so a bare name doesn't find a user's own bin directory. The policy decides whether it runs, not who owns it: a command the caller can change runs as the target user when a line allows it. What the kernel adds is a binding to its contents. It looks at that file and every file that will really run for it (a catalog command's glue, module and imports module, and the `package.json` that defines it, a script and the interpreter its `#!` line or `binfmt` rule names, with the `package.json` that defines the rule). A file is omitted from the binding when it and every directory on its path are root-owned and not writable by group or others, and every symlink traversed, including links in a link target, is root-owned. Thus a root-only file behind root's own links counts like a direct path. Every other file is **user-writable**: its real path and sha256 go into the approval request (`userWritable`, below), and an `'always'` answer records them in its rule (`Sha256`). When the command starts, just before the kernel loads it, it hashes those files again; if one differs, is gone, or another user-writable file now runs for the command, nothing runs and `sudo` fails with `sudo: <word> changed since it was approved`, using the command name as typed, not the changed backing file (`EPERM`). Each requested path must still name the real file it identified at approval: exchanging two hashed files' links is refused even if their contents are identical. For a script the kernel plans each interpreter and its arguments from the same read it hashes. A `..` in a command or interpreter name goes to the parent of the directory actually reached, including when it occurs inside a symlink target. Each such lookup can follow at most 40 links in total, counting both directory and final-name links. Sudo checks that the target user can search every directory on the named command’s route, even one later left by `..`. After a grant, if that route can no longer be walked to the approved executable, nothing starts: sudo reports the supplied command name as changed (`EPERM`), not a fresh lookup error. It binds the requested route to the physical interpreter and checks execute permission on the file it will run. A missing directory before `..` cannot be skipped to find another executable. Sudo builds the command catalog and `binfmt` rules for that plan from the manifest bytes it verifies, even when `package.json` links outside the watched roots. Lookups within one plan reuse the same scoped tables and one read per real manifest. Binding is narrower than scanning. It includes writable manifests of providers that name the selected command or an interpreter, including competing or replacing providers, and the global project manifests that determine their dependency precedence. For binfmt it includes declarations of matching rule keys, even an earlier nonmatching declaration that hides a matching one. An unrelated sibling is not an approval input; if it becomes a provider, the next plan sees it. Root-held manifests stay out of `userWritable`. `sudo -l` shares one catalog scan across its rules but computes each rule's writable inputs separately. At start, and after a package-replacement wait, the selected interpreter chain must also match the approved chain; a vanished rule cannot silently become a different interpreter. The modules and glue the kernel loads itself (a wasm module, a JS program's module, an Emscripten glue or imports module) are taken from the bytes it read and hashed then, never from its cache of compiled programs, which keys a file by its size and modification time, so a user-writable module swapped for another of the same size and time runs as approved or not at all. If a directly named Wasm file vanishes after the final hash, a warm entry keyed by that digest can still run the approved bytes. A file the kernel loads for the command that `sudo` didn't hash, such as the module of a [variant](#commands) the environment picked, must be root's and writable by root only, with every directory above it the same, and reached only through symlinks that root owns, so that no other user can change which file the path names; otherwise nothing runs (`sudo: <word> changed since it was approved`). Being root-only at the end of a link another user can repoint isn't enough, so a link repointed at another root-only program after the check doesn't run it. That holds whatever allowed the run (an approval, a `NOPASSWD` line, a [timestamp](#sudo-timestamps), an effective uid of 0): the hashes are the ones `sudo` saw when it decided. This also binds the script the interpreter opens. For each user-writable interpreted input (a `#!` script or a `binfmt` file), the child inherits a read-only, seekable descriptor for the very bytes used to plan the interpreter and verify the digest. The script argument becomes `/dev/fd/N`, including at each user-writable level of a nested interpreter chain. A rewrite or unlink after the check cannot substitute new contents. Each open of the descriptor path starts at offset zero, so a script can read `$0` without moving the interpreter's cursor. `dup` and `fork` still share the offset of the description they inherit. This applies to `sudoRun` too. **Compatibility:** bash sees `$0=/dev/fd/N`; Python sees the same descriptor path as `sys.argv[0]`. Self-relative lookups through `dirname "$0"` no longer find the script's directory. Pass the directory separately if needed. A bash script cannot re-exec the descriptor path directly with `exec "$0"`: exec looks up programs in the filesystem, not the process's fd table. Use `bash "$0"` to read the same snapshot again. Opening the snapshot path for write is `EACCES`, including from Emscripten. JS also gets `EACCES` on a write-open of `/dev/fd/N` for an unlinked read-only file. Writing to an already-open read-only descriptor is `EBADF`. The snapshot stays in memory until the last descriptor holding it closes, including in a descendant; this can matter for large binfmt inputs. Root-only scripts (including ones behind root-held links) and scripts run outside sudo keep their original path. `sudo --help` describes this difference. Files that are root-only throughout are not listed or pinned, and a command whose files all are behaves as before. `sudo -l` ends the line of a rule whose command is user-writable with ` # user-writable command`. A command that wouldn't start as the target user (a `#!` line naming an interpreter that is only the caller's, say) fails with `command not found` before anything is asked. Other files a program loads at run time (a package's libraries) are the admin's to keep safe, as on Linux. The caller's directory, which the program passes on, must be a directory the caller may enter, or `sudo` refuses (`EACCES`). The kernel resolves it to its real path once, shows that in the request, and runs the command there; if it no longer resolves the same, or the caller can no longer enter it, when the answer comes or when the command starts, nothing runs.
|
|
1408
1408
|
- **The environment** is the kernel's, as sudo's is under `env_reset`: the kernel's own variables (`HOSTNAME`, `TZ`, the proxy and CA settings, and its `env` option), the target user's `HOME`, `USER`, `LOGNAME`, `SHELL`, `PNPM_HOME` and `NPM_CONFIG_PREFIX`, the fixed `PATH` above, `PWD`, the caller's `TERM` when it is a plain terminal name, and `SUDO_USER`, `SUDO_UID`, `SUDO_GID` and `SUDO_COMMAND`. Nothing else of the caller's environment reaches the command unless the policy keeps it with sudoers(5)'s `env_keep`, so a tool that reads a token from the environment works under `sudo` as it does on Linux:
|
|
1409
1409
|
```
|
|
1410
1410
|
Defaults env_keep += "GH_TOKEN GITHUB_TOKEN"
|
|
@@ -1416,8 +1416,8 @@ With `users: 'enforce'` the kernel checks every file call that reaches it agains
|
|
|
1416
1416
|
- `sudo -l` shows the entries that match the caller as sudo prints them (`env_keep+="GH_TOKEN GITHUB_TOKEN"`, `env_keep-=GH_TOKEN`, `!env_keep`), and `visudo -c` the list for everyone.
|
|
1417
1417
|
- **Upgrading:** kernels before this refused an `env_keep` line (`sudo` and `visudo -c` reported it, and nothing was kept), so one already in the policy starts to count.
|
|
1418
1418
|
- **Compared with Linux sudo:** sudo(8) runs whatever path the policy allows, whoever owns it, and checks a command's contents only when its sudoers line names a digest (`sha256:<hex> /path`). The kernel runs what the policy allows too, and binds every user-writable file to the hash `sudo` saw, for every run, without a digest in the policy, and for all the files that run for the command (glue, module, `package.json`, script and interpreter), not only the command itself. A hand-written line without `Sha256` for a user-writable path is the admin's choice, as a sudoers line without a digest is: it runs the file as it is when it starts. Only the policy files themselves must be root-only, as only sudo's own files must be on Linux. The fixed `PATH` list, the checks on the caller's directory below, the symlink rule for what the command opens and the tags stay as they were. **Upgrading:** kernels before this refused a command that wasn't root-only, whatever the policy said (`sudo: <file> must be root's, and writable by root only`). Such a command now runs when a line allows it, so a `NOPASSWD` line or a `%sudo` line naming a user-writable path starts to count; an approver should show `userWritable`.
|
|
1419
|
-
- **The decision:** a caller whose effective uid is 0 runs anything (the binding of user-writable files still applies). Otherwise a matching `NOPASSWD` line runs the command at once; any other matching line asks `approve`; nothing matching is refused (`sudo: cone is not allowed to run
|
|
1420
|
-
- **Approval:** `approve(req, { signal })` gets `{ id, kind: 'sudo', user, uid, target, argv, path, cwd, pid, tag?, tty?, createdAt, expiresAt, always, stdin, rootOnly, userWritable?, changedManifests?, routeSha256?, chainSha256?, validate?, timestamp: true }`: the caller's name and real uid, the target user, the argv as typed, the resolved `path`, the caller's directory, pid, tag and terminal, and the times in ms. `always` is whether an `'always'` answer can be recorded: `false` when the argv, the path, the directory or a user-writable file's path has a control character (`\p{Cc}`, U+0085 included) or a line or paragraph separator (U+2028, U+2029), which a policy line can't hold, and `true` otherwise; nothing else sets it. `stdin` (`SudoStdin`) is what the caller's standard input is: `'tty'` (a terminal, possibly a pseudo-terminal a program drives), `'none'` (closed or `/dev/null`), `'pipe'` (a pipe, socket or other stream) or `'file'` (a file or another device). `rootOnly` maps the directory, and each argument (and the value of each `--opt=value`) that is an absolute path or names an existing path relative to the directory, resolved against it (`..` collapsed, links not followed), to whether every component actually traversed is root-owned, not a symlink and writable by root only, up to the nearest existing parent for a missing operand. A directory left by `..` must pass too; a missing or non-directory component before `..` gives `false`. This is the stricter no-symlink test used for policy files. The map contains at most 64 entries from the first 256 arguments. `userWritable`, there only when the command has [user-writable files](#sudo), lists each as `{ path, sha256 }` (`SudoFile`), the command first, so the approver can show that the caller can change what it approves, and what it holds now: the command runs only with those contents. `routeSha256` is the route digest described above, omitted when the hashed paths are all direct. `changedManifests`, when present, lists real manifest paths whose added, removed or changed digests differ from otherwise applicable hash-bound rules. `chainSha256` identifies the selected catalog entry (including resolved environment defaults), or the script paths, interpreter words, binfmt manifests and final interpreter entry for an interpreted command. Pass both digests back unchanged for `sudoRun`. An older saved request without the chain digest needs a fresh request when the current plan requires one. File facts have their own 1 MiB budget (UTF-8 path bytes plus 66 bytes per digest and separators), not the 256-argument `rootOnly` limit. A request too large to replay fails with `E2BIG` before the approval hook is called. A hash-bound rule also needs to be recorded again if its recorded set differs from today's provider set. In particular, a rule from a kernel that pinned every scanned sibling may need recording once without the unrelated paths; those siblings' later edits then stop invalidating it. These are facts for the approver, which decides what to offer; the kernel keeps no list of commands. `timestamp: true`, on every request, says this kernel takes the answer `{ answer: 'once' | 'always', timestamp: true }` (`SudoApproval`), which means a person approved, and `validate: true` marks the request of a `sudo -v`, with `argv: []`, `path: ''`, `always: false` and `rootOnly: {}`: it asks to start a timestamp for `user` and runs nothing (see [Sudo timestamps](#sudo-timestamps)). It answers `'once'` (run it), `'always'` (run it, and append `NOPASSWD <user> (<target>) Cwd <dir> Stdin none [ChainSha256 <sha256>] [RouteSha256 <sha256>] [Sha256 none|<file>=<sha256>…] Cmnd <path> <args…>` to `/etc/sudoers.d/<user>`, each argument a literal (a `*` written as `\*`), `""` for a call without arguments, and one `Sha256` for each user-writable file, root's `0440`, so it's never asked again for this command, these arguments and these contents, in this directory, with no input or at a terminal; if a user-writable file changed while the request waited, nothing is recorded or run (`sudo: <
|
|
1419
|
+
- **The decision:** a caller whose effective uid is 0 runs anything (the binding of user-writable files still applies). Otherwise a matching `NOPASSWD` line runs the command at once; any other matching line asks `approve`; nothing matching is refused (`sudo: cone is not allowed to run ls as root`). For a caller with no policy rules, this refusal comes before looking up the command, whether or not it exists. The refusal quotes the command and arguments as supplied, not the target of a symlink. Policy matching and the approver’s `path` still use the resolved executable.
|
|
1420
|
+
- **Approval:** `approve(req, { signal })` gets `{ id, kind: 'sudo', user, uid, target, argv, path, cwd, pid, tag?, tty?, createdAt, expiresAt, always, stdin, rootOnly, userWritable?, changedManifests?, routeSha256?, chainSha256?, validate?, timestamp: true }`: the caller's name and real uid, the target user, the argv as typed, the resolved `path`, the caller's directory, pid, tag and terminal, and the times in ms. `always` is whether an `'always'` answer can be recorded: `false` when the argv, the path, the directory or a user-writable file's path has a control character (`\p{Cc}`, U+0085 included) or a line or paragraph separator (U+2028, U+2029), which a policy line can't hold, and `true` otherwise; nothing else sets it. `stdin` (`SudoStdin`) is what the caller's standard input is: `'tty'` (a terminal, possibly a pseudo-terminal a program drives), `'none'` (closed or `/dev/null`), `'pipe'` (a pipe, socket or other stream) or `'file'` (a file or another device). `rootOnly` maps the directory, and each argument (and the value of each `--opt=value`) that is an absolute path or names an existing path relative to the directory, resolved against it (`..` collapsed, links not followed), to whether every component actually traversed is root-owned, not a symlink and writable by root only, up to the nearest existing parent for a missing operand. A directory left by `..` must pass too; a missing or non-directory component before `..` gives `false`. This is the stricter no-symlink test used for policy files. The map contains at most 64 entries from the first 256 arguments. `userWritable`, there only when the command has [user-writable files](#sudo), lists each as `{ path, sha256 }` (`SudoFile`), the command first, so the approver can show that the caller can change what it approves, and what it holds now: the command runs only with those contents. `routeSha256` is the route digest described above, omitted when the hashed paths are all direct. `changedManifests`, when present, lists real manifest paths whose added, removed or changed digests differ from otherwise applicable hash-bound rules. `chainSha256` identifies the selected catalog entry (including resolved environment defaults), or the script paths, interpreter words, binfmt manifests and final interpreter entry for an interpreted command. Pass both digests back unchanged for `sudoRun`. An older saved request without the chain digest needs a fresh request when the current plan requires one. File facts have their own 1 MiB budget (UTF-8 path bytes plus 66 bytes per digest and separators), not the 256-argument `rootOnly` limit. A request too large to replay fails with `E2BIG` before the approval hook is called. A hash-bound rule also needs to be recorded again if its recorded set differs from today's provider set. In particular, a rule from a kernel that pinned every scanned sibling may need recording once without the unrelated paths; those siblings' later edits then stop invalidating it. These are facts for the approver, which decides what to offer; the kernel keeps no list of commands. `timestamp: true`, on every request, says this kernel takes the answer `{ answer: 'once' | 'always', timestamp: true }` (`SudoApproval`), which means a person approved, and `validate: true` marks the request of a `sudo -v`, with `argv: []`, `path: ''`, `always: false` and `rootOnly: {}`: it asks to start a timestamp for `user` and runs nothing (see [Sudo timestamps](#sudo-timestamps)). It answers `'once'` (run it), `'always'` (run it, and append `NOPASSWD <user> (<target>) Cwd <dir> Stdin none [ChainSha256 <sha256>] [RouteSha256 <sha256>] [Sha256 none|<file>=<sha256>…] Cmnd <path> <args…>` to `/etc/sudoers.d/<user>`, each argument a literal (a `*` written as `\*`), `""` for a call without arguments, and one `Sha256` for each user-writable file, root's `0440`, so it's never asked again for this command, these arguments and these contents, in this directory, with no input or at a terminal; if a user-writable file changed while the request waited, nothing is recorded or run (`sudo: <word> changed since it was approved`); if that can't be written, nothing runs and `sudo` fails with `sudo: the rule could not be recorded`. A command line whose `always` was `false` runs once and records nothing, and `sudo` prints `sudo: ran once; this command line can't be recorded as always` on standard error before the command starts) or `'deny'`, or a denial that says who refused and why, `{ answer: 'deny', message: 'sudo: denied by the approval judge: <reason>' }` (`SudoDenial`): `sudo` prints the message (`EACCES`) on one line, with line breaks and tabs turned into spaces, other control characters removed, and cut to 500 characters (the last one `…`), when it starts with `sudo: ` and says something after it; otherwise, and for a throw, any other answer or no hook at all, it prints `sudo: approval denied`. After 5 minutes the request expires (`signal` aborts with `'expired'`, and `sudo` fails with `sudo: the request expired`); when the requester ends or gets a signal while it waits, `^C` included, `signal` aborts with `'withdrawn'` and `sudo` ends with that signal's status. `sudo: the request was withdrawn` means it was interrupted before any answer came: an answer the hook gave before the abort (its promise had settled) is reported, so a denial still prints its message, while `'once'` or `'always'` runs nothing once the requester has gone, and reads withdrawn (or expired); an answer after the abort is ignored. A user has at most one request waiting; another fails with `sudo: another request is pending`. On the page, `createKernel` relays the request from the kernel worker and back (a denial as `{ answer, message }` and a person's approval as `{ answer, timestamp: true }`, without any other field; any other object reads as a denial, as before), and the abort too, and what counts as first is what reaches the kernel worker first; `terminate()` or a failed worker aborts every request still waiting with `'withdrawn'`.
|
|
1421
1421
|
- **What `'always'` covers:** the same command with the same arguments in the same directory, with no input or at a terminal, and, when the command has user-writable files, with the same contents (once one of them changes, the rule no longer matches and `sudo` asks again, or refuses when no other line allows it), so a relative argument (`tee config.toml`) can't be pointed elsewhere by running it from another directory, and piped or redirected input (a pipe, a file) asks again; a terminal counts as no input, even one a program drives through a pseudo-terminal. It doesn't make a command that writes, or an interpreter (`bash -c`, `tee`, `cp`), safe to allow: what such a command touches depends on the files it is given, which the caller may control (a symlink, a file it owns). Keep `'always'` to commands that are safe in any state of the files they're given. Lines that kernels before `Cwd` recorded have no `Cwd`, so they match in any directory; to drop them, rewrite `/etc/sudoers.d/<user>` as root.
|
|
1422
1422
|
- **Running:** the command runs as the caller's child, with all six ids and the groups of the target user, in the caller's directory, on its terminal, standard input, output and error, in a **process group of its own** in the caller's session, as sudo(8) runs it without a pty. When `sudo` has the terminal's foreground, it hands the terminal to the command's group, so `^C`, `^\` and `^Z` reach the command, and takes it back when the command stops or ends. `sudo` exits with the command's status, and passes `SIGTERM`, `SIGHUP`, `SIGINT`, `SIGQUIT`, `SIGUSR1`, `SIGUSR2` and `SIGALRM` on to the command's whole group, so its children get them too; it installs these relays before it asks, so one that comes while the command starts is passed on once it runs (the kernel lets `sudo` signal the group of the command it started, which its own user may not). When the command stops (`^Z`), `sudo` stops by the same signal, so the shell's `jobs`, `fg` and `bg` work on it; when it is continued, it hands the terminal back to the command if it is in the foreground (`fg`) and continues the command's group. A `sudo` killed with `-9` leaves the command running in its group, as sudo(8) does, and the shell takes the terminal back as for any job;
|
|
1423
1423
|
- **Symlinks:** a command `sudo` started, and every process it starts in turn, follows a symlink only when root or the target user owns it: Linux's `protected_symlinks`, applied in every directory rather than only in sticky world-writable ones. Any other link is `EACCES`, and the denial names the link. That holds in every runtime: in the kernel's own path walk (JS programs' `ctx.fs` and `ctx.open`, WASI paths, `exec` and `cd` by path), in an Emscripten program's lookups (where the denial's op is `follow`), and where a WASI program resolves `..` itself. So a link the caller put where a rule's file or directory is expected (`/tmp/k4l` → `/etc/fnox`, or `config.toml` → `/etc/fnox/config.toml` in the caller's own directory) leads nowhere. `readlink`, `ls -l`, `lstat`, and removing or renaming a link still work, since they don't follow it.
|
|
@@ -1454,8 +1454,8 @@ A request can end without an answer: nobody was there within the 5 minutes, and
|
|
|
1454
1454
|
- `user` still exists, with `uid` (`ENOENT`, `sudo: unknown user <user>`; `EPERM`, `sudo: <user> is no longer uid <uid>`), and so does `target` (`ENOENT`).
|
|
1455
1455
|
- A policy line still lets `user` ask for `path` with these arguments as `target`, in `cwd`, with the contents in `userWritable`, `NOPASSWD` or not (`EACCES`, `sudo: <user> may no longer ask to run <command> as <target>`). There is no caller process any more, so its groups are the ones `/etc/group` gives the user now: a user taken out of `sudo` since can't have its old request run. A root user's request passes, as root's `sudo` does.
|
|
1456
1456
|
- `cwd` resolves to the same real path (`EACCES`, `sudo: <cwd> changed since it was requested`), and `user` may still enter it (`EACCES`, `sudo: cannot run in <cwd>: it isn't a directory <user> can enter`). Both are checked once more just before the command starts, as for a command `sudo` starts, and a directory that no longer resolves to itself then (a symlink swapped in meanwhile) is refused with the first sentence, so the command never runs somewhere else.
|
|
1457
|
-
- The first word of `argv` still finds `path`, by the same search as `sudo`'s (`ENOENT`, `sudo: <word>: command not found`; `EPERM`, `sudo: <word>
|
|
1458
|
-
- The command's user-writable files are the same files with the same sha256 as in `userWritable`, with the same requested-to-real path bindings (`routeSha256`) and interpreter chain (`chainSha256`) (`EPERM`, `sudo: <
|
|
1457
|
+
- The first word of `argv` still finds `path`, by the same search as `sudo`'s (`ENOENT`, `sudo: <word>: command not found`; `EPERM`, `sudo: <word> changed since it was requested` if it resolves elsewhere, without printing either destination).
|
|
1458
|
+
- The command's user-writable files are the same files with the same sha256 as in `userWritable`, with the same requested-to-real path bindings (`routeSha256`) and interpreter chain (`chainSha256`) (`EPERM`, `sudo: <word> changed since it was requested`). If the user-writable file hashes still match but the current plan requires a digest the saved request lacks, the error names the missing field or fields. A changed file is reported without that hint: the original request may have been complete. If the original request is unavailable, ask for a fresh approval; do not fill in the digest from the current plan.
|
|
1459
1459
|
- No entry of `rootOnly` that was `true` is false now (`EPERM`, `sudo: <path> is no longer root-only`).
|
|
1460
1460
|
- **How it runs:** as `sudo` would have run it, as `target` with all six ids and its groups, with `sudo`'s environment (`SUDO_USER`, `SUDO_COMMAND`, the fixed `PATH` and the rest) and the caller's umask, but none of the variables `env_keep` names (the request holds no environment, so there is nothing to copy them from), in `cwd`, with the [symlink rule](#sudo) for it and everything it starts, and the binding of its user-writable files checked once more when the kernel loads them. It isn't the child of any process: it leads a session and a process group of its own (`pgid` and its session are its `pid`, its parent is pid 1), has no terminal, and reads `/dev/null`. It has every tag of the request, in their order, after the tag of the client's connection, and then `tag` (a string or a list of at most 8), so `ps` and [`trace`](#clienttracetag-onevents--limit---promise-close-) show it as the agent's and the run's: give each run a tag of its own (`sudo-run:<id>`) and subscribe to it before the call.
|
|
1461
1461
|
- **Output:** `stdout` and `stderr` are absolute paths that the kernel opens as `user`, as the caller's shell opens `sudo command > file`: the caller must be able to write the file, or create it in its directory (`EACCES`, `sudo: <path>: Permission denied`; a missing directory is `ENOENT`, `sudo: <path>: No such file or directory`, since the kernel makes none), a symlink on the way must be root's or the caller's, and the file is truncated, or created as the caller's with mode `0600`. Once the kernel holds the file, it checks the path again, and refuses one that changed meanwhile (a symlink in its place: `EACCES`, `sudo: <path> changed while it was opened`). The same path for both opens one file, as `> file 2>&1` does. Without them, output goes to `/dev/null`. Because the output goes to files, not to the client, the run doesn't depend on the client: it goes on when the client detaches or its worker restarts, and nothing kills it for writing to a reader that is gone.
|
|
@@ -1715,7 +1715,7 @@ OPFS stays authoritative: an entry is consulted only for a path that exists in O
|
|
|
1715
1715
|
|
|
1716
1716
|
**Telling running kernels about files written to OPFS:** a writer outside the kernel (an installer worker, a service worker, the page) that changes files on a root a kernel may be running on calls `import { postFsNotice } from '@ai-ecoverse/slicc-kernel/meta'` and `postFsNotice({ paths?, trees? }, { metadata? })` **after** each write has committed: after `close()` of its writable, `removeEntry` or `move()` has resolved. `paths` are absolute paths written, created or removed. List a created or removed name's parent directory too, so listings refresh. `trees` are absolute directories whose whole subtree changed, for a recursive replace or a sweep. The notice goes on the BroadcastChannel `slicc-kernel-dirs:<metadata>` (default `slicc-kernel-dirs:slicc-kernel`), the one kernels on that root already use between themselves, as `{ paths, trees }`. One notice per batch of writes is enough, if it's posted after the last of them. A kernel that receives it drops its cached lookups, handles and misses for those paths (for a tree, everything under it), tells its open files to reread, and publishes the paths to its programs' caches. If one of them is at or under a command root (`/node_modules`, `PNPM_HOME`, a `commands.append` root) or names a `node_modules` directory, the kernel also reads its command catalog (the packages' `package.json` files) again before its next exec, so a running shell's next command sees a command a manifest added or changed ([#1703](https://github.com/ai-ecoverse/slicc-kernel/issues/1703)). A tree marks every path changed for them, so a running program's next look at any path goes to the kernel. **The residual window:** a reader can still see the old state between the write's commit and the notice's delivery (a message, usually well under a millisecond, but not bounded). A writer that runs while no kernel is up needs no notice: a kernel's caches start empty when it boots. A notice for a path that exists as a regular file, listed in `paths` (a `trees` entry refreshes caches but stamps no times, since a tree can hold thousands of files), also gives it a new modification time, before running programs are told of the change: the notice's arrival, with the change time along, unless its modification time is already later (an explicit future one is kept, with its change time), as a write does on Linux, recorded once per burst of notices for the same file ([#1275](https://github.com/ai-ecoverse/slicc-kernel/issues/1275)). That matters because Chrome can keep a file's OPFS `lastModified` across an append through `createWritable({ keepExistingData: true })`, and the kernel reports `lastModified` for files it didn't write, so `-nt` and make wouldn't see the change. A notice without a real change still moves the time, so a make may rebuild once. An outside write that posts no notice keeps OPFS's time. Notices between kernels (the array form they post for their own writes) don't stamp: those kernels record their times themselves. That's part of the channel's contract: kernels post their own change notices on the dirs channel as a plain array of paths, and only the `{ paths, trees }` object form that `postFsNotice` sends counts as an outside writer's. A kernel must keep posting arrays there, which `fs-notice-page.test.mjs`'s peer row checks. **Without a notice** a kernel that is alone on its root keeps what it cached: a running program's stats of a path stay as they were for as long as the program runs, and the kernel's own directory handles for up to a second. So a writer that doesn't post notices must not change files a running kernel uses ([#1156](https://github.com/ai-ecoverse/slicc-kernel/issues/1156)).
|
|
1717
1717
|
|
|
1718
|
-
**Replacing a package in place** ([#1703](https://github.com/ai-ecoverse/slicc-kernel/issues/1703)): an installer that rewrites a package's files where they are, as the BIOS installer does, wraps those writes in `import { replacing } from '@ai-ecoverse/slicc-kernel/meta'` and `await replacing(paths, task, { metadata? })`, so that no exec loads a mix of old and new files (a new wasm with the old glue fails to link, exit 70). `paths` are the absolute package directories being replaced, the ones holding each `package.json` (`EINVAL` for a relative one); they are normalized, merged and sorted. For each one, `replacing` takes the exclusive Web Lock `slicc-kernel-replacing:v1:<metadata>:<directory>` (the directory verbatim, `metadata` defaulting to `slicc-kernel`, so for example `slicc-kernel-replacing:v1:slicc-kernel:/node_modules/@ai-ecoverse/wasm-bash`), runs `task`, posts `postFsNotice({ trees: paths })`, waits 150 ms and then releases, also when the task throws. It resolves to what the task returns or rejects with its error. The wait outlasts the longest a kernel's lookups serve a file's earlier state (100 ms, above), so no exec after the release reads a stat from before the last write. Every exec of a program that lives in a package takes the same lock in shared mode, from the moment its files are known until they are read and compiled, never while it runs: one Web Lock request per package its files are in, which is one for a program whose glue, module, variants and imports module share a package (about 60 µs in Chrome, under 0.2% of a fork and exec from bash). It makes no other OPFS request for it. An exec that comes while a replacement runs waits for it, then plans again from fresh lookups and a fresh command catalog and loads the new files, and a replacement waits for the execs that are already reading. The new plan goes through the same checks as the first (the caller's credentials, scope and exec permissions). A spawn that redeems a sealed exec ticket (see [`/dev/sealed`](#devsealed)) is also held to what the vault approved: if the plan after the wait has other files, another interpreter chain or another `trusted` than the ones `materializeConsume` was asked about, the spawn fails with `EACCES` and never starts, so the values never reach a process. A `sudo` exec and a `sudoRun` are held to their approval the same way: after the wait, the chain of interpreters and [`binfmt` rule](#commands) manifests must be the approved one and every user-writable file must have the sha256 `sudo` saw, or nothing runs and it fails with `sudo: <
|
|
1718
|
+
**Replacing a package in place** ([#1703](https://github.com/ai-ecoverse/slicc-kernel/issues/1703)): an installer that rewrites a package's files where they are, as the BIOS installer does, wraps those writes in `import { replacing } from '@ai-ecoverse/slicc-kernel/meta'` and `await replacing(paths, task, { metadata? })`, so that no exec loads a mix of old and new files (a new wasm with the old glue fails to link, exit 70). `paths` are the absolute package directories being replaced, the ones holding each `package.json` (`EINVAL` for a relative one); they are normalized, merged and sorted. For each one, `replacing` takes the exclusive Web Lock `slicc-kernel-replacing:v1:<metadata>:<directory>` (the directory verbatim, `metadata` defaulting to `slicc-kernel`, so for example `slicc-kernel-replacing:v1:slicc-kernel:/node_modules/@ai-ecoverse/wasm-bash`), runs `task`, posts `postFsNotice({ trees: paths })`, waits 150 ms and then releases, also when the task throws. It resolves to what the task returns or rejects with its error. The wait outlasts the longest a kernel's lookups serve a file's earlier state (100 ms, above), so no exec after the release reads a stat from before the last write. Every exec of a program that lives in a package takes the same lock in shared mode, from the moment its files are known until they are read and compiled, never while it runs: one Web Lock request per package its files are in, which is one for a program whose glue, module, variants and imports module share a package (about 60 µs in Chrome, under 0.2% of a fork and exec from bash). It makes no other OPFS request for it. An exec that comes while a replacement runs waits for it, then plans again from fresh lookups and a fresh command catalog and loads the new files, and a replacement waits for the execs that are already reading. The new plan goes through the same checks as the first (the caller's credentials, scope and exec permissions). A spawn that redeems a sealed exec ticket (see [`/dev/sealed`](#devsealed)) is also held to what the vault approved: if the plan after the wait has other files, another interpreter chain or another `trusted` than the ones `materializeConsume` was asked about, the spawn fails with `EACCES` and never starts, so the values never reach a process. A `sudo` exec and a `sudoRun` are held to their approval the same way: after the wait, the chain of interpreters and [`binfmt` rule](#commands) manifests must be the approved one and every user-writable file must have the sha256 `sudo` saw, or nothing runs and it fails with `sudo: <word> changed since it was approved` (`EPERM`). The lock names keep their `v1` across kernel versions, so an installer can use the `replacing` of whichever version is installed while kernels of other versions run. Feature-test it with `typeof replacing === 'function'`; a kernel without it takes no lock. Without `navigator.locks`, `replacing` runs the task and posts the notice. The contract:
|
|
1719
1719
|
|
|
1720
1720
|
- **Write each file whole,** with `createWritable()` without `keepExistingData`, then `close()`: the kernel keys what it compiled on a file's size and modification time, and Chrome can keep `lastModified` across a `keepExistingData` write (see the notices above).
|
|
1721
1721
|
- **Name package directories:** an exec locks only the directory of its program's package (`<…>/node_modules/<name>` or `<…>/node_modules/@scope/<name>`, or a package directly under `modules` or a `commands.append` root), so a path above a package, such as `/node_modules`, doesn't hold its programs. Packages nested in one another are separate locks and may be replaced at the same time.
|
package/dist/async-process.js
CHANGED
|
@@ -1535,7 +1535,7 @@ function createParentRefreshCount() {
|
|
|
1535
1535
|
}
|
|
1536
1536
|
|
|
1537
1537
|
// src/version.ts
|
|
1538
|
-
var KERNEL_VERSION = true ? "1.196.
|
|
1538
|
+
var KERNEL_VERSION = true ? "1.196.19" : "0.0.0-dev";
|
|
1539
1539
|
var OS_RELEASE = "6.0.0-slicc";
|
|
1540
1540
|
function procVersion() {
|
|
1541
1541
|
return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
|