Repository navigation
feat(agent): read 2.0 package requests and run their operations in the package broker - #2230
Benoît Cortier (CBenoit) wants to merge 31 commits into
Conversation
A route gets one function per request body, from the body bytes to the request type of the 2.0 API or a `BadRequest` marker, so no route parses JSON on its own and every body is held to the same rules. The tests take each rule from the wire contract: the JSON rules, the member tables of the five request objects, and request equality. One of them is ignored because the API types read a closed-set value written as an object, which the contract makes `BadRequest`. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…luator A package request read from a 2.0 body becomes the evaluator's input, and the evaluator's decision and validation errors become the members a 2.0 response carries, so a route never maps a member by hand. Each closed set is mapped by a match without a wildcard arm, and tested name by name against the contract's list, so a value added on either side cannot be dropped or renamed unnoticed. A bypass request becomes the package request the contract reads it as, with its own source name or the one the caller found for it. One timestamp test is ignored because the API types write the leap second chrono can hold with the seconds 60, which no timestamp has. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A request line's method and target give the row of the endpoint table they match, with the operation id of the path where the row has one, so every route applies the same matching: exact characters, no decoding, and a query that is ignored. A path whose operation id is not an identifier still matches its row, because the checks that come before `OperationNotFound`, such as authentication, depend on the row. The tests go through the contract's table row by row, body limits and client requirements included. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The rule was checked through the evaluation request only, and each request type has its own reader. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A route gets a constructor per kind of error response, so the message limit and the member each code carries are decided in one place. A message is cut to the 2048 bytes a response may carry, at a character boundary. A member is written only with a code whose row has it, and a response whose code needs a member it was not given becomes `InternalError`, which the contract lets replace each such code, rather than a response the contract does not allow. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A derived reader takes a list in place of an object, member by member, and the list with no entry does not tell such a reader apart. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Each builder that refuses an elevated run derived the elevation from the request, where a user-scope request lowers it to a standard run. A 2.0 request states the elevation of its run on its own, so the builders now take it as a parameter, and the existing entry points keep deriving it the same way. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The first frame of an event channel states the protocol version, which was fixed at 1.0. A channel opened for an operation of the 2.0 protocol announces 2.0, the version its clients require, while the channels of the 1.x routes keep announcing 1.0. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An allowed 2.0 package request becomes an operation the broker starts on the executor the 1.x routes use, tracks, reports and cancels as the 2.0 protocol states. These operations live in their own registry, so a 1.x request never names one and a 2.0 request never names an operation of a 1.x route. An operation belongs to the user and the executable of its caller, and a request id is unique per owner: an equal request with the same id gets the operation it started, and an unequal one conflicts. The caller supplies what decides that two requests are equal, because that depends on their encoding. The command comes from the existing builders, which now take the elevation of the run and the WinGet installer arguments beside the 1.x request they read. The run has the elevation the request states, whatever its scope. An operation ends `Failed` without running a step when it has a pre or post command and an elevated run, when it updates under a manager that updates from the source recorded at install, which the broker does not read yet, and when no command can be built for it. The module root moves to `execution/mod.rs` because the crate's lints require that form for a module with sub-modules. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ting The pipe of an operation's event channel granted the local system and Administrators full control, which lets them write to a one-way channel and change who can open the pipe. A channel that announces 2.0 now grants them read access, as it grants the operation owner's user. The channel of a 1.x operation keeps its access, which 1.x clients may depend on. The broker's own end is the handle that created the pipe, so its writes do not depend on these entries. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ands A request with `PrePostCommands` whose `Elevation` is `Elevated` is `NotRunnable`, for which the broker runs nothing. The two tests of the refusal behind that answer cited the rule about a `NonElevated` request whose token turns out elevated, which says nothing about this request. `Operations::start` now states that its caller answers `NotRunnable` without calling it, because a call takes the request id. The test that built a 1.x tracker and a 2.0 registry sharing nothing, and checked that neither finds the other's operation, is removed: no change to either could make it fail, since the routes choose which one a request reaches. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`Operations::start` built the plan of a request while it held the lock of the registry, so every status, cancel and execution request waited for the command builders. The plan depends on the request only and is now made first. The lookup and the insertion stay under one acquisition of the lock, and so does the creation of the event pipe: a channel opened for a request that turns out to have an operation could only be closed by finishing it, which keeps its pipe open for 60 seconds. The names of `KillBeforeOperation` that the executor cannot hand to `taskkill` as one image name were left out of the plan without a trace. They are still left out, since nothing can be attempted for them, and each is now logged with the id of its operation. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A 2.0 request names the version its command installs and has no member that asks for pre-release versions, so the command never had the option that makes PowerShellGet and PSResourceGet include pre-releases in what they find. PowerShellGet documents that naming a pre-release version is not enough to install it, so an allowed request for one ran a command its manager refused. The command of a `PowerShell` or `PowerShell7` request now has `-AllowPrerelease` or `-Prerelease` exactly when `Package.Version` is a version with a pre-release under the contract's version scheme. The evaluator does not export its reading of that scheme, so the plan reads the version itself. No other manager gets the option, because the builders of several refuse a request that has it. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The steps of an operation run on a detached task, which alone records how the operation ends. When that task ended without doing so, as when a step panics, the operation kept a status that is not terminal: the broker held it for ever, its request id replayed it for ever, and its event channel never got `FINISH`. The task now holds a guard that ends the operation `Failed` when it is dropped while the operation has not ended. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The local system and Administrators got full control of the pipe of every channel but one announcing 2.0, so a version added later would have got full control without anyone deciding it. The channel version is now an enumeration, and the access is a match on it with no default: full control is for 1.0, which existing 1.x clients may depend on, and a new version does not compile until its access is chosen. The comment on the access entries claimed that the two principals cannot change who can open the pipe. The entries only withhold write access to the data of the pipe; the owner of the pipe keeps the right to read and to change its DACL. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An operation whose task panics is ended `Failed` while the panic unwinds. Ending it queues a status update and a finish on the event channel, and both panicked when the lock of the queue was poisoned; a panic during unwinding aborts the broker. Both now take a poisoned queue as it is, as marking the output incomplete already does, so the record ends `Failed` and the queue is closed. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The name comes from the request and may hold control characters, so logging it as it is let a request write a line break and text of its choice into a text log. It is logged escaped, as the executor logs the names it stops. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The rows for the installer arguments of winget now name the option that must be absent, and the rows of the endpoint table name the operation identifier their path holds. Both were computed in the test from another column of the row, so a row could not state anything else and a mistake in that computation would have been part of the expectation. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The body of the execution request was the serialization of the package request the test then expects back, so a member written and read under the same wrong name would have passed. The body is now the literal one the test of the package request reads, with a request id. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s it The contract gives the least time an ended operation is held, not the time it is dropped. Two tests that need an operation to be gone expected it gone at that least time, so a broker holding operations longer, as the contract allows, would have failed them. They now pass the time the broker holds an operation, and the 300 seconds stay in the test of the bound. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Every pair of paths expected to give two owners differed in its number of code points, so a comparison that only counted them, or that mapped every code point to the same one, made each pair two owners as well. One pair now has paths of one length that differ by a letter. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Some tests of the 2.0 requests named a source that does not decide what they expect, or named only part of it: - an operation with `PrePostCommands` and an elevated token ending `Failed` without a step is a rule of the operations, not only of `NotRunnable`; - the reading of keys and escapes of a request body rests on the wire contract and RFC 8259, where only the policy contract was cited; - a plan for a version with a pre-release under a manager with no pre-release option follows from the cases in which no command is built, and was marked as a guard against a fault; - no pre-release switch for a version without a pre-release is such a guard, since the contract only says which versions have none, and that is cited where the versions are listed. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The reason comes from the plan or the executor, whose errors quote members of the request, so a control character in one of them reached the log as it was. The reason is now logged escaped, like the process names left out of an operation. Issue: DGW-499 Changelog: ignore Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Intent drift audit: 2.0 request reading, operation plan and registry, 2.0 event channel (audited at
|
| ID | Statement (abridged) | Status | Evidence | Note |
|---|---|---|---|---|
CONTRACT.wire.md#values-4, #json-4 |
A closed-set value "matches only with its exact characters"; a value of the wrong JSON type makes the request BadRequest |
violates (known) | v2/wire/read.rs:59-61; ignored test v2/wire/read.rs:1095-1096 |
The published types read a closed-set value written as an object, such as {"Install": null}. Already reported; in the dependency. |
CONTRACT.wire.md#values-3, CONTRACT.policy.md#timestamps-2 |
A timestamp has "seconds ... 00 to 59" | violates (known) | v2/wire/convert.rs:165-167; ignored test v2/wire/convert.rs:999-1000 |
The published Timestamp::from_datetime writes a leap second held by chrono as seconds 60. Already reported; in the dependency. |
CONTRACT.wire.md#def-owner-2, CONTRACT.policy.md#text-comparison-1 |
Two owners are the same when their paths are equal ignoring case by the simple uppercase mapping of UnicodeData.txt 16.0.0 |
partial | v2/execution/owner.rs:60-66; UNTESTED: at owner.rs:52-59 |
Uses the standard library's full mapping of the toolchain's Unicode version, keeping the code point when the mapping has several characters. Differs for code points such as U+1F80. Introduced. |
CONTRACT.wire.md#opt-ins-4, #operations-1 |
The operation "stops the processes" of every KillBeforeOperation image name |
partial (known) | v2/execution/plan.rs:83-91; v2/execution/operations.rs:384-392; evaluator/builtin_rules.rs:81-93 |
A well-formed name that does not end in .exe, or holds \, /, :, ", ' or a control character, is left out of the plan and logged; the operation runs. Already recorded. Introduced. |
CONTRACT.wire.md#opt-ins-4 |
Processes are stopped "as taskkill /F /IM does" |
partial | executor/windows/mod.rs:602-614, 426-430 |
The command adds /FI "SESSION eq <caller session>", and /FI "USERNAME eq <caller>" on an elevated run, so fewer processes are stopped than taskkill /F /IM stops. Pre-existing executor, reached from v2/execution/operations.rs:327-343. |
CONTRACT.policy.md#managers-4, INTENT.md#trusted-sources-10 |
For an Update under a manager that updates from the recorded source, the broker reads every record before running anything and refuses unless each names Source.Name |
partial (known) | v2/execution/plan.rs:60-67, 108-110 |
Every Update under Scoop or PowerShell ends Failed without a step; no record is read. Fails closed, and agrees with CONTRACT.wire.md#operations-6. Already reported. Introduced. |
CONTRACT.policy.md#managers-2 |
"no command the broker builds limits an uninstall to packages installed from Source.Name" |
partial | command_builder/powershell.rs:59-68, 142-148, 303-320; reached from v2/execution/plan.rs:81, 192-195 |
The PowerShell and PowerShell7 uninstall scripts throw unless every installed version records Source.Name as its repository. A 2.0 request always has Source.Name, so the check always runs, and an allowed uninstall naming another repository ends Failed. Pre-existing builder. |
CONTRACT.wire.md#event-channel-8 |
The broker closes the channel only "when writing a frame has made no progress for 30 seconds" (among the listed cases) | partial | event_channel.rs:574, 717-726 |
The deadline covers the whole write of one frame, so a client that reads steadily but takes more than 30 seconds for one frame is closed although the write progressed. Pre-existing. |
Cannot verify
| ID | Statement (abridged) | Status | Evidence | Note |
|---|---|---|---|---|
CONTRACT.wire.md#operations-10 |
"The broker never gives two operations the same OperationId" |
cannot-verify | v2/execution/operations.rs:305-310, 378 |
The id is op- and a version 4 UUID; nothing checks it against the ids held, and an equal id would replace the held record. Unique with overwhelming probability, not by construction. UNTESTED: at 305-309. |
CONTRACT.wire.md#event-channel-3 (local system, Administrators) |
The local system and members of Administrators open the pipe "for reading only" | cannot-verify | event_channel.rs:745-759, 761-780 |
The two entries grant FILE_GENERIC_READ, and a test reads the entries (event_channel.rs:1294). No test opens the pipe as either principal, and the pipe's owner keeps the right to change the DACL. UNTESTED: at 745-755. |
CONTRACT.policy.md#reading-10 |
"The broker runs the command whose reading it evaluated" | cannot-verify | command_builder/mod.rs:87-106; v2/execution/plan.rs:159-248 |
Checked for WinGet, Scoop, PowerShell and PowerShell7 (rows below). The Bun, Cargo, Npm, Pip, Dotnet, Chocolatey and Vcpkg builders, and the scripts the executor writes around a command, were not compared with their readings rule by rule; the diff only adds an elevation parameter to them. |
INTENT.md#broker-limits-3 |
On a run as administrator, a source name resolves only through machine-wide configuration | cannot-verify | command_builder/mod.rs:87-106; powershell.rs:225-245; scoop.rs:97-101; dotnet.rs:113-130; winget.rs:64-71 |
The run's elevation now reaches every builder that tests it. WinGet relies on a property its own UNTESTED: comment records, and Chocolatey was not read. |
Not yet realised
| ID | Statement (abridged) | Status | Evidence | Note |
|---|---|---|---|---|
INTENT.legacy.md#format-1-1 |
"The broker converts a 1.x policy in memory when it loads it" | not-yet-realised (known) | outside the files of this diff | The 2.0 side holds no accepted policy for a 1.x file (Invalid / Unconvertible), and the 1.x endpoints keep enforcing it. Already reported. |
CONTRACT.wire.md#bypass-reading-4 |
A bypass request without Source under Scoop, Vcpkg or "every other case" is read with no Source.Name |
not-yet-realised | v2/wire/convert.rs:92-96; test convert.rs:823 |
The conversion returns None when the list gives no name; the reading without a name is left to the bypass endpoint. |
CONTRACT.wire.md#event-channel-5 |
For an operation started by a bypass request, frames go only to a connection authenticated as the owner | not-yet-realised | event_channel.rs:639-677 |
The channel sends HELLO to the first connection, whoever opened it; the registry has no bypass operation yet. |
CONTRACT.wire.md#bypass-17 |
A bypass RequestId neither conflicts with nor replays an execution request, and the reverse |
not-yet-realised | v2/execution/operations.rs:145-152 |
One registry maps (Owner, RequestId) to one operation, with no kind of request in the key; the separation depends on how the bypass endpoint uses the registry. |
Conforms
| ID | Statement (abridged) | Status | Evidence | Note |
|---|---|---|---|---|
CONTRACT.wire.md#values-1 |
Lengths of strings count bytes in UTF-8 | conforms | v2/wire/error.rs:36-45; v2/execution/operations.rs:215-224 |
Introduced. |
CONTRACT.wire.md#values-2 |
An identifier is 1 to 128 of the listed characters, the first a letter or digit | conforms | v2/wire/route.rs:66; v2/wire/read.rs:722-735; v2/execution/operations.rs:310 |
Published Identifier. |
CONTRACT.wire.md#values-3 |
The broker writes every timestamp with the offset Z |
conforms | v2/wire/convert.rs:165-167; test convert.rs:951 |
Except the leap second above. |
CONTRACT.wire.md#json-2 |
A body is malformed when it is malformed JSON, starts with a byte order mark, or repeats a key after escapes are decoded | conforms | v2/wire/read.rs:59-61; tests read.rs:768, 868, 928 |
Nesting deeper than 64 and a top-level value that is no object are BadRequest too, since every request object is shallow and strict. |
CONTRACT.wire.md#json-3 |
Keys, null, key order and whitespace are read as the policy contract reads them; an optional member is absent rather than null; list order is part of the value |
conforms | v2/wire/read.rs:59-61; tests read.rs:1325-1393 |
Published object! types reject null. |
CONTRACT.wire.md#json-4 |
An unlisted member, an absent required member, a wrong JSON type and a value outside its domain are each BadRequest |
conforms | v2/wire/read.rs:27-61; tests read.rs:1155-1207 |
Except the closed-set value above. |
CONTRACT.wire.md#json-6 |
The broker writes exactly the members the table lists and whose condition holds (error responses) | conforms | v2/wire/error.rs:83-121; tests error.rs:224-311 |
Other responses are written by the routes. |
CONTRACT.wire.md#transport-6 |
The request target is the path, optionally followed by a query, which the broker ignores | conforms | v2/wire/route.rs:56; tests route.rs:309, 323 |
|
CONTRACT.wire.md#endpoints-1 |
The table is the closed set of endpoints | conforms | v2/wire/route.rs:58-69; tests route.rs:196, 227 |
Rows come from the published Endpoint::ALL. |
CONTRACT.wire.md#endpoints-2 |
A method and path that match no row are UnknownEndpoint |
conforms | v2/wire/route.rs:55-70; tests route.rs:235, 255 |
|
CONTRACT.wire.md#endpoints-3 (table) |
Each row has its body limit and required client | conforms | tests v2/wire/route.rs:208, 217 |
Enforcing RequestTooLarge is the routes'. |
CONTRACT.wire.md#endpoints-4 |
A path matches only with the same characters, and {OperationId} matches one or more characters other than / |
conforms | v2/wire/route.rs:73-81; test route.rs:336 |
|
CONTRACT.wire.md#endpoints-5 |
A segment that is not an identifier names no operation | conforms | v2/wire/route.rs:66; test route.rs:356 |
|
CONTRACT.wire.md#errors-1 |
An error response has Code and Message always, and Decision, Management or Errors only with their codes |
conforms | v2/wire/error.rs:56-121 |
|
CONTRACT.wire.md#errors-1 (Message) |
Message is at most 2048 bytes |
conforms | v2/wire/error.rs:11, 36-45; tests error.rs:336, 353 |
|
CONTRACT.wire.md#errors-1 (Decision, Errors) |
NotRunnable carries an allowing decision; InvalidPolicy a non-empty list |
conforms | v2/wire/error.rs:93-95; tests error.rs:305, 311 |
|
CONTRACT.wire.md#errors-2 |
The table is the closed set of error codes, each with its HTTP status | conforms | v2/wire/error.rs:56-81; test error.rs:213 |
The match has no wildcard, so a new code fails to compile. |
CONTRACT.wire.md#errors-7 |
InternalError may replace an outcome of item 8 |
conforms | v2/wire/error.rs:112-120; test error.rs:286 |
Only codes of item 8 can fall back. |
CONTRACT.wire.md#package-request-1 |
A package request has the members of its two tables | conforms | v2/wire/read.rs:27-29; tests in read.rs |
Published PackageRequest. |
CONTRACT.wire.md#package-request-2 |
Scope Machine with Elevation NonElevated is BadRequest |
conforms | v2/wire/read.rs:27-43 |
Published check, for evaluation, execution and bypass requests. |
CONTRACT.wire.md#opt-ins-2 |
A key present asks for its opt-in; no OptIns, or {}, asks for none |
conforms | v2/wire/convert.rs:34-81; test convert.rs:654 |
|
CONTRACT.wire.md#opt-ins-3 (table) |
Each key has the value its row gives | conforms | v2/wire/read.rs:27-36; v2/wire/convert.rs:34-81; test convert.rs:733 |
|
CONTRACT.wire.md#equal-requests-1 |
Two package requests are equal when they have the same members with equal values, ignoring RequestId |
conforms | tests v2/wire/read.rs:1325, 1345, 1387; v2/execution/operations.rs:160 |
The registry compares the key its caller gives it. |
CONTRACT.wire.md#equal-requests-2 |
Strings by code points, lists in order, objects whatever their key order | conforms | tests v2/wire/read.rs:1325-1393 |
|
CONTRACT.wire.md#decision-1 |
A decision has Outcome, Check, Rules, OptIns, Audited |
conforms | v2/wire/convert.rs:128-147; tests convert.rs:831, 868 |
|
CONTRACT.wire.md#decision-2 |
A rule object has Id, and Reason only when the rule has one |
conforms | v2/wire/convert.rs:128-147; test convert.rs:887 |
|
CONTRACT.wire.md#evaluate-1 |
An evaluation request is a package request, and a RequestId in it is BadRequest |
conforms | v2/wire/read.rs:27-29; test read.rs:1115 |
|
CONTRACT.wire.md#execute-1 |
An execution request is a package request with a required RequestId, an identifier |
conforms | v2/wire/read.rs:34-36; test read.rs:1121 |
|
CONTRACT.wire.md#execute-2 (outcome 1) |
RequestIdConflict when the owner's held operation for the RequestId has an unequal request |
conforms | v2/execution/operations.rs:156-170, 300-303; test operations.rs:892 |
|
CONTRACT.wire.md#execute-2 (outcome 2) |
The replayed response when the requests are equal | conforms | v2/execution/operations.rs:156-170, 490-492; test operations.rs:846 |
|
CONTRACT.wire.md#execute-4 |
The broker starts one operation before writing the response, and its owner is the request's owner | conforms | v2/execution/operations.rs:292-422, 350 |
|
CONTRACT.wire.md#execute-5 |
A request that starts no operation leaves its RequestId unused |
conforms | v2/execution/operations.rs:485-492; test operations.rs:929 |
The registry takes an id only in start; operations.rs:285-287 tells the caller not to call it for NotRunnable. |
CONTRACT.wire.md#execute-7 |
A replayed response has the first response's values and the current Status; nothing is evaluated or started |
conforms | v2/execution/operations.rs:161-166; test operations.rs:846 |
|
CONTRACT.wire.md#execute-8 |
Requests of one owner with one RequestId arriving together start at most one operation |
conforms | v2/execution/operations.rs:296-303, 375-378 |
One acquisition of the lock covers lookup and insertion. UNTESTED: at 296-299. |
CONTRACT.wire.md#execute-9 |
Sending the request again gets the operation it started, while the broker holds it | conforms | v2/execution/operations.rs:156-170; test operations.rs:1149 |
|
CONTRACT.wire.md#execute-10 |
Once the broker no longer holds it, the request is evaluated again | conforms | v2/execution/operations.rs:497-509; test operations.rs:1309 |
|
CONTRACT.wire.md#bypass-2 |
The bypass body: Source optional for Install and Update and refused for Uninstall, no OptIns key but NoUpgrade, no Architecture |
conforms | v2/wire/read.rs:41-43; tests read.rs:1155, 1193, 1207 |
Published BypassRequest. |
CONTRACT.wire.md#bypass-reading-1 |
A bypass request with Source is read as the package request with the same members, without RequestId |
conforms | v2/wire/convert.rs:88-121; tests convert.rs:782, 793 |
|
CONTRACT.wire.md#bypass-reading-4 (listed name) |
Under a manager whose reading names its only source name, Source.Name is that name |
conforms | v2/wire/convert.rs:92-95; test convert.rs:810 |
The caller supplies the listed name. |
CONTRACT.wire.md#operations-1 |
Steps in order: stop processes, Pre, manager, Post, skipping an absent one |
conforms | v2/execution/plan.rs:86-102; executor/windows/mod.rs:432-517 |
Executor pre-existing. |
CONTRACT.wire.md#operations-2 |
The table is the closed set of statuses | conforms | v2/execution/operations.rs:34-67 |
|
CONTRACT.wire.md#operations-3 |
A status changes only Starting to Running, Starting or Running to Canceling, and non-terminal to terminal |
conforms | v2/execution/operations.rs:197-200, 474-482, 551-555; test operations.rs:1033 |
|
CONTRACT.wire.md#operations-4 |
A process that runs too long is stopped | conforms | executor/windows/process.rs:300-332 |
The limit is 3600 seconds per process (operation_tracker.rs:23); announcing it is the capabilities endpoint's. |
CONTRACT.wire.md#operations-5 |
With PrePostCommands and an elevated token, no step runs and the operation ends Failed |
conforms | v2/execution/plan.rs:56-58; v2/execution/operations.rs:338, 365-367; executor/windows/mod.rs:526-549; test operations.rs:1103 |
The token check runs before the first step (mod.rs:386, 434). UNTESTED: at plan.rs:51-55 and mod.rs:529-530. |
CONTRACT.wire.md#operations-6 |
An Update whose recorded source the broker has not read runs no step and ends Failed |
conforms | v2/execution/plan.rs:60-67; v2/execution/operations.rs:365-367; test operations.rs:1136 |
|
CONTRACT.wire.md#operations-7 |
A failure to stop a process is ignored | conforms | executor/windows/mod.rs:434-449 |
|
CONTRACT.wire.md#operations-8 |
When Pre cannot run, exits non-zero or runs too long, no later step runs and the operation ends Failed |
conforms | executor/windows/mod.rs:452-472; v2/execution/operations.rs:455-459 |
|
CONTRACT.wire.md#operations-9 |
When the manager cannot be launched or runs too long, no later step runs and the operation ends Failed |
conforms | executor/windows/mod.rs:479-488; process.rs:320-359; test operations.rs:773 |
A builder that refuses the request ends it the same way (operations.rs:346, 365-367). |
CONTRACT.wire.md#operations-9 (exit) |
When the manager exits on its own, Post runs, then Completed for code 0 and Failed otherwise, however Post ends |
conforms | executor/windows/mod.rs:493-519; v2/execution/operations.rs:434-450; tests operations.rs:712, 754 |
|
CONTRACT.wire.md#operations-11 |
An operation started outside this contract is not one of this contract | conforms | v2/execution/operations.rs:127-133 |
1.x operations are not in this registry. |
CONTRACT.wire.md#operations-12 |
The broker holds every non-terminal operation, and a terminal one for at least 300 seconds | conforms | v2/execution/operations.rs:24, 232-251, 497-509; tests operations.rs:1235, 1275 |
|
CONTRACT.wire.md#operations-13 |
Once not held, the OperationId is OperationNotFound and the RequestId is unused again |
conforms | v2/execution/operations.rs:503-508, 530-537; test operations.rs:1309 |
|
CONTRACT.wire.md#operations-14 |
A status or cancel request names an operation only for its owner | conforms | v2/execution/operations.rs:530-537, 544-549; tests operations.rs:949, 975 |
Subject to the owner comparison above. |
CONTRACT.wire.md#status-1 |
Status response members: Status, StartedAt, CompletedAt, ExitCode, Message with their conditions |
conforms | v2/execution/operations.rs:72-83, 197-205, 434-459, 469-483; tests operations.rs:712-790 |
ExitCode only when the executor returned an exit; Message cut to 2048 bytes. Writing the response is the routes'. |
CONTRACT.wire.md#cancel-2 |
A non-terminal operation becomes Canceling and runs no later step |
conforms | v2/execution/operations.rs:551-558; executor/windows/mod.rs:374-376, 446, 494-495; process.rs:120-123 |
|
CONTRACT.wire.md#cancel-3 |
Before the manager has exited, the running process is stopped and the operation ends Canceled |
conforms | executor/windows/process.rs:304-308, 355; v2/execution/operations.rs:451-454; test operations.rs:997 |
|
CONTRACT.wire.md#cancel-4 |
Once the manager has exited, Post is stopped or skipped and the operation ends as the exit decides |
conforms | executor/windows/mod.rs:493-519; test operations.rs:1033 |
|
CONTRACT.wire.md#cancel-5 |
The response's Status is Canceling when it was not terminal, the terminal status otherwise |
conforms | v2/execution/operations.rs:551-560; test operations.rs:1061 |
|
CONTRACT.wire.md#cancel-6 |
Sending a cancel request again has no other effect | conforms | v2/execution/operations.rs:552-557 |
|
CONTRACT.wire.md#event-channel-1 |
The broker creates the pipe before the response, and the response has no EventPipe when creating it fails |
conforms | v2/execution/operations.rs:313-322; event_channel.rs:600-627 |
|
CONTRACT.wire.md#execute-3 (EventPipe) |
EventPipe is 1 to 256 ASCII letters, digits, ., _ and - |
conforms | event_channel.rs:27, 38-40; v2/execution/operations.rs:310 |
The fixed prefix and op-<uuid>. |
CONTRACT.wire.md#event-channel-2 |
The pipe is the first instance of its name and allows no other | conforms | event_channel.rs:616-620 |
|
CONTRACT.wire.md#event-channel-3 (owner's user) |
A process of the owner's user opens the pipe for reading only | conforms | event_channel.rs:774-779, 785-802; test event_channel.rs:1309 |
Introduced for 2.0: the two privileged entries are read-only too. |
CONTRACT.wire.md#event-channel-4 |
The broker serves at most one connection | conforms | event_channel.rs:619, 647-655 |
|
CONTRACT.wire.md#event-channel-6 |
The channel closes after FINISH |
conforms | event_channel.rs:679-709 |
After up to 30 seconds for the client to drain. |
CONTRACT.wire.md#event-channel-7 |
The channel closes when no connection opened 60 seconds after the terminal status | conforms | event_channel.rs:565, 647-659 |
|
CONTRACT.wire.md#event-channel-9 |
The channel closes when the client closes its end | conforms | event_channel.rs:679-691 |
|
CONTRACT.wire.md#event-channel-11 |
Closing the channel never affects the operation | conforms | event_channel.rs:341-356 |
Producers become no-ops. |
CONTRACT.wire.md#frames-1 |
A frame is a 4-byte size, a 2-byte kind and a body, little-endian, of the kinds in the table | conforms | event_channel.rs:717-718 |
Published encoder and kind numbers, unchanged. |
CONTRACT.wire.md#frames-2 (HELLO) |
HELLO has major version 2 and minor version 0 |
conforms | event_channel.rs:530-536, 664-668; test event_channel.rs:1227 |
Introduced. |
CONTRACT.wire.md#frame-order-2 |
HELLO is the first frame and is sent once |
conforms | event_channel.rs:664-677 |
|
CONTRACT.wire.md#frame-order-3 |
STATUS_UPDATED follows each status change |
conforms | v2/execution/operations.rs:189-194; test operations.rs:1197 |
|
CONTRACT.wire.md#frame-order-4 |
At a terminal status: STATUS_UPDATED, then output read earlier, then FINISH last |
conforms | v2/execution/operations.rs:197-211; event_channel.rs:285-313; test operations.rs:1235 |
|
CONTRACT.wire.md#frame-order-5 |
Each stream is the Pre output and then the manager's |
conforms | executor/windows/mod.rs:459, 484, 504; v2/execution/operations.rs:340 |
The stop commands and Post are not captured. |
CONTRACT.wire.md#frame-order-6 |
Each stream is decoded as one UTF-8 sequence, with U+FFFD for each maximal ill-formed subpart | conforms | event_channel.rs:56-90, 117-125 |
Pre-existing. |
CONTRACT.wire.md#frame-order-7 |
A code point is never split across frames | conforms | event_channel.rs:134-156 |
|
CONTRACT.wire.md#frame-order-8 |
Dropped output is the oldest unsent of its stream, announced by an overflow frame before the next data frame or FINISH |
conforms | event_channel.rs:400-442, 464-475 |
|
CONTRACT.wire.md#frame-order-9 |
Overflow numbers count decoded bytes and use several frames when one cannot hold them | conforms | event_channel.rs:445-453 |
|
CONTRACT.wire.md#frame-order-10 |
No HELLO, STATUS_UPDATED or FINISH frame is dropped while the channel is open |
conforms | event_channel.rs:419-442 |
Only data frames are evicted. |
CONTRACT.wire.md#policy-errors-1 |
A policy error has Code and Pointer |
conforms | v2/wire/convert.rs:152-157, 264-277; test convert.rs:911 |
|
CONTRACT.wire.md#validation-1 |
A validation request has the one member Document, a string |
conforms | v2/wire/read.rs:48-50 |
|
CONTRACT.wire.md#replacement-1 |
A replacement request has ExpectedStoreToken, a store token, and Document |
conforms | v2/wire/read.rs:55-57 |
|
CONTRACT.policy.md#request-input-1 |
The evaluator's input is the well-formed package request without its RequestId |
conforms | v2/wire/convert.rs:12-32; tests convert.rs:599, 608, 721 |
|
CONTRACT.policy.md#reading-7 |
Custom parameters are passed as they are and in their order, neither split nor joined | conforms | v2/execution/plan.rs:219-225; command_builder/winget.rs:141-145; scoop.rs:50-54 |
As command elements; see the cannot-verify row for the executor's scripts. |
CONTRACT.policy.md#manager-winget-2 |
The id is passed whole as the value of --id, with --exact |
conforms | command_builder/winget.rs:55-62 |
|
CONTRACT.policy.md#manager-winget-4 |
--custom or --override, then Arguments, as two elements before the custom parameters |
conforms | command_builder/winget.rs:123-145; v2/execution/plan.rs:74-81; test plan.rs:307 |
Introduced. |
CONTRACT.policy.md#manager-winget-5 |
On an Uninstall the broker passes neither | conforms | command_builder/winget.rs:126; test v2/execution/plan.rs:357 |
Introduced. |
CONTRACT.policy.md#manager-winget-12 |
The scope is unknown when neither Scope nor --scope sets it |
conforms | command_builder/winget.rs:90-98; test v2/execution/plan.rs:375 |
No --scope without Scope. |
CONTRACT.policy.md#manager-scoop-9 |
The broker passes Package.Id alone for a manifest URL, and <Source.Name>/<Package.Id> otherwise |
conforms | command_builder/scoop.rs:143-180 |
Pre-existing. |
CONTRACT.policy.md#manager-powershell-2 |
The id is passed whole as the value of -Name |
conforms | command_builder/powershell.rs:77, 157 |
|
CONTRACT.policy.md#manager-powershell-3 |
Under PowerShell7, Source.Name is passed as -Repository to Update-PSResource |
conforms | command_builder/powershell.rs:158-162; test v2/execution/plan.rs:520 |
|
CONTRACT.policy.md#version-scheme-6 |
A version is a pre-release when it has a pre-release | conforms | v2/execution/plan.rs:125-153; test plan.rs:654 |
Used only to tell PowerShellGet and PSResourceGet to find the version the request names. |
INTENT.md#broker-limits-1 |
The broker never runs pre/post commands for a request that runs elevated | conforms | v2/execution/plan.rs:44-58; executor/windows/mod.rs:95-97, 545-549; test plan.rs:430 |
|
INTENT.md#broker-limits-2 |
An allowed request that asks for one runs nothing, and the refusal is not a decision | conforms | v2/execution/plan.rs:35-40, 56-58; v2/execution/operations.rs:365-367 |
Answering NotRunnable is the routes'. |
INTENT.md#rules-11 |
Pre-release is checked against the version, not a flag the client sends | conforms | v2/execution/plan.rs:112-123, 214 |
|
INTENT.wire.md#opt-ins-1 |
A request lists its opt-ins under OptIns, keyed like Grants and Forbids |
conforms | v2/wire/convert.rs:34-81, 250-262; test convert.rs:433 |
|
INTENT.wire.md#targeting-2 |
A user-scope request may run elevated | conforms | v2/execution/plan.rs:69-72; v2/execution/operations.rs:337-338; test plan.rs:394 |
|
INTENT.wire.md#targeting-3 |
Machine scope with a non-elevated run is a bad request, not silently elevated |
conforms | v2/wire/read.rs:27-43; v2/execution/operations.rs:337-338 |
|
INTENT.wire.md#fields-1 |
No pre-release flag, no channel, no source URL | conforms | v2/wire/read.rs:27-29; v2/execution/plan.rs:192-206, 214 |
Unknown members are refused; the 1.x builder request gets none of the three from the client. |
INTENT.wire.md#bypass-2 |
A bypass request is a 2.0 package request loosened only where remote use needs it | conforms | v2/wire/read.rs:41-43; v2/wire/convert.rs:88-121 |
|
INTENT.wire.md#encodings-2 |
A 2.0 request or response carries no version or kind field | conforms | v2/wire/read.rs:27-61; v2/wire/route.rs:58-69 |
Violations
- Closed-set value written as an object is read (
CONTRACT.wire.md#values-4,#json-4). Known. The contract requiresBadRequest; the published enums accept{"Install": null}. Fix: in now-policy-api, read a closed-set value from a JSON string only; then un-ignorev2/wire/read.rs:1096. - Leap second written with seconds
60(CONTRACT.wire.md#values-3,CONTRACT.policy.md#timestamps-2). Known. The contract allows seconds 00 to 59; the publishedTimestamp::from_datetimeprints what chrono holds. Fix: in now-policy-api, write a leap second as59with the largest fraction, or refuse it; then un-ignorev2/wire/convert.rs:1000.
Partials
- Owner path comparison (
CONTRACT.wire.md#def-owner-2). Required: the pinned simple uppercase mapping. Done: the standard library's mapping, which the code's ownUNTESTED:comment says differs. Fix: have now-policy-eval export its comparison (text.rssimple_uppercaseispub(crate)) and use it inv2/execution/owner.rs:60-66. - Image names the executor cannot pass (
CONTRACT.wire.md#opt-ins-4). Known. Required: every well-formed name is attempted. Done: names failingis_acceptable_kill_process_nameare skipped and logged. Fix: either the contract narrows the domain of an image name, or the executor passes any well-formed name totaskkill /IMas one literal. - Session and user filters on
taskkill(CONTRACT.wire.md#opt-ins-4). Required: astaskkill /F /IMdoes. Done: only processes of the caller's session, and of the caller on an elevated run. Fix: state the limit in the contract; dropping the filters would let an elevated run stop other users' processes. - Recorded source of an Update (
CONTRACT.policy.md#managers-4). Known. Required: read every record first and refuse on a mismatch. Done: refuse every Update underScoopandPowerShell. Fix: read the Scoop install record and the installed module's repository before the first step. - PowerShell uninstall depends on
Source.Name(CONTRACT.policy.md#managers-2). Required: no built command limits an uninstall to packages installed fromSource.Name. Done: the uninstall script throws unless the recorded repository isSource.Name. Fix: skipappend_installed_repository_checkfor an Uninstall built for a 2.0 request, or state the check in the contract. - Write deadline per frame (
CONTRACT.wire.md#event-channel-8). Required: close when a write made no progress for 30 seconds. Done: close when one frame is not fully written in 30 seconds. Fix: restart the deadline whenever bytes are accepted, or word the contract as a per-frame limit.
Cannot verify
CONTRACT.wire.md#operations-10: needs either a check of a new id against the ids held (operations.rs:310) or a contract wording that accepts random ids.CONTRACT.wire.md#event-channel-3: needs a test that opens a 2.0 pipe for reading and for writing as the local system and as an elevated administrator, as theUNTESTED:comment says.CONTRACT.policy.md#reading-10: needs each remaining builder and the executor's script wrappers compared with its manager's reading.INTENT.md#broker-limits-3: needs the Chocolatey builder read and the WinGet source property checked on a real system.
Not yet realised
INTENT.legacy.md#format-1-1: 1.x policy conversion (known).CONTRACT.wire.md#bypass-reading-4: the reading withoutSource.Name;bypass_package_requestreturnsNonefor it.CONTRACT.wire.md#event-channel-5: authenticating the reader of a bypass operation's channel.CONTRACT.wire.md#bypass-17: keeping bypass and executionRequestIds apart in the registry.
Outside this change
Listed once, not audited:
CONTRACT.wire.md: §transport except the query rule; enforcingRequestTooLarge; §authentication; the order of outcomes in §errors and answering without reading the body; §health; §capabilities; §policy-identity; the outcomes and responses of §evaluate and §execute other than replay and conflict; answeringNotRunnable; §bypass except its body (token, header, outcomes,ProtectedPackage, using up a token), the unreadable cases of §bypass-reading; §management and §management-state; what §validation and §replacement do with a request; every rule for clients.CONTRACT.policy.md: the policy document, its validation errors, rules, selections, trusted sources, evaluation, precedence, audit mode, properties and risk guidance; which requests each manager's reading makes unreadable, which the evaluator decides.INTENT.md: vocabulary, ownership, rules, trusted sources except the update record, decisions, fail-closed checks, remote operations, warnings.INTENT.wire.md: §replacement, the rest of §bypass, and the encoding of responses.INTENT.legacy.md: §wire-1.
Not covered by intent
- The 2.0 plan rewrites its request as a 1.x request for the command builders, with placeholders for the 1.x-only members, and calls helpers of the 1.x evaluator (
v2/execution/plan.rs:91,101,155-248).INTENT.legacy.mdasks that removing an earlier format leave the current reader and evaluator unchanged; it says nothing about the builders, which will need a new input type when the 1.x encoding goes. - With the exact token check, a
NonElevatedrequest withoutPrePostCommandsalso endsFailedwithout a step when the token obtained is elevated (executor/windows/mod.rs:531-533).CONTRACT.wire.mdstates this for bypass requests and forPrePostCommandsonly. - WinGet appends
--accept-package-agreementsafter the custom parameters (command_builder/winget.rs:147-149), so it follows a custom parameter that is exactly--, which the reading allows.
Related UNTESTED: comments
v2/execution/owner.rs:52-59, v2/execution/plan.rs:51-55, v2/execution/operations.rs:296-299, 305-309, event_channel.rs:745-755, executor/windows/mod.rs:529-530, command_builder/winget.rs:65-68, command_builder/scoop.rs:81-85.
Line numbers are those of ee58b28af; the commit after it on this branch adds three lines to v2/execution/operations.rs and two to v2/execution/plan.rs.
Note
LLM-assisted content (no human feedback).
Evidence, deviations and open pointsLines changed against #2229 (approximate split): production +1686 −48, tests +4058. Checks run on
|
There was a problem hiding this comment.
🟡 Changes recommended
Critical flaws can expose bypass output to unauthorized same-user processes, delete elevated Dotnet installs during cleanup, and leave operations hanging indefinitely.
16 open issues
Reject elevated Dotnet plans without a persistent install location · New Authenticate bypass clients before sending event frames · New Bound output-reader draining after process exit · New Reset the event-channel stall deadline after partial writes · New Separate request namespaces and include the bypass token · New Release the event sink when an operation finishes · New Apply the specified process matching behavior to 2.0 · New Check for natural manager exit before canceling · New Use Unicode simple uppercase for owner equality · New Support safe non-.exe image names in 2.0 · New Preserve absent sources for bypass requests · New Reject object-form values for closed API enums · New Share the manager dispatch table between command builders · New Reuse published operation status and message types · New Put each comment sentence on its own source line · New Move the nested helper after the function's final expression · New
What changed in this PR
Adds internal 2.0 request handling and operation execution to the Agent’s package broker, building on the policy evaluation work in #2229.
The /v2/ routes remain for a follow-up.
Changes:
- Adds request readers, endpoint matching, evaluator conversions and error response helpers.
- Introduces an owner-scoped operation registry with replay, cancellation, retention and 2.0 event channels.
- Extends command builders to accept explicit execution elevation and WinGet installer arguments.
| File | Description |
|---|---|
crates/now-package-broker/src/v2/wire/route.rs |
Matches methods and paths to 2.0 endpoints. |
crates/now-package-broker/src/v2/wire/read.rs |
Reads request bodies and tests contract rules. |
crates/now-package-broker/src/v2/wire/mod.rs |
Exports wire handling helpers. |
crates/now-package-broker/src/v2/wire/error.rs |
Builds contract-shaped error responses. |
crates/now-package-broker/src/v2/wire/convert.rs |
Maps wire and evaluator types. |
crates/now-package-broker/src/v2/execution/plan.rs |
Builds execution plans from evaluated requests. |
crates/now-package-broker/src/v2/execution/owner.rs |
Defines operation owner identity. |
crates/now-package-broker/src/v2/execution/operations.rs |
Tracks operation lifecycle and request replay. |
crates/now-package-broker/src/v2/execution/mod.rs |
Exports execution types and registry. |
crates/now-package-broker/src/v2/execution.rs |
Removes the placeholder module file. |
crates/now-package-broker/src/event_channel.rs |
Adds 2.0 announcements, access rules and unwind-safe notifications. |
crates/now-package-broker/src/command_builder/winget.rs |
Supports installer arguments before custom parameters. |
crates/now-package-broker/src/command_builder/vcpkg.rs |
Validates explicit execution elevation. |
crates/now-package-broker/src/command_builder/scoop.rs |
Validates explicit execution elevation. |
crates/now-package-broker/src/command_builder/powershell.rs |
Passes explicit elevation through PowerShell builders. |
crates/now-package-broker/src/command_builder/pip.rs |
Validates explicit execution elevation. |
crates/now-package-broker/src/command_builder/npm.rs |
Validates explicit execution elevation. |
crates/now-package-broker/src/command_builder/mod.rs |
Adds dispatch for explicit elevation and installer arguments. |
crates/now-package-broker/src/command_builder/cargo.rs |
Validates explicit execution elevation. |
crates/now-package-broker/src/command_builder/bun.rs |
Validates explicit execution elevation. |
Review effort: Max (adaptive)
| match request.manager { | ||
| ManagerName::Bun => bun::build_bun_command_as(request, elevation), | ||
| ManagerName::Cargo => cargo::build_cargo_command_as(request, elevation), | ||
| ManagerName::Dotnet => dotnet::build_dotnet_command(request), |
| let (events, event_pipe, channel_error) = | ||
| match open_operation_channel_announcing(ChannelVersion::V2_0, &operation_id, user_sid) { | ||
| Ok((sink, channel)) => (Some(sink), Some(channel.path), None), |
| capture_output: true, | ||
| cancel_token: cancel.clone(), | ||
| event_sink: events.clone(), |
| tokio::spawn(async move { | ||
| run_channel(server, writer_sink, &operation_id).await; | ||
| run_channel(version, server, writer_sink, &operation_id).await; |
| /// The id of the operation each request id of an owner started. | ||
| /// | ||
| /// INVARIANT: Every value is a key of `operations`, and every operation has exactly one entry here. | ||
| request_ids: HashMap<(Owner, String), String>, |
| fn read<T: DeserializeOwned>(body: &[u8]) -> Result<T, BadRequest> { | ||
| serde_json::from_slice(body).map_err(|_| BadRequest) |
| pub(crate) fn build_command_as( | ||
| request: &PackageRequest, | ||
| elevation: Elevation, | ||
| installer_arguments: Option<winget::InstallerArguments<'_>>, | ||
| ) -> anyhow::Result<Vec<String>> { | ||
| match request.manager { |
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum Status { | ||
| /// The operation was started, and its manager process has not been launched. | ||
| Starting, | ||
| /// The operation has launched its manager process. | ||
| Running, | ||
| /// The operation was asked to cancel and has not ended. | ||
| Canceling, | ||
| /// The operation ended after its manager process exited on its own with code 0. | ||
| Completed, | ||
| /// The operation ended otherwise. | ||
| Failed, | ||
| /// The broker ended the operation on a cancel request. | ||
| Canceled, |
| // Nothing here may panic: this runs while a panic of the task unwinds, where a second panic aborts the | ||
| // broker. The registry lock is never poisoned, and the event sink takes a status update and a finish without | ||
| // panicking, even on a queue whose lock a panic poisoned. |
| fn is_pre_release(version: &str) -> bool { | ||
| fn is_numeric(text: &str) -> bool { | ||
| text.bytes().all(|byte| byte.is_ascii_digit()) | ||
| } | ||
|
|
||
| let version = version.strip_prefix(['v', 'V']).unwrap_or(version); | ||
| // The build metadata may have a `-`, which starts no pre-release. | ||
| let (version, build_metadata) = version.split_once('+').unwrap_or((version, "")); | ||
| let Some((release, pre_release)) = version.split_once('-') else { | ||
| return false; | ||
| }; | ||
|
|
||
| release | ||
| .split('.') | ||
| .all(|component| !component.is_empty() && is_numeric(component)) | ||
| && pre_release.split('.').all(|identifier| { | ||
| !identifier.is_empty() | ||
| && identifier | ||
| .bytes() | ||
| .all(|byte| byte.is_ascii_alphanumeric() || byte == b'-') | ||
| && !(is_numeric(identifier) && 1 < identifier.len() && identifier.starts_with('0')) | ||
| }) | ||
| && build_metadata | ||
| .bytes() | ||
| .all(|byte| byte.is_ascii_alphanumeric() || byte == b'-' || byte == b'.') | ||
| } |
…equests-7702d2 The evaluator's request now has an optional source, so the conversion of a package request gives it one, and the plan of an operation hands a request without one to the command builders as the request that leaves the choice of source to its manager. The API types at the new revision read a closed-set value from a string only and refuse a timestamp of a leap second, so the two tests that waited for that run. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ames a source The contract has an Update end Failed for an unread record of its source only when the Update has a source. An Update without one names no source that a record could differ from, so the plan no longer refuses it for that reason. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A request without a source leaves the choice of source to its manager. The builders read a 1.x request, where an empty source name builds no install, so the plan now tells them that the request has no source instead of handing them an empty name. Such a request gets the command of the only source name of its manager where the manager has one, and otherwise a command that passes no source: no `--source` for WinGet and Chocolatey, no `-Repository` for PowerShell. A request that names its source builds the command it built before. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ource Without a source the request names no bucket, so the command passes the package id alone and Scoop looks it up in its buckets. An update is built too: the builder refuses the update of a request that names a bucket because Scoop updates from the bucket recorded at install, and a request without a source names no bucket for that record to differ from. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ource Without a source the request names no triplet, so the command passes the package id as it is: Vcpkg acts on the triplet the id carries, or on its default triplet when the id carries none. A request that names its source with an empty name still needs a triplet in its package id. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…r what decides it The builders decide which managers get no elevated command, so the test guards their refusal against a change that would lift it for a request that names no source. Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… is written for Issue: DGW-499 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Update for head Checks run locallyRun on
The tests of this head on its own are left to CI. What changed
|
There was a problem hiding this comment.
🟡 Changes recommended
Bypass output is exposed to other same-user executables, output draining can hang operations indefinitely, and temporary-profile cleanup can delete successful elevated .NET tool installations.
19 open issues
Reject elevated .NET requests without a persistent install destination · New Bound output-reader draining after process exit Authenticate bypass clients before sending event frames Reject elevated Dotnet plans without a persistent install location Skip the repository guard for 2.0 manager uninstalls · New Reject object-form values for closed API enums Preserve absent sources for bypass requests Support safe non-.exe image names in 2.0 Use Unicode simple uppercase for owner equality Check for natural manager exit before canceling Apply the specified process matching behavior to 2.0 Release the event sink when an operation finishes Separate request namespaces and include the bypass token Reset the event-channel stall deadline after partial writes Put each comment sentence on its own source line · New Move the nested helper after the function's final expression Put each comment sentence on its own source line Reuse published operation status and message types Share the manager dispatch table between command builders
Review effort: Max (adaptive)
| match request.manager { | ||
| ManagerName::Bun => bun::build_bun_command_as(request, source, elevation), | ||
| ManagerName::Cargo => cargo::build_cargo_command_as(request, source, elevation), | ||
| ManagerName::Dotnet => dotnet::build_dotnet_command_with(request, source), |
| let source = match request.source { | ||
| Some(_) => SourceChoice::Request, | ||
| None => SourceChoice::Manager, | ||
| }; |
| //! The run's elevation, the WinGet installer arguments and the absence of a source, which a 1.x request does not | ||
| //! state, are passed beside it. |
|
The point the earlier comment listed as waiting for a decision is settled, with no change to the code: PowerShell 7 keeps Note LLM-assisted content (no human feedback). |
There was a problem hiding this comment.
🟡 Changes recommended
Critical security gaps let other same-user executables read bypass output and allow elevated operations to use unchecked installation destinations.
26 open issues
Restrict inherited capture handles to each child process · New Preserve the manager's raw exit code for 2.0 operations · New Ensure cancellation stops the manager process · New Reject unacceptable install paths before building the command · New Reject elevated .NET requests without a persistent install destination Bound output-reader draining after process exit Authenticate bypass clients before sending event frames Reject elevated Dotnet plans without a persistent install location Match the specified process-kill scope without a session filter · New Use the pinned Unicode 16 simple-uppercase mapping · New Skip the repository guard for 2.0 manager uninstalls Reject object-form values for closed API enums Preserve absent sources for bypass requests Support safe non-.exe image names in 2.0 Use Unicode simple uppercase for owner equality Check for natural manager exit before canceling Apply the specified process matching behavior to 2.0 Release the event sink when an operation finishes Separate request namespaces and include the bypass token Reset the event-channel stall deadline after partial writes
And 6 more that still need to be addressed.
Review effort: Max (adaptive)
| // The request states the elevation of its run, which the scope never lowers. | ||
| token_elevation_check: TokenElevationCheck::Exact, | ||
| custom_install_location: plan.custom_install_location, | ||
| capture_output: true, |
| info!(%operation_id, exit_code = output.exit_code, "Manager process exited"); | ||
| if output.exit_code == 0 { | ||
| (Status::Completed, Some(0), None) |
| // The executor runs no later step once the token is canceled, and stops the process that is running. | ||
| record.cancel.cancel(); |
| Elevation::NonElevated => v1::Elevation::Standard, | ||
| Elevation::Elevated => v1::Elevation::Elevated, | ||
| }; | ||
| let builder_request = builder_request(request, elevation); |
| post_command: plan.post_command, | ||
| effective_user: caller.display_name.clone(), | ||
| user_sid: user_sid.clone(), | ||
| session_id: caller.session_id, |
| fn simple_uppercase(character: char) -> char { | ||
| let mut mapping = character.to_uppercase(); | ||
| match (mapping.next(), mapping.next()) { | ||
| (Some(upper), None) => upper, | ||
| _ => character, | ||
| } |
| fn truncated(mut text: String, max_bytes: usize) -> String { | ||
| if max_bytes < text.len() { | ||
| let mut end = max_bytes; | ||
| while !text.is_char_boundary(end) { | ||
| end -= 1; | ||
| } | ||
| text.truncate(end); | ||
| } | ||
| text | ||
| } |



Temporary git dependencies, each of which must become a crates.io version before this merges (introduced by the pull request this one builds on, unchanged here):
now-policy,now-policy-apiandnow-policy-server-template:[patch.crates-io]in the rootCargo.toml, onDevolutions/now-librariesat5b23b1a616ca97590d4d6b9e610cd07772d30453.now-policy-eval: a dependency ofcrates/now-package-broker, same repository at25e75110c067239e44e42f005abbf566f32f803a.Builds on #2229, which builds on #2224, #2225 and #2226.
The package broker reads the bodies of the 2.0 request encoding and runs the operations they start.
No route serves them yet: the
/v2/endpoints follow in the pull request stacked on this one, and the 1.x routes do not change.A body is read into the published
now_policy_api::v2types by a reader that applies the contract's reading rules those types do not: a repeated key, a key spelled with other characters, a byte order mark or a member outside the tables of the request make the body a bad request.The broker converts a request it read to the evaluator's request and a decision back to the published response, matches a method and path to an endpoint with its body limit and the client it requires, and builds error responses whose code, status and members come from the contract's table.
Operations started by 2.0 requests live in their own registry.
The owner of an operation is the SID of the caller and the path of its executable, compared without case, and an operation of another owner is one the broker does not hold.
A
RequestIdreplays the first response to an equal request, conflicts with an unequal one, and stays unused when the request started nothing.An operation goes through the statuses of the contract, is held for at least 300 seconds once it ended, and tells each status change on an event channel that announces version 2.0 and that its user can open only for reading.
The plan of an operation follows the manager readings of
CONTRACT.policy.md:Scope.Elevated, whatever its scope.PreorPostcommands never gets a plan for an elevated run: the operation runs no step and endsFailed.Failed.now_policy_api::v2types on the wire,now_policy_eval::Requestfor evaluation and planningv2::wire::convert:evaluator_request_has_every_member_of_the_package_request,evaluator_request_asks_for_exactly_the_opt_ins_of_the_package_request,decision_is_written_with_the_members_of_its_tablev2::wire::read:repeated_key_is_bad_request_in_every_request,body_with_byte_order_mark_is_bad_request,evaluation_request_outside_its_tables_is_bad_request,execution_request_is_a_package_request_with_a_request_id,bypass_request_outside_its_tables_is_bad_request,replacement_request_outside_its_table_is_bad_requestv2::wire::route:every_row_is_matched_by_its_method_and_path,every_row_has_the_body_limit_of_the_table,table_has_every_endpoint;v2::wire::error:every_code_has_the_http_status_of_the_table,message_has_at_most_2048_bytesv2::execution::owner:owners_with_one_sid_and_paths_differing_only_in_case_are_the_same,owners_whose_paths_differ_beyond_simple_uppercase_mappings_are_different;operations:the_operation_of_another_owner_is_one_the_broker_does_not_hold,a_request_id_belongs_to_its_owneroperations: the registry holds only what 2.0 requests started; the routes that prove it end to end are in the next pull requestoperations:an_equal_request_with_the_same_id_replays_the_first_response_with_the_current_status,an_unequal_request_with_the_same_id_conflicts_and_starts_nothing,a_cancel_request_makes_an_operation_canceling_until_the_broker_has_stopped_it,an_ended_operation_is_held_for_300_secondsevent_channel:the_channel_of_a_2_0_operation_announces_version_2_0,the_user_of_a_2_0_operation_opens_its_pipe_for_reading_and_never_for_writing,the_pipe_of_a_1_x_operation_grants_the_local_system_and_administrators_full_controlPreorPostcommands for an elevated runplan::pre_post_commands_never_get_a_plan_for_an_elevated_run;operations::pre_post_commands_for_an_elevated_run_end_the_operation_failed_without_a_stepFailedwithout a stepplan::an_update_from_a_recorded_source_gets_no_plan_while_the_record_is_not_read,only_an_update_waits_for_the_record_of_its_source,an_update_without_a_source_waits_for_no_record;operations::an_update_from_a_recorded_source_the_broker_has_not_read_ends_failed_without_a_stepplan:winget_install_and_update_pass_installer_arguments_before_custom_parameters,winget_uninstall_passes_no_installer_argumentsScopeplan::winget_without_scope_passes_no_scope_optionplan:a_request_without_a_source_gets_the_command_of_the_only_source_name_of_its_manager,a_command_without_a_source_is_the_one_of_a_source_without_its_source_option,a_powershell_command_without_a_source_names_its_module_and_no_repository,a_scoop_command_without_a_source_passes_the_package_id_alone,a_vcpkg_command_without_a_source_passes_the_package_id_as_it_is;command_builder::scoop,command_builder::vcpkgv2::wire::read::closed_set_value_written_as_an_object_is_bad_request,v2::wire::convert::timestamp_of_a_leap_second_has_seconds_up_to_59Issue: DGW-499
Changelog: ignore
🤖 Generated with Claude Code