From 3dfdd4555431991719b072dac47bd5967ac79883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Wed, 2 Dec 2026 02:02:48 +0900 Subject: [PATCH 1/6] docs(agent): run package operations via bypass route The 2.0 broker runs a remote package operation from a request that the Agent writes and authorizes with a bypass token, so the Agent need not refuse the requests that the 1.x grant route cannot express, such as Chocolatey operations, machine scope outside WinGet, or installs without a source. Specify the ExecuteBypassRequest registration-pipe command, through which UniGetUI forwards the Agent's request and token to the bypass route unchanged; how the Agent maps each Authority field into that request; how it gives and withdraws tokens; and how it turns what the broker shows into an operation result. A UniGetUI that answers UnsupportedCommand gets the operation on the grant route instead, once the Agent has withdrawn the unused token, so no operation runs twice. The Authority request and result are unchanged. Issue: DGW-512 Co-Authored-By: Claude Opus 5.5 --- .../CONTRACT.package-management.md | 186 ++++++++++++++---- 1 file changed, 145 insertions(+), 41 deletions(-) diff --git a/crates/agent-channel-proto/CONTRACT.package-management.md b/crates/agent-channel-proto/CONTRACT.package-management.md index f9409a877..dbda73346 100644 --- a/crates/agent-channel-proto/CONTRACT.package-management.md +++ b/crates/agent-channel-proto/CONTRACT.package-management.md @@ -14,6 +14,8 @@ The UniGetUI IPC and broker request details below describe cross-component behav - **Instance**: one running UniGetUI process and its IPC endpoint. - **Target user SID**: the Windows user SID whose session supplies the UniGetUI instance for an operation. - **Scope**: proven user or machine installation ownership, or unknown when ownership cannot be established. +- **Bypass token**: the single-use authorization that the Agent gives the Broker for one request on the bypass route, as [`CONTRACT.wire.md §def-bypass-token`][wire def bypass token] defines it. +- **Grant**: the single-use authorization that the Agent mints for one request on the grant route. ## Channel @@ -38,8 +40,8 @@ The extension framing and any UniGetUI-to-Broker request details not specified b | `InventoryUnavailable` | Agent to Authority | `target_user_uuid`, `registry_epoch`, `reason` | | `InstalledPackage` | Agent to Authority | `manager`, `source`, `source_name`, `id`, `name`, `version`, `available_version`, `scope`, `reported_scope` | | `PackageOperationRequest` | Authority to Agent | `operation_id`, `type`, `manager`, `source`, `package_id`, `version`, `scope`, `target_user_uuid`, `registry_epoch`, `reported_scope` | -| `UniGetUIOperationRequest` | Agent to UniGetUI | `operation`, `grant` | -| `BrokerOperationRequest` | UniGetUI to Broker | `operation`, `grant` | +| `UniGetUIOperationRequest` | Agent to UniGetUI | `request` and `token`, or `operation` and `grant` | +| `BrokerOperationRequest` | UniGetUI to Broker | `request` and `token`, or `operation` and `grant` | | `PackageOperationResult` | Agent to Authority | `operation_id`, `success`, `error`, `status`, `execution_started` | User UUIDs and registry epochs are non-nil UUIDs encoded as lowercase hyphenated strings. @@ -60,7 +62,7 @@ Agent and Authority versions that do not both enforce the UUID and epoch fields Remote inventory and remote writes have separate Agent configuration switches, both enabled by default. They are `DeviceManagement.RemoteInventoryEnabled` and `DeviceManagement.RemoteWritesEnabled` in the Agent configuration. When inventory is disabled, the Agent reports `SAFE_ENDPOINT_UNAVAILABLE` without querying UniGetUI. -When writes are disabled, the Agent rejects a new operation without contacting UniGetUI or issuing a grant. +When writes are disabled, the Agent rejects a new operation without contacting UniGetUI, giving the Broker a bypass token or issuing a grant. Previously journaled operation IDs retain their recorded status. Neither switch disables discovery. @@ -89,7 +91,7 @@ The Authority stores and selects the target user UUID and may display a safe use Every package operation includes a target user UUID, including a machine-scope operation. The Agent maps a known UUID to a user SID and resolves a live instance for that user when it executes the request. It rejects a missing, malformed, nil or unknown user UUID, or a request for a different registry epoch, before Broker execution. -While its operation journal retains the operation ID, the Agent sends the write at most once to one resolved instance and does not retry it against that or another endpoint. +While its operation journal retains the operation ID, the Agent sends the write at most once to one resolved instance and does not retry it against that or another endpoint, except for the fallback of `CONTRACT.package-management.md §bypass-route`, which follows proof that the first send can start nothing. Inventory covers the package managers and scopes exposed by UniGetUI. Remote writes are limited to operations supported by the existing package broker and fail closed when unsupported. Remote writes never fall back to local package execution. @@ -111,7 +113,7 @@ Restoring an older mapping store with the same epoch can lose mappings without a UniGetUI connects to `\\.\pipe\Devolutions.Now.PackageBroker.Registration.v1`, served by the Broker inside the `DevolutionsAgent` service. It is separate from the Broker execution pipe, which serves one HTTP request per connection from a small shared pool, so held connections would starve it. -Grant execution stays on the Broker execution pipe. +Grant and bypass execution stay on the Broker execution pipe. The Agent creates the first instance with `FILE_FLAG_FIRST_PIPE_INSTANCE`; if that fails, registration is unavailable and discovery reports `COLLECTION_FAILED`. The pipe rejects remote clients, and its DACL denies NETWORK access while granting SYSTEM and Administrators full control and `BUILTIN\Users` only `FILE_GENERIC_READ` and `FILE_WRITE_DATA`, never `FILE_APPEND_DATA`, which for pipes is `FILE_CREATE_PIPE_INSTANCE`. UniGetUI opens the pipe with `GENERIC_READ | FILE_WRITE_DATA` and `SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION`. @@ -140,8 +142,8 @@ UniGetUI must be installed for all users in an administrator-protected directory The Agent logs the reason when those checks reject a registration. Signature verification uses the retained image file and rejects a different signed file substituted at its path. Values that UniGetUI reports about itself are never used for identity or targeting. -The client process ID identifies only the process that connected; same-user code may be able to duplicate the connected handle and read or write later frames, including `Request` arguments that carry a grant. -Such a process may redeem a grant only for its bound SID and effectful payload. +The client process ID identifies only the process that connected; same-user code may be able to duplicate the connected handle and read or write later frames, including `Request` arguments that carry a grant or a bypass token. +Such a process may redeem a grant or a bypass token only for its bound SID and effectful payload. An operation response on this connection alone does not establish the operation's outcome. Registration does not prove which process sends a later frame. @@ -150,7 +152,7 @@ Registration does not prove which process sends a later frame. Each frame is a 4-byte unsigned little-endian length `N`, followed by `N` bytes of a UTF-8 JSON object. `N` is 1 to 1,048,576; a frame outside that range, invalid JSON, a missing `kind` or an unknown `kind` closes the connection. Unknown members in a frame envelope or non-operation command are ignored and are never interpreted or forwarded. -For `ExecutePackageOperation` arguments, `CONTRACT.package-management.md §operations` takes precedence. +For `ExecuteBypassRequest` and `ExecutePackageOperation` arguments, `CONTRACT.package-management.md §operations` takes precedence. All identifiers are lowercase hyphenated UUIDs. | `kind` | Direction | Members | @@ -174,13 +176,14 @@ UniGetUI answers each `Request` with exactly one `Response` carrying the same `i Responses may arrive in any order, and the Agent has at most 8 outstanding requests per connection. `error` has a `code` string and a `message` string of at most 2,048 characters with no credentials, local paths or captured output. `code` is `UnsupportedCommand`, `InvalidArguments`, `Busy` or `Failed`. -An unlisted command receives `UnsupportedCommand` without starting work. +An unlisted command receives `UnsupportedCommand`, and UniGetUI answers `UnsupportedCommand` only to a request for which it started no work. | `command` | `arguments` | `result` | | --- | --- | --- | | `GetInventorySnapshot` | none | `{ "completedAt": string, "updateCompletedAt": string or null, "managers": array, "sources": array, "installedPackages": array, "updates": array }` | | `RescanInventory` | none | `{}` | | `ExecutePackageOperation` | `operationId`, `brokerRequestId`, `operation`, `manager`, `sourceName`, `packageId`, `version`, `scope`, `reportedScope`, `grant` | `{ "status": "Succeeded" \| "Failed" \| "Unknown", "error": string }` | +| `ExecuteBypassRequest` | `operationId`, `request`, `token` | `{}` | Each `GetInventorySnapshot.managers` item has exactly the members `name`, `displayName`, `enabled`, `ready`, `notificationsSuppressed`, `executablePath`, `executableArguments`, `capabilities` and `health`. `name` and `displayName` are strings, and `enabled`, `ready` and `notificationsSuppressed` are booleans. @@ -199,6 +202,7 @@ An installed-package item may omit `systemRestartPending` when no value was capt `updateCompletedAt` may be omitted or null when no complete update scan is available; in that case, `updates` is empty. When UniGetUI cannot produce the installed snapshot required by `CONTRACT.package-management.md §inventory`, it answers `Failed` or `UnsupportedCommand` without a snapshot. `CONTRACT.package-management.md §inventory-rescan` specifies `RescanInventory`. +`CONTRACT.package-management.md §bypass-route` specifies `ExecuteBypassRequest`. `operation` is `Install`, `Update` or `Uninstall`; `version` is empty when not requested. `scope` is the administrator's requested execution scope, `User` or `Machine`. `sourceName` is empty for uninstall and may be empty for update, as specified in `CONTRACT.package-management.md §operations`. @@ -317,14 +321,14 @@ Besides listing installed packages and available updates, a rescan only refreshe A Reload is the reload of the package lists that the UniGetUI user requests. The package-index refresh a Reload performs runs only for managers whose refresh updates a catalogue and nothing else, and is skipped for any manager whose refresh updates the manager itself or a working tree. -The Agent sends `RescanInventory` when a package operation that it sent to UniGetUI as `ExecutePackageOperation` reaches its final result, whether success, failure or `UNKNOWN`. +The Agent sends `RescanInventory` when a package operation that it sent to UniGetUI as `ExecuteBypassRequest` or `ExecutePackageOperation` reaches its final result, whether success, failure or `UNKNOWN`. It sends the request on the connection that carried the operation, after it recorded the result in its operation journal and before it reports the result to the Authority. When that connection is closed, the Agent sends no `RescanInventory`, including on another connection of the same instance. -The Agent waits for the response at most 3 minutes from recording the result, including the time the request is held unsent, and no longer than until 30 minutes after it sent the operation's `ExecutePackageOperation`. +The Agent waits for the response at most 3 minutes from recording the result, including the time the request is held unsent, and no longer than until 30 minutes after it sent the operation's last command, `ExecuteBypassRequest` or, after a fallback, `ExecutePackageOperation`. The wait ends when the response arrives, when the connection closes or when that time has passed, and the Agent then reports the result. On an error response, including the `UnsupportedCommand` that `CONTRACT.package-management.md §registration` specifies for a command UniGetUI does not list, the Agent ends the wait without sending another `RescanInventory`. The response never changes the reported result: a rejected, unanswered or unsent `RescanInventory` only delays the report by the time the Agent waited. -The Agent also sends no `RescanInventory` when it could not record the result in its operation journal, when the operation's `ExecutePackageOperation` was never written to the connection, when the delivery repeats an operation ID, when remote inventory is disabled, when the Agent service is already stopping once the result is recorded, or when the connection already has 8 outstanding requests. +The Agent also sends no `RescanInventory` when it could not record the result in its operation journal, when none of the operation's commands was written to the connection, when the delivery repeats an operation ID, when remote inventory is disabled, when the Agent service is already stopping once the result is recorded, or when the connection already has 8 outstanding requests. When 8 operations are already waiting for a rescan, the Agent reports a further operation's result without sending `RescanInventory`. The Authority does not infer from an operation result that a rescan completed. An inventory request after the result still returns the last completed scan, as `CONTRACT.package-management.md §inventory` specifies. @@ -341,31 +345,132 @@ When the Agent service stops during the wait, the Agent stops waiting, and the r ## Package operations +The Agent runs each package operation on the bypass route, `CONTRACT.package-management.md §bypass-route`, on which UniGetUI forwards a request that the Agent wrote. +It runs an operation on the grant route, `CONTRACT.package-management.md §grant-route`, on which UniGetUI builds the request from the operation's fields, only as the bypass route's fallback for a UniGetUI that lacks the bypass route's command. +The operation type is exactly one of `install`, `update` or `uninstall`. +An install may replace an existing installation when the manager cannot prevent it. +The Authority-to-Agent request contains an operation ID, operation type, manager, source, package ID, requested version when applicable, scope, target user UUID, registry epoch and selected row's reported scope when applicable, but no bypass token. +An update may name its current execution feed or leave the source empty to use the manager's normal default feed. +Uninstall uses no feed and carries an empty source. +`PackageOperationRequest.reported_scope` is optional string field 11 and is present for update and uninstall, even when empty, and absent for install. +The Authority copies that field from the selected observation without changing it. +The Agent rejects an update or uninstall when that field is absent. +The Agent accepts Broker manager names ignoring ASCII case and maps the inventory IDs `winps`, `pwsh` and `dotnet-tool` to `PowerShell`, `PowerShell7` and `Dotnet`, respectively, also ignoring ASCII case. +Broker manager names are spelled as the manager identifiers of [`CONTRACT.policy.md §managers`][policy managers]. +An alias without an agreed mapping is rejected. + +The Agent and the Broker refuse every remote uninstall that names the Devolutions Agent, and no local policy, setting or grant lifts this rule. +An uninstall names the Devolutions Agent when its manager and package ID are WinGet `Devolutions.Agent` or Chocolatey `devo-agent`, compared ignoring ASCII case after removing from the package ID a reference suffix that starts at its first `#` and then a version suffix that starts at its last `@`. +A WinGet uninstall also names it when its package ID contains the product code of the installed Devolutions Agent MSI in hyphenated form, compared ignoring ASCII case. +When the Agent cannot read the installed product code, it refuses every uninstall with the known failure `cannot verify that the operation does not uninstall the Devolutions Agent: nothing was started`. +Otherwise, it refuses an uninstall that names the Devolutions Agent with the known failure `the Devolutions Agent cannot be uninstalled remotely: nothing was started`. +The Agent decides both refusals before it gives the Broker a bypass token or mints a grant, and each is the reported failure even when the Broker, the target user or every UniGetUI instance is unavailable. +An uninstall that the Agent does not admit, that arrives while remote writes are disabled, or that the Agent rejects as invalid gets the result of that check instead, and nothing is started for it either. +Unlike the capacity failures, the Agent records both refusals, so a repeated delivery of the operation ID returns the recorded failure. +The Broker applies the same rule on the grant route without consulting local policy, before it consumes a grant. +When the Broker cannot read the installed product code, it rejects every `Uninstall` grant request with HTTP 422, `Code` `ValidationFailed` and the `Message` `the package broker cannot verify that the request does not uninstall the Devolutions Agent`. +Otherwise, it rejects an `Uninstall` grant request that names the Devolutions Agent with the same status and code and the `Message` `the package broker does not uninstall the Devolutions Agent`. +On the bypass route, the Broker refuses the same uninstalls, including every uninstall while it cannot read the installed product code, with `ProtectedPackage` ([`CONTRACT.wire.md §protected-package`][wire protected package]), without using the bypass token. +A remote install or update of the Devolutions Agent is not refused by this rule. + + +### Bypass route + +On the bypass route, the Agent writes a bypass request, gives the Broker a bypass token bound to it, and has UniGetUI send the request unchanged to the Broker's `POST /v2/package-requests/execute-bypass`, as [`CONTRACT.wire.md §bypass`][wire bypass] specifies. +The Broker runs the request without consulting local policy, and its reading of the request ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]) decides what runs, so the Agent checks only what it needs to write the request. + +The bypass request is a JSON object with exactly the members of this table, which the Agent takes from the Authority request. + +| Member | Value | +| --- | --- | +| `RequestId` | a new random UUID in lowercase hyphenated form | +| `Operation` | `Install`, `Update` or `Uninstall`, the operation type | +| `Manager` | the canonical Broker name of the manager, as `CONTRACT.package-management.md §operations` maps it | +| `Source` | for an install or update with a nonempty source, an object whose only member is `Name`, the source; absent otherwise | +| `Package` | an object whose members are `Id`, the package ID, and, for an install or update with a nonempty requested version, `Version`, that version | +| `Scope` | `User` for the scope `user`, and `Machine` for the scope `machine` | +| `Elevation` | `NonElevated` for the scope `user`, and `Elevated` for the scope `machine` | +| `OptIns` | for a WinGet install, an object whose only member is `NoUpgrade`, whose value is `{}`; absent otherwise | + +The Agent compares the scope with `user` and `machine` ignoring ASCII case and rejects any other scope. +The scope is the only elevation choice that the Authority request makes, so a machine-scope operation runs as administrator, a user-scope operation runs with the target user's own rights, and the Agent never writes `Elevation` `Elevated` with `Scope` `User`. +An uninstall's request has no `Source` and no `Package.Version`, whatever source and requested version the Authority sent, and [`CONTRACT.wire.md §bypass`][wire bypass] forbids `Source` on an uninstall. +An install or update without a source has no `Source`, which leaves the choice of source to the manager. +`NoUpgrade` keeps a WinGet install from replacing an existing installation, as on the grant route. +The Agent rejects an operation whose package ID, or whose source or requested version when the request carries it, is outside the domain that [`CONTRACT.wire.md §package-request`][wire package request] gives the member it fills, so that it never sends a request that the Broker answers `BadRequest`. +It does not check whether the Broker can read the request, such as an elevated install or update without `Source` ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]), and the outcome table below covers the Broker's answer. + +The Agent generates each bypass token from a cryptographically secure random source, with at least 128 random bits, in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token, so that no process can guess a token it was not given. +It gives the Broker the token in process, bound to the bypass request, `RequestId` included, and to the SID of the target user, as [`CONTRACT.wire.md §bypass`][wire bypass] expects. +It gives the Broker each token once and binds no other request to it, because the Broker remembers a used-up token for a limited time and holds a token given again after that as a new one. +The Agent records the operation in its journal before it gives the Broker the token, and gives the Broker the token before it sends `ExecuteBypassRequest`. +When the Broker does not hold the token it was given, the Agent sends nothing for the operation and reports the result that the outcome table below gives when no request used the token. + +The `ExecuteBypassRequest` arguments are exactly `operationId`, the Authority's operation ID, `request`, the bypass request as JSON text, and `token`, the bypass token, each a string. +`request` is a string rather than an object so that UniGetUI passes on the Agent's text without parsing it. +UniGetUI answers `InvalidArguments` without sending anything when the arguments are not exactly these or when `token` is not in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token. +Otherwise, UniGetUI sends `POST /v2/package-requests/execute-bypass` over the Broker execution pipe with `Content-Type: application/json`, exactly one `X-Devolutions-Bypass-Token` header whose value is `token`, and the UTF-8 encoding of `request` as the body. +UniGetUI does not rebuild, reinterpret or check the body, so that the Broker receives exactly the request that the token binds. +It opens the execution pipe with the access rights and security quality of service of the grant route, and authenticates the pipe server as `CONTRACT.package-management.md §registration` states. +It sends `token` with no other request and `request` with no other token, does not copy the token into exceptions, traces or logs, and never runs the operation locally or on the grant route. +Before it answers, UniGetUI may send the same request again with the same token where [`CONTRACT.wire.md §transport`][wire transport] or [`CONTRACT.wire.md §bypass`][wire bypass] lets a client send a request again; once it has answered, it sends the request no more. +UniGetUI answers once it has stopped sending the request, without waiting for the operation to end: with `ok` true and the result `{}` when the Broker's last response to the request was a bypass response or a replayed bypass response, and with the error `Failed` otherwise. +An answer to `ExecuteBypassRequest` says what UniGetUI saw, not whether an operation started, because same-user code may write frames on the connection (`CONTRACT.package-management.md §registration`). + +When UniGetUI answers, whatever the answer, the Agent withdraws the token unless a request has used it. +A withdrawal and a request presenting the token never both take effect: either the request used the token first, or it gets `BypassTokenRejected` and no request uses the token afterwards. +When the answer is `UnsupportedCommand` and the withdrawal found the token unused, the Agent falls back to the grant route: it issues a new grant and sends `ExecutePackageOperation` on the same connection, and the operation continues as `CONTRACT.package-management.md §grant-route` specifies. +On any other answer, without an answer, or when a request used the token, the Agent does not fall back. +After the withdrawal, no request can start an operation with the token, so the fallback does not run the operation twice, even when the answer did not come from UniGetUI. +Registration is unchanged, so the Agent learns that an instance lacks `ExecuteBypassRequest` only from this answer. +While its operation journal retains the operation ID, the Agent sends `ExecuteBypassRequest` for it at most once and only to the resolved instance. + +The Agent learns the outcome from the Broker in process, never from UniGetUI's answer or the operation's event channel. +The Broker shows whether a request used the token and, once one did, the operation it started: its `OperationId`, its status ([`CONTRACT.wire.md §operations`][wire operations]), whether its manager process was launched, and that process's exit code once it exited on its own, as the `StartedAt` and `ExitCode` members of [`CONTRACT.wire.md §status`][wire status] state them. +The Agent waits until the operation's status is terminal, the Broker does not hold the token and no request used it, the Agent stops, or 30 minutes have passed since it sent `ExecuteBypassRequest`, whichever comes first. +When the wait ends while no request has used the token, the Agent withdraws the token first, so that no request uses it afterwards. +The Agent durably records start evidence before it continues to wait, and reports the result that this table gives for what the Broker shows when the wait ends. + +| The Broker shows | Result | `execution_started` | +| --- | --- | --- | +| no request used the token | known failure `the package broker did not start the package manager: nothing was started` | absent | +| a terminal status, and no launched manager process | the same known failure | absent | +| `Completed` | known success | true | +| `Failed`, and an exit code | known failure in the exit-code format of `CONTRACT.package-management.md §grant-route` | true | +| `Failed` or `Canceled`, and a launched manager process without an exit code | `UNKNOWN` | true | +| a status that is not terminal | `UNKNOWN` | true when the manager process was launched, absent otherwise | + +For a manager that `CONTRACT.package-management.md §grant-route` does not list among the managers whose exit code establishes the outcome, the Agent reports `UNKNOWN` instead of a known success or of a known failure with an exit code, because only for the listed managers are the Broker's launch paths known to return the manager's own exit code. +UniGetUI's request gets one of the outcomes of [`CONTRACT.wire.md §bypass`][wire bypass], and each reaches the Agent only through what the Broker shows: + +- the bypass response used the token and started the operation; +- the replayed bypass response started nothing and names the operation that the token started; +- `BypassTokenRejected`, `ProtectedPackage`, `BypassRequestUnreadable`, `BrokerBusy` and every other error response started nothing and did not use the token, so unless a later request uses the token, the operation ends with the known failure when the wait ends. + + +### Grant route + +The grant route runs an operation for a UniGetUI that does not list `ExecuteBypassRequest`, and the Agent uses it only as the fallback of `CONTRACT.package-management.md §bypass-route`. +A check by which this section has the Agent reject an operation applies only on this route: on the fallback, the operation ends with the result of that check, and the Agent sends nothing more for it. +`CONTRACT.package-management.md §broker-grant-response` and `CONTRACT.package-management.md §broker-grant-errors` give the Broker's responses on this route. `ExecutePackageOperation` accepts only the argument members listed in `CONTRACT.package-management.md §registration`. UniGetUI rejects any other argument member before submitting the request to the Broker. -The operation type is exactly one of `install`, `update` or `uninstall`. Remote writes allow install, update and uninstall for Broker-supported managers when they run unelevated with the target user's token. An operation runs elevated only when its manager is WinGet and the administrator requests `Machine` execution scope. The Agent rejects `Machine` execution scope for other managers. When a Broker builder supports an installed-scope selector, it passes the selected row's reported scope to the manager. WinGet instead uses the administrator's requested execution scope. -An install may replace an existing installation when the manager cannot prevent it. -The Authority-to-Agent request contains an operation ID, operation type, manager, source, package ID, requested version when applicable, scope, target user UUID, registry epoch and selected row's reported scope when applicable, but no bypass token. An install requires a nonempty canonical Broker source name, not the inventory display label. -An update may name its current execution feed or leave the source empty to use the manager's normal default feed. -Uninstall uses no feed and carries an empty source. For WinGet update and uninstall, the administrator selects the package by manager and package ID and chooses its execution scope independently of the row's reported scope. For other managers, update and uninstall identify the installed package by manager, package ID and the selected inventory row's raw `reported_scope` without proving its original source. -`PackageOperationRequest.reported_scope` is optional string field 11 and is present for update and uninstall, even when empty, and absent for install. -The Authority copies that field from the selected observation without changing it. -The Agent rejects an update or uninstall when that field is absent, and forwards it to UniGetUI unchanged as `reportedScope`. +The Agent forwards `reported_scope` to UniGetUI unchanged as `reportedScope`. UniGetUI rejects a write targeting an existing installation when it cannot identify the authorized row. An installation with `UNKNOWN` ownership may be updated or uninstalled unelevated. The administrator may request an elevated WinGet update or uninstall without a claim about the row's ownership. When the manager cannot select the authorized row by scope, UniGetUI checks its current installed list immediately before submission. It rejects the operation unless exactly one listed installation matches the manager and package ID and that installation is the authorized row. The installed list may omit an installation that the manager can act on, so the manager may affect another installation accessible to the target user's unelevated token. -The Agent mints an opaque, short-lived, single-use grant, also called a bypass token, held in the Broker's memory. +The Agent mints an opaque, short-lived, single-use grant held in the Broker's memory. The grant binds the target user SID, operation type, manager, source, package ID, version, scope, requested elevation and Broker request ID. UniGetUI sends `POST /v1/package-operations/execute-grant` over the Broker's named pipe while running unelevated as the target user. UniGetUI opens the execution pipe with `GENERIC_READ | FILE_WRITE_DATA` and `SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION`, never `GENERIC_WRITE`, which includes `FILE_CREATE_PIPE_INSTANCE`; the Broker grants that right only to SYSTEM and Administrators, so an open requesting it fails for standard users. @@ -391,10 +496,8 @@ UniGetUI's broker request builder maps source, custom parameters and pre-operati These execution-affecting fields are visible in the [UniGetUI broker request builder][UniGetUI broker request fields]. The Broker request's `Operation` must match the Authority operation type. -The Agent accepts Broker manager names ignoring ASCII case and maps the inventory IDs `winps`, `pwsh` and `dotnet-tool` to `PowerShell`, `PowerShell7` and `Dotnet`, respectively, also ignoring ASCII case. -It sends the canonical Broker name to UniGetUI. +The Agent sends the canonical Broker name to UniGetUI. The Broker compares `Manager` to the authorized manager using ASCII case-insensitive comparison of the Broker enum spelling. -An alias without an agreed mapping is rejected. `Source.Name`, `Package.Id` and a nonempty requested version are compared exactly as decoded Unicode strings, without trimming or case folding. For an update with an empty source, `Source.Name` is empty and `Source.Url` is absent; the grant binds the choice of the manager's default feed. For uninstall, `Source.Name` is empty and `Source.Url` is absent. @@ -415,19 +518,6 @@ It also rejects `Interactive`, `SkipHashCheck`, `PreRelease` and `UninstallPrevi When the manager's Broker builder supports `NoUpgrade`, the Agent binds it as true and the Broker requires it for an install. Any future execution-affecting request field must be explicitly authorized or rejected. -The Agent and the Broker refuse every remote uninstall that names the Devolutions Agent, and no local policy, setting or grant lifts this rule. -An uninstall names the Devolutions Agent when its manager and package ID are WinGet `Devolutions.Agent` or Chocolatey `devo-agent`, compared ignoring ASCII case after removing from the package ID a reference suffix that starts at its first `#` and then a version suffix that starts at its last `@`. -A WinGet uninstall also names it when its package ID contains the product code of the installed Devolutions Agent MSI in hyphenated form, compared ignoring ASCII case. -When the Agent cannot read the installed product code, it refuses every uninstall with the known failure `cannot verify that the operation does not uninstall the Devolutions Agent: nothing was started`. -Otherwise, it refuses an uninstall that names the Devolutions Agent with the known failure `the Devolutions Agent cannot be uninstalled remotely: nothing was started`. -The Agent decides both refusals before it mints a grant, and each is the reported failure even when the Broker, the target user or every UniGetUI instance is unavailable. -An uninstall that the Agent does not admit, that arrives while remote writes are disabled, or that the Agent rejects as invalid gets the result of that check instead, and nothing is started for it either. -Unlike the capacity failures, the Agent records both refusals, so a repeated delivery of the operation ID returns the recorded failure. -The Broker applies the same rule on the grant route without consulting local policy, before it consumes a grant. -When the Broker cannot read the installed product code, it rejects every `Uninstall` grant request with HTTP 422, `Code` `ValidationFailed` and the `Message` `the package broker cannot verify that the request does not uninstall the Devolutions Agent`. -Otherwise, it rejects an `Uninstall` grant request that names the Devolutions Agent with the same status and code and the `Message` `the package broker does not uninstall the Devolutions Agent`. -A remote install or update of the Devolutions Agent is not refused by this rule. - The Broker requires `RequestKind` to be `PackageRequest` and `RequestVersion` to be `1.0`. The request is a JSON `PackageRequest`; unknown or duplicate fields at any object level are rejected. The Agent generates a Broker request ID as a lowercase, hyphenated UUID and binds it to the grant. @@ -483,6 +573,12 @@ A wait that ends without evidence of exit reports `UNKNOWN`. The .NET broker passes `--source` for install and for updates with an explicit source, which overrides NuGet configuration including Package Source Mapping. The source override is documented in [dotnet tool install]. +The Broker-owned record is looked up by the issued grant and Broker request ID, not by an operation ID supplied in a registration response. +A rejection is a failure only before a grant for that operation has been made available and when the journal confirms that no earlier submission could have started. + + +### Results and the operation journal + An operation result identifies the operation ID. When the outcome is known, it reports success or failure with a nonempty error on failure. When the Agent cannot recover an operation's outcome, it reports `UNKNOWN`. @@ -497,7 +593,7 @@ The Authority does not record success or failure for a result whose field and st The Authority ignores `success` when the status is `UNKNOWN`. Agent and Authority versions must both understand `UNKNOWN` when they exchange operation results, including queued results after reconnect or rollback. Mixed versions that do not satisfy this requirement are unsupported. -The Agent durably records an operation before making a grant for it available and does not submit another operation for the same operation ID. +The Agent durably records an operation before giving the Broker a bypass token for it or making a grant for it available, and does not submit another operation for the same operation ID. The Authority's new operation ID is a UUID in 36-character lowercase 8-4-4-4-12 hexadecimal form. The Agent compares and echoes the ID exactly as sent. A recorded operation retains its replay rules even when its ID is outside that form. @@ -552,8 +648,6 @@ An interrupted index replacement does not discard the entries that the Agent per When the operation journal is missing, the Agent creates a new one; operations recorded only in the missing journal may execute again. The Authority may submit a new operation ID after an `UNKNOWN` outcome only by explicitly accepting that the earlier operation may have completed. The Broker's request-ID replay tracking does not replace this Authority operation-ID tracking. -The Broker-owned record is looked up by the issued grant and Broker request ID, not by an operation ID supplied in a registration response. -A rejection is a failure only before a grant for that operation has been made available and when the journal confirms that no earlier submission could have started. A lost or malformed response after submission is not evidence of failure. An unrecoverable record in an existing journal is `UNKNOWN`, and any UniGetUI recovery query uses the same resolved instance. Local broker policy is bypassed only for a valid DVLS-authorized operation; local policy continues to govern user self-service operations. @@ -670,8 +764,9 @@ While its operation journal retains the operation ID, the Agent does not replay UniGetUI must expose each safely reportable canonical Broker source name as `sourceName` independently of its display label, or leave `sourceName` empty when it cannot establish that identity. UniGetUI must pass the Agent-minted operation token through IPC to the package broker's named pipe without elevating its process. -UniGetUI must reject remote operations when broker routing is disabled, the manager is unsupported, the source cannot use broker routing, or the token does not authorize all execution-affecting fields; it must not fall back to local process execution. +For `ExecutePackageOperation`, UniGetUI must reject remote operations when broker routing is disabled, the manager is unsupported, the source cannot use broker routing, or the token does not authorize all execution-affecting fields; it must not fall back to local process execution. This fail-closed requirement covers the existing local-fallback paths in [PackageOperations.cs][UniGetUI operation fallback]. +UniGetUI must implement `ExecuteBypassRequest` as `CONTRACT.package-management.md §bypass-route` specifies. The current fixed mapping is in [`BrokerRequestBuilder.TryMapManagerName`][UniGetUI manager mapping] at commit `da6be7b86100302a79a208e7ab4d5c6fcd695fd5`. A Broker route for the UniGetUI `Installer` manager requires feed-item resolution, installer hash, identity and signature verification, and installed-version receipt handling; adding a manager enum value alone is insufficient. These operations are implemented in the pinned [WinInstaller runner], [WinInstaller manager] and [Installer receipt] sources. @@ -686,3 +781,12 @@ DVLS/RDM shows the Agent-reported user and session in an instance picker and sen [WinInstaller runner]: https://github.com/Devolutions/UniGetUI/blob/da6be7b86100302a79a208e7ab4d5c6fcd695fd5/src/UniGetUI.PackageEngine.Managers.WinInstaller/Internal/WinInstallerRunner.cs#L30-L106 [WinInstaller manager]: https://github.com/Devolutions/UniGetUI/blob/da6be7b86100302a79a208e7ab4d5c6fcd695fd5/src/UniGetUI.PackageEngine.Managers.WinInstaller/WinInstaller.cs [Installer receipt]: https://github.com/Devolutions/UniGetUI/blob/da6be7b86100302a79a208e7ab4d5c6fcd695fd5/src/UniGetUI.PackageEngine.Managers.WinInstaller/Internal/InstallReceipts.cs +[wire def bypass token]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#def-bypass-token +[wire transport]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#transport +[wire package request]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#package-request +[wire protected package]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#protected-package +[wire bypass]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#bypass +[wire bypass reading]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#bypass-reading +[wire operations]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#operations +[wire status]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.wire.md#status +[policy managers]: https://github.com/Devolutions/now-libraries/blob/master/policies/CONTRACT.policy.md#managers From c80ade556826d53db0af97dee6e036801098ec4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Wed, 2 Dec 2026 02:59:52 +0900 Subject: [PATCH 2/6] docs(agent): bound bypass token waits and outcomes Have the Broker show the Agent whether a request used a token for as long as the Agent waits on it, so a used token is never reported as "nothing was started" and the fallback never follows a hidden use. Bound the wait from when the Agent gives the token, end it when the command was provably not written, and report UNKNOWN when the Broker no longer holds a started operation. Scope the grant route's source requirements to ExecutePackageOperation, state that the bypass request carries no row identity, and tighten the response, elevation and body-encoding wording. Issue: DGW-512 Co-Authored-By: Claude Opus 5.5 --- .../CONTRACT.package-management.md | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/crates/agent-channel-proto/CONTRACT.package-management.md b/crates/agent-channel-proto/CONTRACT.package-management.md index dbda73346..9f9426c76 100644 --- a/crates/agent-channel-proto/CONTRACT.package-management.md +++ b/crates/agent-channel-proto/CONTRACT.package-management.md @@ -62,7 +62,7 @@ Agent and Authority versions that do not both enforce the UUID and epoch fields Remote inventory and remote writes have separate Agent configuration switches, both enabled by default. They are `DeviceManagement.RemoteInventoryEnabled` and `DeviceManagement.RemoteWritesEnabled` in the Agent configuration. When inventory is disabled, the Agent reports `SAFE_ENDPOINT_UNAVAILABLE` without querying UniGetUI. -When writes are disabled, the Agent rejects a new operation without contacting UniGetUI, giving the Broker a bypass token or issuing a grant. +When writes are disabled, the Agent rejects a new operation without contacting UniGetUI, and neither gives the Broker a bypass token nor issues a grant for it. Previously journaled operation IDs retain their recorded status. Neither switch disables discovery. @@ -220,8 +220,8 @@ While its operation journal retains the operation ID, the Agent never resends it Every package and update entry carries `source`, a display label, and `sourceName`, the canonical Broker `Source.Name`. `sourceName` is empty when the canonical name is unknown, ambiguous within the manager, or unsafe to report. There is no separate opaque source reference. -An install requires a nonempty `sourceName`. -When a request names a source, UniGetUI resolves it by ordinal comparison against the manager's source names and rejects the request with `InvalidArguments` when no source or more than one matches. +For `ExecutePackageOperation`, an install requires a nonempty `sourceName`. +When an `ExecutePackageOperation` request names a source, UniGetUI resolves it by ordinal comparison against the manager's source names and rejects the request with `InvalidArguments` when no source or more than one matches. Update and uninstall do not require proof of the installed package's original source. UniGetUI never substitutes another source or the display label. @@ -377,7 +377,7 @@ A remote install or update of the Devolutions Agent is not refused by this rule. ### Bypass route On the bypass route, the Agent writes a bypass request, gives the Broker a bypass token bound to it, and has UniGetUI send the request unchanged to the Broker's `POST /v2/package-requests/execute-bypass`, as [`CONTRACT.wire.md §bypass`][wire bypass] specifies. -The Broker runs the request without consulting local policy, and its reading of the request ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]) decides what runs, so the Agent checks only what it needs to write the request. +The Broker runs the request without consulting local policy, and its reading of the request ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]) decides what runs, so besides the rules of `CONTRACT.package-management.md §operations`, the Agent checks only what it needs to write the request. The bypass request is a JSON object with exactly the members of this table, which the Agent takes from the Authority request. @@ -393,23 +393,27 @@ The bypass request is a JSON object with exactly the members of this table, whic | `OptIns` | for a WinGet install, an object whose only member is `NoUpgrade`, whose value is `{}`; absent otherwise | The Agent compares the scope with `user` and `machine` ignoring ASCII case and rejects any other scope. -The scope is the only elevation choice that the Authority request makes, so a machine-scope operation runs as administrator, a user-scope operation runs with the target user's own rights, and the Agent never writes `Elevation` `Elevated` with `Scope` `User`. +The scope is the only elevation choice that the Authority request makes, so a machine-scope operation runs with the target user's elevated token, a user-scope operation runs with the target user's own rights, and the Agent never writes `Elevation` `Elevated` with `Scope` `User`. +When the Broker cannot run a machine-scope operation with that token, the operation launches no manager process and ends `Failed`, as [`CONTRACT.wire.md §bypass`][wire bypass] specifies. An uninstall's request has no `Source` and no `Package.Version`, whatever source and requested version the Authority sent, and [`CONTRACT.wire.md §bypass`][wire bypass] forbids `Source` on an uninstall. An install or update without a source has no `Source`, which leaves the choice of source to the manager. +No member carries `reported_scope`, and UniGetUI does not check the selected row, so an update or uninstall acts on what the manager finds for `Package.Id` in `Scope`, which may be another installation than the selected row. `NoUpgrade` keeps a WinGet install from replacing an existing installation, as on the grant route. The Agent rejects an operation whose package ID, or whose source or requested version when the request carries it, is outside the domain that [`CONTRACT.wire.md §package-request`][wire package request] gives the member it fills, so that it never sends a request that the Broker answers `BadRequest`. It does not check whether the Broker can read the request, such as an elevated install or update without `Source` ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]), and the outcome table below covers the Broker's answer. +Elevated installs and updates rely on the Broker's reading for which sources they use, and the Agent does not verify the effective feed. The Agent generates each bypass token from a cryptographically secure random source, with at least 128 random bits, in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token, so that no process can guess a token it was not given. It gives the Broker the token in process, bound to the bypass request, `RequestId` included, and to the SID of the target user, as [`CONTRACT.wire.md §bypass`][wire bypass] expects. It gives the Broker each token once and binds no other request to it, because the Broker remembers a used-up token for a limited time and holds a token given again after that as a new one. +How long the Broker holds a token that no request used is what [`CONTRACT.wire.md §bypass`][wire bypass] states. The Agent records the operation in its journal before it gives the Broker the token, and gives the Broker the token before it sends `ExecuteBypassRequest`. When the Broker does not hold the token it was given, the Agent sends nothing for the operation and reports the result that the outcome table below gives when no request used the token. The `ExecuteBypassRequest` arguments are exactly `operationId`, the Authority's operation ID, `request`, the bypass request as JSON text, and `token`, the bypass token, each a string. `request` is a string rather than an object so that UniGetUI passes on the Agent's text without parsing it. UniGetUI answers `InvalidArguments` without sending anything when the arguments are not exactly these or when `token` is not in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token. -Otherwise, UniGetUI sends `POST /v2/package-requests/execute-bypass` over the Broker execution pipe with `Content-Type: application/json`, exactly one `X-Devolutions-Bypass-Token` header whose value is `token`, and the UTF-8 encoding of `request` as the body. +Otherwise, UniGetUI sends `POST /v2/package-requests/execute-bypass` over the Broker execution pipe with `Content-Type: application/json`, exactly one `X-Devolutions-Bypass-Token` header whose value is `token`, and the UTF-8 encoding of `request`, without a byte order mark, as the body. UniGetUI does not rebuild, reinterpret or check the body, so that the Broker receives exactly the request that the token binds. It opens the execution pipe with the access rights and security quality of service of the grant route, and authenticates the pipe server as `CONTRACT.package-management.md §registration` states. It sends `token` with no other request and `request` with no other token, does not copy the token into exceptions, traces or logs, and never runs the operation locally or on the grant route. @@ -418,39 +422,45 @@ UniGetUI answers once it has stopped sending the request, without waiting for th An answer to `ExecuteBypassRequest` says what UniGetUI saw, not whether an operation started, because same-user code may write frames on the connection (`CONTRACT.package-management.md §registration`). When UniGetUI answers, whatever the answer, the Agent withdraws the token unless a request has used it. -A withdrawal and a request presenting the token never both take effect: either the request used the token first, or it gets `BypassTokenRejected` and no request uses the token afterwards. +A withdrawal and a request presenting the token never both take effect: either the request used the token first, or the request starts no operation, and no request uses the token after the withdrawal. +A withdrawal tells the Agent whether a request had used the token. When the answer is `UnsupportedCommand` and the withdrawal found the token unused, the Agent falls back to the grant route: it issues a new grant and sends `ExecutePackageOperation` on the same connection, and the operation continues as `CONTRACT.package-management.md §grant-route` specifies. On any other answer, without an answer, or when a request used the token, the Agent does not fall back. After the withdrawal, no request can start an operation with the token, so the fallback does not run the operation twice, even when the answer did not come from UniGetUI. -Registration is unchanged, so the Agent learns that an instance lacks `ExecuteBypassRequest` only from this answer. +An answer that arrives after the Agent recorded the operation's result changes nothing. +Neither `Hello` nor `Welcome` says which commands an instance supports, so the Agent learns that an instance lacks `ExecuteBypassRequest` only from this answer. While its operation journal retains the operation ID, the Agent sends `ExecuteBypassRequest` for it at most once and only to the resolved instance. The Agent learns the outcome from the Broker in process, never from UniGetUI's answer or the operation's event channel. -The Broker shows whether a request used the token and, once one did, the operation it started: its `OperationId`, its status ([`CONTRACT.wire.md §operations`][wire operations]), whether its manager process was launched, and that process's exit code once it exited on its own, as the `StartedAt` and `ExitCode` members of [`CONTRACT.wire.md §status`][wire status] state them. -The Agent waits until the operation's status is terminal, the Broker does not hold the token and no request used it, the Agent stops, or 30 minutes have passed since it sent `ExecuteBypassRequest`, whichever comes first. +Until the Agent's wait for the token ends, however long the Broker holds or remembers the token on the bypass route, the Broker shows the Agent whether a request used the token and, once one did, the operation it started: its `OperationId`, its status ([`CONTRACT.wire.md §operations`][wire operations]), whether its manager process was launched, and that process's exit code once it exited on its own, as the `StartedAt` and `ExitCode` members of [`CONTRACT.wire.md §status`][wire status] state them. +The Agent waits until the operation's status is terminal, the Broker does not hold the token and no request used it, the Agent stops, or 30 minutes have passed since it gave the Broker the token, whichever comes first. +When the Agent proves that it did not write `ExecuteBypassRequest` to the connection, it withdraws the token and the wait ends. When the wait ends while no request has used the token, the Agent withdraws the token first, so that no request uses it afterwards. -The Agent durably records start evidence before it continues to wait, and reports the result that this table gives for what the Broker shows when the wait ends. +The Agent durably records start evidence before it continues to wait. +Unless it falls back to the grant route, it reports the result of the first row of this table that matches what the Broker shows when the wait ends. | The Broker shows | Result | `execution_started` | | --- | --- | --- | | no request used the token | known failure `the package broker did not start the package manager: nothing was started` | absent | -| a terminal status, and no launched manager process | the same known failure | absent | +| a request used the token, and the Broker no longer holds the operation it started | `UNKNOWN` | true when the Agent recorded start evidence, absent otherwise | +| a terminal status, and no launched manager process | the known failure of the first row | absent | | `Completed` | known success | true | -| `Failed`, and an exit code | known failure in the exit-code format of `CONTRACT.package-management.md §grant-route` | true | +| `Failed`, and an exit code | known failure in the exit-code format of `CONTRACT.package-management.md §grant-route`, whose `` is the Authority request's `manager` string | true | | `Failed` or `Canceled`, and a launched manager process without an exit code | `UNKNOWN` | true | | a status that is not terminal | `UNKNOWN` | true when the manager process was launched, absent otherwise | For a manager that `CONTRACT.package-management.md §grant-route` does not list among the managers whose exit code establishes the outcome, the Agent reports `UNKNOWN` instead of a known success or of a known failure with an exit code, because only for the listed managers are the Broker's launch paths known to return the manager's own exit code. -UniGetUI's request gets one of the outcomes of [`CONTRACT.wire.md §bypass`][wire bypass], and each reaches the Agent only through what the Broker shows: +Each response to UniGetUI's request ([`CONTRACT.wire.md §bypass`][wire bypass]) reaches the Agent only through what the Broker shows: - the bypass response used the token and started the operation; - the replayed bypass response started nothing and names the operation that the token started; -- `BypassTokenRejected`, `ProtectedPackage`, `BypassRequestUnreadable`, `BrokerBusy` and every other error response started nothing and did not use the token, so unless a later request uses the token, the operation ends with the known failure when the wait ends. +- `BypassTokenRejected`, `ProtectedPackage`, `BypassRequestUnreadable` and `BrokerBusy` started nothing and did not use the token, so unless a later request uses the token, the operation ends with the known failure when the wait ends; +- after any other response, such as `InternalError`, or none, whether a request used the token is only what the Broker shows. ### Grant route -The grant route runs an operation for a UniGetUI that does not list `ExecuteBypassRequest`, and the Agent uses it only as the fallback of `CONTRACT.package-management.md §bypass-route`. +The grant route runs an operation for a UniGetUI that answers `ExecuteBypassRequest` with `UnsupportedCommand`, and the Agent uses it only as the fallback of `CONTRACT.package-management.md §bypass-route`. A check by which this section has the Agent reject an operation applies only on this route: on the fallback, the operation ends with the result of that check, and the Agent sends nothing more for it. `CONTRACT.package-management.md §broker-grant-response` and `CONTRACT.package-management.md §broker-grant-errors` give the Broker's responses on this route. `ExecutePackageOperation` accepts only the argument members listed in `CONTRACT.package-management.md §registration`. From ca68a0a862c726a5fa141c01f46a264e3cc833b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Wed, 2 Dec 2026 03:17:47 +0900 Subject: [PATCH 3/6] docs(agent): clarify where the Agent learns outcomes A failed execution-pipe check after sending leaves only UniGetUI without the outcome; the Agent still learns it from the Broker. Name the Authority request's manager string in the exit-code error on both routes, state that elevated runs use machine-wide sources, and narrow the bypass route's own checks to writing the request. Issue: DGW-512 Co-Authored-By: Claude Opus 5.5 --- .../CONTRACT.package-management.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/agent-channel-proto/CONTRACT.package-management.md b/crates/agent-channel-proto/CONTRACT.package-management.md index 9f9426c76..27bcfee52 100644 --- a/crates/agent-channel-proto/CONTRACT.package-management.md +++ b/crates/agent-channel-proto/CONTRACT.package-management.md @@ -127,7 +127,7 @@ The service name is fixed in UniGetUI and never taken from the server. UniGetUI does not open the server process, because a standard user cannot obtain the process access needed to pin a SYSTEM service process. On any failure, UniGetUI closes the connection without sending data and retries under the reconnect rules. UniGetUI applies the same check to every Broker execution pipe connection before writing to it. -On the execution pipe, a failed check is a transport failure that is never retried on another route; after the request was sent, the outcome is `UNKNOWN`. +On the execution pipe, a failed check is a transport failure that is never retried on another route; after the request was sent, UniGetUI does not know the outcome, and the Agent learns it only as `CONTRACT.package-management.md §operations` specifies. The issuing Broker keeps grants in memory, and a grant becomes invalid when that Broker instance stops. The grant client applies the same server check to the event connection and requires its server PID to match the execution connection; an event authentication failure after submission is `UNKNOWN`. Same-user code can duplicate UniGetUI's pipe handles, so these checks do not guarantee process-exclusive output confidentiality. @@ -377,7 +377,7 @@ A remote install or update of the Devolutions Agent is not refused by this rule. ### Bypass route On the bypass route, the Agent writes a bypass request, gives the Broker a bypass token bound to it, and has UniGetUI send the request unchanged to the Broker's `POST /v2/package-requests/execute-bypass`, as [`CONTRACT.wire.md §bypass`][wire bypass] specifies. -The Broker runs the request without consulting local policy, and its reading of the request ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]) decides what runs, so besides the rules of `CONTRACT.package-management.md §operations`, the Agent checks only what it needs to write the request. +The Broker runs the request without consulting local policy, and its reading of the request ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]) decides what runs, so the only checks that the Agent makes on this route alone are those it needs to write the request. The bypass request is a JSON object with exactly the members of this table, which the Agent takes from the Authority request. @@ -397,11 +397,11 @@ The scope is the only elevation choice that the Authority request makes, so a ma When the Broker cannot run a machine-scope operation with that token, the operation launches no manager process and ends `Failed`, as [`CONTRACT.wire.md §bypass`][wire bypass] specifies. An uninstall's request has no `Source` and no `Package.Version`, whatever source and requested version the Authority sent, and [`CONTRACT.wire.md §bypass`][wire bypass] forbids `Source` on an uninstall. An install or update without a source has no `Source`, which leaves the choice of source to the manager. -No member carries `reported_scope`, and UniGetUI does not check the selected row, so an update or uninstall acts on what the manager finds for `Package.Id` in `Scope`, which may be another installation than the selected row. +No member carries `reported_scope`, and UniGetUI does not check the selected row, so an update or uninstall acts on what the manager finds for `Package.Id` in `Scope`, which may be an installation other than the selected row. `NoUpgrade` keeps a WinGet install from replacing an existing installation, as on the grant route. The Agent rejects an operation whose package ID, or whose source or requested version when the request carries it, is outside the domain that [`CONTRACT.wire.md §package-request`][wire package request] gives the member it fills, so that it never sends a request that the Broker answers `BadRequest`. It does not check whether the Broker can read the request, such as an elevated install or update without `Source` ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]), and the outcome table below covers the Broker's answer. -Elevated installs and updates rely on the Broker's reading for which sources they use, and the Agent does not verify the effective feed. +Elevated installs and updates use only sources from machine-wide configuration ([`CONTRACT.wire.md §bypass-reading`][wire bypass reading]), and the Agent does not verify the effective feed. The Agent generates each bypass token from a cryptographically secure random source, with at least 128 random bits, in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token, so that no process can guess a token it was not given. It gives the Broker the token in process, bound to the bypass request, `RequestId` included, and to the SID of the target user, as [`CONTRACT.wire.md §bypass`][wire bypass] expects. @@ -432,7 +432,7 @@ Neither `Hello` nor `Welcome` says which commands an instance supports, so the A While its operation journal retains the operation ID, the Agent sends `ExecuteBypassRequest` for it at most once and only to the resolved instance. The Agent learns the outcome from the Broker in process, never from UniGetUI's answer or the operation's event channel. -Until the Agent's wait for the token ends, however long the Broker holds or remembers the token on the bypass route, the Broker shows the Agent whether a request used the token and, once one did, the operation it started: its `OperationId`, its status ([`CONTRACT.wire.md §operations`][wire operations]), whether its manager process was launched, and that process's exit code once it exited on its own, as the `StartedAt` and `ExitCode` members of [`CONTRACT.wire.md §status`][wire status] state them. +Until the Agent's wait ends, however long the Broker holds or remembers the token on the bypass route, the Broker shows the Agent whether a request used the token and, once one did, the operation it started: its `OperationId`, its status ([`CONTRACT.wire.md §operations`][wire operations]), whether its manager process was launched, and that process's exit code once it exited on its own, as the `StartedAt` and `ExitCode` members of [`CONTRACT.wire.md §status`][wire status] state them. The Agent waits until the operation's status is terminal, the Broker does not hold the token and no request used it, the Agent stops, or 30 minutes have passed since it gave the Broker the token, whichever comes first. When the Agent proves that it did not write `ExecuteBypassRequest` to the connection, it withdraws the token and the wait ends. When the wait ends while no request has used the token, the Agent withdraws the token first, so that no request uses it afterwards. @@ -445,7 +445,7 @@ Unless it falls back to the grant route, it reports the result of the first row | a request used the token, and the Broker no longer holds the operation it started | `UNKNOWN` | true when the Agent recorded start evidence, absent otherwise | | a terminal status, and no launched manager process | the known failure of the first row | absent | | `Completed` | known success | true | -| `Failed`, and an exit code | known failure in the exit-code format of `CONTRACT.package-management.md §grant-route`, whose `` is the Authority request's `manager` string | true | +| `Failed`, and an exit code | known failure in the exit-code format of `CONTRACT.package-management.md §grant-route` | true | | `Failed` or `Canceled`, and a launched manager process without an exit code | `UNKNOWN` | true | | a status that is not terminal | `UNKNOWN` | true when the manager process was launched, absent otherwise | @@ -560,7 +560,7 @@ Otherwise the Agent reports `UNKNOWN`. A nonzero code from such a wrapper may mean that the manager could not start, such as 9009 from `cmd.exe`, and is a known failure in the format below. Exit code 0 is a known success. Any other exit code is a known failure whose error is exactly ` exited with code `. -`` is the request's `manager` string, unchanged. +`` is the Authority request's `manager` string, unchanged. `` is the exit code as an unsigned 32-bit integer in plain decimal. For example, a `Winget` request whose process exits with `0x8A150010` fails with `Winget exited with code 2316632080`, not `-1978335216`. An exit code does not prove the package's state: exit code 0 can mean that nothing changed, and a nonzero code can be a success that needs a restart. From 2796f28666bf41a34c78882fecb0ea3e6b71544a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Wed, 2 Dec 2026 18:04:45 +0900 Subject: [PATCH 4/6] docs(agent): refuse only WinGet uninstalls on unreadable code Only a WinGet uninstall can name the Devolutions Agent by its MSI product code, so an unreadable product code refuses only WinGet uninstalls, on the Agent and on both Broker routes, and a device without the Agent MSI has no product code rather than an unreadable one. Cite the wire contract for the limit on answering a request with a held bypass token as busy, and for relying on the Agent to give each token once. Issue: DGW-512 Co-Authored-By: Claude Opus 5.5 --- .../CONTRACT.package-management.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/agent-channel-proto/CONTRACT.package-management.md b/crates/agent-channel-proto/CONTRACT.package-management.md index 27bcfee52..b0e2f2449 100644 --- a/crates/agent-channel-proto/CONTRACT.package-management.md +++ b/crates/agent-channel-proto/CONTRACT.package-management.md @@ -362,15 +362,16 @@ An alias without an agreed mapping is rejected. The Agent and the Broker refuse every remote uninstall that names the Devolutions Agent, and no local policy, setting or grant lifts this rule. An uninstall names the Devolutions Agent when its manager and package ID are WinGet `Devolutions.Agent` or Chocolatey `devo-agent`, compared ignoring ASCII case after removing from the package ID a reference suffix that starts at its first `#` and then a version suffix that starts at its last `@`. A WinGet uninstall also names it when its package ID contains the product code of the installed Devolutions Agent MSI in hyphenated form, compared ignoring ASCII case. -When the Agent cannot read the installed product code, it refuses every uninstall with the known failure `cannot verify that the operation does not uninstall the Devolutions Agent: nothing was started`. +When no Devolutions Agent MSI is installed, there is no installed product code, and reading it has not failed. +Only a WinGet uninstall can name the Devolutions Agent by its product code, so when the Agent cannot read the installed product code, it refuses every WinGet uninstall with the known failure `cannot verify that the operation does not uninstall the Devolutions Agent: nothing was started`. Otherwise, it refuses an uninstall that names the Devolutions Agent with the known failure `the Devolutions Agent cannot be uninstalled remotely: nothing was started`. The Agent decides both refusals before it gives the Broker a bypass token or mints a grant, and each is the reported failure even when the Broker, the target user or every UniGetUI instance is unavailable. An uninstall that the Agent does not admit, that arrives while remote writes are disabled, or that the Agent rejects as invalid gets the result of that check instead, and nothing is started for it either. Unlike the capacity failures, the Agent records both refusals, so a repeated delivery of the operation ID returns the recorded failure. The Broker applies the same rule on the grant route without consulting local policy, before it consumes a grant. -When the Broker cannot read the installed product code, it rejects every `Uninstall` grant request with HTTP 422, `Code` `ValidationFailed` and the `Message` `the package broker cannot verify that the request does not uninstall the Devolutions Agent`. +When the Broker cannot read the installed product code, it rejects every `Uninstall` grant request whose `Manager` is `Winget` with HTTP 422, `Code` `ValidationFailed` and the `Message` `the package broker cannot verify that the request does not uninstall the Devolutions Agent`. Otherwise, it rejects an `Uninstall` grant request that names the Devolutions Agent with the same status and code and the `Message` `the package broker does not uninstall the Devolutions Agent`. -On the bypass route, the Broker refuses the same uninstalls, including every uninstall while it cannot read the installed product code, with `ProtectedPackage` ([`CONTRACT.wire.md §protected-package`][wire protected package]), without using the bypass token. +On the bypass route, the Broker refuses the same uninstalls, including every WinGet uninstall while it cannot read the installed product code, with `ProtectedPackage` ([`CONTRACT.wire.md §protected-package`][wire protected package]), without using the bypass token. A remote install or update of the Devolutions Agent is not refused by this rule. @@ -405,7 +406,7 @@ Elevated installs and updates use only sources from machine-wide configuration ( The Agent generates each bypass token from a cryptographically secure random source, with at least 128 random bits, in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token, so that no process can guess a token it was not given. It gives the Broker the token in process, bound to the bypass request, `RequestId` included, and to the SID of the target user, as [`CONTRACT.wire.md §bypass`][wire bypass] expects. -It gives the Broker each token once and binds no other request to it, because the Broker remembers a used-up token for a limited time and holds a token given again after that as a new one. +It gives the Broker each token once and binds no other request to it, because [`CONTRACT.wire.md §bypass`][wire bypass] relies on the Agent for a token to start at most one operation. How long the Broker holds a token that no request used is what [`CONTRACT.wire.md §bypass`][wire bypass] states. The Agent records the operation in its journal before it gives the Broker the token, and gives the Broker the token before it sends `ExecuteBypassRequest`. When the Broker does not hold the token it was given, the Agent sends nothing for the operation and reports the result that the outcome table below gives when no request used the token. @@ -457,6 +458,8 @@ Each response to UniGetUI's request ([`CONTRACT.wire.md §bypass`][wire bypass]) - `BypassTokenRejected`, `ProtectedPackage`, `BypassRequestUnreadable` and `BrokerBusy` started nothing and did not use the token, so unless a later request uses the token, the operation ends with the known failure when the wait ends; - after any other response, such as `InternalError`, or none, whether a request used the token is only what the Broker shows. +[`CONTRACT.wire.md §bypass`][wire bypass] limits when a request presenting a token that the Broker holds is `BrokerBusy`, so the Broker's other connections do not keep UniGetUI's request from using the token. + ### Grant route From 624fd7f2c1a50b725150bb0268326d2887824501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Wed, 2 Dec 2026 18:17:40 +0900 Subject: [PATCH 5/6] docs(agent): serve held bypass tokens over the busy limit The Broker's connection-limit rule now defers to the wire contract for a bypass request presenting a token the Broker holds, so it no longer answers such a request busy where the wire contract serves it. Name the failure for an uninstall that names the Agent whatever the product-code read found, state the absent-MSI case by what the read finds, and state the single-use rule by the token's characters. Issue: DGW-512 Co-Authored-By: Claude Opus 5.5 --- .../CONTRACT.package-management.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/agent-channel-proto/CONTRACT.package-management.md b/crates/agent-channel-proto/CONTRACT.package-management.md index b0e2f2449..fc591881b 100644 --- a/crates/agent-channel-proto/CONTRACT.package-management.md +++ b/crates/agent-channel-proto/CONTRACT.package-management.md @@ -362,15 +362,15 @@ An alias without an agreed mapping is rejected. The Agent and the Broker refuse every remote uninstall that names the Devolutions Agent, and no local policy, setting or grant lifts this rule. An uninstall names the Devolutions Agent when its manager and package ID are WinGet `Devolutions.Agent` or Chocolatey `devo-agent`, compared ignoring ASCII case after removing from the package ID a reference suffix that starts at its first `#` and then a version suffix that starts at its last `@`. A WinGet uninstall also names it when its package ID contains the product code of the installed Devolutions Agent MSI in hyphenated form, compared ignoring ASCII case. -When no Devolutions Agent MSI is installed, there is no installed product code, and reading it has not failed. +A read that finds no installed Devolutions Agent MSI finds no product code, which is not a failure to read it. Only a WinGet uninstall can name the Devolutions Agent by its product code, so when the Agent cannot read the installed product code, it refuses every WinGet uninstall with the known failure `cannot verify that the operation does not uninstall the Devolutions Agent: nothing was started`. -Otherwise, it refuses an uninstall that names the Devolutions Agent with the known failure `the Devolutions Agent cannot be uninstalled remotely: nothing was started`. +It refuses any other uninstall that names the Devolutions Agent with the known failure `the Devolutions Agent cannot be uninstalled remotely: nothing was started`. The Agent decides both refusals before it gives the Broker a bypass token or mints a grant, and each is the reported failure even when the Broker, the target user or every UniGetUI instance is unavailable. An uninstall that the Agent does not admit, that arrives while remote writes are disabled, or that the Agent rejects as invalid gets the result of that check instead, and nothing is started for it either. Unlike the capacity failures, the Agent records both refusals, so a repeated delivery of the operation ID returns the recorded failure. The Broker applies the same rule on the grant route without consulting local policy, before it consumes a grant. When the Broker cannot read the installed product code, it rejects every `Uninstall` grant request whose `Manager` is `Winget` with HTTP 422, `Code` `ValidationFailed` and the `Message` `the package broker cannot verify that the request does not uninstall the Devolutions Agent`. -Otherwise, it rejects an `Uninstall` grant request that names the Devolutions Agent with the same status and code and the `Message` `the package broker does not uninstall the Devolutions Agent`. +It rejects any other `Uninstall` grant request that names the Devolutions Agent with the same status and code and the `Message` `the package broker does not uninstall the Devolutions Agent`. On the bypass route, the Broker refuses the same uninstalls, including every WinGet uninstall while it cannot read the installed product code, with `ProtectedPackage` ([`CONTRACT.wire.md §protected-package`][wire protected package]), without using the bypass token. A remote install or update of the Devolutions Agent is not refused by this rule. @@ -406,7 +406,7 @@ Elevated installs and updates use only sources from machine-wide configuration ( The Agent generates each bypass token from a cryptographically secure random source, with at least 128 random bits, in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token, so that no process can guess a token it was not given. It gives the Broker the token in process, bound to the bypass request, `RequestId` included, and to the SID of the target user, as [`CONTRACT.wire.md §bypass`][wire bypass] expects. -It gives the Broker each token once and binds no other request to it, because [`CONTRACT.wire.md §bypass`][wire bypass] relies on the Agent for a token to start at most one operation. +It never gives the Broker a token with the characters of one it gave before, and binds no other request to a token, because [`CONTRACT.wire.md §bypass`][wire bypass] relies on the Agent for a token to start at most one operation. How long the Broker holds a token that no request used is what [`CONTRACT.wire.md §bypass`][wire bypass] states. The Agent records the operation in its journal before it gives the Broker the token, and gives the Broker the token before it sends `ExecuteBypassRequest`. When the Broker does not hold the token it was given, the Agent sends nothing for the operation and reports the result that the outcome table below gives when no request used the token. @@ -458,7 +458,7 @@ Each response to UniGetUI's request ([`CONTRACT.wire.md §bypass`][wire bypass]) - `BypassTokenRejected`, `ProtectedPackage`, `BypassRequestUnreadable` and `BrokerBusy` started nothing and did not use the token, so unless a later request uses the token, the operation ends with the known failure when the wait ends; - after any other response, such as `InternalError`, or none, whether a request used the token is only what the Broker shows. -[`CONTRACT.wire.md §bypass`][wire bypass] limits when a request presenting a token that the Broker holds is `BrokerBusy`, so the Broker's other connections do not keep UniGetUI's request from using the token. +[`CONTRACT.wire.md §bypass`][wire bypass] limits when a request presenting a token that the Broker holds is `BrokerBusy`, so requests that present another token, or none, do not make UniGetUI's request `BrokerBusy`. ### Grant route @@ -719,11 +719,11 @@ Messages and details contain no grant value, captured output, command preview or | Conflicting request or operation identity | 409 | `Conflict` | | Grant route not implemented by a rebuilt Broker | 501 | `UnsupportedEndpoint` | | Grant route absent on an older Broker | 404 | No structured body is required. | -| Broker over its connection limit, overall or for the caller's user, and not serving the request in a grant slot as described below | 503 | `BrokerBusy` | +| Broker over its connection limit, overall or for the caller's user, and not serving the request in a grant slot as described below or as [`CONTRACT.wire.md §bypass`][wire bypass] has it serve a bypass request presenting a token it holds | 503 | `BrokerBusy` | The Broker classifies a connection over its connection limit from its request line and headers, before routing the request. A `POST /v1/package-operations/execute-grant` request with exactly one grant header naming a pending grant, one that is issued, unexpired, unconsumed and not revoked, is served instead of refused, unless 8 such connections are already being served or another one presents the same grant. -A request over the limit that is not served this way gets the busy reply, which therefore never consumes a grant. +A request over the limit that is not served this way, or as [`CONTRACT.wire.md §bypass`][wire bypass] has the Broker serve a bypass request presenting a token it holds, gets the busy reply, which therefore never consumes a grant. The Broker sends `BrokerBusy` only in the busy reply, so a client tells that reply from any other 503 by its code, without reading headers. The Agent never runs more than 8 concurrent package operations, so while UniGetUI presents each of its grants once, before it expires, and no other connection presents them, the Broker never answers the Agent's grant requests busy, whatever other connections it has. A busy reply to a grant request therefore means that one of these conditions did not hold; like any other rejection, it does not establish the operation's outcome. From c29fcee1b18e1cfc90b064ed65b2176f7e713690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Wed, 2 Dec 2026 18:18:52 +0900 Subject: [PATCH 6/6] docs(agent): leave held bypass tokens out of the unread-close count A bypass request presenting a held token is served like a grant slot, so it no longer counts toward the over-limit connections that make the Broker close a further one unread. Issue: DGW-512 Co-Authored-By: Claude Opus 5.5 --- crates/agent-channel-proto/CONTRACT.package-management.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/agent-channel-proto/CONTRACT.package-management.md b/crates/agent-channel-proto/CONTRACT.package-management.md index fc591881b..57d94da24 100644 --- a/crates/agent-channel-proto/CONTRACT.package-management.md +++ b/crates/agent-channel-proto/CONTRACT.package-management.md @@ -406,7 +406,7 @@ Elevated installs and updates use only sources from machine-wide configuration ( The Agent generates each bypass token from a cryptographically secure random source, with at least 128 random bits, in the form that [`CONTRACT.wire.md §bypass`][wire bypass] gives a bypass token, so that no process can guess a token it was not given. It gives the Broker the token in process, bound to the bypass request, `RequestId` included, and to the SID of the target user, as [`CONTRACT.wire.md §bypass`][wire bypass] expects. -It never gives the Broker a token with the characters of one it gave before, and binds no other request to a token, because [`CONTRACT.wire.md §bypass`][wire bypass] relies on the Agent for a token to start at most one operation. +It never gives the Broker a token with the characters of one it gave before, and binds each token to one request, because [`CONTRACT.wire.md §bypass`][wire bypass] relies on the Agent for a token to start at most one operation. How long the Broker holds a token that no request used is what [`CONTRACT.wire.md §bypass`][wire bypass] states. The Agent records the operation in its journal before it gives the Broker the token, and gives the Broker the token before it sends `ExecuteBypassRequest`. When the Broker does not hold the token it was given, the Agent sends nothing for the operation and reports the result that the outcome table below gives when no request used the token. @@ -723,11 +723,11 @@ Messages and details contain no grant value, captured output, command preview or The Broker classifies a connection over its connection limit from its request line and headers, before routing the request. A `POST /v1/package-operations/execute-grant` request with exactly one grant header naming a pending grant, one that is issued, unexpired, unconsumed and not revoked, is served instead of refused, unless 8 such connections are already being served or another one presents the same grant. -A request over the limit that is not served this way, or as [`CONTRACT.wire.md §bypass`][wire bypass] has the Broker serve a bypass request presenting a token it holds, gets the busy reply, which therefore never consumes a grant. +A request over the limit that is served neither this way nor as [`CONTRACT.wire.md §bypass`][wire bypass] has the Broker serve a bypass request presenting a token it holds gets the busy reply, which therefore never consumes a grant. The Broker sends `BrokerBusy` only in the busy reply, so a client tells that reply from any other 503 by its code, without reading headers. The Agent never runs more than 8 concurrent package operations, so while UniGetUI presents each of its grants once, before it expires, and no other connection presents them, the Broker never answers the Agent's grant requests busy, whatever other connections it has. A busy reply to a grant request therefore means that one of these conditions did not hold; like any other rejection, it does not establish the operation's outcome. -While the Broker is already reading or answering 16 connections over its limit, not counting those served in grant slots, it closes a further one without reading its request or responding, which also consumes no grant. +While the Broker is already reading or answering 16 connections over its limit, not counting those served in grant slots or served as bypass requests presenting a token it holds, it closes a further one without reading its request or responding, which also consumes no grant. Each rejection starts no work for that request. It consumes no grant, except that a consumed grant may have been used by an earlier request. Another concurrent request may independently consume the same grant.