You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(agent): serve the 2.0 request encoding in the package broker - #2231
Temporary git dependencies, each of which must become a crates.io version before this merges (introduced at the bottom of this stack, unchanged here):
now-policy, now-policy-api and now-policy-server-template: [patch.crates-io] in the root Cargo.toml, on Devolutions/now-libraries at 5b23b1a616ca97590d4d6b9e610cd07772d30453.
now-policy-eval: a dependency of crates/now-package-broker, same repository at 25e75110c067239e44e42f005abbf566f32f803a.
The package broker serves the 2.0 request encoding: every endpoint of CONTRACT.wire.md under /v2/, decided against a policy in format 2.x.
A request whose path starts with /v2/ goes to its own router, and every other request reaches the 1.x router as before, so a later release can delete the 1.x routes without touching these.
Each request is answered by the first of the contract's outcomes that applies: BrokerBusy, UnknownEndpoint, UnsupportedMediaType, Unauthenticated, AdministratorRequired, RequestTooLarge, BadRequest, then the endpoint's own.
The first five are decided without reading any byte of the body, and a panic while answering is InternalError.
GET /v2/health answers any client with only Status, Ready exactly when the broker holds an accepted policy.
GET /v2/capabilities names the version of the Devolutions Agent that hosts the broker, which the Agent gives the broker when it starts it, the operation timeout and, for each manager, the opt-ins of its reading that the broker acts on.
POST /v2/package-requests/evaluate answers ProtectedPackage for a protected uninstall whether or not the broker holds a policy, then the decision of the accepted policy, PolicyUnavailable without one, and NotRunnable for an allowed request that would run a Pre or Post command elevated, audit mode included.
POST /v2/package-requests/execute, GET /v2/operations/{OperationId} and POST /v2/operations/{OperationId}/cancel start, report and cancel the operations of their owner. An execution request that is a protected uninstall is answered ProtectedPackage once its RequestId is known to be unused, starts nothing and leaves that RequestId unused. Operations of the 1.x routes are not ones a 2.0 request names or replays.
GET /v2/policy/management, POST /v2/policy/validate and POST /v2/policy read the management state, report the policy errors of a document, and replace the policy for an elevated administrator, with the audit records the 1.x route leaves.
POST /v2/package-requests/execute-bypass starts an operation without any policy for a request its bypass token authorizes. The request is read by the evaluator's bypass reading, so one without a source runs with the only source name of its manager, or leaves the choice of source to the manager, or is BypassRequestUnreadable. The broker holds tokens in memory, as digests, each bound to one bypass request and one user for 60 seconds. A token is used up once the broker holds the operation it started, and a used-up token is refused when the broker is given it again within those 60 seconds. No code issues a token yet: the entry point that binds one has no caller until the Agent's side exists, so every bypass request is answered BypassTokenRejected in a released broker.
A protected uninstall is a request that removes a package, by Uninstall or by the UninstallPrevious opt-in of an Install or Update, and either names Devolutions Agent or arrives while the broker cannot read the product code of the installed Agent.
An Install or Update that names the Agent without UninstallPrevious is evaluated like any other request.
The plan of an operation still refuses to remove the Agent, as a second check behind the routes.
The event channel of an operation a bypass request started sends its frames only to a process the broker identifies as the operation's owner, the way the request pipe identifies a client.
A client is identified as soon as it connects; any other connection is closed without a frame, and the same pipe instance listens again one second later, until the owner connects or the channel ends.
An identification that does not complete within 30 seconds closes the channel, so the identification keeps the pipe only while it reads the id of the client process.
A process of the same user that connects in a loop can therefore keep the owner off the channel, but reads nothing and cannot make the channel outlive its 60 seconds after the operation ended; the owner still learns the status with status requests.
A client whose process the broker cannot identify used to have its connection closed without a response.
Its /v2/ requests are now answered as the contract says: health normally, every other endpoint Unauthenticated without reading the body.
A request under any other path on such a connection still gets no response.
Scope item
Outcome
Evidence
Every /v2/ endpoint of CONTRACT.wire.md
Done: ten endpoints
v2::routes::tests, one group per endpoint; v2::wire::route::table_has_every_endpoint
1.x routes in a separate code path
Done: 1.x router and handlers unchanged, reached for every path outside /v2/
A token with the same characters given again later than 60 seconds after the first, while the broker holds the operation the first one started for the same owner
Kept: the Agent never gives the same token twice, and the broker names a bypass operation by the digest of its token, so it answers such a request as one that carries the first token
comment at Existing::Conflict in v2/routes/bypass.rs
Protected uninstall of Devolutions Agent on evaluate, execute and bypass
Done: ProtectedPackage at its place among the outcomes of each endpoint
A request whose path starts with `/v2/` no longer reaches the 1.x router.
It gets the outcome the wire contract ranks first: `BrokerBusy`,
`UnknownEndpoint`, `UnsupportedMediaType`, `Unauthenticated` and
`AdministratorRequired` are answered without reading the body, then
`RequestTooLarge` and `BadRequest`.
An endpoint that passes these checks answers `InternalError`, because none
is served yet, and a panic while answering does too, so such a request
never gets a 1.x body.
A refused policy replacement leaves a denial record naming
`POST /v2/policy`, counted apart from the denials of the 1.x route, whose
records do not change.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`GET /v2/health` says `Ready` only while the broker holds an accepted 2.x
policy, so a policy file in format 1.x leaves the 2.0 endpoints paused
while the 1.x routes keep their policy.
`GET /v2/capabilities` names the managers found for the client's user and
the timeout the executor stops a process after.
A manager capability lists the opt-ins the broker handles itself, and
the custom parameters and install location where the manager takes them.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`POST /v2/package-requests/evaluate` answers the decision of the 2.x
evaluator, the identity of the policy that decided and the evaluation
time, and starts nothing.
A denial is a decision in a 200 response, not an error.
Without an accepted 2.x policy the request is `PolicyUnavailable`, which
is also the answer while the policy file is in format 1.x.
An allowed request that would run a command with an elevated token is
`NotRunnable` with its decision, in audit mode too.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An execution request under /v2/ is evaluated against the accepted policy and, when allowed, starts an operation held apart from those of the 1.x routes, so neither encoding names, replays or conflicts with an operation of the other.
The status and cancel requests answer for the owner of an operation only, with the same response for another owner's operation as for one the broker does not hold.
An allowed request that would uninstall the Devolutions Agent, or any uninstall while the product code of the installed Agent cannot be read, starts an operation that runs no step and ends Failed, because the broker never removes the Agent it runs in.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The policy management, validation and replacement requests under /v2/ answer from the 2.0 view of the policy store, so a client of the 2.0 encoding manages a 2.x policy file without the 1.x routes.
A replacement is recorded under its own request, from the attempt of an administrator to its result, and a request refused for its body leaves a result too.
The store and the wire model each mapped the validation errors of the evaluator; the wire model's mapping is the one that remains.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The broker binds a bypass token to a 1.x request and uses the token up
when it checks it, so it can neither compare a 2.0 bypass request with
the bound request nor refuse one without using up its token.
A well-formed bypass request is therefore answered with InternalError,
which lets the client treat its outcome as unknown, and no command runs
for it.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The 2.0 bypass route answered InternalError to every request, because
the tokens of the 1.x remote operations bind a 1.x request and are used
up when checked.
The broker now holds the bypass tokens of the 2.0 encoding in a store of
their own, which binds each one to a 2.0 bypass request and to a user,
and tells whether a token authorizes a request without using it up.
The route uses a token up and starts its operation while the tokens are
locked, so requests with one token that arrive together start one
operation and each equal one gets it.
Bypass operations have a registry of their own, so a RequestId of a
bypass request neither conflicts with nor replays an execution request.
A request without Source is read under the only source name of its
manager when it has one.
Any other request without Source that is not unreadable by its elevation
is answered InternalError and keeps its token, because the reading and
the command builders take a package request, which always names a
source.
Devolutions Agent does not give the broker a token of this encoding yet,
so no request is authorized outside tests.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s body
A client that may replace the policy and whose request is refused as
too large, as not well-formed, or because its body could not be read
left no trace, while the same request on the 1.x route leaves its
attempt and a rejection. An administrator who looks for who tried to
change the policy has to find these requests as well, so they now
leave the attempt and a request_rejected denial under the request of
the 2.0 encoding.
A replacement the policy store fails to decide is answered before any
attempt is recorded, so its log line now names the client.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… the broker read
The broker reads a package request as the wire contract defines it
before it asks the evaluator for a decision, so a refusal by the
evaluator means the two read the contract differently. BadRequest was
the answer, yet that code wins over PolicyUnavailable and over a
replayed response, which the broker has decided by then, so a client
could be told its request is malformed when the contract gives it
another outcome. The failure is the broker's and no other code names
it: it is now logged and answered as InternalError.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… on for a manager
The capability of a manager named the commands and the processes the
broker runs itself, custom parameters and a custom install location,
and nothing else. A client that offers what the capabilities name
never offered Interactive, SkipHashCheck, InstallerArguments,
UninstallPrevious or NoUpgrade, which the WinGet, Chocolatey and Scoop
commands carry, and offered Cargo pre and post commands and processes
to stop, which make a Cargo request unreadable.
Each manager now gets the opt-ins that change what the broker runs
for it: the keys its reading accepts, less those its command carries
nothing for, as the PowerShell commands do for every key of the
manager itself.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ker cannot identify
The pipe server closed the connection of a client whose process it failed
to identify, for example one whose executable is on a network share, before
reading any request. The 2.0 encoding answers every request of a connected
client: the health endpoint answers any client, a request to any other
endpoint is `Unauthenticated` when the broker does not authenticate the
client process, and a connection closes without a response only on a
timeout.
Such a client now stays connected as an unidentified one. Its 2.0 requests
get `UnknownEndpoint` and `UnsupportedMediaType` first, then the health
response or `Unauthenticated`, without the broker reading a body it does not
need, and a refused policy replacement leaves a denial record that names the
user the process seemed to run as. That user reaches nothing else: the
client owns nothing, starts nothing, and is never named to the policy store.
The 1.x routes still serve no such client. The connection closes without a
response once the header of a request outside the 2.0 encoding is read.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The event channel of a bypass operation was the channel of an execution:
it served the first connection to its pipe, so any process of the user
could read the output of an operation the policy did not decide, and the
owner connecting after it got nothing. The 2.0 encoding sends the frames
of such an operation only on a connection from a process the broker
authenticates as the owner, and closes any other connection without a
frame.
The channel of a bypass operation now identifies the process of a
connection the way the request pipe identifies a client, before the
hello frame, and compares it with the owner of the operation. A
connection it refuses is disconnected and the same pipe instance listens
again, for as long as the channel would have waited for a first
connection: until 60 seconds after the status became terminal.
Identifying a process costs the broker much more than connecting costs a
client, so after a refusal the channel waits one second before it
identifies another client, with the pipe listening meanwhile. A process
of the user that connects in a loop therefore keeps no thread busy, but
can still hold the single instance of the pipe against the owner, who
keeps the status endpoint.
The channel of an execution and the 1.x channel serve the first
connection as before.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The broker forgot a bypass token as soon as a request used it up, so
the same token given once more was held as a new one and authorized a
request again: for another owner of the same user at once, and for the
owner once its operation was no longer held. A used-up token never
authorizes a request again.
The broker now remembers a used-up token until the lifetime it was held
with ends. During that time it refuses to hold the token again, the
token authorizes nothing, and it counts toward the bound on held tokens,
so remembering it costs no more memory than holding it did. Past that
time nothing tells the token from a new one, which is why whoever gives
the broker tokens must give each one once; `hold` says so.
A test also covers the equal request that arrives once the broker no
longer holds the operation its token started, which is refused.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tion
The broker used a bypass token up before it started the operation of
the request. When starting the operation failed, the token was gone and
no operation was held, so the request the token authorized could never
run: a bypass request that starts no operation does not use up its
token.
The token is now used up after the start returned, with the tokens
still locked, so no other request sees the operation without the token
used up, nor the token used up without the operation.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ted endpoints
The table of endpoints for authenticated clients already sends the
capabilities request of a client the broker does not authenticate.
It now checks each refusal as a whole error response, content type and
message length included, so the separate capabilities test repeated one
of its rows.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…rator requirement
A request that meets both `Unauthenticated` and `AdministratorRequired`
is answered with the first.
No test sent the policy replacement of a client that is neither
authenticated nor an administrator, so a broker that checked the
administrator requirement first passed every test.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An elevated Install or Update without `Source` is unreadable unless its
manager is `Winget` or `Chocolatey`.
The only test that told apart a broker that refused those two as well
expected the answer the broker gives today for a request without a
source name, so it would follow a change of that answer.
The new test states what the contract does: such a request is not
unreadable.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tion
`Operations` is a non-empty list.
Every manager the broker drives has an operation, so no request shows
what the capabilities do with one that has none, and a response that
listed such a manager with an empty list passed every test.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… as it connects
After the channel of a bypass operation refused a connection, its pipe
listened during the pause that follows, and a client that connected
then was identified only once the pause ended.
The process that connected had up to one second to exit and let another
process take its id before the broker read that id and opened the
process.
The channel now identifies a client at once whenever one connects, and
after a refusal its pipe listens again only once the pause has passed.
A client that opens the pipe during the pause gets a busy pipe.
The wait for the end of the channel still wins over the pause and over
the listening, and is still one wait for the whole loop.
The pause is a parameter of the channel so that tests choose it.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…its pipe up
A channel that could no longer tell who its pipe was connected to (the
identification of a client panicked, the pipe failed to listen or to
close a refused connection, or the read of that connection did not end)
closed its pipe, logged that no client connected, and left its queue
open.
The queue then went on taking output that nobody would read.
Such a channel now closes its queue, and the broker logs the failure
for what it is, as a warning that names its cause.
A channel to which no admitted client connected before its end keeps
its behaviour and its log line.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The test of a refused connection said that the pipe allows no other
instance.
Creating an instance fails there because the access control of the pipe
gives the user of the test no right to create one, whatever the number
of instances the pipe allows: the probe shows that the channel kept its
pipe, which its comment and its message now say.
The bypass route said that a start that panics holds no operation.
That holds for a panic before the registry takes the operation only;
after it, the registry holds an operation whose token is not used up.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Intent drift audit: 2.0 routes, bypass endpoint and tokens, event channel of a bypass operation, unidentified clients (audited at 1577e5704)
Audited against, as copied from now-libraries policies/ at 77307f5106d9764d03a420d22fd8377c99432af5:
CONTRACT.wire.md (90 rows; the sections listed under "Outside this change" are not audited one by one)
CONTRACT.policy.md (2 rows)
INTENT.md (no row of its own; the second text of 6 rows)
INTENT.wire.md (4 rows)
INTENT.legacy.md (2 rows)
A row that cites two texts is counted under the first.
A statement ID is the section anchor plus the ordinal of the sentence in its section; a list or a table counts with the sentence that introduces it, and .n names an item of a list. #operations, #event-channel, #cancel and #replacement keep the numbers of the two earlier reports. #bypass-20 here is the statement the earlier report called #bypass-17.
Evidence is file:line at 1577e5704. Paths are relative to crates/now-package-broker/src/, and tests.rs alone is v2/routes/tests.rs.
"Published types" are now_policy_api::v2 at the pinned revision; they are a dependency, not part of the diff.
The last column says whether the behaviour is introduced by this diff or pre-existing code the diff now reaches from a 2.0 request.
Reading bodies, the operation registry, plans and the policy store were audited with the two changes below this one; a row cites them where a route depends on them.
Counts: 98 rows. 86 conforms, 2 violates (both known, both in the published types), 7 partial (4 introduced, 1 pre-existing, 2 known), 1 cannot-verify, 2 not-yet-realised (both known).
Violations and partials
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/routes/mod.rs:306-327, through v2/wire/read.rs:27-57; ignored test v2/wire/read.rs:1095-1096
The published types read a closed-set value written as an object, such as {"Install": null}, so every route that reads a body accepts it. Already reported; in the dependency.
v2/routes/mod.rs:280; v2/routes/operations.rs:179-180; ignored test v2/wire/convert.rs:999-1000
EvaluatedAt, StartedAt and CompletedAt are written by the published Timestamp::from_datetime, which writes a leap second held by chrono as seconds 60. Already reported; in the dependency.
CONTRACT.wire.md#transport-13, #transport-5
While it serves other connections the broker has no instance listening (ERROR_PIPE_BUSY) or answers BrokerBusy; the contract defines the response to every /v2/ request
A connected client is closed without any response when the 16 busy replies are taken as well as the connection slots, when the spare instance is not ready, when the user of the client cannot be looked up (so GET /v2/health too), and when the user changed during capture. #transport-12 allows no response only at the 5 and 30 second limits. Pre-existing limits; the diff narrows the capture case to a client whose user cannot be looked up either (pipe.rs:198-208).
CONTRACT.wire.md#capabilities-1 (ServerVersion)
"a string of 1 to 128 bytes naming the broker's version"
partial (judgement)
v2/routes/capabilities.rs:17; ../Cargo.toml:3
The value is the version of the crate, which is 0.0.0 in every build, so it is in its domain and names no release. The 1.x responses use the same constant (server/responses.rs:19). Introduced use.
A used-up token is remembered until the 60 seconds it was held with end, and then forgotten. Given again after that, the same characters are held as a new token, and authorize the request again once the broker no longer holds the first operation. The code says so (tokens.rs:101-103) and relies on the Agent never giving a token twice. Introduced.
CONTRACT.wire.md#bypass-reading-4 (Scoop, Vcpkg, "every other case")
A bypass request without Source is read with no Source.Name, and the broker runs its command
Only the managers with an only source name are read. Every other request without Source, which includes every Uninstall under Winget, Chocolatey, PowerShell, PowerShell7, Scoop, Vcpkg and Dotnet, is answered InternalError and keeps its token. #errors-7 allows the code, so the response is one the contract allows; the reading is not realised. Introduced.
CONTRACT.wire.md#operations-5 to -9 (the rules as a whole)
"These rules decide how an operation that is not canceled ends"
An allowed execution request that removes Devolutions Agent (an Uninstall, or an Install with UninstallPrevious), and any removing request while the product code of the Agent cannot be read, runs no step and ends Failed. No rule of the list says so; the contract names the protection for bypass requests only (#bypass-9.3). CONTRACT.policy.md#evaluation-4 lets an allowed request not run. Introduced.
CONTRACT.wire.md#event-channel-6 to -10 (bypass operations)
"The broker closes the channel only" in the five listed cases
partial
event_channel.rs:822-828, 835-838, 841-850, 589
The channel of a bypass operation gives the pipe up when closing a refused connection fails, when the read of a refused connection has not ended after 5 seconds, and when the task that identifies a client fails. Failure paths only; the operation is unaffected. Introduced.
For an Update under a manager that updates from the recorded source, the broker reads every record first and refuses unless each names Source.Name
partial (known)
v2/execution/plan.rs:60-67, 134-136
Every Update under Scoop or PowerShell ends Failed without a step, now for execution and bypass requests alike. Fails closed, and agrees with CONTRACT.wire.md#operations-6. Already reported; from the change below this one.
Cannot verify
ID
Statement (abridged)
Status
Evidence
Note
CONTRACT.wire.md#event-channel-5 (the owner)
For a bypass operation, the broker sends frames on a connection from a process it authenticates as the operation's owner
cannot-verify
v2/routes/held.rs:109-116; v2/execution/operations.rs:169-170; test with a stand-in identification v2/execution/operations.rs:1445; UNTESTED: at v2/routes/held.rs:97-108
The identification is the one the request pipe uses (PipeClient::from_connected_pipe, validate_connection, owner_of), so the code reads right. No test connects a process that this function identifies as the owner, and the owner comparison is the one the earlier report found partial (v2/execution/owner.rs:60-66). Needs the check with a signed client that the comment asks for. Introduced.
Not yet realised
ID
Statement (abridged)
Status
Evidence
Note
CONTRACT.wire.md#bypass-4
"The Agent gives the broker each token with the bypass request it binds, RequestId included, and the SID of the Windows user it binds"
not-yet-realised (known)
v2/bypass/tokens.rs:106-115
BypassTokens::hold is the entry point, and nothing outside tests calls it, so a released broker holds no token and answers every well-formed bypass request BypassTokenRejected, which is outcome 2 as the contract has it. Already reported.
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; test tests.rs:1126
With a 1.x file the 2.0 routes answer Paused, PolicyUnavailable and a management state Invalid / Unconvertible, and the 1.x routes keep enforcing the file. Already reported.
Conforms
ID
Statement (abridged)
Status
Evidence
Note
CONTRACT.wire.md#transport-1
The broker listens on \\.\pipe\Devolutions.Now.PackageBroker.v1
conforms
pipe.rs:29
Pre-existing.
CONTRACT.wire.md#transport-2
Each connection carries one request and its response, and the broker closes it after the response
conforms
server/connection.rs:73
Keep-alive is off. Pre-existing.
CONTRACT.wire.md#transport-4
A body is framed by Content-Length or by the chunked transfer coding
conforms
v2/routes/mod.rs:462-477; tests tests.rs:397, 458
CONTRACT.wire.md#transport-5
The contract covers every request whose path starts with /v2/; another path is outside it
A /v2/ request never passes the layers of the 1.x router, which is handed over whole as the other router. Introduced.
CONTRACT.wire.md#transport-6
The broker ignores the query of the request target
conforms
v2/routes/mod.rs:108, 396
Both read uri().path(); the router itself was audited at v2/wire/route.rs.
CONTRACT.wire.md#transport-9
A request to an endpoint with a body is UnsupportedMediaType unless its Content-Type has the media type application/json, ignoring ASCII case and parameters
When allowed, the broker starts one operation before writing the response, owned by the request's owner
conforms
v2/routes/operations.rs:28-37, 67-71; test tests.rs:1595
CONTRACT.wire.md#execute-5, #execute-6
A request that starts no operation, BrokerBusy included, leaves its RequestId unused
conforms
v2/routes/operations.rs:53-65; v2/routes/mod.rs:93-105; test tests.rs:1655
Only start takes a RequestId.
CONTRACT.wire.md#execute-7
A replayed response has the first response's Decision, Policy, EvaluatedAt, OperationId, EventPipe and the current Status; nothing is evaluated or started
conforms
v2/routes/operations.rs:49-51, 138-147; v2/routes/held.rs:23-29; test tests.rs:1708
CONTRACT.wire.md#execute-8
Requests of one owner with one RequestId that arrive together start at most one operation
Both registries are searched by id for the owner. That two operations never share an id is the earlier report's cannot-verify row (v2/execution/operations.rs:392-397).
CONTRACT.wire.md#status-2
Status always; StartedAt, CompletedAt, ExitCode, Message under their conditions
conforms
v2/routes/operations.rs:176-184; test tests.rs:1771
The values are the registry's, audited earlier.
CONTRACT.wire.md#cancel-5
The response has one member, Status: Canceling, or the terminal status
A token authorizes a request when the broker holds it, the request has exactly one header whose field value is the token, the body equals the bound request with its RequestId, and the owner's SID is the bound user's
The bypass response has OperationId, Status and EventPipe only: no decision, no policy identity
conforms
v2/routes/bypass.rs:132-145; test tests.rs:2621
CONTRACT.wire.md#bypass-13
For the bypass response the broker uses up the token and starts one operation before writing the response, owned by the request's owner
conforms
v2/routes/bypass.rs:28, 91-96
CONTRACT.wire.md#bypass-14
Every process runs with a token of the bound user, elevated exactly when Elevation is Elevated; otherwise no step runs and the operation ends Failed
conforms
v2/execution/operations.rs:415-431; executor/windows/token.rs:81-128; executor/windows/mod.rs:254, 271, 526-533; test tests.rs:2984
The bound user is the request's owner's (v2/bypass/tokens.rs:177). The executor is pre-existing, with its UNTESTED: at executor/windows/mod.rs:529-530.
One response whatever the reason of the rejection.
CONTRACT.wire.md#bypass-17
A replayed response has the OperationId and EventPipe of the first and the current Status; nothing is started
conforms
v2/routes/bypass.rs:44-45, 132-145; test tests.rs:2682
CONTRACT.wire.md#bypass-18
Requests with one token that arrive together start at most one operation, and each one with the owner, body and RequestId of the starter gets the response or its replay
conforms
v2/routes/bypass.rs:42-96; v2/bypass/tokens.rs:149-158; test tests.rs:3048
The tokens stay locked from the lookup of the operation to the use of the token. UNTESTED: at v2/routes/bypass.rs:32-41.
CONTRACT.wire.md#bypass-19
The same request with the same token gets the operation it started while the broker holds it, and BypassTokenRejected after
The evaluator exports no reading, so the code evaluates against a fixed policy and looks only at whether the check is UnreadableRequest, the first of CONTRACT.policy.md#precedence.
For a bypass operation, the broker closes any connection that is not from the owner without sending a frame, and that connection is not the one it serves
The 1.x router is unchanged. A 1.x request of a client the broker cannot identify still gets no response, now once its header is read.
Violations
Closed-set value written as an object is read (CONTRACT.wire.md#values-4, #json-4). Known. Every 2.0 endpoint that reads a body now accepts {"Install": null} where the contract requires BadRequest. Fix: in now-policy-api, read a closed-set value from a JSON string only; then un-ignore v2/wire/read.rs:1096.
Leap second written with seconds 60 (CONTRACT.wire.md#values-3, CONTRACT.policy.md#timestamps-2). Known. EvaluatedAt, StartedAt and CompletedAt can carry it. Fix: in now-policy-api, write a leap second as 59 with the largest fraction, or refuse it; then un-ignore v2/wire/convert.rs:1000.
Neither is in the code of this diff, and the diff adds no violation of its own.
Partials
Clients closed without a response (CONTRACT.wire.md#transport-13). Required: ERROR_PIPE_BUSY or BrokerBusy, and no response only at the two time limits. Done: a connected client is dropped when both pools are full, when the spare instance is missing, when its user cannot be looked up, and when its user changed during capture. Fix: let the contract allow a closed connection for a client over the limits or one whose user the broker cannot read, or answer these with BrokerBusy from a bounded writer.
ServerVersion is 0.0.0 (CONTRACT.wire.md#capabilities-1). Required: a string naming the broker's version. Done: the version of a crate that is never bumped. Fix: write the version of the Devolutions Agent build that hosts the broker.
A used-up token given again after 60 seconds (CONTRACT.wire.md#bypass-15). Required: a used-up token never authorizes again. Done: never within the lifetime it was held with; afterwards the broker cannot tell it from a new token. Fix: have the Agent's side guarantee fresh tokens and say so where it calls hold, or remember used-up digests for the life of the process within a bound, or word the contract as "while the broker remembers it".
Bypass requests without a source name (CONTRACT.wire.md#bypass-reading-4). Known. Required: the reading without Source.Name under Scoop, Vcpkg and every other manager. Done: InternalError, token kept. Fix: an evaluator request type, or a reading function exported by now-policy-eval, that takes a request without Source.Name; until then no bypass Uninstall runs outside Npm, Bun, Cargo and Pip.
Execution requests that remove Devolutions Agent (CONTRACT.wire.md#operations-5 to -9). Required: the listed rules decide how an operation ends. Done: one more rule, which ends the operation Failed without a step. Fix: add the rule to #operations, next to the two that already end an operation without a step.
Failure paths that close a bypass channel (CONTRACT.wire.md#event-channel-6 to -10). Required: the channel closes only in the five listed cases. Done: three failures while refusing a connection close it too. Fix: add "when the broker fails to serve the pipe" to the list, or recreate the instance instead of giving it up.
Recorded source of an Update (CONTRACT.policy.md#managers-4). Known; unchanged by this diff, now reached by both kinds of request.
Cannot verify
CONTRACT.wire.md#event-channel-5 (the owner): needs a run with a signed client, checking that the process that sent a bypass request reads the frames of its operation, and that an unsigned copy of it and another executable of the same user read none, as v2/routes/held.rs:105-106 asks.
Not yet realised
CONTRACT.wire.md#bypass-4: the Agent's side that gives the broker a token (known).
A 1.x policy file is not converted: not-yet-realised (known) against INTENT.legacy.md#format-1-1; the 2.0 routes answer as a broker without an accepted policy, and the 1.x routes keep enforcing the file (tests.rs:1126).
Two mismatches in the published types, kept as ignored tests: violates (known), both rows above; in the dependency.
An Update under Scoop or PowerShell ends Failed without a step: partial (known) against CONTRACT.policy.md#managers-4; conforms to CONTRACT.wire.md#operations-6.
No code issues a bypass token: not-yet-realised (known) against CONTRACT.wire.md#bypass-4; the BypassTokenRejected a released broker answers conforms to #bypass-9.2.
A bypass request without Source under a manager with several source names is InternalError and keeps its token: partial (known) against CONTRACT.wire.md#bypass-reading-4; the response conforms to #errors-7 and #bypass-16.
A policy replacement whose body never arrives leaves no audit record, and the denial record of an unidentified client has an empty executable: no statement of the governing texts covers audit records, so neither is a drift; both are under "Not covered by intent".
Intent rot
None found: no audited statement describes something the code has moved away from on purpose, apart from the partials above whose fix is a contract wording.
Outside this change
Listed once, not audited:
CONTRACT.wire.md: §definitions, §values, §json, §package-request, §opt-ins, §equal-requests, §decision and §policy-errors; the table of endpoints and its path matching; the members and reasons of §management-state; the store side of §validation and §replacement; the steps, statuses and rules of §operations, and what §cancel does to an operation; §event-channel other than the rows above, §frames and §frame-order; every rule for clients (#transport-3, -7, -14, #errors-8, -9, the client's part of #execute-9, #bypass-19 and #replacement-10); what the contract leaves outside itself (#transport-8, #endpoints-6, #authentication-4).
CONTRACT.policy.md: everything but §evaluation and the only source names cited above.
INTENT.md: vocabulary other than the bypass token, ownership, rules, trusted sources, decisions, fail-closed checks, #broker-limits-3, warnings.
INTENT.wire.md: §opt-ins, §targeting, §fields, #bypass-2, #bypass-6, #encodings-2 and -4.
INTENT.legacy.md: the rest of §format-1.
Not covered by intent
Audit records of a 2.0 policy replacement. A replacement leaves its attempt and its result, one refused for its body its attempt and its rejection, and a refused client a denial (v2/routes/mod.rs:144-151, 188-215, 322-327; tests tests.rs:558, 691, 2433, 2489). Three gaps, the first two known: a request whose body never arrives is dropped at the connection deadline while the body is read and leaves no record, as on the 1.x route; the denial of a client the broker did not identify names the user the client seemed to run as and an empty executable (v2/routes/mod.rs:366-373); a replacement the store fails to decide leaves a log line only (v2/routes/policy.rs:72-83, with its UNTESTED: comment).
Limits of the token store. A token lives 60 seconds and the broker holds 256 at most, refusing a further one (v2/bypass/tokens.rs:18, 23, 125-127). The contract lets the broker discard a token early and says nothing about refusing to hold one; that is for the Agent's side to handle.
One lock for every bypass request. The tokens stay locked while the registry is read for the product code and while the operation starts (v2/routes/bypass.rs:42-96), so bypass requests are answered one at a time.
A second read of the product code. A bypass Uninstall is checked against the contract's naming rule and then against the 1.x rule when its plan is made (v2/execution/plan.rs:120-125). If the second read fails, the operation starts, ends Failed, and the token is used up.
The pause after a refused connection. The channel of a bypass operation waits one second after a refusal before it judges the next client (event_channel.rs:585, 812, 852), and the pipe has one instance. Another executable of the same user that connects in a loop delays the owner's frames and can keep the owner from connecting within the 60 seconds. The contract makes the channel best effort; a status request still answers.
1.x pieces the 2.0 routes call. The capabilities use the 1.x probe and its type and the timeout of the 1.x tracker (v2/routes/capabilities.rs:13-14; server/mod.rs:746), the plan uses helpers of the 1.x evaluator (v2/execution/plan.rs:120-123), and the audit records go through the 1.x audit functions with a label of their own (audit.rs:556-583, 789-794). INTENT.wire.md#encodings-1 wants the earlier routes to be a block the broker can drop; these need a home of their own when it is dropped.
A body that stops or is framed wrongly is BadRequest (v2/routes/mod.rs:480-488). The contract leaves such messages outside itself.
Line numbers are those of 1577e5704. The commits after it on this branch add tests, and change the event channel of a bypass operation in event_channel.rs: a client is identified as soon as it connects, the pipe does not listen for one second after a refusal, and a channel that fails before it serves a client closes its queue and logs the failure. The rows on #event-channel keep their verdicts; their line numbers moved.
…nel as the code keeps them
The comment on the wait for the end of the channel said its 60 seconds
start when the status becomes terminal. They start the first time the
loop looks at the wait after that, which is later when a client is being
identified or refused at that moment.
That a client is handed to its identification as soon as it connects is
the reason the pause comes before the listening, and no test bounds the
time between the two, so the comment there now says what to keep when
the function changes.
The exit for a refused connection that sent bytes was missing from the
comment on the exits no test reaches, and the comment on the token lock
did not name the start that panics once its registry took the operation.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Not run: anything with a signed client, and no integration test in testsuite (see below).
UNTESTED: properties added
crates/now-package-broker/src/event_channel.rs:814: The wait for the end of the channel is one wait for the whole loop: its 60 seconds start the first time the loop looks at the wait once the status is terminal, and no refused connection starts them again. A wait that started again with each refused connection would let a process that connects in a loop keep the pipe and the queued output for as long as it likes. The loop looks at the wait only where it pauses and where it listens. A status that becomes terminal while the channel identifies a client it then refuses, or closes the connection of that client, therefore starts the 60 seconds once that is over, and a wait that ends at such a time closes the channel once that is over. The start is late once at most, and the end is late once at most, whatever the clients do. No test waits 60 seconds; when changing this function, keep one wait for the whole loop, and let it win over the pause and over the listening.
crates/now-package-broker/src/event_channel.rs:851: A channel that fails to listen, to close a connection it refused, or to see the read of that connection end with nothing read, serves nobody and gives its pipe up: each of these exits returns its error at once, which drops the pipe, and the caller closes the queue. After any of them the channel no longer knows who its pipe is connected to, and the frames it would write next could reach a client it refused. No test makes a pipe fail in these ways; when changing this function, check that none of these exits listens again or returns the pipe.
crates/now-package-broker/src/event_channel.rs:866: The channel hands a client to its identification as soon as the client is connected: this function awaits nothing between the two, and the identification starts when a thread of the blocking pool takes it. In any time left between them, the process that connected may exit and its id go to another process, which the channel would then identify in its place. No test bounds that time; when changing this function, keep every wait, the pause after a refusal included, out of the lines between the connection and this call.
crates/now-package-broker/src/pipe.rs:219: The pipe server identifies a client process with PipeClient::from_connected_pipe, and a process that capture refuses, such as one whose executable is on a network share, is served as an unidentified client. A weaker capture here would let the routes trust a process the broker did not verify. The tests pass their own capture to ConnectedClient::capture, so none runs this function or a capture that fails on a real process. When changing this, check that the accept loop still captures with this function, and that it passes the full identity capture.
crates/now-package-broker/src/task.rs:93: The broker stops holding the operations of the 2.0 encoding once they ended long enough ago. Without this task every ended operation stays in memory, and its request id stays taken, until the broker restarts. No test runs the broker task, so check that this call remains when changing how the task starts.
crates/now-package-broker/src/v2/routes/bypass.rs:32: Another request finds either the token held and no operation started with it, or the token used up and the operation it started held, and nothing in between unless the start panics once its registry took the operation. Were the token used up before the operation is held, of two equal requests that arrive together, the second could be answered BypassTokenRejected while the first starts the operation, where the contract has it get that operation. Were the operation held before the token is used up, the same request from another executable of the user could start a second operation with the token. Everything from the lookup of the operation to the use of the token happens while the tokens are locked, and a test that sends requests together passes most of the time without that; when changing this function, keep the lock from the lookup until the token is used up.
crates/now-package-broker/src/v2/routes/capabilities.rs:50: An opt-in listed for a manager is one the command builder of that manager acts on, or one the broker runs itself for it, and no other opt-in is. The tests compare the list with the keys the reading of each manager accepts, not with what the builders do, so a builder that starts or stops carrying an opt-in leaves them passing while a client is told the wrong thing. When a command builder or the plan of an operation changes what it does with an opt-in, change this list with it.
crates/now-package-broker/src/v2/routes/held.rs:97: The event channel of a bypass operation identifies the process of a connection the way the request pipe identifies the client of a request: PipeClient::from_connected_pipe, then validate_connection with the setting of the broker state, and the owner that Connection::caller makes of such a client. A weaker identification would send the output of a bypassed operation to a process the broker does not authenticate as its owner, and an owner made another way would be refused its own frames. The tests of the channel identify with a function of their own, and the one test that runs this function connects another executable, which gets no frame; none connects a process that this function identifies as the owner, because capture does not accept the test process on every machine. When changing this, check with a signed client that the process that sent a bypass request reads the frames of its operation, and that an unsigned copy of it and another executable of the same user read none. The process identified is the one that opened the connection: a handle that process gives to another one is used without the broker seeing it.
crates/now-package-broker/src/v2/routes/policy.rs:73: A replacement the policy store fails to decide names its client in the log. The store fails before the attempt is recorded, so this line is the only trace of who asked. When this changes, check that every failure of replace_document still comes before its attempt is recorded, and that the line keeps the SID and the executable of the client.
Stopped or deferred
Issuing a bypass token.BypassTokens::hold is the entry point that binds a token to a bypass request and a user, and nothing calls it outside tests: the Agent's side does not exist yet. A released broker therefore answers every bypass request BypassTokenRejected.
Bypass request without Source. Where the manager's reading needs a source name to tell which of several the request means, the evaluator's request type cannot express the request, so it is answered InternalError and its token stays unused. This covers every manager but Npm, Bun, Cargo and Pip, and for Dotnet every operation but Install and Update; it includes every Uninstall under WinGet, Chocolatey, PowerShell, Scoop, Vcpkg and Dotnet.
A used-up token given again. The broker refuses it for the 60 seconds it was held with; afterwards nothing tells it from a new token, so hold documents that its caller never gives a token twice.
Limit on tokens. A used-up token counts toward the 256 the broker holds until its 60 seconds end, so the broker accepts at most 256 tokens a minute even when each is used at once. Whoever writes the issuing side decides whether remembered tokens get a larger bound of their own.
Event channel of a bypass operation.
A process of the same user that connects in a loop reads nothing but can keep the owner off the single pipe instance, and after each refusal the pipe is busy for one second. The owner still learns the status with status requests.
The identification of a connected client has no deadline: the call cannot be canceled and keeps the pipe, so a client whose identification stalls keeps the pipe, the queued output and one blocking thread past the channel's 60 seconds. One such channel exists per bypass operation.
A channel that can no longer tell who its pipe is connected to (listening fails, the identification panics, closing a refused connection fails, or the read of a refused connection does not end) gives its pipe up and serves nobody. The list of §event-channel of when the broker closes a channel has no entry for that.
A process the broker identified as the owner can hand its pipe handle to another process without the broker seeing it.
No test connects a process the production identification accepts as the owner, because the identity capture does not accept the test process on every machine; the refusal side is tested with a real other executable.
Uninstall of Devolutions Agent through evaluate or execute.CONTRACT.wire.md names the protection only for bypass (ProtectedPackage). An allowed execution request that would remove the Agent, and any removing request while the Agent's product code cannot be read, starts an operation that runs no step and ends Failed; the list of §operations has no rule for it.
ServerVersion. It is the version of the broker crate, which is 0.0.0, as on the 1.x routes.
Clients the broker cannot identify. Their /v2/ requests are answered as the contract says; a request under another path still gets no response, and a client is still closed without a response when the connection and busy-reply pools are both full, when its user cannot be looked up, or when its user changed during the capture.
Audit records of a policy replacement. A replacement whose body never arrives leaves no audit record, as on the 1.x route. The denial record of a client the broker did not identify has an empty executable. A replacement the store fails to decide leaves only a log line that names the client.
Bypass requests are served one at a time. The token lock is held from the lookup of the operation until the token is used up, which includes reading the Agent's product code and starting the operation.
1.x routes against a 2.x policy file. They report the file as invalid and never write over it; serving them from a 2.x policy is not part of this change.
1.x pieces the 2.0 routes call. The capability probe, the operation timeout, evaluator helpers and the audit functions are shared with the 1.x routes and need a home of their own when the 1.x encoding is dropped.
Single pipe instance.max_instances(1) and first_pipe_instance(true) are in the code, and no test pins them: a test process has no right to create an instance on these pipes, whatever the limit.
Deviations from the conventions
The description starts with the list of temporary git dependencies and carries the scope table, so it holds more than a squash commit body would.
All tests added are unit tests in the crate, as in the two pull requests below. No integration test was added to testsuite: nothing there drives the package broker through the Agent binary yet, so the routes are tested through the crate's router, with real named pipes for the event channels.
Review and pruning
Review: the last full review of the range found no behavioural defect and asked for comment changes only, which the last commit makes; a separate reading of that commit checked each changed comment against the code. Left from the reviews, not blocking:
the test of an identification that panics cites §event-channel for all it asserts, and the contract does not decide that the pipe is gone afterwards;
the wait for the end of a bypass channel could be made a parameter, as the pause is, so that tests cover it instead of the UNTESTED: comment;
every_manager_capability_names_at_least_one_operation would pass on an empty list of managers (three other tests catch that today);
the_capability_of_a_manager_names_the_opt_ins_its_reading_accepts cites CONTRACT.policy.md §managers for the keys each reading accepts, while listing exactly those keys is the broker's own rule;
a panic in the start of a bypass operation after the registry took the operation would leave an operation held with its token unused; no such panic is known, and the comment at that code says so;
the Issue: footer of four test commits is separated from the co-author line by a blank line, which the squash removes.
Dependencies: no manifest or lockfile change in this range.
Tests: 113 tests in scope, none removed for lack of value; one test that repeated a table row was folded into the table, whose rows now check the whole error response. 20 mutants written from the contract without sight of the tests: 18 caught, 2 survived, and three added tests now catch all 20. 23 mutants written against single tests were all caught, each by a test nothing else replaces. On the later event-channel commits: listening during the pause, no pause, no closing of the queue, and no draining read after a refusal are each caught; a wait between the connection and the identification is not, which is the UNTESTED: comment at that code. cargo-mutants was not run on any file of this range (about 30 seconds a mutant).
clippy prints a manifest warning about an unused sysevent-winevent dependency of the broker crate; it is on master and not part of this change.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved handle-inheritance flaws can expose bypass output to concurrent child processes and violate Windows’ cross-session restrictions for service-mode launches.
When no client connects, returning here leaves the queued output in the sink retained by the operation record. A terminal operation is held for at least 300 seconds, so after the 60-second channel linger each unconsumed operation can retain up to 2 MiB of output for several more minutes. Abandon the sink before returning, as the error branch already does, to release the queue when nobody can read it.
A replacement canceled by the connection deadline during this body read leaves no audit record; rejecting its media type in find_endpoint also bypasses auditing. Record the appropriate denial or start an attempt guard before those exits and awaits, without changing response precedence. Carry that guard into the store so cancellation records a rejection and completed requests produce exactly one attempt/result pair.
These newly served operations capture output through non-strict event sinks, but executor/windows/process.rs joins their blocking readers without a post-exit deadline. A descendant that keeps stdout or stderr open can leave an operation Running or Canceling indefinitely after exit, cancellation, or the advertised timeout. Use stoppable readers with bounded post-exit draining before assigning the terminal status.
Use the selected intent in terminal audit records
crates/now-package-broker/src/audit.rs:521
Optional: the terminal audit recorders still hard-code INTENT or DOCUMENT_INTENT instead of using the intent chosen in begin_as. A mismatched completion method would then label the attempt and result as different requests. Use state.intent in failed_at, succeeded_at, document_failed_at, and document_succeeded_at so every record has one source of truth.
Share the policy test double instead of duplicating it
TestPolicyFile duplicates the byte storage, generation-based observation, retained-target handling, and conditional write logic of FileDouble in policy_store/document_tests.rs:37–209. Keeping both implementations makes it easy to update the storage behavior for only one set of tests. Share the existing double through a #[cfg(test)] support module and extend its fault cases as needed.
…ities
The 2.0 capabilities carry the version of the Devolutions Agent that
hosts the broker, and the broker named the version of its own crate,
which is not one any Agent is released with.
The Agent now gives its package version to the broker task.
A version the capabilities cannot carry, empty or longer than 128 bytes,
is refused when the task is created, so the service fails to start with
the cause instead of answering every capabilities request with an
internal error.
The 1.x routes keep reporting the version they reported.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…Package
The wire contract has no request start an operation that would uninstall
the Devolutions Agent, which hosts the broker, and names where
`ProtectedPackage` falls among the outcomes of an evaluation, an
execution and a bypass request.
The broker answered it for a bypass request only: an evaluation said
such a request was allowed, and an execution started an operation that
ended `Failed` and kept its `RequestId`.
One function now decides a protected uninstall for the three requests.
A request that removes a package, by its operation or by
`UninstallPrevious`, is refused when it names the Agent or when the
product code of the installed Agent cannot be read; the product code is
read for no other request.
An evaluation answers it before anything else, and an execution after a
used `RequestId` and before the policy is looked at, so it starts
nothing and leaves its `RequestId` unused.
The plan of an operation still refuses to remove the Agent, for a
request the Agent turns out to be named by once the operation starts.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The wire contract now states how long the broker holds a bypass token:
it discards one no later than 60 seconds after the Agent gave it,
remembers a used-up one until then, and takes a token with the same
characters given after that for a new token.
The token store already does this, so its tests now name the contract as
the source of these instants instead of pinning them as the broker's own
choice, and one test follows a used-up token across the 60 seconds.
What the contract leaves to the broker, the exact instant a lifetime
ends and how a remembered token counts against the bound, stays pinned
as such.
The comments of the store and of the bypass route say the same, and the
route names what a token digest cannot tell apart while the broker holds
the operation an earlier token started.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…dable
A client refuses the status of a `Completed` operation that has no
`StartedAt`, since a manager process that exited on its own was
launched.
The status route copies what the registry recorded, and the registry
records a launch only when the executor reports one, so the response
depends on a property of the executor that no test checks.
The comment names that property where the response is built.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…the event channel
The wire contract now states that the broker does not listen on the
event pipe for one second after it closes a connection it does not
serve, that opening the pipe fails with a busy pipe meanwhile, and that
the broker closes the channel when a failure leaves it unable to tell
which process is connected.
The channel already behaves so, and its tests pinned the pause and the
busy pipe as the broker's own choice: they now name the contract as
their source, and the comments at the pause and at the exits that give
the pipe up name the section that decides them.
No test of the pause runs with the value the broker uses, which a
comment at that value now says.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… for what it shows
The test of where `ProtectedPackage` falls among the outcomes of an
execution named two replies `replay` and `reply`, which clippy refuses
as too similar and which told a reader nothing of the second.
It is the reply that comes before the policy is looked at, and is named
so.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ion of its client
The identification of the client connected to an event channel owned the
pipe for as long as it ran, so the channel could do nothing with its
pipe until the identification returned.
The channel now keeps the pipe and lends it: the identification reaches
it through the channel each time it asks the pipe something, and the
channel takes it back once the identification is over.
What the channel sends, and how a client is identified, do not change.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…does not complete
The wire contract has the broker close an event channel when the
identification of a process connected to its pipe does not complete,
since the broker then cannot tell which process is connected.
The channel waited for the identification for as long as it ran, so one
that never returned left the pipe connected to a client the channel knew
nothing of, and busy for every other client, for as long as the broker
ran.
The channel now waits 30 seconds for the identification of a client.
When they pass it closes its pipe at once, sends no frame and closes its
queue, as it does when the identification panics.
It does not wait for the identification, which reaches the pipe through
the channel and finds none from then on; a pipe that the identification
is asking something at that instant closes as soon as it has answered.
The channels that identify no client are unchanged.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…its client
An event channel closes its pipe when the identification of a client
does not complete in time, and cannot close it while the identification
keeps it.
The identification of the broker kept the pipe for the whole capture of
the client process, which opens the executable of the client and checks
who can write it, so a capture that never returned still left the pipe
connected and busy.
The capture asks the pipe one thing, the id of the client process, as it
starts and once more before it returns.
It now takes that question as a function, and the identification of an
event channel answers it through the channel, which keeps the pipe only
for the length of each answer.
The capture of the client of a request is the same function with the
pipe it is given, and does what it did.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A request without a source that got a plan with a source option, or no
plan at all, was still answered with an operation id, so the test of the
route passed either way. It now waits for the run and reads its command.
An elevated Install or Update without a source through Windows
PowerShell or .NET tool gets a command from its builder, so only the
reading of the bypass request refuses it: both are now cases of the
unreadable requests.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The channel marked a pipe as given up with an atomic flag and then tried
the lock a query of the pipe held, while the query unlocked and then
read the flag. Each of the two could read the other's earlier value on a
processor that lets a load run ahead of a store, as ARM64 does, and then
neither closed the pipe: it stayed connected until the identification
returned, which the deadline exists not to wait for.
A query now takes the pipe out of the lock for as long as it runs and
puts it back, or closes it when the channel gave it up meanwhile, so
every change of the state happens under the lock and none waits for a
query.
The test of a pipe given up during a query drives the pipe itself, so it
no longer depends on the identification reaching its query before the
deadline passes.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…est takes
The assertion that a bypass request without a source runs a command
without one looked for two spellings in every case, though half of the
cases build a command that has neither spelling with a source as well.
Each case now names the option its manager takes a source with, or none,
and a case whose operation does not run fails under its name.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
No test asked the pipe of a channel anything and then expected the
channel to serve its client, so a pipe that a query did not give back
left every test passing while no owner could read a frame. The audience
of the pipe tests now asks the pipe twice, as an identification does.
A test through the channel makes the deadline pass while a query of the
pipe runs: a channel that only took its pipe back then would leave it
connected once the query returned.
The test of a pipe given up during a query bounds the time giving up
takes, so a pipe that waited for the query fails it.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… command shows
Half of the cases had no source option to look for and took another path
through the body of the test. They are a test of their own, which checks
that their operation runs, and both tests let the operation end, so no
executor outlives its case.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Update for head 1f4c8e97f, which follows CONTRACT.wire.md at Devolutions/now-libraries@3014fcbb899d. It replaces the matching parts of the earlier evidence comment.
cargo test -p now-package-broker: 1146 passed, 0 failed, 2 ignored.
cargo test -p devolutions-agent --no-run: builds.
ci/check-oracle-markers.ps1 on the files this stack changes: clean.
What changed since the earlier comment
A bypass request without Source is no longer InternalError: the evaluator's bypass reading decides whether it is readable, and a readable one runs.
ProtectedPackage is an outcome of evaluate, execute and bypass. The earlier comment listed the Agent uninstall on evaluate and execute as a deviation; it no longer is one.
ServerVersion is the version of the hosting Agent.
The event channel of a bypass operation closes when the identification of a connected process does not complete within 30 seconds.
UNTESTED: properties added or changed
v2/execution/plan.rs: an elevated Install or Update without a source under a manager other than WinGet and Chocolatey runs no step. The plan does not refuse it; the route does, by reading the request as a bypass request first.
command_builder/scoop.rs: the Update refusal now covers only a request that chooses its source.
event_channel.rs: the pause after a refused connection is the contract's one second; the identification deadline is longer than an identification that completes and shorter than the 60 seconds of an ended operation's channel.
v2/routes/held.rs: the identification keeps the pipe of the channel only while it reads the id of the client process.
v2/routes/operations.rs: the response of a Completed operation has StartedAt, which relies on the executor reporting the launch of every process whose exit it returns.
devolutions-agent/src/service.rs: the broker is given the package version of the Agent that hosts it.
Stopped, waiting for a decision
A token with the same characters given again later than 60 seconds after the first, while the broker still holds the operation the first one started for the same owner. The broker names a bypass operation by the digest of its token, so an equal request replays the held operation and an unequal one is BypassTokenRejected, though the new token authorizes it. One way out with little change: refuse to hold a token whose digest names a bypass operation the broker still holds, with the answer it gives for a token it already holds. No code issues a token yet, so nothing reaches this today.
PowerShell 7 passes -TrustRepository on an Install or Update without a source, as it does with one. Without a source the manager picks the repository, so the option then trusts whichever repository that is.
Notes for the reviewer
The 30 seconds of the identification deadline are a choice of this change: the contract says the channel closes when the identification does not complete, and names no duration.
A thread that is inside the one question the identification asks the pipe (GetNamedPipeClientProcessId) keeps the pipe until that call returns. An identification that hangs elsewhere, reading the executable or validating its signature, no longer keeps it.
An identification that never returns still keeps one thread of the blocking pool for as long as it runs: the deadline frees the pipe, not the thread.
Once a channel closed at the deadline, its pipe name is free while the operation may still run, as it is after any other close of a channel.
The plan of an operation still refuses to remove the Agent, with the rules it had; a request the routes let through and the plan refuses ends Failed.
A removing request reads the product code of the installed Agent from the registry while the bypass tokens are locked, and a request that starts reads it a second time in its plan.
BrokerTaskConfig::default() names the broker crate's own version; the Agent service overrides it.
Still out of scope here: installer arguments that remove the Agent, product codes under managers other than WinGet, and KillBeforeOperation.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical authorization race allows expired bypass tokens to start new operations after lock contention, and client identification can extend event-channel retention beyond the 60-second post-completion limit.
…heir own
The query of the test that lets the deadline pass during it waited for
the test to release it. A channel that waited for that query would do so
on the thread the test runs on, and the test would never end instead of
failing, so the query now ends after a bounded time.
The test of bypass requests that arrive together lets its operation end,
so its executor does not outlive it, and the wait for the operation of a
bypass request without a source shows a status request that fails.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Head is now 7fecff236: one more commit, tests only, on top of the head the comment above describes.
It bounds a wait in the event-channel test that lets the deadline pass during a query, lets the operation of the test of bypass requests that arrive together end, and makes the wait for a sourceless bypass operation show a status request that fails.
Run locally on this head: cargo +nightly fmt --all -- --check clean, cargo clippy -p now-package-broker --all-targets -- -D warnings clean, cargo test -p now-package-broker 1146 passed, 0 failed, 2 ignored, ci/check-oracle-markers.ps1 clean.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Token authorization can accept expired tokens after mutex contention, and event-channel waits can extend channel retention beyond the required 60-second post-completion limit.
The two points the earlier comment listed as waiting for a decision are settled, with no change to the code:
A token given again while the broker still holds the operation its earlier use started is treated as the earlier one. The Agent never gives the same token twice, and the broker's single use of a token relies on that.
PowerShell 7 keeps -TrustRepository on an Install or Update without a source, which is never an elevated one.
…-routes-7702d2
A connection over a limit is classified by the grant its request
presents, and its client is no longer served by a router of its own.
The router that classifies it is wrapped so that a request of the 2.0
encoding still gets `BrokerBusy` in that encoding: no such request
presents a grant, since the grant route is a 1.x route.
A client is admitted with the lookup of its user first, then with the
capture that keeps a client whose process is not identified.
The busy reply of the 1.x encoding now carries `BrokerBusy` as well, so
the test that tells the two encodings apart reads the `ResponseKind`
member, which only a 1.x error has.
Issue: DGW-499
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Merged master up the stack (merge commits only); head 1834430d7.
master reworked what the broker does with a connection over a limit: the request is classified by the grant it presents, and the busy reply carries BrokerBusy on the 1.x routes too. Two places met the 2.0 routes:
The router that classifies a connection over a limit is wrapped by the 2.0 busy routing, so a request under /v2/ still gets BrokerBusy in the 2.0 encoding and every other request is classified as on master. No 2.0 request presents a grant, since the grant route is a 1.x route. a_request_of_the_2_0_encoding_over_the_limit_gets_the_busy_reply_of_that_encoding covers the wiring on a real pipe.
A client is admitted with the lookup of its user first, as on master, then with the capture that keeps a client whose process is not identified.
The test that tells the two encodings apart on a busy connection now reads ResponseKind, which only a 1.x error has, because both busy replies carry BrokerBusy.
Open point, unchanged by the merge: master rate-limits the warnings for rejected clients so that a local flood of failing connections cannot fill the log, and the warning logged for a client whose process is not identified (which is served, not rejected) is not rate-limited.
Checked locally on this head: cargo +nightly fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p now-package-broker (1158 passed, 2 ignored), cargo test -p devolutions-agent --no-run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Temporary git dependencies, each of which must become a crates.io version before this merges (introduced at the bottom of this stack, 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 #2230, which builds on #2229, which builds on #2224, #2225 and #2226.
The package broker serves the 2.0 request encoding: every endpoint of
CONTRACT.wire.mdunder/v2/, decided against a policy in format 2.x.A request whose path starts with
/v2/goes to its own router, and every other request reaches the 1.x router as before, so a later release can delete the 1.x routes without touching these.Each request is answered by the first of the contract's outcomes that applies:
BrokerBusy,UnknownEndpoint,UnsupportedMediaType,Unauthenticated,AdministratorRequired,RequestTooLarge,BadRequest, then the endpoint's own.The first five are decided without reading any byte of the body, and a panic while answering is
InternalError.GET /v2/healthanswers any client with onlyStatus,Readyexactly when the broker holds an accepted policy.GET /v2/capabilitiesnames the version of the Devolutions Agent that hosts the broker, which the Agent gives the broker when it starts it, the operation timeout and, for each manager, the opt-ins of its reading that the broker acts on.POST /v2/package-requests/evaluateanswersProtectedPackagefor a protected uninstall whether or not the broker holds a policy, then the decision of the accepted policy,PolicyUnavailablewithout one, andNotRunnablefor an allowed request that would run aPreorPostcommand elevated, audit mode included.POST /v2/package-requests/execute,GET /v2/operations/{OperationId}andPOST /v2/operations/{OperationId}/cancelstart, report and cancel the operations of their owner. An execution request that is a protected uninstall is answeredProtectedPackageonce itsRequestIdis known to be unused, starts nothing and leaves thatRequestIdunused. Operations of the 1.x routes are not ones a 2.0 request names or replays.GET /v2/policy/management,POST /v2/policy/validateandPOST /v2/policyread the management state, report the policy errors of a document, and replace the policy for an elevated administrator, with the audit records the 1.x route leaves.POST /v2/package-requests/execute-bypassstarts an operation without any policy for a request its bypass token authorizes. The request is read by the evaluator's bypass reading, so one without a source runs with the only source name of its manager, or leaves the choice of source to the manager, or isBypassRequestUnreadable. The broker holds tokens in memory, as digests, each bound to one bypass request and one user for 60 seconds. A token is used up once the broker holds the operation it started, and a used-up token is refused when the broker is given it again within those 60 seconds. No code issues a token yet: the entry point that binds one has no caller until the Agent's side exists, so every bypass request is answeredBypassTokenRejectedin a released broker.A protected uninstall is a request that removes a package, by
Uninstallor by theUninstallPreviousopt-in of an Install or Update, and either names Devolutions Agent or arrives while the broker cannot read the product code of the installed Agent.An Install or Update that names the Agent without
UninstallPreviousis evaluated like any other request.The plan of an operation still refuses to remove the Agent, as a second check behind the routes.
The event channel of an operation a bypass request started sends its frames only to a process the broker identifies as the operation's owner, the way the request pipe identifies a client.
A client is identified as soon as it connects; any other connection is closed without a frame, and the same pipe instance listens again one second later, until the owner connects or the channel ends.
An identification that does not complete within 30 seconds closes the channel, so the identification keeps the pipe only while it reads the id of the client process.
A process of the same user that connects in a loop can therefore keep the owner off the channel, but reads nothing and cannot make the channel outlive its 60 seconds after the operation ended; the owner still learns the status with status requests.
A client whose process the broker cannot identify used to have its connection closed without a response.
Its
/v2/requests are now answered as the contract says: health normally, every other endpointUnauthenticatedwithout reading the body.A request under any other path on such a connection still gets no response.
/v2/endpoint ofCONTRACT.wire.mdv2::routes::tests, one group per endpoint;v2::wire::route::table_has_every_endpoint/v2/a_path_outside_the_prefix_reaches_the_other_router,the_1_x_routes_hold_a_policy_exactly_when_the_file_is_in_format_1unknown_endpoint_wins_over_the_media_type_and_the_client,unsupported_media_type_wins_over_the_client,unauthenticated_wins_over_an_oversized_body,unauthenticated_wins_over_administrator_required,administrator_required_wins_over_an_oversized_body,the_first_five_outcomes_are_answered_without_any_byte_of_the_body,a_busy_broker_answers_broker_busy_whatever_the_request/v2/healthreturns onlyStatushealth_is_ready_exactly_when_the_broker_holds_an_accepted_policy,health_answers_a_client_the_broker_does_not_authenticatean_evaluation_names_the_decision_the_policy_and_the_evaluation_time,an_evaluation_without_an_accepted_policy_is_policy_unavailable,a_denied_evaluation_is_answered_with_its_decisionPreorPostcommands for an elevated run, audit mode includedNotRunnablean_allowed_request_with_commands_for_an_elevated_run_is_not_runnable,a_request_the_contract_refuses_whatever_the_policy_is_refused_in_audit_mode_tooa_request_id_belongs_to_its_owner,a_status_or_cancel_request_for_an_operation_the_broker_does_not_hold_for_its_owner_is_operation_not_found/v2/an_operation_of_the_1_x_routes_is_not_one_a_2_0_request_names_or_replaysRevisionfor the sameIda_replacement_with_the_id_of_the_accepted_policy_and_no_higher_revision_is_revision_not_higher, with the other replacement outcomes beside ita_policy_replacement_leaves_its_attempt_and_its_result_under_its_own_request,a_policy_replacement_refused_for_its_body_leaves_its_attempt_and_its_rejection,a_refused_policy_replacement_leaves_a_denial_recordthe_outcomes_of_a_bypass_request_come_in_their_order,a_used_up_token_authorizes_no_other_request,a_used_up_token_the_broker_is_given_again_authorizes_no_request,bypass_requests_with_one_token_that_arrive_together_start_one_operation,a_bypass_request_that_fails_before_the_broker_holds_its_operation_keeps_its_token,an_equal_bypass_request_with_the_token_of_an_operation_the_broker_no_longer_holds_is_bypass_token_rejected,a_bypass_request_to_uninstall_devolutions_agent_is_protected_package,a_bypass_operation_runs_as_the_bound_user_with_the_elevation_of_the_request;v2::bypass::tokensanother_process_of_the_user_reads_the_frames_of_an_execution_and_none_of_a_bypass;operations::a_channel_for_the_owner_sends_its_frames_to_the_process_identified_as_the_owner_and_to_no_other;event_channel::pipe_tests:a_refused_connection_gets_no_frame_and_the_next_admitted_one_gets_them_all,the_pipe_of_a_channel_is_busy_during_the_pause_after_a_refusal,a_channel_whose_identification_of_a_client_panics_sends_no_frame_and_gives_its_pipe_up,a_channel_whose_identification_of_a_client_does_not_complete_sends_no_frame_and_gives_its_pipe_up,a_channel_whose_deadline_passes_while_the_identification_asks_its_pipe_something_gives_its_pipe_up,a_pipe_given_up_while_it_is_asked_something_closes_once_it_has_answeredSourcea_readable_bypass_request_without_source_runs_its_command_without_the_source_option_of_its_manager,a_readable_bypass_request_without_source_whose_command_has_no_source_option_runs,a_bypass_request_without_source_that_its_other_members_make_unreadable_is_bypass_request_unreadable;v2::bypass::reading:a_request_without_source_is_read_with_the_only_source_name_of_its_manager,a_request_without_source_whose_manager_names_no_only_source_name_is_read_without_one,a_scoop_request_without_source_whose_id_names_one_app_is_readable,a_vcpkg_request_without_source_is_read_by_its_port_spec_aloneExisting::Conflictinv2/routes/bypass.rsProtectedPackageat its place among the outcomes of each endpointan_evaluation_or_execution_request_that_is_a_protected_uninstall_is_protected_package,a_request_that_is_no_protected_uninstall_is_evaluated,protected_package_comes_before_the_other_outcomes_of_an_evaluation,protected_package_comes_after_a_used_request_id_and_before_the_other_outcomes_of_an_execution,a_protected_uninstall_starts_no_operation_and_leaves_its_request_id_unused,a_bypass_request_to_uninstall_devolutions_agent_is_protected_package;v2::routes::protectionServerVersionis the version of the hosting Agentdevolutions-agentpasses its package version, and a version the capabilities cannot carry fails the creation of the broker taskcapabilities_name_the_version_of_the_agent_that_hosts_the_broker;task:the_state_of_a_task_has_the_agent_version_of_its_configuration,a_task_is_not_created_with_an_agent_version_the_capabilities_cannot_carry/v2/paths; other paths keep the close without a responsehealth_answers_a_client_whose_process_the_broker_did_not_identify,a_client_the_broker_did_not_identify_is_answered_in_order_without_any_byte_of_the_body,a_request_outside_the_prefix_from_a_client_the_broker_did_not_identify_gets_no_response;pipeteststhe_1_x_routes_hold_a_policy_exactly_when_the_file_is_in_format_1Issue: DGW-499
🤖 Generated with Claude Code