Repository navigation
feat(risk): send begin and settle through droid risk (VAL-648) - #273
factory-droid[bot] wants to merge 3 commits into
Conversation
The begin/settle requests and the judge session send FACTORY_API_KEY to whatever api_base_url / judge_api_base_url the workflow sets. Refuse any URL that is not https on factory.ai or a subdomain of it, before anything is sent. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
The action no longer makes its own risk HTTP calls with the API key. Begin and settle run `droid risk begin|settle`, which sends only to the Factory host the CLI resolves. The CLI is installed right before begin. api_base_url and risk_api_base_url are ignored, with a warning when set. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
🟡 Changes recommendedBegin and settle now use the CLI, but installer provenance and mutable settlement binaries expose credentials, and timeout and oversized-response handling regress. The first existing-test run could not load dependencies; after installing locked dependencies, all 147 tests passed, while ad hoc probes reproduced these four defects. - The release dependency remains explicit: the installed CLI must include the risk commands before this change ships. 🔒 Security review: 2 findings (High). 7 open findings ·
What changedMoves risk begin and settle from direct HTTP requests to a CLI subprocess with stdin JSON and an environment allow-list. Both actions install Droid before begin and pass its absolute path through frozen settlement; legacy URL inputs become ignored warnings, and judge API overrides gain Factory-host validation.
flowchart LR
A[Action installs CLI] --> B[CLI begin]
B --> F[Factory API]
F --> J[Judge session]
J --> S[CLI settle]
S --> F
Fix with an agentReply to a finding with a question, or comment |
There was a problem hiding this comment.
Droid found 7 issues (2 P1, 5 P2) in b811ba8. Summary
Install the Droid CLI with system tools only, run the judge with the same installed CLI, treat a CLI stopped at its deadline as a request with no answer, report an oversized answer explicitly, and let the response schema reject a null body. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Factory Code Review: Web · Desktop
Closes VAL-648
Ships only after a Droid CLI release that includes
droid risk(factory-mono#38337). The action installs the latest CLI at run time. Against an older CLI, begin fails withdroid_risk_unavailable("update the Droid CLI"), so don't merge until that release is out.Stacked on #272. This branch starts from #272's commit, so merge #272 first; this diff then shrinks to this PR's own commit.
What
The action no longer makes its own risk HTTP calls with
FACTORY_API_KEY. Begin and settle run the CLI's hiddendroid risk begin/droid risk settle. The CLI sends the request to the Factory host it already uses for everything else, and refuses unless that host is https onfactory.aior a subdomain of it.src/core/risk/droid-risk.ts(new): runsdroid risk <step>by absolute path. The request and OIDC token go on stdin as{"request","oidcToken"}, and the CLI answers{"status","body"}or{"error","message"}. The child's environment is an allow-list:PATH=/usr/bin:/bin,HOME,FACTORY_API_KEY, andFACTORY_API_BASE_URL(_EU)when set. It runs in the temp directory, so no.envin the checkout reaches it. The wrapper keeps its own deadline, so a CLI that handles SIGTERM and exits 143 still counts as no answer (retried). Output over 16 MiB fails asdroid_risk_output_too_largeinstead of being parsed truncated.src/core/risk/client.ts: thefetchclient, its base URL and its header building are gone. Retries (gateway status or no answer, with a fresh OIDC token each attempt), problem-document errors, the trusted-workflow skip, and unknown-variant handling are unchanged. They now read the CLI's answer. A CLI refusal (untrusted_api_url) fails without retrying.assertFactoryApiBaseUrlfrom fix(risk): refuse risk API URLs that are not Factory hosts (VAL-647) #272 stays forjudge_api_base_url.risk/action.yml: "Install Droid CLI" moves from after begin (judge runs only) to before begin (every run). It outputs the binary's path, which begin and settle get asRISK_DROID_BIN.action.yml: "Install Droid CLI for risk" (risk_droid) runs right beforerisk_beginwhenever risk runs, after the review's App token is revoked. It replaces "Install Droid CLI for the risk judge" and still keeps the judge off a binary the review session could have replaced./usr/bin/env -i PATH=/usr/bin:/bin HOME=... /bin/sh -c '/usr/bin/curl ... | /bin/sh', so acurlorshthe review put on PATH is not used.DROID_BINset to the same install's path, so begin, judge and settle use one binary.HOME,RISK_DROID_BINandFACTORY_API_BASE_URL(_EU)through itsenv -i, instead ofRISK_API_BASE_URL.api_base_url/risk_api_base_urlare ignored. They stay declared, now with an empty default, so pinned workflows keep working, and begin warns when one is set.Staging
There's no workflow URL input any more. To test against dev or preprod, set
FACTORY_API_BASE_URL(for examplehttps://dev.api.factory.ai) in the job's environment. The CLI honors it only for factory.ai hosts.Tests
test/core/risk/droid-risk.test.ts(new): runs a fakedroidand checks the argv, stdin envelope, env allow-list (no workflow token or OIDC request credentials), and that cwd is outside the checkout. It also covers a CLI error answer, a CLI without the command, a missing CLI, a CLI that traps SIGTERM and exits 143 at the deadline, a 1.5 MiB answer returned whole, and output past the bound.test/core/risk/client.test.ts: the same cases as before, against a stubbeddroid riskcall, plus: a CLI host refusal is not retried, any other CLI error is not retried, and a null body is rejected by the response schema for both begin and settle.test/core/risk/fixtures.ts:writeFakeDroid, a stand-in CLI that POSTs to$FACTORY_API_BASE_URLwith the key and prints{status, body}.risk-entrypoints,risk-bundled-runtime,risk-tail-runtime): these now run the fake CLI against their local Factory stand-in. That restores the positive begin/settle cases fix(risk): refuse risk API URLs that are not Factory hosts (VAL-647) #272 had to turn into refusals, including the lease token surviving settle'senv -i. New: begin ignores the URL input with a warning, and begin without the CLI sends nothing.risk-action-wiring,credential-exposure-wiring): the risk steps now start atrisk_droid. The install comes before begin, still after the App token is revoked, and feedsRISK_DROID_BINto begin and settle andDROID_BINto the judge. A new test runs the real install step script with a fakecurlandshahead on PATH (installer served from a localfile://URL) and checks neither runs.all-comments-trusted-wrapper-maintenancenow selects only wrapper steps that check a digest, since the install step also usesenv -i.bun test: 2977 pass, 0 fail.typecheckandformat:checkare clean.beginRiskviadroid-devreachedhttps://dev.api.factory.aiand got the backend'shttp_400"Invalid api key format" for a bogus key.droid-local(http://localhost:3000), it failed withuntrusted_api_urland was not retried.Compatibility
Commits customers already pinned (for example
5536f19) keep their own client. The backend contract is unchanged.