hostedwire: signed requests and responses for the controller
ed25519-signed requests (key ID, timestamp, nonce, signature headers, each exactly once) and responses bound to status, the request's nonce and the body hash. Verify checks headers, key, 60 s skew, body size and signature before it records the nonce; a replay or a nonce store error denies. A public key listed under two key IDs is refused, because the key ID is not in the signed message. api.go holds the strict JSON types for every controller route and DecodeStrict, which refuses unknown fields, other-case or repeated keys, trailing data and bodies over MaxBody.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+1,343
−0
docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md+20 −0internal/hostedwire/api.go+254 −0internal/hostedwire/api_test.go+127 −0internal/hostedwire/main_test.go+9 −0internal/hostedwire/sign.go+208 −0internal/hostedwire/sign_test.go+518 −0internal/hostedwire/verify.go+207 −0
CI passed — run details
CI log
=== prepare ===
ci-box: machine: aarch64, 32 CPUs, 62 GiB memory, kernel 7.0.0-1017-aws
ci-box: python 3.12.3; Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2
ci-box: user namespaces allowed: 233151
ci-box: cgroup: cgroup2fs
ci-box: disk /home/ci/work/repos/oficina__equipo/wt/hosted-runners-1a: Type Size Avail | ext4 96G 84G
ci-box: disk /home/ci/.cache/equipo-ci-box: Type Size Avail | ext4 96G 84G
ci-box: bwrap: fetched and verified in 0.3s
ci-box: claude: fetched and verified in 1.4s
ci-box: codex: fetched and verified in 3.4s
ci-box: codex-code-mode-host: fetched and verified in 1.3s
ci-box: libwrap: fetched and verified in 0.3s
ci-box: socat: fetched and verified in 0.3s
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
ci-box: image pulled in 9.9s
ci-box: pi: installed and verified in 7.6s
ci-box: opencode: installed and verified in 2.3s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 8.6s
ci-box: clone deepened in 3.9s
ci-box: file times set from content: 2862 files, 190 directories
ci-box: ready in 17.5s
=== copy ===
EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$' -count=1
ok amadan.net/oficina/equipo/internal/equipotest 0.249s
=== compile ===
go build ./...
go: downloading github.com/aws/aws-sdk-go-v2 v1.48.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.350.0
go: downloading github.com/aws/aws-sdk-go-v2/service/lambdamicrovms v1.13.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sns v1.48.0
go: downloading github.com/aws/smithy-go v1.28.9
go: downloading github.com/aws/aws-sdk-go-v2/internal/configsources v1.5.12
go: downloading github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.8.12
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.14.12
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.25
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py compile
+ go build -tags testbuild ./...
1.1s
+ go list -export -test -tags testbuild -f ./...
0.8s
+ go list -export -test -tags browser,testbuild -f ./internal/equipo ./internal/headless ./internal/idtest ./internal/plan3test ./internal/thintest
0.3s
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 -version
staticcheck 2026.1 (v0.7.0)
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 -version
Go: go1.26.11
Scanner: govulncheck@v1.8.0
DB: https://vuln.go.dev
DB updated: 2026-11-11 02:51:11 +0000 UTC
go run github.com/zricethezav/gitleaks/v8@v8.30.1 version
version is set by build process
=== check ===
--- shard 0 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-work: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestHeadless$/^4c_rebase$|^TestHeadless$/^4b_ask$|^TestHeadless$/^4c_checks_card$|^TestHeadless$/^4_step_crash$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 1m22.93s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m21.356s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m21.36s amadan.net/oficina/equipo/internal/headless TestHeadless
machine: 32 CPUs, load 38.18, cpu waiting 25.78%, memory waiting 0.00%, io waiting 0.47%
--- shard 1 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-review: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestHeadless$/^4_review$|^TestHeadless$/^2b_access$|^TestHeadless$/^runner_crash$|^TestHeadless$/^2b_first_message$|^TestHeadless$/^4_checks_honest$|^TestHeadless$/^7_stream_resume$|^TestHeadless$/^2b_notebook$|^TestHeadless$/^2b_move_in$|^TestHeadless$/^2b_desk_failure$|^TestHeadless$/^cancel$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 1m26.096s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m24.362s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m24.36s amadan.net/oficina/equipo/internal/headless TestHeadless
machine: 32 CPUs, load 38.09, cpu waiting 25.47%, memory waiting 0.00%, io waiting 0.44%
--- shard 2 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-connections: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestHeadlessConnections$|^TestHeadlessTokenPasteEndToEnd$|^TestHeadlessTokenConnection$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 1m27.411s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m25.272s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m14.21s amadan.net/oficina/equipo/internal/headless TestHeadlessConnections
receipt: slow test 6.12s amadan.net/oficina/equipo/internal/headless TestHeadlessTokenPasteEndToEnd
receipt: slow test 4.93s amadan.net/oficina/equipo/internal/headless TestHeadlessTokenConnection
machine: 32 CPUs, load 38.09, cpu waiting 24.97%, memory waiting 0.00%, io waiting 0.43%
--- shard 3 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-mac: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestMacWorker$|^TestHeadlessAttachments$|^TestHeadlessPrewarm$|^TestHeadless$/^1_first_token$|^TestHeadless$/^6_quick_messages$|^TestHeadless$/^8_instance_restart$|^TestHeadless$/^3_runner_offline$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 1m22.631s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m20.998s amadan.net/oficina/equipo/internal/headless
receipt: slow test 39.8s amadan.net/oficina/equipo/internal/headless TestMacWorker
receipt: slow test 21.09s amadan.net/oficina/equipo/internal/headless TestHeadless
receipt: slow test 10.59s amadan.net/oficina/equipo/internal/headless TestHeadlessAttachments
receipt: slow test 9.52s amadan.net/oficina/equipo/internal/headless TestHeadlessPrewarm
machine: 32 CPUs, load 38.18, cpu waiting 25.78%, memory waiting 0.00%, io waiting 0.47%
--- shard 4 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-guards: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestHeadlessCopyRotation$|^TestHeadlessPolicyGuards$|^TestHeadlessRunnerKillLeavesNoCopies$|^TestHeadlessNewHouseRuleStartsFresh$|^TestHeadless$/^3_engineering$|^TestHeadless$/^3_step_cancel$|^TestHeadless$/^3_step_contained$|^TestHeadless$/^3_empty_repo$|^TestHeadless$/^3_empty_engineering$|^TestHeadless$/^3_empty_merge$|^TestHeadless$/^3_empty_merge_rebuilt$|^TestHeadless$/^3_empty_fix_round$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 1m41.157s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m39.347s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m2.78s amadan.net/oficina/equipo/internal/headless TestHeadless
receipt: slow test 11.42s amadan.net/oficina/equipo/internal/headless TestHeadlessRunnerKillLeavesNoCopies
receipt: slow test 10.23s amadan.net/oficina/equipo/internal/headless TestHeadlessCopyRotation
receipt: slow test 8.99s amadan.net/oficina/equipo/internal/headless TestHeadlessPolicyGuards
receipt: slow test 5.93s amadan.net/oficina/equipo/internal/headless TestHeadlessNewHouseRuleStartsFresh
machine: 32 CPUs, load 32.66, cpu waiting 21.12%, memory waiting 0.00%, io waiting 0.35%
--- shard 5 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-rest: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -skip '^TestHeadless$/^4c_rebase$|^TestHeadless$/^4b_ask$|^TestHeadless$/^4c_checks_card$|^TestHeadless$/^4_step_crash$|^TestHeadless$/^4_review$|^TestHeadless$/^2b_access$|^TestHeadless$/^runner_crash$|^TestHeadless$/^2b_first_message$|^TestHeadless$/^4_checks_honest$|^TestHeadless$/^7_stream_resume$|^TestHeadless$/^2b_notebook$|^TestHeadless$/^2b_move_in$|^TestHeadless$/^2b_desk_failure$|^TestHeadless$/^cancel$|^TestHeadlessConnections$|^TestHeadlessTokenPasteEndToEnd$|^TestHeadlessTokenConnection$|^TestMacWorker$|^TestHeadlessAttachments$|^TestHeadlessPrewarm$|^TestHeadless$/^1_first_token$|^TestHeadless$/^6_quick_messages$|^TestHeadless$/^8_instance_restart$|^TestHeadless$/^3_runner_offline$|^TestHeadlessCopyRotation$|^TestHeadlessPolicyGuards$|^TestHeadlessRunnerKillLeavesNoCopies$|^TestHeadlessNewHouseRuleStartsFresh$|^TestHeadless$/^3_engineering$|^TestHeadless$/^3_step_cancel$|^TestHeadless$/^3_step_contained$|^TestHeadless$/^3_empty_repo$|^TestHeadless$/^3_empty_engineering$|^TestHeadless$/^3_empty_merge$|^TestHeadless$/^3_empty_merge_rebuilt$|^TestHeadless$/^3_empty_fix_round$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 3m23.13s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 3m21.068s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m48.98s amadan.net/oficina/equipo/internal/headless TestHeadlessAssistant
receipt: slow test 24.79s amadan.net/oficina/equipo/internal/headless TestHeadless
receipt: slow test 20.65s amadan.net/oficina/equipo/internal/headless TestHeadlessResearchHandoff
receipt: slow test 8.11s amadan.net/oficina/equipo/internal/headless TestHeadlessClaudeSignIn
receipt: slow test 7.37s amadan.net/oficina/equipo/internal/headless TestHeadlessTurnBatching
machine: 32 CPUs, load 6.90, cpu waiting 3.76%, memory waiting 0.00%, io waiting 0.05%
--- shard 6 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane thintest: ./internal/thintest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^Test([^C]|C[^o]|Co[^n]|Con[^t])|^TestContract(Assistant|Outcome|Team|Handoff|HostAllowlist|HostIsPerPerson|Look|Use[A-Z]|RemoteCall|LanesRunAtOnce|NoMergeQuestionWhenGateMerges|PreviewHeldUntilPublishAnswer|PreviewNotHeldBelow19|PublishNeedsOwnerAnswer)' ./internal/thintest
receipt: test step 1.179s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 2m1.624s amadan.net/oficina/equipo/internal/thintest
receipt: slow test 7.84s amadan.net/oficina/equipo/internal/thintest TestContractTeamJobSettledStates
receipt: slow test 6.74s amadan.net/oficina/equipo/internal/thintest TestExplorePreviewsOff
receipt: slow test 4.31s amadan.net/oficina/equipo/internal/thintest TestContractTeamUpdatePersonNeeds
receipt: slow test 3.81s amadan.net/oficina/equipo/internal/thintest TestContractPreviewHeldUntilPublishAnswer
receipt: slow test 3.52s amadan.net/oficina/equipo/internal/thintest TestContractTeamNudgePersonNeeds
machine: 32 CPUs, load 1.15, cpu waiting 1.17%, memory waiting 0.00%, io waiting 1.83%
--- shard 7 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane thintest-contract: ./internal/thintest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -skip '^Test([^C]|C[^o]|Co[^n]|Con[^t])|^TestContract(Assistant|Outcome|Team|Handoff|HostAllowlist|HostIsPerPerson|Look|Use[A-Z]|RemoteCall|LanesRunAtOnce|NoMergeQuestionWhenGateMerges|PreviewHeldUntilPublishAnswer|PreviewNotHeldBelow19|PublishNeedsOwnerAnswer)' ./internal/thintest
receipt: test step 1.136s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1m26.784s amadan.net/oficina/equipo/internal/thintest
receipt: slow test 9.08s amadan.net/oficina/equipo/internal/thintest TestContractPreviewNotScheduled
receipt: slow test 5.03s amadan.net/oficina/equipo/internal/thintest TestContractPublishNotOffered
receipt: slow test 4.41s amadan.net/oficina/equipo/internal/thintest TestContractMacRecheckMergeAuthority
receipt: slow test 2.4s amadan.net/oficina/equipo/internal/thintest TestContractPreview
receipt: slow test 2.34s amadan.net/oficina/equipo/internal/thintest TestContractPublishNameTaken
machine: 32 CPUs, load 1.15, cpu waiting 0.02%, memory waiting 0.00%, io waiting 1.83%
--- shard 8 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane runner-thin: ./internal/runner/thin
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m ./internal/runner/thin
cache miss: amadan.net/oficina/equipo/internal/runner/thin: its inputs changed
budget note: internal/runner/thin took 4m31.821s, over the 45s its record on line 44 allows; reported only, timing fails on CI
receipt: test step 4m44.87s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 4m31.821s amadan.net/oficina/equipo/internal/runner/thin
receipt: slow test 36.98s amadan.net/oficina/equipo/internal/runner/thin TestModelsProbeAnsweredByAnotherModel
receipt: slow test 36.93s amadan.net/oficina/equipo/internal/runner/thin TestModelsEngineeringProbesThenRunsTheStrongest
receipt: slow test 36.82s amadan.net/oficina/equipo/internal/runner/thin TestModelsUnhealthyRetriedOnDemand
receipt: slow test 18.45s amadan.net/oficina/equipo/internal/runner/thin TestModelsProbeRunsInsideTheAdmission
receipt: slow test 6.84s amadan.net/oficina/equipo/internal/runner/thin TestOpenCodeStepsRealOpenCode
machine: 32 CPUs, load 2.46, cpu waiting 0.95%, memory waiting 0.00%, io waiting 0.00%
--- shard 9 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane runner-bug: ./internal/runner
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestDirectBugWorkflow$|^TestEnrolKeepsTheRole$' ./internal/runner
cache miss: amadan.net/oficina/equipo/internal/runner: its inputs changed
receipt: test step 47.934s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 46.701s amadan.net/oficina/equipo/internal/runner
receipt: slow test 26.67s amadan.net/oficina/equipo/internal/runner TestDirectBugWorkflow
receipt: slow test 20.02s amadan.net/oficina/equipo/internal/runner TestEnrolKeepsTheRole
machine: 32 CPUs, load 31.71, cpu waiting 23.33%, memory waiting 0.00%, io waiting 0.85%
--- shard 10 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane runner-plans: ./internal/runner
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestPlanWorkflowCandidateOrder$|^TestPlanWorkflowFeature$|^TestCoordinatorRecoveryCallRefusalKeepsServing$|^TestCoordinatorRefusalMatrix$' ./internal/runner
cache miss: amadan.net/oficina/equipo/internal/runner: its inputs changed
receipt: test step 50.495s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 48.414s amadan.net/oficina/equipo/internal/runner
receipt: slow test 38.39s amadan.net/oficina/equipo/internal/runner TestPlanWorkflowCandidateOrder
receipt: slow test 34.67s amadan.net/oficina/equipo/internal/runner TestPlanWorkflowFeature
receipt: slow test 8.4s amadan.net/oficina/equipo/internal/runner TestCoordinatorRecoveryCallRefusalKeepsServing
receipt: slow test 1.61s amadan.net/oficina/equipo/internal/runner TestCoordinatorRefusalMatrix
machine: 32 CPUs, load 35.17, cpu waiting 23.94%, memory waiting 0.00%, io waiting 0.82%
--- shard 11 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane runner-rest: ./internal/runner
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -skip '^TestDirectBugWorkflow$|^TestEnrolKeepsTheRole$|^TestPlanWorkflowCandidateOrder$|^TestPlanWorkflowFeature$|^TestCoordinatorRecoveryCallRefusalKeepsServing$|^TestCoordinatorRefusalMatrix$' ./internal/runner
cache miss: amadan.net/oficina/equipo/internal/runner: its inputs changed
receipt: test step 35.299s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 34.379s amadan.net/oficina/equipo/internal/runner
receipt: slow test 5.12s amadan.net/oficina/equipo/internal/runner TestDirectFaultIsolation
receipt: slow test 3.41s amadan.net/oficina/equipo/internal/runner TestClaimRefusalsBackOff
receipt: slow test 3.1s amadan.net/oficina/equipo/internal/runner TestCoordinatorRecoveryRefusedKeepsServing
receipt: slow test 2.28s amadan.net/oficina/equipo/internal/runner TestToolVerbUnderFakeHarness
receipt: slow test 1.61s amadan.net/oficina/equipo/internal/runner TestReportPostsRetryExactRequest
machine: 32 CPUs, load 22.06, cpu waiting 16.05%, memory waiting 0.00%, io waiting 1.03%
--- shard 12 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: equipotest-a started 30s late; cpu waiting 27.6%, load 15.02
test lane equipotest-a: ./internal/equipotest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^Test[A-D]|^TestQ' ./internal/equipotest
receipt: test step 1m5.7s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m3.752s amadan.net/oficina/equipo/internal/equipotest
receipt: slow test 26.88s amadan.net/oficina/equipo/internal/equipotest TestAuthorityCoreIntegration
receipt: slow test 26.79s amadan.net/oficina/equipo/internal/equipotest TestBootstrapNamesOwnersSetting
receipt: slow test 24.7s amadan.net/oficina/equipo/internal/equipotest TestAccountLabelMigration
receipt: slow test 22.15s amadan.net/oficina/equipo/internal/equipotest TestBudgetConfigurationFailuresAreAtomic
receipt: slow test 22.04s amadan.net/oficina/equipo/internal/equipotest TestAuthorityUsesLiveRoster
machine: 32 CPUs, load 35.16, cpu waiting 22.48%, memory waiting 0.00%, io waiting 0.37%
--- shard 13 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: equipotest-e started 30s late; cpu waiting 27.6%, load 15.02
test lane equipotest-e: ./internal/equipotest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^Test[E-P]' ./internal/equipotest
receipt: test step 1.44s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1m12.399s amadan.net/oficina/equipo/internal/equipotest
receipt: slow test 19.2s amadan.net/oficina/equipo/internal/equipotest TestProjectWritesRequireCurrentOwner
receipt: slow test 19.12s amadan.net/oficina/equipo/internal/equipotest TestProjectOwnersAreMembers
receipt: slow test 19.11s amadan.net/oficina/equipo/internal/equipotest TestProjectsReopen
receipt: slow test 19.11s amadan.net/oficina/equipo/internal/equipotest TestProjectRetryAndRevision
receipt: slow test 19.08s amadan.net/oficina/equipo/internal/equipotest TestProjectsFailuresRollBack
machine: 32 CPUs, load 15.02, cpu waiting 12.65%, memory waiting 0.00%, io waiting 1.11%
--- shard 14 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: equipotest-r started 30s late; cpu waiting 27.6%, load 15.02
test lane equipotest-r: ./internal/equipotest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestR' ./internal/equipotest
cache miss: amadan.net/oficina/equipo/internal/equipotest: its inputs changed
receipt: test step 1m16.877s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m4.557s amadan.net/oficina/equipo/internal/equipotest
receipt: slow test 14.07s amadan.net/oficina/equipo/internal/equipotest TestReleaseStampContract
receipt: slow test 12.89s amadan.net/oficina/equipo/internal/equipotest TestRosterChangesAffectExistingSession
receipt: slow test 9.86s amadan.net/oficina/equipo/internal/equipotest TestRosterRemovalWhileAssigned
receipt: slow test 9.82s amadan.net/oficina/equipo/internal/equipotest TestRosterRemovalRollsBack
receipt: slow test 6.78s amadan.net/oficina/equipo/internal/equipotest TestRosterBootstrapOnce
machine: 32 CPUs, load 30.29, cpu waiting 18.49%, memory waiting 0.00%, io waiting 0.30%
--- shard 15 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: equipotest-rest started 30s late; cpu waiting 27.6%, load 15.02
test lane equipotest-rest: ./internal/equipotest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -skip '^Test[A-D]|^TestQ|^Test[E-P]|^TestR' ./internal/equipotest
cache miss: amadan.net/oficina/equipo/internal/equipotest: its inputs changed
receipt: test step 1m7.355s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m5.385s amadan.net/oficina/equipo/internal/equipotest
receipt: slow test 24.58s amadan.net/oficina/equipo/internal/equipotest TestSigninNoProof
receipt: slow test 24.06s amadan.net/oficina/equipo/internal/equipotest TestSpecialistsSeedExistingTeam
receipt: slow test 24.02s amadan.net/oficina/equipo/internal/equipotest TestSpecialistsSeedRollback
receipt: slow test 22.38s amadan.net/oficina/equipo/internal/equipotest TestSpecialistsUpgrade
receipt: slow test 22.24s amadan.net/oficina/equipo/internal/equipotest TestSpecialistSettingsCurrentOwner
machine: 32 CPUs, load 35.16, cpu waiting 21.81%, memory waiting 0.00%, io waiting 0.36%
--- shard 16 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: plan3test started 30s late; cpu waiting 27.6%, load 15.02
test lane plan3test: ./internal/plan3test
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m ./internal/plan3test
receipt: test step 591ms against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 48.756s amadan.net/oficina/equipo/internal/plan3test
receipt: slow test 3.61s amadan.net/oficina/equipo/internal/plan3test TestPlan3Upgrade
receipt: slow test 3.41s amadan.net/oficina/equipo/internal/plan3test TestCoordinatorAcceptance3B
receipt: slow test 1.5s amadan.net/oficina/equipo/internal/plan3test TestConversationQuestionRace
receipt: slow test 1.47s amadan.net/oficina/equipo/internal/plan3test TestCoordinatorAcceptance3A
receipt: slow test 1.21s amadan.net/oficina/equipo/internal/plan3test TestPlanMigrationUpgrade
machine: 32 CPUs, load 15.02, cpu waiting 11.28%, memory waiting 0.00%, io waiting 1.14%
--- shard 17 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: rest started 30s late; cpu waiting 27.6%, load 15.02
test lane rest: ./cmd/equipo ./cmd/equipo-runner ./cmd/equipo-tool-proxy ./internal/advice ./internal/attach ./internal/attach/attachtest ./internal/chatmarkdown ./internal/chatsend ./internal/chatstream ./internal/coordinator ./internal/coordinatorcontract ./internal/coordinatormail ./internal/copydesk ./internal/equipo ./internal/equipo/activity ./internal/equipo/assist ./internal/equipo/chat ./internal/equipo/conversation ./internal/equipo/conversation/chatstate ./internal/equipo/housekeeping ./internal/equipo/icons ./internal/equipo/identity ./internal/equipo/kernel ./internal/equipo/library ./internal/equipo/mergegate ./internal/equipo/notifications ./internal/equipo/oficina ./internal/equipo/oficina/oficinatest ./internal/equipo/oficinaid ./internal/equipo/ownermode ./internal/equipo/personapi ./internal/equipo/planning ./internal/equipo/push ./internal/equipo/setup ./internal/equipo/team ./internal/equipo/teamcontract ./internal/equipo/triage ./internal/fakeclaude ./internal/fakecodex ./internal/fakeopencode ./internal/fakepi ./internal/hostedwire ./internal/idtest ./internal/isolatedjob ./internal/isolatedjob/awsjob ./internal/isolatedjob/guardfixture ./internal/isolatedjob/isolatedjobtest ./internal/ownermodetest ./internal/release ./internal/runner/checks ./internal/runner/connect ./internal/runner/containment ./internal/runner/containment/sysunix ./internal/runner/egress ./internal/runner/forge ./internal/runner/forge/forgetest ./internal/runner/heartbeat ./internal/runner/mac ./internal/runner/mcpresource ./internal/runner/metered ./internal/runner/planflow ./internal/runner/provider ./internal/runner/provider/claude ./internal/runner/provider/codex ./internal/runner/provider/gotoolchain ./internal/runner/provider/opencode ./internal/runner/provider/pi ./internal/runner/setup ./internal/runner/transporttest ./internal/runner/webread ./internal/runner/workspace ./internal/runnerproto ./internal/schedule ./internal/sealbox ./internal/specialist ./internal/stagingtest ./internal/taskplan ./internal/testci ./internal/toolproxy ./internal/websource ./internal/wire ./internal/wire/wireschema ./internal/wire/wiretest ./tools/drive
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m ./cmd/equipo ./cmd/equipo-runner ./cmd/equipo-tool-proxy ./internal/advice ./internal/attach ./internal/attach/attachtest ./internal/chatmarkdown ./internal/chatsend ./internal/chatstream ./internal/coordinator ./internal/coordinatorcontract ./internal/coordinatormail ./internal/copydesk ./internal/equipo ./internal/equipo/activity ./internal/equipo/assist ./internal/equipo/chat ./internal/equipo/conversation ./internal/equipo/conversation/chatstate ./internal/equipo/housekeeping ./internal/equipo/icons ./internal/equipo/identity ./internal/equipo/kernel ./internal/equipo/library ./internal/equipo/mergegate ./internal/equipo/notifications ./internal/equipo/oficina ./internal/equipo/oficina/oficinatest ./internal/equipo/oficinaid ./internal/equipo/ownermode ./internal/equipo/personapi ./internal/equipo/planning ./internal/equipo/push ./internal/equipo/setup ./internal/equipo/team ./internal/equipo/teamcontract ./internal/equipo/triage ./internal/fakeclaude ./internal/fakecodex ./internal/fakeopencode ./internal/fakepi ./internal/hostedwire ./internal/idtest ./internal/isolatedjob ./internal/isolatedjob/awsjob ./internal/isolatedjob/guardfixture ./internal/isolatedjob/isolatedjobtest ./internal/ownermodetest ./internal/release ./internal/runner/checks ./internal/runner/connect ./internal/runner/containment ./internal/runner/containment/sysunix ./internal/runner/egress ./internal/runner/forge ./internal/runner/forge/forgetest ./internal/runner/heartbeat ./internal/runner/mac ./internal/runner/mcpresource ./internal/runner/metered ./internal/runner/planflow ./internal/runner/provider ./internal/runner/provider/claude ./internal/runner/provider/codex ./internal/runner/provider/gotoolchain ./internal/runner/provider/opencode ./internal/runner/provider/pi ./internal/runner/setup ./internal/runner/transporttest ./internal/runner/webread ./internal/runner/workspace ./internal/runnerproto ./internal/schedule ./internal/sealbox ./internal/specialist ./internal/stagingtest ./internal/taskplan ./internal/testci ./internal/toolproxy ./internal/websource ./internal/wire ./internal/wire/wireschema ./internal/wire/wiretest ./tools/drive
cache miss: amadan.net/oficina/equipo/cmd/equipo-runner: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/copydesk: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/forge: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/provider/opencode: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/equipo/team: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/provider/claude: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/webread: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runnerproto: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/workspace: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/provider/codex: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/checks: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/containment: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/provider/pi: its inputs changed
--- FAIL amadan.net/oficina/equipo/internal/runner/webread TestTimeouts
=== RUN TestTimeouts
fetch_test.go:537: s1: {Source:s1 Origin:paul Parent: URL:https://shop.example.com/slow-body Hops:[{URL:https://shop.example.com/slow-body Address:151.101.1.1 Status:200}] Address:151.101.1.1 Status:200 Type:text/plain Bytes:5 SHA256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 Millis:301 Reason: File:s001.txt}
--- FAIL: TestTimeouts (0.61s)
--- FAIL amadan.net/oficina/equipo/internal/runner/webread (package output)
FAIL
rastrillo-budget/v1 ran 1.06s
FAIL amadan.net/oficina/equipo/internal/runner/webread 1.065s
budget note: internal/equipo took 45.275s, over the 10s the default allows (measured on the run this cached result came from); reported only, timing fails on CI
budget note: internal/equipo/chat took 12.529s, over the 10s the default allows (measured on the run this cached result came from); reported only, timing fails on CI
budget note: internal/idtest took 39.84s, over the 10s the default allows (measured on the run this cached result came from); reported only, timing fails on CI
budget note: internal/release took 34.981s, over the 10s the default allows (measured on the run this cached result came from); reported only, timing fails on CI
budget note: internal/runner/containment took 42.686s, over the 15s its record on line 40 allows; reported only, timing fails on CI
receipt: test step 2m21.057s against a 60s target (the gate's other steps are not in this figure)
receipt: 15 packages ran, 48 cached, 20 without tests, 1 failed
receipt: slow package 57.888s amadan.net/oficina/equipo/internal/runner/provider/opencode
receipt: slow package 52.492s amadan.net/oficina/equipo/internal/runner/provider/pi
receipt: slow package 45.275s amadan.net/oficina/equipo/internal/equipo
receipt: slow package 42.686s amadan.net/oficina/equipo/internal/runner/containment
receipt: slow package 39.84s amadan.net/oficina/equipo/internal/idtest
receipt: slow test 24.26s amadan.net/oficina/equipo/internal/runner/provider/opencode TestOpenCodeAcceptanceHostileRepository
receipt: slow test 16.82s amadan.net/oficina/equipo/internal/runner/containment TestEngineeringOfflineGo
rastrillo: budget test: go test failed
receipt: slow test 10.89s amadan.net/oficina/equipo/internal/idtest TestIDCallbackGuardAndPendingNonce
receipt: slow test 10.82s amadan.net/oficina/equipo/internal/equipo TestAgentReadRechecksIdentity
receipt: slow test 10.03s amadan.net/oficina/equipo/internal/runner/containment TestEngineeringMissingModuleCache
exit status 1
+ go test -tags testbuild -timeout 15m -v -run '^TestTimeouts$' -count=1 ./internal/runner/webread (retry, once)
##############################################################################
FLAKE ./internal/runner/webread:TestTimeouts rest af8096ade2829bb62d7150eb1775445647901bb4 0.61s 11.47
##############################################################################
failed, then passed on its one retry: the step stays green and the flake is on record
machine: 32 CPUs, load 11.47, cpu waiting 6.41%, memory waiting 0.00%, io waiting 0.10%
--- shard 18 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-headless-chat: ./internal/headless
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^TestBrowserChat$|^TestBrowserChatSendStaysOnPage$|^TestBrowserComposer$|^TestBrowserComposerReconcile$|^TestBrowserComposerFocus$|^TestBrowserComposerDock$|^TestBrowserDraftStreamsFormatted$|^TestBrowserDraftIsTheMessage$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 1m23.967s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m22.468s amadan.net/oficina/equipo/internal/headless
receipt: slow test 37.82s amadan.net/oficina/equipo/internal/headless TestBrowserDraftIsTheMessage
receipt: slow test 15.2s amadan.net/oficina/equipo/internal/headless TestBrowserDraftStreamsFormatted
receipt: slow test 11.04s amadan.net/oficina/equipo/internal/headless TestBrowserChat
receipt: slow test 7.84s amadan.net/oficina/equipo/internal/headless TestBrowserComposer
receipt: slow test 6.14s amadan.net/oficina/equipo/internal/headless TestBrowserChatSendStaysOnPage
machine: 32 CPUs, load 38.09, cpu waiting 25.59%, memory waiting 0.00%, io waiting 0.46%
--- shard 19 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-headless-work: ./internal/headless
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^TestBrowserTaskCard$|^TestBrowserReceiptFollowsReview$|^TestBrowserRailFollowsWork$|^TestBrowserTaskThread$|^TestBrowserAskAfterMerge$|^TestBrowserReceiptsDesktop$|^TestBrowserReceiptsTouch$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 1m36.656s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m35.026s amadan.net/oficina/equipo/internal/headless
receipt: slow test 28.1s amadan.net/oficina/equipo/internal/headless TestBrowserRailFollowsWork
receipt: slow test 23.47s amadan.net/oficina/equipo/internal/headless TestBrowserTaskThread
receipt: slow test 14.39s amadan.net/oficina/equipo/internal/headless TestBrowserReceiptFollowsReview
receipt: slow test 10.58s amadan.net/oficina/equipo/internal/headless TestBrowserAskAfterMerge
receipt: slow test 8.61s amadan.net/oficina/equipo/internal/headless TestBrowserTaskCard
machine: 32 CPUs, load 35.16, cpu waiting 21.81%, memory waiting 0.00%, io waiting 0.36%
--- shard 20 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-headless-connections: ./internal/headless
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^TestBrowserConnections|^TestBrowserPasteBox$|^TestBrowserPasteCopiesItsBox$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
receipt: test step 1m42.793s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m41.146s amadan.net/oficina/equipo/internal/headless
receipt: slow test 15.05s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsConversation
receipt: slow test 13.53s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsAdd
receipt: slow test 13.07s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsAddPage
receipt: slow test 10.6s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsMeteredLimitRequired
receipt: slow test 10.25s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsOpenCodeGoLimitRequired
machine: 32 CPUs, load 30.29, cpu waiting 19.76%, memory waiting 0.00%, io waiting 0.32%
--- shard 21 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-headless-rest: ./internal/headless
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestBrowserAskAfterMerge|TestBrowserChat|TestBrowserChatSendStaysOnPage|TestBrowserComposer|TestBrowserComposerDock|TestBrowserComposerFocus|TestBrowserComposerReconcile|TestBrowserConnectionsAdd|TestBrowserConnectionsAddPage|TestBrowserConnectionsConversation|TestBrowserConnectionsCopyLink|TestBrowserConnectionsEndedNote|TestBrowserConnectionsMeteredLimitRequired|TestBrowserConnectionsOpenCodeGoLimitRequired|TestBrowserConnectionsSignIn|TestBrowserConnectionsSignInSwitch|TestBrowserConnectionsToken|TestBrowserCopyContinue|TestBrowserCopySettingAndFlag|TestBrowserDraftIsTheMessage|TestBrowserDraftStreamsFormatted|TestBrowserEmptyExplore|TestBrowserMoveIn|TestBrowserNotebook|TestBrowserNotebookLook|TestBrowserPasteBox|TestBrowserPasteBoxLook|TestBrowserPasteCopiesItsBox|TestBrowserRailFollowsWork|TestBrowserReceiptFollowsReview|TestBrowserReceiptsDesktop|TestBrowserReceiptsTouch|TestBrowserRefreshRace|TestBrowserStalePageReloads|TestBrowserTaskCard|TestBrowserTaskThread|TestBrowserThinkingAndCards|TestBrowserUsageAndAdvice|TestBrowserWaitingTurns|TestNotebookScreenshots)$' -skip '^TestBrowserChat$|^TestBrowserChatSendStaysOnPage$|^TestBrowserComposer$|^TestBrowserComposerReconcile$|^TestBrowserComposerFocus$|^TestBrowserComposerDock$|^TestBrowserDraftStreamsFormatted$|^TestBrowserDraftIsTheMessage$|^TestBrowserTaskCard$|^TestBrowserReceiptFollowsReview$|^TestBrowserRailFollowsWork$|^TestBrowserTaskThread$|^TestBrowserAskAfterMerge$|^TestBrowserReceiptsDesktop$|^TestBrowserReceiptsTouch$|^TestBrowserConnections|^TestBrowserPasteBox$|^TestBrowserPasteCopiesItsBox$' ./internal/headless
--- FAIL amadan.net/oficina/equipo/internal/headless TestBrowserCopyContinue
rastrillo: budget test: go test failed
=== RUN TestBrowserCopyContinue
time=2026-11-22T16:29:16.778Z level=INFO msg="startup phase" phase=state_lock
time=2026-11-22T16:29:16.778Z level=INFO msg="startup phase done" phase=state_lock took=82µs
time=2026-11-22T16:29:16.778Z level=INFO msg="startup phase" phase=claim_roots
time=2026-11-22T16:29:16.778Z level=INFO msg="startup phase done" phase=claim_roots took=105µs
time=2026-11-22T16:29:16.778Z level=INFO msg="startup phase" phase=sweep
time=2026-11-22T16:29:16.815Z level=INFO msg="startup phase done" phase=sweep took=37.166ms
time=2026-11-22T16:29:16.816Z level=INFO msg="startup phase" phase=credentials
time=2026-11-22T16:29:16.816Z level=INFO msg="startup phase done" phase=credentials took=141µs
time=2026-11-22T16:29:16.816Z level=INFO msg="startup phase" phase=open_state
time=2026-11-22T16:29:16.870Z level=INFO msg="startup phase done" phase=open_state took=54.176ms
time=2026-11-22T16:29:16.870Z level=WARN msg="no seal key: token connections cannot be added" err=*fs.PathError
time=2026-11-22T16:29:16.871Z level=INFO msg=connecting host=127.0.0.1:46675 protocol=28
time=2026-11-22T16:29:16.872Z level=INFO msg=connected host=127.0.0.1:46675 took=928µs
time=2026-11-22T16:29:16.873Z level=INFO msg="capabilities gathering"
time=2026-11-22T16:29:16.876Z level=INFO msg="capabilities gathered" took=3.743ms tags=linux,claude,go
time=2026-11-22T16:29:16.877Z level=INFO msg="hello sent" protocol=28
time=2026-11-22T16:29:16.882Z level=INFO msg=welcome protocol=28 role=primary generation=1
browser_copy_test.go:93: continue did not reach Checks: 0 <nil>
--- FAIL: TestBrowserCopyContinue (1.87s)
--- FAIL amadan.net/oficina/equipo/internal/headless TestBrowserEmptyExplore
=== RUN TestBrowserEmptyExplore
time=2026-11-22T16:29:49.383Z level=INFO msg="startup phase" phase=state_lock
time=2026-11-22T16:29:49.383Z level=INFO msg="startup phase done" phase=state_lock took=76µs
time=2026-11-22T16:29:49.383Z level=INFO msg="startup phase" phase=claim_roots
time=2026-11-22T16:29:49.384Z level=INFO msg="startup phase done" phase=claim_roots took=95µs
time=2026-11-22T16:29:49.384Z level=INFO msg="startup phase" phase=sweep
time=2026-11-22T16:29:49.414Z level=INFO msg="startup phase done" phase=sweep took=30.269ms
time=2026-11-22T16:29:49.414Z level=INFO msg="startup phase" phase=credentials
time=2026-11-22T16:29:49.414Z level=INFO msg="startup phase done" phase=credentials took=115µs
time=2026-11-22T16:29:49.414Z level=INFO msg="startup phase" phase=open_state
time=2026-11-22T16:29:49.457Z level=INFO msg="startup phase done" phase=open_state took=42.631ms
time=2026-11-22T16:29:49.457Z level=WARN msg="no seal key: token connections cannot be added" err=*fs.PathError
time=2026-11-22T16:29:49.459Z level=INFO msg=connecting host=127.0.0.1:46137 protocol=28
time=2026-11-22T16:29:49.460Z level=INFO msg=connected host=127.0.0.1:46137 took=1.009ms
time=2026-11-22T16:29:49.460Z level=INFO msg="capabilities gathering"
time=2026-11-22T16:29:49.461Z level=INFO msg="capabilities gathered" took=419µs tags=linux,claude,go
time=2026-11-22T16:29:49.461Z level=INFO msg="hello sent" protocol=28
time=2026-11-22T16:29:49.466Z level=INFO msg=welcome protocol=28 role=primary generation=1
time=2026-11-22T16:29:50.637Z level=INFO msg="connection checked" connection=claude-1 state=healthy
browser_receipts_test.go:169: waiting for [...document.querySelectorAll('[equipo-markdown]:not([data-stream-text])')].some(e=>e.textContent.includes("I'm your coordinator")): context deadline exceeded (last evaluation: <nil>)
--- FAIL: TestBrowserEmptyExplore (5.90s)
--- FAIL amadan.net/oficina/equipo/internal/headless (package output)
FAIL
rastrillo-budget/v1 ran 1m30.244s
FAIL amadan.net/oficina/equipo/internal/headless 90.562s
receipt: test step 1m31.596s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 0 cached, 0 without tests, 1 failed
receipt: slow package 1m30.244s amadan.net/oficina/equipo/internal/headless
receipt: slow test 15.32s amadan.net/oficina/equipo/internal/headless TestBrowserThinkingAndCards
receipt: slow test 12.08s amadan.net/oficina/equipo/internal/headless TestBrowserWaitingTurns
receipt: slow test 10.77s amadan.net/oficina/equipo/internal/headless TestBrowserStalePageReloads
receipt: slow test 10.63s amadan.net/oficina/equipo/internal/headless TestBrowserMoveIn
receipt: slow test 8.08s amadan.net/oficina/equipo/internal/headless TestBrowserRefreshRace
exit status 1
+ go test -tags browser,testbuild -timeout 15m -run '^(TestBrowserAskAfterMerge|TestBrowserChat|TestBrowserChatSendStaysOnPage|TestBrowserComposer|TestBrowserComposerDock|TestBrowserComposerFocus|TestBrowserComposerReconcile|TestBrowserConnectionsAdd|TestBrowserConnectionsAddPage|TestBrowserConnectionsConversation|TestBrowserConnectionsCopyLink|TestBrowserConnectionsEndedNote|TestBrowserConnectionsMeteredLimitRequired|TestBrowserConnectionsOpenCodeGoLimitRequired|TestBrowserConnectionsSignIn|TestBrowserConnectionsSignInSwitch|TestBrowserConnectionsToken|TestBrowserCopyContinue|TestBrowserCopySettingAndFlag|TestBrowserDraftIsTheMessage|TestBrowserDraftStreamsFormatted|TestBrowserEmptyExplore|TestBrowserMoveIn|TestBrowserNotebook|TestBrowserNotebookLook|TestBrowserPasteBox|TestBrowserPasteBoxLook|TestBrowserPasteCopiesItsBox|TestBrowserRailFollowsWork|TestBrowserReceiptFollowsReview|TestBrowserReceiptsDesktop|TestBrowserReceiptsTouch|TestBrowserRefreshRace|TestBrowserStalePageReloads|TestBrowserTaskCard|TestBrowserTaskThread|TestBrowserThinkingAndCards|TestBrowserUsageAndAdvice|TestBrowserWaitingTurns|TestNotebookScreenshots)$' -skip '^TestBrowserChat$|^TestBrowserChatSendStaysOnPage$|^TestBrowserComposer$|^TestBrowserComposerReconcile$|^TestBrowserComposerFocus$|^TestBrowserComposerDock$|^TestBrowserDraftStreamsFormatted$|^TestBrowserDraftIsTheMessage$|^TestBrowserTaskCard$|^TestBrowserReceiptFollowsReview$|^TestBrowserRailFollowsWork$|^TestBrowserTaskThread$|^TestBrowserAskAfterMerge$|^TestBrowserReceiptsDesktop$|^TestBrowserReceiptsTouch$|^TestBrowserConnections|^TestBrowserPasteBox$|^TestBrowserPasteCopiesItsBox$' -v -run '^TestBrowserCopyContinue$|^TestBrowserEmptyExplore$' -count=1 ./internal/headless (retry, once)
##############################################################################
FLAKE ./internal/headless:TestBrowserCopyContinue browser-headless-rest af8096ade2829bb62d7150eb1775445647901bb4 1.87s 36.48
##############################################################################
failed, then passed on its one retry: the step stays green and the flake is on record
##############################################################################
FLAKE ./internal/headless:TestBrowserEmptyExplore browser-headless-rest af8096ade2829bb62d7150eb1775445647901bb4 5.90s 36.48
##############################################################################
failed, then passed on its one retry: the step stays green and the flake is on record
machine: 32 CPUs, load 30.29, cpu waiting 19.76%, memory waiting 0.00%, io waiting 0.32%
--- shard 22 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-rest: ./internal/equipo
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestBrowserPreviewBlocksNavigation)$' ./internal/equipo
receipt: test step 1.074s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 573ms amadan.net/oficina/equipo/internal/equipo
receipt: slow test 570ms amadan.net/oficina/equipo/internal/equipo TestBrowserPreviewBlocksNavigation
browser lane browser-rest: ./internal/idtest
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestBrowserOficinaIDDoor)$' ./internal/idtest
receipt: test step 852ms against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1.673s amadan.net/oficina/equipo/internal/idtest
receipt: slow test 1.67s amadan.net/oficina/equipo/internal/idtest TestBrowserOficinaIDDoor
browser lane browser-rest: ./internal/plan3test
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestTeamsHierarchyBrowser)$' ./internal/plan3test
receipt: test step 188ms against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1.856s amadan.net/oficina/equipo/internal/plan3test
receipt: slow test 1.86s amadan.net/oficina/equipo/internal/plan3test TestTeamsHierarchyBrowser
browser lane browser-rest: ./internal/thintest
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestBrowserAccessEmojiByline|TestBrowserAccessFinalOutcomes|TestBrowserAccessRequest|TestBrowserAccessReview|TestBrowserActivitySubjects|TestBrowserAutonomySettings|TestBrowserCoordinatorQueue|TestBrowserEmptyConversation|TestBrowserEndedNoteStaysGone|TestBrowserHousekeeping|TestBrowserInnerGallery|TestBrowserInnerScreens|TestBrowserInstantThinking|TestBrowserInstantThinkingQueued|TestBrowserMachines|TestBrowserPhoneIndex|TestBrowserPlacementQuestionAndPending|TestBrowserProjectPlacement|TestBrowserProjectsList|TestBrowserReportActionFeedback|TestBrowserReportNextSteps|TestBrowserReportThread|TestBrowserRollup|TestBrowserRosterAlignment|TestBrowserRosterDecisionStates|TestBrowserRosterQuietDay|TestBrowserRosterReports|TestBrowserRosterSetAside|TestBrowserRosterSubchat|TestBrowserRosterThinking|TestBrowserRosterVisual|TestBrowserSettingsHousekeepingGroups|TestBrowserSettingsMenu|TestBrowserSettingsRail|TestBrowserSettingsSaveBar|TestBrowserSettingsShots|TestBrowserSettingsStayOnPage|TestBrowserSettingsTeams|TestBrowserShipsButtons|TestBrowserSpecialistRows|TestBrowserSpendFollowsAnswers|TestBrowserTaskRows|TestBrowserTeamPanel|TestBrowserThinkingCycles|TestBrowserThinkingLinesClear|TestBrowserThinkingSteady|TestBrowserThinkingWords|TestBrowserTokenRowEmail|TestBrowserTrackPulse|TestBrowserTrackStarCentre|TestBrowserTryAgain)$' ./internal/thintest
receipt: test step 1.093s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 3m20.199s amadan.net/oficina/equipo/internal/thintest
receipt: slow test 17.52s amadan.net/oficina/equipo/internal/thintest TestBrowserAccessRequest
receipt: slow test 14.35s amadan.net/oficina/equipo/internal/thintest TestBrowserSettingsTeams
receipt: slow test 12.02s amadan.net/oficina/equipo/internal/thintest TestBrowserThinkingCycles
receipt: slow test 10.55s amadan.net/oficina/equipo/internal/thintest TestBrowserPlacementQuestionAndPending
receipt: slow test 7.93s amadan.net/oficina/equipo/internal/thintest TestBrowserInnerScreens
machine: 32 CPUs, load 4.82, cpu waiting 1.69%, memory waiting 0.00%, io waiting 1.77%
--- shard 23 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
shard 23: make test-quarantine
python3 scripts/ci-test.py quarantine
quarantine: 12 tests from scripts/ci-quarantine.txt; a failure is retried once, and a pass on the retry is reported as a flake
+ go test -tags testbuild -timeout 15m -v -run '^TestHeadlessConnections$/^A5_cancel_and_sign_out$|^TestHeadlessConnections$/^C4_claude_sign_in$|^TestHeadlessConnections$/^C5_engineering_failover$|^TestHeadlessConnections$/^C5_engineering_to_codex$|^TestHeadlessConnections$/^C5_engineering_waits$' ./internal/headless (53s)
ok ./internal/headless TestHeadlessConnections/A5_cancel_and_sign_out 5.23s
ok ./internal/headless TestHeadlessConnections/C4_claude_sign_in 1.48s
ok ./internal/headless TestHeadlessConnections/C5_engineering_failover 9.66s
ok ./internal/headless TestHeadlessConnections/C5_engineering_to_codex 10.03s
ok ./internal/headless TestHeadlessConnections/C5_engineering_waits 25.16s
+ go test -tags testbuild -timeout 15m -v -run '^TestHeadlessConnections$/^C5_review_auth$|^TestHeadlessConnections$/^C5_review_failover$|^TestHeadlessConnections$/^C5_review_on_codex$|^TestHeadlessConnections$/^C5_review_other_family_first$' ./internal/headless (66s)
ok ./internal/headless TestHeadlessConnections/C5_review_auth 14.01s
ok ./internal/headless TestHeadlessConnections/C5_review_failover 14.94s
ok ./internal/headless TestHeadlessConnections/C5_review_on_codex 20.83s
ok ./internal/headless TestHeadlessConnections/C5_review_other_family_first 13.81s
+ go test -tags testbuild -timeout 15m -v -run '^TestMixedVersions$' ./internal/headless (22s)
ok ./internal/headless TestMixedVersions 19.94s
+ go test -tags testbuild -timeout 15m -v -run '^TestCheckSandboxDeniedPathsTampering$' ./internal/runner/checks (2s)
ok ./internal/runner/checks TestCheckSandboxDeniedPathsTampering 0.78s
+ go test -tags testbuild -timeout 15m -v -run '^TestRunnerCancelAndSupersede$' ./internal/runner/thin (1s)
ok ./internal/runner/thin TestRunnerCancelAndSupersede 0.05s
quarantine: 0 flaked (passed on the retry), 0 failed
machine: 32 CPUs, load 38.27, cpu waiting 25.75%, memory waiting 0.00%, io waiting 0.62%
--- shard 24 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
shard 24: make runner-host
python3 scripts/runner-prerequisites.py
CGO_ENABLED=0 RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py retried runner-host -run 'TestDirect|TestProvider|TestCheckSandbox' -count=1 ./internal/runner/provider/... ./internal/runner/checks
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -no-time -run 'TestDirect|TestProvider|TestCheckSandbox' -count=1 ./internal/runner/provider/... ./internal/runner/checks
receipt: test step 8.324s against a 60s target (the gate's other steps are not in this figure)
receipt: 4 packages ran, 0 cached, 3 without tests, 0 failed
receipt: slow package 7.204s amadan.net/oficina/equipo/internal/runner/checks
receipt: slow package 159ms amadan.net/oficina/equipo/internal/runner/provider/claude
receipt: slow package 66ms amadan.net/oficina/equipo/internal/runner/provider/codex
receipt: slow package 3ms amadan.net/oficina/equipo/internal/runner/provider
receipt: slow package 0s amadan.net/oficina/equipo/internal/runner/provider/gotoolchain
receipt: slow test 5.15s amadan.net/oficina/equipo/internal/runner/checks TestCheckSandboxDeniedPathsGoFixture
receipt: slow test 1.66s amadan.net/oficina/equipo/internal/runner/checks TestCheckSandboxDeniedPaths
receipt: slow test 290ms amadan.net/oficina/equipo/internal/runner/checks TestCheckSandboxDeniedPathsCache
receipt: slow test 160ms amadan.net/oficina/equipo/internal/runner/provider/claude TestDirectJournalAdapterBarrier
receipt: slow test 80ms amadan.net/oficina/equipo/internal/runner/checks TestCheckSandboxToolchain
CGO_ENABLED=0 EQUIPO_REQUIRE_USER_SESSION=1 RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py retried runner-host -run '^TestNamespace' -count=1 ./internal/runner/containment
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -no-time -run '^TestNamespace' -count=1 ./internal/runner/containment
receipt: test step 3.336s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 2.999s amadan.net/oficina/equipo/internal/runner/containment
receipt: slow test 280ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceReadOnlyScratch
receipt: slow test 220ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceRecoveryUnavailableProof
receipt: slow test 140ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceRecoveryCleansScratch
receipt: slow test 130ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceDirectPolicyAdmission
receipt: slow test 110ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceExitStatus
machine: 32 CPUs, load 7.32, cpu waiting 4.76%, memory waiting 0.00%, io waiting 1.55%
--- shard 25 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: runner-dead-references started 30s late; cpu waiting 27.6%, load 15.02
shard 25: make runner-dead-references lanes-check build vet fmt-check budget migration-check
python3 scripts/runner-dead-references.py
reference scan: 2575 text files, 2854 matches, 0 failures
python3 scripts/ci-test.py check
lanes: 18 lanes and 5 browser lanes run every test once; 20-check@29
CGO_ENABLED=0 go build ./...
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o /dev/null ./cmd/equipo-runner
go vet ./...
go vet -tags testbuild ./internal/runner/thin ./internal/headless
GOOS=darwin GOARCH=arm64 go vet ./cmd/equipo-runner/... ./internal/runner/... ./internal/wire/... ./internal/release/...
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size
budget size: 93 directories within budget
CGO_ENABLED=0 go test ./internal/equipo -run '^TestMigrationModels$' -count=1
ok amadan.net/oficina/equipo/internal/equipo 2.486s
machine: 32 CPUs, load 37.77, cpu waiting 25.16%, memory waiting 0.00%, io waiting 0.69%
--- shard 26 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: staticcheck started 30s late; cpu waiting 27.6%, load 15.02
shard 26: make staticcheck
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 -tags browser,perf,testbuild ./...
machine: 32 CPUs, load 27.50, cpu waiting 19.80%, memory waiting 0.00%, io waiting 0.93%
--- shard 27 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: govulncheck started 30s late; cpu waiting 27.6%, load 15.02
shard 27: make govulncheck
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./...
=== Symbol Results ===
No vulnerabilities found.
Your code is affected by 0 vulnerabilities.
This scan also found 0 vulnerabilities in packages you import and 5
vulnerabilities in modules you require, but your code doesn't appear to call
these vulnerabilities.
Use '-show verbose' for more details.
machine: 32 CPUs, load 22.06, cpu waiting 17.52%, memory waiting 0.00%, io waiting 1.00%
--- shard 28 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: gitleaks started 30s late; cpu waiting 27.6%, load 15.02
shard 28: make gitleaks
[90m4:29PM[0m [32mINF[0m [1mUnknown SCM platform. Use --platform to include links in findings.[0m [36mhost=[0mamadan.net
[90m4:29PM[0m [32mINF[0m [1m1109 commits scanned.[0m
[90m4:29PM[0m [32mINF[0m [1mscanned ~61434399 bytes (61.43 MB) in 16.4s[0m
[90m4:29PM[0m [32mINF[0m [1mno leaks found[0m
machine: 32 CPUs, load 31.71, cpu waiting 22.39%, memory waiting 0.00%, io waiting 0.87%
=== perf ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -no-time -require TestPerfScreens,TestPerfBoot -tags perf -count=1 -p 1 -parallel 1 -run '^TestPerf' ./...
perf: GET /: median 1.11ms, worst 1.202ms, budget 150ms
perf: GET /api/runner/protocol: median 81µs, worst 109µs, budget 150ms
perf: GET /api/v1/account-setups/{id}: median 587µs, worst 621µs, budget 150ms
perf: GET /api/v1/accounts: median 434µs, worst 471µs, budget 150ms
perf: GET /api/v1/auth/devices: median 435µs, worst 489µs, budget 150ms
perf: GET /api/v1/budgets: median 480µs, worst 498µs, budget 150ms
perf: GET /api/v1/capabilities: median 252µs, worst 278µs, budget 150ms
perf: GET /api/v1/cards/{id}: median 1.203ms, worst 1.242ms, budget 150ms
perf: GET /api/v1/connections: median 622µs, worst 653µs, budget 150ms
perf: GET /api/v1/connections/{id}: median 570µs, worst 647µs, budget 150ms
perf: GET /api/v1/conversation: median 935µs, worst 1.05ms, budget 150ms
perf: GET /api/v1/conversation/cards: median 1.628ms, worst 1.828ms, budget 150ms
perf: GET /api/v1/coordinator: median 1.934ms, worst 2.139ms, budget 150ms
perf: GET /api/v1/invites/{id}: median 479µs, worst 496µs, budget 150ms
perf: GET /api/v1/journey: median 7.729ms, worst 7.975ms, budget 150ms
perf: GET /api/v1/me: median 446µs, worst 492µs, budget 150ms
perf: GET /api/v1/me/settings: median 516µs, worst 542µs, budget 150ms
perf: GET /api/v1/needs-you: median 7.414ms, worst 7.891ms, budget 150ms
perf: GET /api/v1/notifications: median 1.638ms, worst 1.704ms, budget 150ms
perf: GET /api/v1/onboarding: median 392µs, worst 422µs, budget 150ms
perf: GET /api/v1/people: median 424µs, worst 499µs, budget 150ms
perf: GET /api/v1/playbooks: median 592µs, worst 643µs, budget 150ms
perf: GET /api/v1/playbooks/{id}: median 565µs, worst 630µs, budget 150ms
perf: GET /api/v1/playbooks/{id}/template-diff: median 863µs, worst 912µs, budget 150ms
perf: GET /api/v1/preferences: median 787µs, worst 823µs, budget 150ms
perf: GET /api/v1/projects/{id}: median 466µs, worst 491µs, budget 150ms
perf: GET /api/v1/projects/{id}/settings: median 606µs, worst 650µs, budget 150ms
perf: GET /api/v1/roster: median 490µs, worst 536µs, budget 150ms
perf: GET /api/v1/runners/{id}: median 447µs, worst 479µs, budget 150ms
perf: GET /api/v1/specialists: median 8.163ms, worst 8.433ms, budget 150ms
perf: GET /api/v1/specialists/{id}: median 8ms, worst 8.245ms, budget 150ms
perf: GET /api/v1/specialists/{id}/template-diff: median 847µs, worst 919µs, budget 150ms
perf: GET /api/v1/tasks/{id}/plan: median 1.164ms, worst 1.226ms, budget 150ms
perf: GET /api/v1/tasks/{id}/thread: median 747µs, worst 825µs, budget 150ms
perf: GET /api/v1/teams: median 436µs, worst 477µs, budget 150ms
perf: GET /api/v1/templates: median 644µs, worst 684µs, budget 150ms
perf: GET /api/v1/templates/{id}: median 503µs, worst 543µs, budget 150ms
perf: GET /auth/callback: median 77µs, worst 100µs, budget 150ms
perf: GET /auth/devices/{id}: median 3.489ms, worst 3.549ms, budget 150ms
perf: GET /auth/verify: median 91µs, worst 109µs, budget 150ms
perf: GET /connections: median 3.681ms, worst 5.002ms, budget 150ms
perf: GET /conversation: median 7.372ms, worst 7.586ms, budget 150ms
perf: GET /conversation/connections: median 238µs, worst 284µs, budget 150ms
perf: GET /conversation/notebook: median 245µs, worst 326µs, budget 150ms
perf: GET /conversation/settings: median 3.864ms, worst 4.003ms, budget 150ms
perf: GET /conversation/settings/autonomy: median 3.6ms, worst 3.884ms, budget 150ms
perf: GET /conversation/settings/connections: median 6.296ms, worst 6.353ms, budget 150ms
perf: GET /conversation/settings/connections/add: median 6.254ms, worst 6.343ms, budget 150ms
perf: GET /conversation/settings/copy: median 3.523ms, worst 3.592ms, budget 150ms
perf: GET /conversation/settings/housekeeping: median 4.172ms, worst 6.839ms, budget 150ms
perf: GET /conversation/settings/machines: median 4.543ms, worst 4.739ms, budget 150ms
perf: GET /conversation/settings/machines/add: median 4.448ms, worst 4.573ms, budget 150ms
perf: GET /conversation/settings/notebook: median 3.349ms, worst 3.395ms, budget 150ms
perf: GET /conversation/settings/thinking: median 3.883ms, worst 4.037ms, budget 150ms
perf: GET /housekeeping: median 3.687ms, worst 3.895ms, budget 150ms
perf: GET /invites/new: median 584µs, worst 621µs, budget 150ms
perf: GET /invites/{id}: median 624µs, worst 652µs, budget 150ms
perf: GET /jobs: median 3.175ms, worst 3.279ms, budget 150ms
perf: GET /jobs/{id}: median 4.423ms, worst 4.561ms, budget 150ms
perf: GET /journey: median 11.892ms, worst 12.103ms, budget 150ms
perf: GET /nav/rail: median 3.302ms, worst 5.609ms, budget 150ms
perf: GET /needs-you: median 11.81ms, worst 12.268ms, budget 150ms
perf: GET /onboarding: median 4.175ms, worst 4.422ms, budget 150ms
perf: GET /people: median 3.567ms, worst 3.709ms, budget 150ms
perf: GET /playbook-suggestions/{suggestion}: median 5.065ms, worst 5.271ms, budget 150ms
perf: GET /playbooks: median 4.631ms, worst 4.748ms, budget 150ms
perf: GET /playbooks/new: median 4.814ms, worst 4.979ms, budget 150ms
perf: GET /playbooks/{id}: median 4.702ms, worst 4.772ms, budget 150ms
perf: GET /playbooks/{id}/edit: median 4.559ms, worst 4.756ms, budget 150ms
perf: GET /playbooks/{id}/template-diff: median 3.698ms, worst 3.85ms, budget 150ms
perf: GET /preferences: median 4.221ms, worst 4.538ms, budget 150ms
perf: GET /preferences/sources/{source}: median 4.126ms, worst 4.29ms, budget 150ms
perf: GET /projects: median 5.153ms, worst 5.277ms, budget 150ms
perf: GET /projects/accounts: median 3.477ms, worst 3.58ms, budget 150ms
perf: GET /projects/new: median 3.523ms, worst 3.639ms, budget 150ms
perf: GET /projects/{id}: median 10.288ms, worst 10.539ms, budget 150ms
perf: GET /projects/{id}/edit: median 3.629ms, worst 3.802ms, budget 150ms
perf: GET /runners/enrol: median 4.337ms, worst 4.369ms, budget 150ms
perf: GET /settings: median 3.354ms, worst 3.426ms, budget 150ms
perf: GET /settings/coordinator: median 5.466ms, worst 8.122ms, budget 150ms
perf: GET /settings/devices: median 3.333ms, worst 3.516ms, budget 150ms
perf: GET /settings/recovery: median 3.388ms, worst 3.504ms, budget 150ms
perf: GET /settings/recovery/release: median 3.361ms, worst 3.478ms, budget 150ms
perf: GET /settings/thinking: median 239µs, worst 264µs, budget 150ms
perf: GET /signin: median 313µs, worst 358µs, budget 150ms
perf: GET /specialists/new: median 3.251ms, worst 3.367ms, budget 150ms
perf: GET /specialists/{key}: median 10.472ms, worst 10.738ms, budget 150ms
perf: GET /specialists/{key}/edit: median 3.501ms, worst 3.613ms, budget 150ms
perf: GET /specialists/{key}/template-diff: median 3.587ms, worst 3.707ms, budget 150ms
perf: GET /tasks: median 4.954ms, worst 5.178ms, budget 150ms
perf: GET /tasks/new: median 3.108ms, worst 3.193ms, budget 150ms
perf: GET /tasks/{id}: median 5.588ms, worst 6.937ms, budget 150ms
perf: GET /tasks/{id}/merge: median 4.783ms, worst 5.025ms, budget 150ms
perf: GET /tasks/{id}/move: median 4.537ms, worst 4.617ms, budget 150ms
perf: GET /tasks/{id}/plan: median 5.574ms, worst 5.717ms, budget 150ms
perf: GET /tasks/{id}/preview: median 1.508ms, worst 1.662ms, budget 150ms
perf: GET /tasks/{id}/questions/{question}: median 5.196ms, worst 5.359ms, budget 150ms
perf: GET /tasks/{id}/rendered-change: median 4.595ms, worst 4.811ms, budget 150ms
perf: GET /tasks/{id}/rendered-change/{hash}.png: median 4.181ms, worst 4.314ms, budget 150ms
perf: GET /tasks/{id}/thread: median 7.849ms, worst 8.11ms, budget 150ms
perf: GET /team/{specialist}: median 4.306ms, worst 4.472ms, budget 150ms
perf: GET /teams: median 10.051ms, worst 11.773ms, budget 150ms
perf: GET /templates: median 3.356ms, worst 3.422ms, budget 150ms
perf: GET /usage: median 4.024ms, worst 4.231ms, budget 150ms
perf: GET /work: median 2.959ms, worst 3.002ms, budget 150ms
perf: cold boot: median 262ms of [261.181774ms 262.269062ms 265.408202ms], budget 500ms
receipt: test step 42.722s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 89 without tests, 0 failed
receipt: slow package 8.921s amadan.net/oficina/equipo/internal/equipotest
receipt: slow package 0s amadan.net/oficina/equipo/cmd/equipo-runner
receipt: slow package 0s amadan.net/oficina/equipo/cmd/equipo-tool-proxy
receipt: slow package 0s amadan.net/oficina/equipo/internal/advice
receipt: slow package 0s amadan.net/oficina/equipo/internal/attach
receipt: slow test 8.08s amadan.net/oficina/equipo/internal/equipotest TestPerfScreens
receipt: slow test 840ms amadan.net/oficina/equipo/internal/equipotest TestPerfBoot
=== cache ===
ci-box: build cache /home/ci/work/repos/oficina__equipo/cache/go-build: 5.61 GiB in 28503 files
ci-box: module cache /home/ci/work/repos/oficina__equipo/cache/go-mod: 0.90 GiB in 32501 files
ci-box: build cache over 4.0 GiB: dropped 2.66 GiB this job did not read, kept 2.95 GiB
diff --git a/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md| index bda0a2b6..362f7909 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md |
| @@ -161,3 +161,23 @@ Fix round 1 (review r1). `Vanish(ref)` makes the fake provider forget a VM: Get, |
| | guard: `import _ "github.com/aws/aws-sdk-go-v2/aws"` in `guardfixture/doc.go` (`go build ./internal/isolatedjob/guardfixture` succeeds) | `go test ./internal/isolatedjob -run '^TestProviderTypesStayInAdapter$' -count=1` | `providerguard_test.go:84: packages outside amadan.net/oficina/equipo/internal/isolatedjob/awsjob depend on the AWS SDK or the adapter: amadan.net/oficina/equipo/internal/isolatedjob/guardfixture (via github.com/aws/aws-sdk-go-v2/aws)` | yes, passes | |
| | guard: `guardModule + "/internal/isolatedjob/guardfixture"` added to `providerAllowed` | same | `providerguard_test.go:35: providerAllowed holds amadan.net/oficina/equipo/internal/isolatedjob/guardfixture; only cmd/ composition points may depend on the AWS SDK or awsjob` | yes, passes | |
| | extra: guard sees test-only imports (scratch `guardfixture/leak_test.go` importing `github.com/aws/smithy-go`, then removed) | same | `providerguard_test.go:84: ... guardfixture (via github.com/aws/smithy-go)` | yes, file removed, passes | |
| + |
| +## Task 8 |
| + |
| +`internal/hostedwire`: ed25519-signed requests (headers `Equipo-Key-Id`, `Equipo-Timestamp`, `Equipo-Nonce`, `Equipo-Signature`, each exactly once, matched without regard to case) and responses (`Equipo-Signature`, bound to status, the request's nonce and the body hash), plus strict JSON wire types for every Task 15 route and `DecodeStrict`. Verify order: strict headers, key lookup (a public key shared by two IDs is refused, since the key ID is not in the signed message), skew (60 s either way, against `Verifier.Now`), body size, signature, then `Remember(r.Context(), id, nonce, now+10min)`; a held nonce is a replay and a store error denies. `DecodeStrict` reads at most `MaxBody`, needs exactly one object, and refuses unknown fields, keys not lower-case snake_case, and a key repeated in one object. RED was taken against stubs (signing real, verification and decoding naive): every test but `TestSignatureCoversEveryField`, `TestSignRequestRefusesBadInput`, `TestNewNonce` and `TestWireNames` failed by assertion; the first is shown red by the body-hash mutation below. |
| + |
| +| Mutation | Command | Observed failure | Restored | |
| +| --- | --- | --- | --- | |
| +| drop the body hash (`sha256.Sum256(nil)` in `requestMessage`) | `go test ./internal/hostedwire -run 'TestSignatureCoversEveryField' -count=1` | `sign_test.go:227: Verify after changing the body = <nil>, want hostedwire: bad signature` | yes, passes | |
| +| skip `Remember` (`fresh, err := true, error(nil)`) | `go test ./internal/hostedwire -run 'TestNonceReplayRefused' -count=1` | `sign_test.go:286: replayed Verify = ("inst-1", <nil>), want ErrReplay` | yes, passes | |
| +| store error treated as fresh (`fresh, err = true, nil` in the error branch) | `go test ./internal/hostedwire -run 'TestNonceStoreErrorDenies' -count=1` | `sign_test.go:305: Verify with a failing nonce store = ("inst-1", <nil>), want ErrNonceStore wrapping the store error` | yes, passes | |
| +| skew bound off (`if false && (...) {`) | `go test ./internal/hostedwire -run 'TestSkewRefused' -count=1` | `sign_test.go:257: Verify with the clock -1m1s off = <nil>, want hostedwire: timestamp outside the allowed skew` | yes, passes | |
| +| response not bound to the request nonce (nonce dropped from `responseMessage`) | `go test ./internal/hostedwire -run 'TestResponseBoundToRequestNonce' -count=1` | `sign_test.go:364: VerifyResponse with a changed another request's nonce = <nil>, want hostedwire: bad signature` | yes, passes | |
| +| strict decode: unknown fields allowed (`DisallowUnknownFields` commented out) | `go test ./internal/hostedwire -run 'TestDecodeStrict' -count=1` | `api_test.go:45: DecodeStrict(unknown field) = <nil>, want hostedwire: body is not one strict JSON object` | yes, passes | |
| +| strict decode: trailing values allowed (`values < 1`) | same | `api_test.go:45: DecodeStrict(trailing value) = <nil>, want ...` | yes, passes | |
| +| strict decode: repeated key allowed | same | `api_test.go:45: DecodeStrict(duplicate field) = <nil>, want ...` | yes, passes | |
| +| strict decode: key case not checked | same | `api_test.go:45: DecodeStrict(field in another case) = <nil>, want ...` | yes, passes | |
| +| strict decode: top-level object not required | same | `api_test.go:45: DecodeStrict(null) = <nil>, want ...` | yes, passes | |
| +| shared public key allowed (`if false && other != id ...`) | `go test ./internal/hostedwire -run 'TestSharedPublicKeyRefused' -count=1` | `sign_test.go:461: Verify as op-alias with a shared public key = ("op-alias", <nil>), want ErrSharedKey` | yes, passes | |
| +| repeated header allowed (`case 1, 2:` in `single`) | `go test ./internal/hostedwire -run 'TestRequestHeadersStrict' -count=1` | `sign_test.go:444: Verify with key id twice = <nil>, want hostedwire: signature header malformed or repeated` | yes, passes | |
| +| oversize body allowed in Verify | `go test ./internal/hostedwire -run 'TestOversizeBodyRefused' -count=1` | `sign_test.go:389: Verify of 1048577 signed bytes = <nil>, want ErrTooLarge` | yes, passes | |
diff --git a/internal/hostedwire/api.go b/internal/hostedwire/api.go| new file mode 100644 |
| index 00000000..879b3978 |
| --- /dev/null |
| +++ b/internal/hostedwire/api.go |
| @@ -0,0 +1,254 @@ |
| +package hostedwire |
| + |
| +import ( |
| + "bytes" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "io" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/isolatedjob" |
| +) |
| + |
| +// Wire types for the controller's routes. Every body is one JSON object with |
| +// lower-case snake_case keys, read with DecodeStrict. Durations are whole |
| +// milliseconds in fields ending _ms; times are RFC 3339. |
| +// |
| +// POST /v1/jobs LaunchRequest -> JobView |
| +// GET /v1/jobs/{attempt} (empty body) -> JobView |
| +// POST /v1/jobs/{attempt}/stop StopRequest -> StopProof |
| +// POST /v1/jobs/{attempt}/drain DrainRequest -> DrainResponse |
| +// POST /v1/jobs/{attempt}/quiescent QuiescentRequest -> QuiescentResponse |
| +// POST /v1/jobs/{attempt}/suspend SuspendRequest -> SuspendResponse |
| +// POST /v1/jobs/{attempt}/reopen ReopenRequest -> ReopenResponse |
| +// POST /v1/jobs/{attempt}/resume ResumeRequest -> ResumeResponse |
| +// GET /v1/vms (empty body) -> VMListResponse |
| +// |
| +// A refused request gets an ErrorResponse. Every response, refusals included, |
| +// is signed with SignResponse. |
| + |
| +// ErrBadJSON is a body DecodeStrict refuses for any reason but its size. |
| +var ErrBadJSON = errors.New("hostedwire: body is not one strict JSON object") |
| + |
| +// LaunchRequest asks for one VM for one task attempt. |
| +type LaunchRequest struct { |
| + AttemptID string `json:"attempt_id"` |
| + TaskID string `json:"task_id"` |
| + Account string `json:"account"` |
| + Replaces string `json:"replaces"` // attempt this one replaces, or "" |
| + Image isolatedjob.ImageDigest `json:"image"` |
| + Size isolatedjob.Size `json:"size"` |
| + MaxLifetimeMS int64 `json:"max_lifetime_ms"` |
| + InstanceCode string `json:"instance_code"` |
| +} |
| + |
| +// MaxLifetime is MaxLifetimeMS as a duration. |
| +func (q LaunchRequest) MaxLifetime() time.Duration { |
| + return time.Duration(q.MaxLifetimeMS) * time.Millisecond |
| +} |
| + |
| +// JobView is the controller's view of one attempt. The *_in_ms fields count |
| +// down from the moment the controller answered, in controller time. |
| +type JobView struct { |
| + AttemptID string `json:"attempt_id"` |
| + LaunchID string `json:"launch_id"` |
| + State string `json:"state"` |
| + VMRef isolatedjob.Ref `json:"vm_ref"` |
| + Epoch int64 `json:"epoch"` |
| + DeadlineInMS int64 `json:"deadline_in_ms"` |
| + DrainInMS int64 `json:"drain_in_ms"` |
| + StopInMS int64 `json:"stop_in_ms"` |
| +} |
| + |
| +// StopRequest stops an attempt's VM. |
| +type StopRequest struct { |
| + Reason string `json:"reason"` |
| +} |
| + |
| +// StopProof says the provider reported the VM terminal, or gone after the |
| +// stop request. |
| +type StopProof struct { |
| + AttemptID string `json:"attempt_id"` |
| + VMRef isolatedjob.Ref `json:"vm_ref"` |
| + State isolatedjob.State `json:"state"` |
| + ObservedAt time.Time `json:"observed_at"` |
| +} |
| + |
| +// DrainRequest opens a new pause generation. It has no fields; its body is {}. |
| +type DrainRequest struct{} |
| + |
| +type DrainResponse struct { |
| + Generation int64 `json:"generation"` |
| +} |
| + |
| +type QuiescentRequest struct { |
| + Generation int64 `json:"generation"` |
| +} |
| + |
| +type QuiescentResponse struct { |
| + Generation int64 `json:"generation"` |
| +} |
| + |
| +type SuspendRequest struct { |
| + Generation int64 `json:"generation"` |
| +} |
| + |
| +type SuspendResponse struct { |
| + Generation int64 `json:"generation"` |
| +} |
| + |
| +type ReopenRequest struct { |
| + Generation int64 `json:"generation"` |
| +} |
| + |
| +type ReopenResponse struct { |
| + Generation int64 `json:"generation"` |
| +} |
| + |
| +// ResumeRequest resumes a suspended VM. OperationID makes a retry of the same |
| +// resume return the same epoch. |
| +type ResumeRequest struct { |
| + OperationID string `json:"operation_id"` |
| +} |
| + |
| +type ResumeResponse struct { |
| + Epoch int64 `json:"epoch"` |
| +} |
| + |
| +// VMView is one VM the provider lists, for operators. AttemptID is "" for a |
| +// VM no job or intent owns. |
| +type VMView struct { |
| + VMRef isolatedjob.Ref `json:"vm_ref"` |
| + State isolatedjob.State `json:"state"` |
| + AttemptID string `json:"attempt_id"` |
| + AgeKnown bool `json:"age_known"` |
| + AgeMS int64 `json:"age_ms"` |
| +} |
| + |
| +type VMListResponse struct { |
| + VMs []VMView `json:"vms"` |
| +} |
| + |
| +// ErrorResponse is the body of every refusal. Code is a short fixed word the |
| +// client can branch on; Message is for people and never holds key material |
| +// or request bodies. |
| +type ErrorResponse struct { |
| + Code string `json:"code"` |
| + Message string `json:"message"` |
| +} |
| + |
| +// BootstrapVersion is the Bootstrap layout this package writes. |
| +const BootstrapVersion = 1 |
| + |
| +// Bootstrap is the one-time payload the VM's /run hook receives. Slice 1b |
| +// adds ProxyCode. |
| +type Bootstrap struct { |
| + Version int `json:"version"` |
| + LaunchID string `json:"launch_id"` |
| + InstanceCode string `json:"instance_code"` |
| +} |
| + |
| +// DecodeStrict reads at most MaxBody bytes from r and decodes them into v. |
| +// The body must be exactly one JSON object, with nothing after it but white |
| +// space. It refuses fields v does not have, keys that are not lower case |
| +// (encoding/json would otherwise match "Reason" to "reason"), and a key that |
| +// appears twice in one object (encoding/json would keep the last). Error |
| +// texts name the rule broken, never the body. |
| +func DecodeStrict(r io.Reader, v any) error { |
| + data, err := io.ReadAll(io.LimitReader(r, MaxBody+1)) |
| + if err != nil { |
| + return fmt.Errorf("hostedwire: reading body: %w", err) |
| + } |
| + if len(data) > MaxBody { |
| + return ErrTooLarge |
| + } |
| + // checkKeys also refuses anything after the one object. |
| + if err := checkKeys(data); err != nil { |
| + return err |
| + } |
| + dec := json.NewDecoder(bytes.NewReader(data)) |
| + dec.DisallowUnknownFields() |
| + if err := dec.Decode(v); err != nil { |
| + return fmt.Errorf("%w: does not fit the request type", ErrBadJSON) |
| + } |
| + return nil |
| +} |
| + |
| +// checkKeys walks the tokens of data: one top-level object, every key lower |
| +// case snake_case, no key twice in one object. |
| +func checkKeys(data []byte) error { |
| + type frame struct { |
| + object bool |
| + wantKey bool |
| + keys map[string]bool |
| + } |
| + var stack []*frame |
| + values := 0 |
| + valueDone := func() { |
| + if n := len(stack); n > 0 && stack[n-1].object { |
| + stack[n-1].wantKey = true |
| + } else if n == 0 { |
| + values++ |
| + } |
| + } |
| + dec := json.NewDecoder(bytes.NewReader(data)) |
| + dec.UseNumber() |
| + for first := true; ; first = false { |
| + tok, err := dec.Token() |
| + if err == io.EOF { |
| + break |
| + } |
| + if err != nil { |
| + return fmt.Errorf("%w: syntax", ErrBadJSON) |
| + } |
| + if first && tok != json.Delim('{') { |
| + return fmt.Errorf("%w: not an object", ErrBadJSON) |
| + } |
| + if n := len(stack); n > 0 && stack[n-1].object && stack[n-1].wantKey { |
| + if tok == json.Delim('}') { |
| + stack = stack[:n-1] |
| + valueDone() |
| + continue |
| + } |
| + key, _ := tok.(string) |
| + if !validWireKey(key) { |
| + return fmt.Errorf("%w: key not lower-case snake_case", ErrBadJSON) |
| + } |
| + if stack[n-1].keys[key] { |
| + return fmt.Errorf("%w: key repeated", ErrBadJSON) |
| + } |
| + stack[n-1].keys[key] = true |
| + stack[n-1].wantKey = false |
| + continue |
| + } |
| + switch tok { |
| + case json.Delim('{'): |
| + stack = append(stack, &frame{object: true, wantKey: true, keys: map[string]bool{}}) |
| + case json.Delim('['): |
| + stack = append(stack, &frame{}) |
| + case json.Delim(']'): |
| + stack = stack[:len(stack)-1] |
| + valueDone() |
| + default: |
| + valueDone() |
| + } |
| + } |
| + if values != 1 || len(stack) != 0 { |
| + return fmt.Errorf("%w: not one complete object", ErrBadJSON) |
| + } |
| + return nil |
| +} |
| + |
| +func validWireKey(s string) bool { |
| + if s == "" { |
| + return false |
| + } |
| + for i := 0; i < len(s); i++ { |
| + c := s[i] |
| + if !(c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '_') { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
diff --git a/internal/hostedwire/api_test.go b/internal/hostedwire/api_test.go| new file mode 100644 |
| index 00000000..7074f86f |
| --- /dev/null |
| +++ b/internal/hostedwire/api_test.go |
| @@ -0,0 +1,127 @@ |
| +package hostedwire |
| + |
| +import ( |
| + "bytes" |
| + "encoding/json" |
| + "errors" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/isolatedjob" |
| +) |
| + |
| +func TestDecodeStrict(t *testing.T) { |
| + pad := func(n int) string { |
| + // {"reason":"aaa..."} padded to exactly n bytes. |
| + const frame = `{"reason":""}` |
| + return `{"reason":"` + strings.Repeat("a", n-len(frame)) + `"}` |
| + } |
| + cases := []struct { |
| + name string |
| + in string |
| + want error |
| + }{ |
| + {"valid", `{"reason":"done"}`, nil}, |
| + {"valid with space", " \n{\"reason\":\"done\"}\n ", nil}, |
| + {"exactly MaxBody", pad(MaxBody), nil}, |
| + {"over MaxBody", pad(MaxBody + 1), ErrTooLarge}, |
| + {"unknown field", `{"reason":"done","extra":1}`, ErrBadJSON}, |
| + {"field in another case", `{"Reason":"done"}`, ErrBadJSON}, |
| + {"duplicate field", `{"reason":"a","reason":"b"}`, ErrBadJSON}, |
| + {"trailing value", `{"reason":"a"} {"reason":"b"}`, ErrBadJSON}, |
| + {"trailing garbage", `{"reason":"a"}x`, ErrBadJSON}, |
| + {"empty", ``, ErrBadJSON}, |
| + {"null", `null`, ErrBadJSON}, |
| + {"array", `[]`, ErrBadJSON}, |
| + {"truncated", `{"reason":"a"`, ErrBadJSON}, |
| + {"wrong type", `{"reason":5}`, ErrBadJSON}, |
| + } |
| + for _, c := range cases { |
| + var v StopRequest |
| + err := DecodeStrict(strings.NewReader(c.in), &v) |
| + if !errors.Is(err, c.want) || (c.want == nil) != (err == nil) { |
| + name := c.name |
| + t.Fatalf("DecodeStrict(%s) = %v, want %v", name, err, c.want) |
| + } |
| + if c.want == nil && v.Reason == "" { |
| + t.Fatalf("DecodeStrict(%s) left Reason empty", c.name) |
| + } |
| + } |
| + |
| + // Nested objects are held to the same rules. |
| + nested := []struct { |
| + name string |
| + in string |
| + want error |
| + }{ |
| + {"valid", `{"vms":[{"vm_ref":"vm-1","state":"running","attempt_id":"a1","age_known":true,"age_ms":5}]}`, nil}, |
| + {"nested duplicate", `{"vms":[{"vm_ref":"vm-1","vm_ref":"vm-2"}]}`, ErrBadJSON}, |
| + {"nested unknown", `{"vms":[{"vm_ref":"vm-1","owner":"x"}]}`, ErrBadJSON}, |
| + {"nested other case", `{"vms":[{"VM_REF":"vm-1"}]}`, ErrBadJSON}, |
| + {"same key in sibling objects", `{"vms":[{"vm_ref":"vm-1"},{"vm_ref":"vm-2"}]}`, nil}, |
| + } |
| + for _, c := range nested { |
| + var v VMListResponse |
| + err := DecodeStrict(strings.NewReader(c.in), &v) |
| + if !errors.Is(err, c.want) || (c.want == nil) != (err == nil) { |
| + t.Fatalf("DecodeStrict(%s) = %v, want %v", c.name, err, c.want) |
| + } |
| + } |
| +} |
| + |
| +// TestWireNames pins the JSON names, so the controller and the instance cannot |
| +// drift apart silently. |
| +func TestWireNames(t *testing.T) { |
| + at := time.Date(2026, 11, 22, 10, 0, 0, 0, time.UTC) |
| + cases := []struct { |
| + v any |
| + into func() any |
| + want string |
| + }{ |
| + {LaunchRequest{AttemptID: "a1", TaskID: "t1", Account: "acct", Replaces: "a0", Image: "sha256:ab", Size: isolatedjob.SizeSmall, MaxLifetimeMS: 1000, InstanceCode: "code"}, |
| + func() any { return &LaunchRequest{} }, |
| + `{"attempt_id":"a1","task_id":"t1","account":"acct","replaces":"a0","image":"sha256:ab","size":"small","max_lifetime_ms":1000,"instance_code":"code"}`}, |
| + {JobView{AttemptID: "a1", LaunchID: "l1", State: "running", VMRef: "vm-1", Epoch: 2, DeadlineInMS: 3, DrainInMS: 4, StopInMS: 5}, |
| + func() any { return &JobView{} }, |
| + `{"attempt_id":"a1","launch_id":"l1","state":"running","vm_ref":"vm-1","epoch":2,"deadline_in_ms":3,"drain_in_ms":4,"stop_in_ms":5}`}, |
| + {StopRequest{Reason: "done"}, func() any { return &StopRequest{} }, `{"reason":"done"}`}, |
| + {StopProof{AttemptID: "a1", VMRef: "vm-1", State: isolatedjob.StateStopped, ObservedAt: at}, |
| + func() any { return &StopProof{} }, |
| + `{"attempt_id":"a1","vm_ref":"vm-1","state":"stopped","observed_at":"2026-11-22T10:00:00Z"}`}, |
| + {DrainRequest{}, func() any { return &DrainRequest{} }, `{}`}, |
| + {DrainResponse{Generation: 4}, func() any { return &DrainResponse{} }, `{"generation":4}`}, |
| + {QuiescentRequest{Generation: 4}, func() any { return &QuiescentRequest{} }, `{"generation":4}`}, |
| + {QuiescentResponse{Generation: 4}, func() any { return &QuiescentResponse{} }, `{"generation":4}`}, |
| + {SuspendRequest{Generation: 4}, func() any { return &SuspendRequest{} }, `{"generation":4}`}, |
| + {SuspendResponse{Generation: 4}, func() any { return &SuspendResponse{} }, `{"generation":4}`}, |
| + {ReopenRequest{Generation: 4}, func() any { return &ReopenRequest{} }, `{"generation":4}`}, |
| + {ReopenResponse{Generation: 4}, func() any { return &ReopenResponse{} }, `{"generation":4}`}, |
| + {ResumeRequest{OperationID: "op1"}, func() any { return &ResumeRequest{} }, `{"operation_id":"op1"}`}, |
| + {ResumeResponse{Epoch: 3}, func() any { return &ResumeResponse{} }, `{"epoch":3}`}, |
| + {VMListResponse{VMs: []VMView{{VMRef: "vm-1", State: isolatedjob.StateRunning, AttemptID: "a1", AgeKnown: true, AgeMS: 9}}}, |
| + func() any { return &VMListResponse{} }, |
| + `{"vms":[{"vm_ref":"vm-1","state":"running","attempt_id":"a1","age_known":true,"age_ms":9}]}`}, |
| + {ErrorResponse{Code: "forbidden", Message: "not yours"}, func() any { return &ErrorResponse{} }, `{"code":"forbidden","message":"not yours"}`}, |
| + {Bootstrap{Version: BootstrapVersion, LaunchID: "l1", InstanceCode: "code"}, |
| + func() any { return &Bootstrap{} }, |
| + `{"version":1,"launch_id":"l1","instance_code":"code"}`}, |
| + } |
| + for _, c := range cases { |
| + b, err := json.Marshal(c.v) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if string(b) != c.want { |
| + t.Fatalf("json of %T = %s, want %s", c.v, b, c.want) |
| + } |
| + back := c.into() |
| + if err := DecodeStrict(bytes.NewReader(b), back); err != nil { |
| + t.Fatalf("DecodeStrict(%s) into %T = %v", b, back, err) |
| + } |
| + again, _ := json.Marshal(back) |
| + if string(again) != c.want { |
| + t.Fatalf("round trip of %T = %s, want %s", c.v, again, c.want) |
| + } |
| + } |
| +} |
diff --git a/internal/hostedwire/main_test.go b/internal/hostedwire/main_test.go| new file mode 100644 |
| index 00000000..0ff87b4b |
| --- /dev/null |
| +++ b/internal/hostedwire/main_test.go |
| @@ -0,0 +1,9 @@ |
| +package hostedwire |
| + |
| +import ( |
| + "amadan.net/rastrillo/rastrillo/budget" |
| + "os" |
| + "testing" |
| +) |
| + |
| +func TestMain(m *testing.M) { os.Exit(budget.Main(m)) } |
diff --git a/internal/hostedwire/sign.go b/internal/hostedwire/sign.go| new file mode 100644 |
| index 00000000..bea70f82 |
| --- /dev/null |
| +++ b/internal/hostedwire/sign.go |
| @@ -0,0 +1,208 @@ |
| +// Package hostedwire is the signed protocol between the Equipo instance (and |
| +// operators) and equipo-hosted-controller, plus the strict JSON types of the |
| +// controller's HTTP routes. |
| +// |
| +// Every request carries four headers: the key ID, a Unix timestamp in |
| +// seconds, a single-use nonce and an ed25519 signature over |
| +// |
| +// "equipo-hosted-request-v1\n" + method + "\n" + escaped path and raw query + |
| +// "\n" + timestamp + "\n" + nonce + "\n" + hex(sha256(body)) |
| +// |
| +// Every response carries a signature by the controller's key over |
| +// |
| +// "equipo-hosted-response-v1\n" + status + "\n" + request nonce + "\n" + |
| +// hex(sha256(body)) |
| +// |
| +// so a response cannot be moved to another request. The key ID is not in the |
| +// signed message; it only picks the public key, and the Verifier refuses a key |
| +// table where two IDs share one public key. |
| +package hostedwire |
| + |
| +import ( |
| + "crypto/ed25519" |
| + "crypto/rand" |
| + "crypto/sha256" |
| + "encoding/base64" |
| + "encoding/hex" |
| + "fmt" |
| + "net/http" |
| + "net/url" |
| + "strconv" |
| + "strings" |
| + "time" |
| +) |
| + |
| +// Header names. Each must appear exactly once. |
| +const ( |
| + HeaderKeyID = "Equipo-Key-Id" |
| + HeaderTimestamp = "Equipo-Timestamp" // Unix seconds, decimal, no sign or leading zero |
| + HeaderNonce = "Equipo-Nonce" |
| + HeaderSignature = "Equipo-Signature" // base64 (standard, padded) of the 64-byte signature |
| +) |
| + |
| +const ( |
| + // MaxBody is the largest request or response body either side accepts. |
| + MaxBody = 1 << 20 |
| + // MaxSkew is how far a request's timestamp may be from the verifier's |
| + // clock, either way. |
| + MaxSkew = 60 * time.Second |
| + // NonceTTL is how long a verifier keeps a nonce, from the time it |
| + // verified the request. It must outlive the skew window, so a request |
| + // whose nonce has been forgotten is already refused as skewed. |
| + NonceTTL = 10 * time.Minute |
| + |
| + requestDomain = "equipo-hosted-request-v1" |
| + responseDomain = "equipo-hosted-response-v1" |
| +) |
| + |
| +// KeyID names a verify key in the controller's key table. |
| +type KeyID string |
| + |
| +// Role is what a key may do. |
| +type Role string |
| + |
| +const ( |
| + RoleInstance Role = "instance" |
| + RoleOperator Role = "operator" |
| +) |
| + |
| +// VerifyKey is a public key and the role it holds. |
| +type VerifyKey struct { |
| + Public ed25519.PublicKey |
| + Role Role |
| +} |
| + |
| +// NewNonce returns a fresh request nonce: 32 characters of base64url from |
| +// 24 random bytes. |
| +func NewNonce() (string, error) { |
| + var b [24]byte |
| + if _, err := rand.Read(b[:]); err != nil { |
| + return "", fmt.Errorf("hostedwire: nonce: %w", err) |
| + } |
| + return base64.RawURLEncoding.EncodeToString(b[:]), nil |
| +} |
| + |
| +// SignRequest sets the four signature headers on r for body, which must be |
| +// the exact bytes r will send. It replaces any existing signature headers. |
| +func SignRequest(r *http.Request, body []byte, id KeyID, key ed25519.PrivateKey, now time.Time, nonce string) error { |
| + if len(key) != ed25519.PrivateKeySize { |
| + return fmt.Errorf("%w: signing key has the wrong length", ErrNotConfigured) |
| + } |
| + if !validKeyID(string(id)) { |
| + return fmt.Errorf("%w: key ID", ErrMalformed) |
| + } |
| + if !validNonce(nonce) { |
| + return fmt.Errorf("%w: nonce", ErrMalformed) |
| + } |
| + if len(body) > MaxBody { |
| + return ErrTooLarge |
| + } |
| + target, err := requestTarget(r) |
| + if err != nil { |
| + return err |
| + } |
| + ts := now.Unix() |
| + if ts < 0 { |
| + return fmt.Errorf("%w: timestamp before 1970", ErrMalformed) |
| + } |
| + sig := ed25519.Sign(key, requestMessage(r.Method, target, ts, nonce, body)) |
| + if r.Header == nil { |
| + r.Header = http.Header{} |
| + } |
| + for _, name := range []string{HeaderKeyID, HeaderTimestamp, HeaderNonce, HeaderSignature} { |
| + deleteFold(r.Header, name) |
| + } |
| + r.Header.Set(HeaderKeyID, string(id)) |
| + r.Header.Set(HeaderTimestamp, strconv.FormatInt(ts, 10)) |
| + r.Header.Set(HeaderNonce, nonce) |
| + r.Header.Set(HeaderSignature, base64.StdEncoding.EncodeToString(sig)) |
| + return nil |
| +} |
| + |
| +// SignResponse sets the response signature header in h. requestNonce is the |
| +// nonce of the request being answered. key must be a full ed25519 private |
| +// key; ed25519.Sign panics otherwise. |
| +func SignResponse(h http.Header, status int, requestNonce string, body []byte, key ed25519.PrivateKey) { |
| + sig := ed25519.Sign(key, responseMessage(status, requestNonce, body)) |
| + deleteFold(h, HeaderSignature) |
| + h.Set(HeaderSignature, base64.StdEncoding.EncodeToString(sig)) |
| +} |
| + |
| +func requestMessage(method, target string, ts int64, nonce string, body []byte) []byte { |
| + sum := sha256.Sum256(body) |
| + return []byte(requestDomain + "\n" + method + "\n" + target + "\n" + |
| + strconv.FormatInt(ts, 10) + "\n" + nonce + "\n" + hex.EncodeToString(sum[:])) |
| +} |
| + |
| +func responseMessage(status int, requestNonce string, body []byte) []byte { |
| + sum := sha256.Sum256(body) |
| + return []byte(responseDomain + "\n" + strconv.Itoa(status) + "\n" + requestNonce + "\n" + |
| + hex.EncodeToString(sum[:])) |
| +} |
| + |
| +// requestTarget is the escaped path and, when there is one, "?" and the raw |
| +// query. Opaque URLs and control characters are refused. |
| +func requestTarget(r *http.Request) (string, error) { |
| + if r.URL == nil || r.URL.Opaque != "" { |
| + return "", fmt.Errorf("%w: request URL", ErrMalformed) |
| + } |
| + if r.Method == "" || hasControlOrSpace(r.Method) { |
| + return "", fmt.Errorf("%w: method", ErrMalformed) |
| + } |
| + target := escapedPath(r.URL) |
| + if r.URL.RawQuery != "" { |
| + target += "?" + r.URL.RawQuery |
| + } |
| + if hasControlOrSpace(target) { |
| + return "", fmt.Errorf("%w: request target", ErrMalformed) |
| + } |
| + return target, nil |
| +} |
| + |
| +func escapedPath(u *url.URL) string { |
| + p := u.EscapedPath() |
| + if p == "" { |
| + return "/" |
| + } |
| + return p |
| +} |
| + |
| +func hasControlOrSpace(s string) bool { |
| + for i := 0; i < len(s); i++ { |
| + if s[i] <= ' ' || s[i] == 0x7f { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// validNonce: 16 to 64 characters of [A-Za-z0-9_-]. |
| +func validNonce(s string) bool { |
| + return len(s) >= 16 && len(s) <= 64 && onlyChars(s, "_-") |
| +} |
| + |
| +// validKeyID: 1 to 64 characters of [A-Za-z0-9._-]. |
| +func validKeyID(s string) bool { |
| + return len(s) >= 1 && len(s) <= 64 && onlyChars(s, "._-") |
| +} |
| + |
| +func onlyChars(s, extra string) bool { |
| + for i := 0; i < len(s); i++ { |
| + c := s[i] |
| + ok := c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || strings.IndexByte(extra, c) >= 0 |
| + if !ok { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| +// deleteFold removes every key equal to name ignoring case, including keys |
| +// that were set without canonicalisation. |
| +func deleteFold(h http.Header, name string) { |
| + for k := range h { |
| + if strings.EqualFold(k, name) { |
| + delete(h, k) |
| + } |
| + } |
| +} |
diff --git a/internal/hostedwire/sign_test.go b/internal/hostedwire/sign_test.go| new file mode 100644 |
| index 00000000..3815deca |
| --- /dev/null |
| +++ b/internal/hostedwire/sign_test.go |
| @@ -0,0 +1,518 @@ |
| +package hostedwire |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "crypto/ed25519" |
| + "encoding/base64" |
| + "errors" |
| + "io" |
| + "net/http" |
| + "net/http/httptest" |
| + "strconv" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| +) |
| + |
| +const ( |
| + nonceA = "nonce-aaaaaaaaaaaaaaaa" |
| + nonceB = "nonce-bbbbbbbbbbbbbbbb" |
| +) |
| + |
| +func testKey(seed byte) ed25519.PrivateKey { |
| + return ed25519.NewKeyFromSeed(bytes.Repeat([]byte{seed}, ed25519.SeedSize)) |
| +} |
| + |
| +func pub(k ed25519.PrivateKey) ed25519.PublicKey { return k.Public().(ed25519.PublicKey) } |
| + |
| +// memNonces is a NonceStore that keeps every nonce it is shown. |
| +type memNonces struct { |
| + mu sync.Mutex |
| + seen map[string]bool |
| + calls int |
| + lastUntil time.Time |
| + err error |
| +} |
| + |
| +func (m *memNonces) Remember(_ context.Context, id KeyID, nonce string, until time.Time) (bool, error) { |
| + m.mu.Lock() |
| + defer m.mu.Unlock() |
| + m.calls++ |
| + m.lastUntil = until |
| + if m.err != nil { |
| + return false, m.err |
| + } |
| + k := string(id) + "\x00" + nonce |
| + if m.seen[k] { |
| + return false, nil |
| + } |
| + m.seen[k] = true |
| + return true, nil |
| +} |
| + |
| +func (m *memNonces) count() int { |
| + m.mu.Lock() |
| + defer m.mu.Unlock() |
| + return m.calls |
| +} |
| + |
| +type fixture struct { |
| + now time.Time |
| + inst ed25519.PrivateKey |
| + inst2 ed25519.PrivateKey |
| + op ed25519.PrivateKey |
| + ctl ed25519.PrivateKey |
| + nonces *memNonces |
| + v *Verifier |
| +} |
| + |
| +func newFixture() *fixture { |
| + f := &fixture{ |
| + now: time.Unix(1_800_000_000, 0).UTC(), |
| + inst: testKey(1), |
| + inst2: testKey(2), |
| + op: testKey(3), |
| + ctl: testKey(4), |
| + nonces: &memNonces{seen: map[string]bool{}}, |
| + } |
| + f.v = &Verifier{ |
| + Keys: map[KeyID]VerifyKey{ |
| + "inst-1": {Public: pub(f.inst), Role: RoleInstance}, |
| + "inst-2": {Public: pub(f.inst2), Role: RoleInstance}, |
| + "op-1": {Public: pub(f.op), Role: RoleOperator}, |
| + }, |
| + Nonces: f.nonces, |
| + Now: func() time.Time { return f.now }, |
| + } |
| + return f |
| +} |
| + |
| +// signed builds a request as the controller's handler sees it, signed by the |
| +// given key at time at. |
| +func (f *fixture) signed(t *testing.T, method, target string, body []byte, id KeyID, key ed25519.PrivateKey, at time.Time, nonce string) *http.Request { |
| + t.Helper() |
| + r := httptest.NewRequest(method, "http://controller.test"+target, bytes.NewReader(body)) |
| + if err := SignRequest(r, body, id, key, at, nonce); err != nil { |
| + t.Fatalf("SignRequest: %v", err) |
| + } |
| + return r |
| +} |
| + |
| +func TestSignedRequestRoundTrip(t *testing.T) { |
| + f := newFixture() |
| + type seen struct { |
| + id KeyID |
| + role Role |
| + err error |
| + } |
| + got := make(chan seen, 1) |
| + reply := []byte(`{"generation":7}`) |
| + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + body, err := io.ReadAll(io.LimitReader(r.Body, MaxBody+1)) |
| + if err != nil { |
| + got <- seen{err: err} |
| + w.WriteHeader(http.StatusBadRequest) |
| + return |
| + } |
| + id, key, err := f.v.Verify(r, body) |
| + got <- seen{id, key.Role, err} |
| + if err != nil { |
| + w.WriteHeader(http.StatusUnauthorized) |
| + return |
| + } |
| + SignResponse(w.Header(), http.StatusOK, r.Header.Get(HeaderNonce), reply, f.ctl) |
| + w.WriteHeader(http.StatusOK) |
| + _, _ = w.Write(reply) |
| + })) |
| + defer srv.Close() |
| + |
| + cases := []struct { |
| + method, target string |
| + body []byte |
| + id KeyID |
| + key ed25519.PrivateKey |
| + role Role |
| + }{ |
| + {"POST", "/v1/jobs/a%2Fb/drain?x=1&y=a+b", []byte(`{}`), "inst-1", f.inst, RoleInstance}, |
| + {"POST", "/v1/jobs", []byte(`{"attempt_id":"a1"}`), "inst-2", f.inst2, RoleInstance}, |
| + {"GET", "/v1/vms", nil, "op-1", f.op, RoleOperator}, |
| + } |
| + for _, c := range cases { |
| + var rd io.Reader |
| + if c.body != nil { |
| + rd = bytes.NewReader(c.body) |
| + } |
| + req, err := http.NewRequest(c.method, srv.URL+c.target, rd) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + nonce, err := NewNonce() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := SignRequest(req, c.body, c.id, c.key, f.now, nonce); err != nil { |
| + t.Fatalf("%s %s: SignRequest: %v", c.method, c.target, err) |
| + } |
| + resp, err := srv.Client().Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + rb, err := io.ReadAll(resp.Body) |
| + _ = resp.Body.Close() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + s := <-got |
| + if s.err != nil || s.id != c.id || s.role != c.role { |
| + t.Fatalf("%s %s: Verify = (%q, %q, %v), want (%q, %q, nil)", c.method, c.target, s.id, s.role, s.err, c.id, c.role) |
| + } |
| + if err := VerifyResponse(resp, rb, nonce, pub(f.ctl)); err != nil { |
| + t.Fatalf("%s %s: VerifyResponse = %v, want nil", c.method, c.target, err) |
| + } |
| + } |
| + if n := f.nonces.count(); n != len(cases) { |
| + t.Fatalf("Remember called %d times, want %d", n, len(cases)) |
| + } |
| +} |
| + |
| +func TestSignatureCoversEveryField(t *testing.T) { |
| + body := []byte(`{"reason":"done"}`) |
| + const target = "/v1/jobs/a%2Fb/stop?x=1" |
| + cases := []struct { |
| + name string |
| + mutate func(f *fixture, r *http.Request) []byte |
| + want error |
| + }{ |
| + {"unchanged", func(_ *fixture, _ *http.Request) []byte { return body }, nil}, |
| + {"method", func(_ *fixture, r *http.Request) []byte { r.Method = "PUT"; return body }, ErrBadSignature}, |
| + {"path", func(_ *fixture, r *http.Request) []byte { |
| + r.URL.Path, r.URL.RawPath = "/v1/jobs/a%2Fc/stop", "" |
| + return body |
| + }, ErrBadSignature}, |
| + {"escaped path", func(_ *fixture, r *http.Request) []byte { r.URL.RawPath = ""; return body }, ErrBadSignature}, |
| + {"query changed", func(_ *fixture, r *http.Request) []byte { r.URL.RawQuery = "x=2"; return body }, ErrBadSignature}, |
| + {"query dropped", func(_ *fixture, r *http.Request) []byte { r.URL.RawQuery = ""; return body }, ErrBadSignature}, |
| + {"timestamp", func(f *fixture, r *http.Request) []byte { |
| + r.Header.Set(HeaderTimestamp, strconv.FormatInt(f.now.Unix()+1, 10)) |
| + return body |
| + }, ErrBadSignature}, |
| + {"nonce", func(_ *fixture, r *http.Request) []byte { r.Header.Set(HeaderNonce, nonceB); return body }, ErrBadSignature}, |
| + {"body", func(_ *fixture, _ *http.Request) []byte { return []byte(`{"reason":"evil"}`) }, ErrBadSignature}, |
| + {"body emptied", func(_ *fixture, _ *http.Request) []byte { return nil }, ErrBadSignature}, |
| + {"key id to another known key", func(_ *fixture, r *http.Request) []byte { r.Header.Set(HeaderKeyID, "inst-2"); return body }, ErrBadSignature}, |
| + {"key id to the operator key", func(_ *fixture, r *http.Request) []byte { r.Header.Set(HeaderKeyID, "op-1"); return body }, ErrBadSignature}, |
| + {"key id unknown", func(_ *fixture, r *http.Request) []byte { r.Header.Set(HeaderKeyID, "nobody"); return body }, ErrUnknownKey}, |
| + {"signature", func(_ *fixture, r *http.Request) []byte { |
| + sig, _ := base64.StdEncoding.DecodeString(r.Header.Get(HeaderSignature)) |
| + sig[10] ^= 1 |
| + r.Header.Set(HeaderSignature, base64.StdEncoding.EncodeToString(sig)) |
| + return body |
| + }, ErrBadSignature}, |
| + } |
| + for _, c := range cases { |
| + t.Run(c.name, func(t *testing.T) { |
| + f := newFixture() |
| + r := f.signed(t, "POST", target, body, "inst-1", f.inst, f.now, nonceA) |
| + b := c.mutate(f, r) |
| + id, key, err := f.v.Verify(r, b) |
| + if c.want == nil { |
| + if err != nil || id != "inst-1" || key.Role != RoleInstance { |
| + t.Fatalf("Verify = (%q, %q, %v), want (inst-1, instance, nil)", id, key.Role, err) |
| + } |
| + return |
| + } |
| + if !errors.Is(err, c.want) { |
| + t.Fatalf("Verify after changing the %s = %v, want %v", c.name, err, c.want) |
| + } |
| + if id != "" || key.Public != nil { |
| + t.Fatalf("Verify refused but returned identity (%q, %v)", id, key) |
| + } |
| + if n := f.nonces.count(); n != 0 { |
| + t.Fatalf("Remember called %d times for a refused request, want 0", n) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestSkewRefused(t *testing.T) { |
| + cases := []struct { |
| + offset time.Duration |
| + want error |
| + }{ |
| + {0, nil}, |
| + {-MaxSkew, nil}, |
| + {MaxSkew, nil}, |
| + {-MaxSkew - time.Second, ErrSkew}, |
| + {MaxSkew + time.Second, ErrSkew}, |
| + {-24 * time.Hour, ErrSkew}, |
| + {24 * time.Hour, ErrSkew}, |
| + } |
| + for _, c := range cases { |
| + f := newFixture() |
| + r := f.signed(t, "GET", "/v1/jobs/a1", nil, "inst-1", f.inst, f.now.Add(c.offset), nonceA) |
| + _, _, err := f.v.Verify(r, nil) |
| + if !errors.Is(err, c.want) || (c.want == nil) != (err == nil) { |
| + t.Fatalf("Verify with the clock %v off = %v, want %v", c.offset, err, c.want) |
| + } |
| + if c.want != nil && f.nonces.count() != 0 { |
| + t.Fatalf("Remember called for a request %v off", c.offset) |
| + } |
| + } |
| + |
| + // A timestamp at the edge of int64 is refused as skew, not wrapped round. |
| + f := newFixture() |
| + r := f.signed(t, "GET", "/v1/jobs/a1", nil, "inst-1", f.inst, f.now, nonceA) |
| + r.Header.Set(HeaderTimestamp, "9223372036854775807") |
| + if _, _, err := f.v.Verify(r, nil); !errors.Is(err, ErrSkew) { |
| + t.Fatalf("Verify with the largest timestamp = %v, want ErrSkew", err) |
| + } |
| +} |
| + |
| +func TestNonceReplayRefused(t *testing.T) { |
| + f := newFixture() |
| + body := []byte(`{"generation":3}`) |
| + r := f.signed(t, "POST", "/v1/jobs/a1/suspend", body, "inst-1", f.inst, f.now, nonceA) |
| + if _, _, err := f.v.Verify(r, body); err != nil { |
| + t.Fatalf("first Verify = %v, want nil", err) |
| + } |
| + firstNow, firstUntil := f.now, f.nonces.lastUntil |
| + |
| + f.now = f.now.Add(30 * time.Second) |
| + again := f.signed(t, "POST", "/v1/jobs/a1/suspend", body, "inst-1", f.inst, firstNow, nonceA) |
| + id, _, err := f.v.Verify(again, body) |
| + if !errors.Is(err, ErrReplay) || id != "" { |
| + t.Fatalf("replayed Verify = (%q, %v), want ErrReplay", id, err) |
| + } |
| + |
| + if want := firstNow.Add(NonceTTL); !firstUntil.Equal(want) { |
| + t.Fatalf("Remember until = %v, want %v", firstUntil, want) |
| + } |
| + // The nonce must outlive every timestamp that could still pass the skew check. |
| + if NonceTTL <= 2*MaxSkew { |
| + t.Fatalf("NonceTTL %v does not outlive the skew window %v", NonceTTL, 2*MaxSkew) |
| + } |
| +} |
| + |
| +func TestNonceStoreErrorDenies(t *testing.T) { |
| + f := newFixture() |
| + storeErr := errors.New("disk full") |
| + f.nonces.err = storeErr |
| + r := f.signed(t, "GET", "/v1/jobs/a1", nil, "inst-1", f.inst, f.now, nonceA) |
| + id, key, err := f.v.Verify(r, nil) |
| + if !errors.Is(err, ErrNonceStore) || !errors.Is(err, storeErr) || id != "" || key.Public != nil { |
| + t.Fatalf("Verify with a failing nonce store = (%q, %v), want ErrNonceStore wrapping the store error", id, err) |
| + } |
| + |
| + for _, broken := range []func(v *Verifier){ |
| + func(v *Verifier) { v.Nonces = nil }, |
| + func(v *Verifier) { v.Now = nil }, |
| + func(v *Verifier) { v.Keys = nil }, |
| + } { |
| + f := newFixture() |
| + broken(f.v) |
| + r := f.signed(t, "GET", "/v1/jobs/a1", nil, "inst-1", f.inst, f.now, nonceA) |
| + if _, _, err := f.v.Verify(r, nil); err == nil { |
| + t.Fatalf("Verify with an incomplete Verifier = nil, want a refusal") |
| + } |
| + } |
| +} |
| + |
| +func TestResponseBoundToRequestNonce(t *testing.T) { |
| + f := newFixture() |
| + body := []byte(`{"epoch":2}`) |
| + h := http.Header{} |
| + SignResponse(h, http.StatusOK, nonceA, body, f.ctl) |
| + resp := func(status int, h http.Header) *http.Response { |
| + return &http.Response{StatusCode: status, Header: h} |
| + } |
| + if err := VerifyResponse(resp(200, h), body, nonceA, pub(f.ctl)); err != nil { |
| + t.Fatalf("VerifyResponse = %v, want nil", err) |
| + } |
| + |
| + dup := h.Clone() |
| + dup.Add(HeaderSignature, h.Get(HeaderSignature)) |
| + lower := h.Clone() |
| + lower["equipo-signature"] = []string{h.Get(HeaderSignature)} |
| + badB64 := http.Header{HeaderSignature: {"!!!"}} |
| + short := http.Header{HeaderSignature: {base64.StdEncoding.EncodeToString(make([]byte, 63))}} |
| + |
| + cases := []struct { |
| + name string |
| + resp *http.Response |
| + body []byte |
| + nonce string |
| + pub ed25519.PublicKey |
| + want error |
| + }{ |
| + {"another request's nonce", resp(200, h), body, nonceB, pub(f.ctl), ErrBadSignature}, |
| + {"status", resp(201, h), body, nonceA, pub(f.ctl), ErrBadSignature}, |
| + {"body", resp(200, h), []byte(`{"epoch":3}`), nonceA, pub(f.ctl), ErrBadSignature}, |
| + {"another key", resp(200, h), body, nonceA, pub(f.inst), ErrBadSignature}, |
| + {"missing signature", resp(200, http.Header{}), body, nonceA, pub(f.ctl), ErrUnsigned}, |
| + {"duplicate signature", resp(200, dup), body, nonceA, pub(f.ctl), ErrMalformed}, |
| + {"duplicate in another case", resp(200, lower), body, nonceA, pub(f.ctl), ErrMalformed}, |
| + {"bad base64", resp(200, badB64), body, nonceA, pub(f.ctl), ErrMalformed}, |
| + {"short signature", resp(200, short), body, nonceA, pub(f.ctl), ErrMalformed}, |
| + {"empty request nonce", resp(200, h), body, "", pub(f.ctl), ErrMalformed}, |
| + {"no controller key", resp(200, h), body, nonceA, nil, ErrNotConfigured}, |
| + {"no response", nil, body, nonceA, pub(f.ctl), ErrUnsigned}, |
| + } |
| + for _, c := range cases { |
| + if err := VerifyResponse(c.resp, c.body, c.nonce, c.pub); !errors.Is(err, c.want) { |
| + t.Fatalf("VerifyResponse with a changed %s = %v, want %v", c.name, err, c.want) |
| + } |
| + } |
| +} |
| + |
| +func TestOversizeBodyRefused(t *testing.T) { |
| + f := newFixture() |
| + big := bytes.Repeat([]byte("a"), MaxBody+1) |
| + r := httptest.NewRequest("POST", "http://controller.test/v1/jobs", nil) |
| + if err := SignRequest(r, big, "inst-1", f.inst, f.now, nonceA); !errors.Is(err, ErrTooLarge) { |
| + t.Fatalf("SignRequest of %d bytes = %v, want ErrTooLarge", len(big), err) |
| + } |
| + |
| + // A peer that signs an oversize body anyway is still refused. |
| + forge := func(body []byte, nonce string) *http.Request { |
| + r := httptest.NewRequest("POST", "http://controller.test/v1/jobs", nil) |
| + ts := f.now.Unix() |
| + r.Header.Set(HeaderKeyID, "inst-1") |
| + r.Header.Set(HeaderTimestamp, strconv.FormatInt(ts, 10)) |
| + r.Header.Set(HeaderNonce, nonce) |
| + sig := ed25519.Sign(f.inst, requestMessage("POST", "/v1/jobs", ts, nonce, body)) |
| + r.Header.Set(HeaderSignature, base64.StdEncoding.EncodeToString(sig)) |
| + return r |
| + } |
| + if _, _, err := f.v.Verify(forge(big, nonceA), big); !errors.Is(err, ErrTooLarge) { |
| + t.Fatalf("Verify of %d signed bytes = %v, want ErrTooLarge", len(big), err) |
| + } |
| + if n := f.nonces.count(); n != 0 { |
| + t.Fatalf("Remember called %d times for an oversize body, want 0", n) |
| + } |
| + limit := big[:MaxBody] |
| + if _, _, err := f.v.Verify(forge(limit, nonceB), limit); err != nil { |
| + t.Fatalf("Verify of exactly MaxBody bytes = %v, want nil", err) |
| + } |
| + |
| + h := http.Header{} |
| + SignResponse(h, 200, nonceA, big, f.ctl) |
| + if err := VerifyResponse(&http.Response{StatusCode: 200, Header: h}, big, nonceA, pub(f.ctl)); !errors.Is(err, ErrTooLarge) { |
| + t.Fatalf("VerifyResponse of %d bytes = %v, want ErrTooLarge", len(big), err) |
| + } |
| +} |
| + |
| +func TestRequestHeadersStrict(t *testing.T) { |
| + cases := []struct { |
| + name string |
| + mutate func(f *fixture, h http.Header) |
| + want error |
| + }{ |
| + {"key id missing", func(_ *fixture, h http.Header) { h.Del(HeaderKeyID) }, ErrUnsigned}, |
| + {"timestamp missing", func(_ *fixture, h http.Header) { h.Del(HeaderTimestamp) }, ErrUnsigned}, |
| + {"nonce missing", func(_ *fixture, h http.Header) { h.Del(HeaderNonce) }, ErrUnsigned}, |
| + {"signature missing", func(_ *fixture, h http.Header) { h.Del(HeaderSignature) }, ErrUnsigned}, |
| + {"key id twice", func(_ *fixture, h http.Header) { h.Add(HeaderKeyID, h.Get(HeaderKeyID)) }, ErrMalformed}, |
| + {"timestamp twice", func(_ *fixture, h http.Header) { h.Add(HeaderTimestamp, h.Get(HeaderTimestamp)) }, ErrMalformed}, |
| + {"nonce twice", func(_ *fixture, h http.Header) { h.Add(HeaderNonce, nonceB) }, ErrMalformed}, |
| + {"signature twice", func(_ *fixture, h http.Header) { h.Add(HeaderSignature, h.Get(HeaderSignature)) }, ErrMalformed}, |
| + {"nonce twice in another case", func(_ *fixture, h http.Header) { h["equipo-nonce"] = []string{h.Get(HeaderNonce)} }, ErrMalformed}, |
| + {"timestamp with a plus", func(f *fixture, h http.Header) { h.Set(HeaderTimestamp, "+"+strconv.FormatInt(f.now.Unix(), 10)) }, ErrMalformed}, |
| + {"timestamp with a leading zero", func(f *fixture, h http.Header) { h.Set(HeaderTimestamp, "0"+strconv.FormatInt(f.now.Unix(), 10)) }, ErrMalformed}, |
| + {"timestamp negative", func(_ *fixture, h http.Header) { h.Set(HeaderTimestamp, "-5") }, ErrMalformed}, |
| + {"timestamp empty", func(_ *fixture, h http.Header) { h.Set(HeaderTimestamp, "") }, ErrMalformed}, |
| + {"timestamp too big", func(_ *fixture, h http.Header) { h.Set(HeaderTimestamp, "99999999999999999999") }, ErrMalformed}, |
| + {"nonce short", func(_ *fixture, h http.Header) { h.Set(HeaderNonce, strings.Repeat("n", 15)) }, ErrMalformed}, |
| + {"nonce long", func(_ *fixture, h http.Header) { h.Set(HeaderNonce, strings.Repeat("n", 65)) }, ErrMalformed}, |
| + {"nonce bad character", func(_ *fixture, h http.Header) { h.Set(HeaderNonce, "nonce-aaaaaaaaaaaa.a") }, ErrMalformed}, |
| + {"signature not base64", func(_ *fixture, h http.Header) { h.Set(HeaderSignature, "not base64!") }, ErrMalformed}, |
| + {"signature unpadded", func(_ *fixture, h http.Header) { |
| + h.Set(HeaderSignature, strings.TrimRight(h.Get(HeaderSignature), "=")) |
| + }, ErrMalformed}, |
| + {"signature short", func(_ *fixture, h http.Header) { |
| + h.Set(HeaderSignature, base64.StdEncoding.EncodeToString(make([]byte, 63))) |
| + }, ErrMalformed}, |
| + {"key id with a space", func(_ *fixture, h http.Header) { h.Set(HeaderKeyID, "inst 1") }, ErrMalformed}, |
| + } |
| + for _, c := range cases { |
| + t.Run(c.name, func(t *testing.T) { |
| + f := newFixture() |
| + r := f.signed(t, "GET", "/v1/jobs/a1", nil, "inst-1", f.inst, f.now, nonceA) |
| + c.mutate(f, r.Header) |
| + if _, _, err := f.v.Verify(r, nil); !errors.Is(err, c.want) { |
| + t.Fatalf("Verify with %s = %v, want %v", c.name, err, c.want) |
| + } |
| + if n := f.nonces.count(); n != 0 { |
| + t.Fatalf("Remember called %d times, want 0", n) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestSharedPublicKeyRefused(t *testing.T) { |
| + f := newFixture() |
| + // The instance key also listed as an operator key would let an instance |
| + // claim the operator role by changing the unsigned key ID header. |
| + f.v.Keys["op-alias"] = VerifyKey{Public: pub(f.inst), Role: RoleOperator} |
| + for _, id := range []KeyID{"op-alias", "inst-1"} { |
| + r := f.signed(t, "GET", "/v1/vms", nil, id, f.inst, f.now, nonceA) |
| + if got, _, err := f.v.Verify(r, nil); !errors.Is(err, ErrSharedKey) { |
| + t.Fatalf("Verify as %s with a shared public key = (%q, %v), want ErrSharedKey", id, got, err) |
| + } |
| + } |
| + |
| + f = newFixture() |
| + f.v.Keys["inst-1"] = VerifyKey{Public: pub(f.inst)[:31], Role: RoleInstance} |
| + r := f.signed(t, "GET", "/v1/jobs/a1", nil, "inst-1", f.inst, f.now, nonceA) |
| + if _, _, err := f.v.Verify(r, nil); !errors.Is(err, ErrNotConfigured) { |
| + t.Fatalf("Verify with a short public key = %v, want ErrNotConfigured", err) |
| + } |
| +} |
| + |
| +func TestSignRequestRefusesBadInput(t *testing.T) { |
| + f := newFixture() |
| + cases := []struct { |
| + name string |
| + id KeyID |
| + key ed25519.PrivateKey |
| + nonce string |
| + url string |
| + want error |
| + }{ |
| + {"bad nonce", "inst-1", f.inst, "short", "http://c.test/v1/vms", ErrMalformed}, |
| + {"bad key id", "inst 1", f.inst, nonceA, "http://c.test/v1/vms", ErrMalformed}, |
| + {"empty key id", "", f.inst, nonceA, "http://c.test/v1/vms", ErrMalformed}, |
| + {"short key", "inst-1", f.inst[:10], nonceA, "http://c.test/v1/vms", ErrNotConfigured}, |
| + {"opaque url", "inst-1", f.inst, nonceA, "mailto:x@example.com", ErrMalformed}, |
| + } |
| + for _, c := range cases { |
| + r, err := http.NewRequest("GET", c.url, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := SignRequest(r, nil, c.id, c.key, f.now, c.nonce); !errors.Is(err, c.want) { |
| + t.Fatalf("SignRequest with %s = %v, want %v", c.name, err, c.want) |
| + } |
| + if r.Header.Get(HeaderSignature) != "" { |
| + t.Fatalf("SignRequest with %s set a signature", c.name) |
| + } |
| + } |
| +} |
| + |
| +func TestNewNonce(t *testing.T) { |
| + seen := map[string]bool{} |
| + for range 100 { |
| + n, err := NewNonce() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !validNonce(n) { |
| + t.Fatalf("NewNonce = %q, not a valid nonce", n) |
| + } |
| + if seen[n] { |
| + t.Fatalf("NewNonce repeated %q", n) |
| + } |
| + seen[n] = true |
| + } |
| +} |
diff --git a/internal/hostedwire/verify.go b/internal/hostedwire/verify.go| new file mode 100644 |
| index 00000000..71c52423 |
| --- /dev/null |
| +++ b/internal/hostedwire/verify.go |
| @@ -0,0 +1,207 @@ |
| +package hostedwire |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "crypto/ed25519" |
| + "encoding/base64" |
| + "errors" |
| + "fmt" |
| + "net/http" |
| + "strconv" |
| + "strings" |
| + "time" |
| +) |
| + |
| +// One sentinel per kind of refusal, so the controller can count them. Error |
| +// texts never hold key material or a body. |
| +var ( |
| + ErrUnsigned = errors.New("hostedwire: signature header missing") |
| + ErrMalformed = errors.New("hostedwire: signature header malformed or repeated") |
| + ErrUnknownKey = errors.New("hostedwire: unknown key ID") |
| + ErrSharedKey = errors.New("hostedwire: public key listed under more than one key ID") |
| + ErrSkew = errors.New("hostedwire: timestamp outside the allowed skew") |
| + ErrTooLarge = errors.New("hostedwire: body too large") |
| + ErrBadSignature = errors.New("hostedwire: bad signature") |
| + ErrReplay = errors.New("hostedwire: nonce already used") |
| + ErrNonceStore = errors.New("hostedwire: nonce store failed") |
| + ErrNotConfigured = errors.New("hostedwire: verifier not configured") |
| +) |
| + |
| +// NonceStore remembers nonces per key. Remember records (id, nonce) until |
| +// the given time and reports true when it was not already held. It must be |
| +// atomic: of two concurrent calls with the same pair, at most one gets true. |
| +type NonceStore interface { |
| + Remember(ctx context.Context, id KeyID, nonce string, until time.Time) (bool, error) |
| +} |
| + |
| +// Verifier checks signed requests. All three fields are required. Now is the |
| +// controller's clock. |
| +type Verifier struct { |
| + Keys map[KeyID]VerifyKey |
| + Nonces NonceStore |
| + Now func() time.Time |
| +} |
| + |
| +// Verify checks r's signature headers against body, the exact bytes read |
| +// from r.Body, and returns the signer. In order it: parses the headers |
| +// strictly, looks up the key, checks the skew against v.Now, checks the body |
| +// size, verifies the signature, and only then records the nonce with |
| +// Remember(r.Context(), id, nonce, now+NonceTTL). A nonce already held is a |
| +// replay; a store error denies. |
| +func (v *Verifier) Verify(r *http.Request, body []byte) (KeyID, VerifyKey, error) { |
| + if v == nil || v.Keys == nil || v.Nonces == nil || v.Now == nil { |
| + return "", VerifyKey{}, ErrNotConfigured |
| + } |
| + h, err := parseRequestHeaders(r.Header) |
| + if err != nil { |
| + return "", VerifyKey{}, err |
| + } |
| + key, err := v.lookup(h.id) |
| + if err != nil { |
| + return "", VerifyKey{}, err |
| + } |
| + now := v.Now() |
| + // A timestamp near the top of int64 wraps inside time.Unix to a date |
| + // far in the past, which the skew check refuses (TestSkewRefused). |
| + sent := time.Unix(h.ts, 0) |
| + if now.Sub(sent) > MaxSkew || sent.Sub(now) > MaxSkew { |
| + return "", VerifyKey{}, ErrSkew |
| + } |
| + if len(body) > MaxBody { |
| + return "", VerifyKey{}, ErrTooLarge |
| + } |
| + target, err := requestTarget(r) |
| + if err != nil { |
| + return "", VerifyKey{}, err |
| + } |
| + if !ed25519.Verify(key.Public, requestMessage(r.Method, target, h.ts, h.nonce, body), h.sig) { |
| + return "", VerifyKey{}, ErrBadSignature |
| + } |
| + fresh, err := v.Nonces.Remember(r.Context(), h.id, h.nonce, now.Add(NonceTTL)) |
| + if err != nil { |
| + return "", VerifyKey{}, fmt.Errorf("%w: %w", ErrNonceStore, err) |
| + } |
| + if !fresh { |
| + return "", VerifyKey{}, ErrReplay |
| + } |
| + return h.id, VerifyKey{Public: bytes.Clone(key.Public), Role: key.Role}, nil |
| +} |
| + |
| +// lookup finds id's key and refuses a table where its public key is also |
| +// listed under another ID: the key ID is not signed, so a shared public key |
| +// would let its holder pick either ID and that ID's role. |
| +func (v *Verifier) lookup(id KeyID) (VerifyKey, error) { |
| + key, ok := v.Keys[id] |
| + if !ok { |
| + return VerifyKey{}, ErrUnknownKey |
| + } |
| + if len(key.Public) != ed25519.PublicKeySize { |
| + return VerifyKey{}, fmt.Errorf("%w: public key for a key ID has the wrong length", ErrNotConfigured) |
| + } |
| + for other, k := range v.Keys { |
| + if other != id && bytes.Equal(k.Public, key.Public) { |
| + return VerifyKey{}, ErrSharedKey |
| + } |
| + } |
| + return key, nil |
| +} |
| + |
| +type requestHeaders struct { |
| + id KeyID |
| + ts int64 |
| + nonce string |
| + sig []byte |
| +} |
| + |
| +func parseRequestHeaders(h http.Header) (requestHeaders, error) { |
| + var out requestHeaders |
| + id, err := single(h, HeaderKeyID) |
| + if err != nil { |
| + return out, err |
| + } |
| + tsText, err := single(h, HeaderTimestamp) |
| + if err != nil { |
| + return out, err |
| + } |
| + nonce, err := single(h, HeaderNonce) |
| + if err != nil { |
| + return out, err |
| + } |
| + sigText, err := single(h, HeaderSignature) |
| + if err != nil { |
| + return out, err |
| + } |
| + if !validKeyID(id) { |
| + return out, fmt.Errorf("%w: key ID", ErrMalformed) |
| + } |
| + ts, err := strconv.ParseInt(tsText, 10, 64) |
| + if err != nil || ts < 0 || strconv.FormatInt(ts, 10) != tsText { |
| + return out, fmt.Errorf("%w: timestamp", ErrMalformed) |
| + } |
| + if !validNonce(nonce) { |
| + return out, fmt.Errorf("%w: nonce", ErrMalformed) |
| + } |
| + sig, err := parseSignature(sigText) |
| + if err != nil { |
| + return out, err |
| + } |
| + return requestHeaders{id: KeyID(id), ts: ts, nonce: nonce, sig: sig}, nil |
| +} |
| + |
| +func parseSignature(text string) ([]byte, error) { |
| + sig, err := base64.StdEncoding.Strict().DecodeString(text) |
| + if err != nil || len(sig) != ed25519.SignatureSize { |
| + return nil, fmt.Errorf("%w: signature", ErrMalformed) |
| + } |
| + return sig, nil |
| +} |
| + |
| +// single returns the one value of the header name, matching keys without |
| +// regard to case so a second copy under a non-canonical key still counts. |
| +func single(h http.Header, name string) (string, error) { |
| + var vals []string |
| + for k, v := range h { |
| + if strings.EqualFold(k, name) { |
| + vals = append(vals, v...) |
| + } |
| + } |
| + switch len(vals) { |
| + case 0: |
| + return "", fmt.Errorf("%w: %s", ErrUnsigned, name) |
| + case 1: |
| + return vals[0], nil |
| + default: |
| + return "", fmt.Errorf("%w: %s repeated", ErrMalformed, name) |
| + } |
| +} |
| + |
| +// VerifyResponse checks that resp, with body (the exact bytes read from |
| +// resp.Body), was signed by pub as the answer to the request whose nonce was |
| +// requestNonce. |
| +func VerifyResponse(resp *http.Response, body []byte, requestNonce string, pub ed25519.PublicKey) error { |
| + if len(pub) != ed25519.PublicKeySize { |
| + return fmt.Errorf("%w: controller key has the wrong length", ErrNotConfigured) |
| + } |
| + if !validNonce(requestNonce) { |
| + return fmt.Errorf("%w: request nonce", ErrMalformed) |
| + } |
| + if resp == nil { |
| + return ErrUnsigned |
| + } |
| + text, err := single(resp.Header, HeaderSignature) |
| + if err != nil { |
| + return err |
| + } |
| + sig, err := parseSignature(text) |
| + if err != nil { |
| + return err |
| + } |
| + if len(body) > MaxBody { |
| + return ErrTooLarge |
| + } |
| + if !ed25519.Verify(pub, responseMessage(resp.StatusCode, requestNonce, body), sig) { |
| + return ErrBadSignature |
| + } |
| + return nil |
| +} |