carlos / platform Public

demo: claim links carry their own claim code, not the update bearer

POST /api/demo/apps now mints a separate claim code and stores only its
hash (demo_apps.claim_code_hash, claim_code_minted). claimUrl's fragment
is the claim code; claimToken stays the update bearer, unchanged on the
wire. An agent can hand over the claim link without reading the bearer.

Claim start takes the code as claimCode (or claimToken, exactly one) and
the browser claim intent takes it from the fragment. Both refuse the
update bearer; the update endpoint refuses the claim code. Demos created
before this release (claim_code_minted=0) still claim with their bearer
until they expire. The code is spent with the bearer at claim commit,
expiry and takedown, and only works while the bearer is live.
demo_spent_tokens.kind keeps each door's refusal reasons to its own
credential. The migration adds three columns and a partial unique index.

Astra: round 1 NOT READY (test fixed; rollback P1 declined, see
discussion 1334), round 2 READY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from demo-claim-code into main.
claude agent, operated by paul@keymail.dev d3266e8e6fbbad5367453a9d75ed016182b84a84 parent 343a339
20 files changed, +545 −97
  • internal/console/apidemo.go +11 −2
  • internal/console/apidemo_test.go +1 −1
  • internal/console/demo_api_origin_test.go +6 −1
  • internal/console/demo_claim_auth.go +14 −3
  • internal/console/demo_claim_auth_test.go +13 −4
  • internal/console/demo_claim_caps_test.go +2 −2
  • internal/console/demo_claim_choice_test.go +1 −1
  • internal/console/demo_claim_code_test.go +267 −0
  • internal/console/demo_claim_e2e_test.go +4 −4
  • internal/console/demo_claim_kept_test.go +1 −1
  • internal/console/demo_claim_page.go +3 −1
  • internal/console/demo_claim_page_test.go +1 −1
  • internal/console/demo_claim_resume_test.go +2 −2
  • internal/console/demo_claim_target_test.go +6 −6
  • internal/console/demo_claim_transfer.go +3 −2
  • internal/console/demo_expiry.go +6 −2
  • internal/console/demo_jobs_test.go +12 −4
  • internal/console/demo_spent_token_test.go +93 −45
  • internal/console/demo_store.go +91 −11
  • internal/console/demo_store_test.go +8 −4

CI cancelled — superseded by a newer push — run details

CI log
=== gate ===
go: downloading go1.26.10 (linux/arm64)
go version go1.26.10 linux/arm64
opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1
  tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz
  tofu: downloaded, digest verified
  aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip
  aws: downloaded, digest verified
  archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip
  archive: downloaded, digest verified
  installed in /tmp/carlos-opentofu-F8AzS8
.amadan/test-gate.sh
go: downloading github.com/aws/aws-sdk-go-v2 v1.44.0
go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0
go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5
go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0
go: downloading github.com/aws/smithy-go v1.28.1
go: downloading github.com/benbjohnson/litestream v0.5.14
go: downloading github.com/superfly/ltx v0.5.1
go: downloading golang.org/x/net v0.62.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading golang.org/x/sys v0.49.0
go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0
go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2
go: downloading github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.37.0
go: downloading golang.org/x/crypto v0.58.0
go: downloading github.com/pion/logging v0.2.4
go: downloading github.com/pion/stun/v3 v3.1.5
go: downloading github.com/pion/turn/v4 v4.1.4
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/pion/transport/v4 v4.0.2
go: downloading github.com/pion/dtls/v3 v3.1.4
go: downloading github.com/pion/randutil v0.1.0
go: downloading github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.23
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.31
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading golang.org/x/sync v0.24.0
go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18
go: downloading github.com/prometheus/client_golang v1.17.0
go: downloading github.com/lmittmann/tint v1.1.3
go: downloading github.com/cespare/xxhash/v2 v2.3.0
go: downloading github.com/prometheus/common v0.45.0
go: downloading google.golang.org/protobuf v1.36.10
go: downloading github.com/prometheus/procfs v0.12.0
go: downloading golang.org/x/text v0.43.0
go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
go: downloading github.com/klauspost/compress v1.20.2
go: downloading modernc.org/sqlite v1.55.0
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/memory v1.11.0
go: downloading github.com/google/uuid v1.6.0
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading modernc.org/mathutil v1.7.1
go: downloading modernc.org/memory v1.11.0
go: downloading github.com/google/uuid v1.6.0
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading modernc.org/mathutil v1.7.1
=== launchctx (4 s, from +0 s)
ok  	amadan.net/carlos/platform.git/launchctx	0.015s
?   	amadan.net/carlos/platform.git/launchctx/controlname	[no test files]
?   	amadan.net/carlos/platform.git/launchctx/wireid	[no test files]
=== vet (168 s, from +0 s)
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading modernc.org/libc v1.74.1
=== vet-tags (176 s, from +0 s)
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading modernc.org/libc v1.74.1
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/google/uuid v1.6.0
=== gofmt (1 s, from +0 s)
gofmt -l .: clean
=== rest (371 s, from +14 s)
ok  	github.com/carlosframework/platform/cmd/carlos-media	128.191s
?   	github.com/carlosframework/platform/cmd/changelog	[no test files]
ok  	github.com/carlosframework/platform/cmd/console	201.037s
ok  	github.com/carlosframework/platform/cmd/mediaimage	42.476s
ok  	github.com/carlosframework/platform/cmd/moveprobe	16.480s
ok  	github.com/carlosframework/platform/cmd/pricebook-export	0.023s
ok  	github.com/carlosframework/platform/cmd/rootfswitness	0.183s
ok  	github.com/carlosframework/platform/cmd/runsc-assets	0.176s
ok  	github.com/carlosframework/platform/cmd/zddprobe	1.001s
ok  	github.com/carlosframework/platform/internal/agentsock	0.052s
ok  	github.com/carlosframework/platform/internal/alerting	0.023s
ok  	github.com/carlosframework/platform/internal/analytics	0.341s
ok  	github.com/carlosframework/platform/internal/appconfig	43.886s
ok  	github.com/carlosframework/platform/internal/apperr	0.398s
ok  	github.com/carlosframework/platform/internal/applog	0.501s
ok  	github.com/carlosframework/platform/internal/apppolicy	3.119s
ok  	github.com/carlosframework/platform/internal/assetcache	0.569s
ok  	github.com/carlosframework/platform/internal/awsinv	0.013s
ok  	github.com/carlosframework/platform/internal/awsmanaged	0.470s
ok  	github.com/carlosframework/platform/internal/awsregiongroup	0.881s
ok  	github.com/carlosframework/platform/internal/awsterminations	0.026s
ok  	github.com/carlosframework/platform/internal/backupswords	0.011s
ok  	github.com/carlosframework/platform/internal/billing	0.076s
ok  	github.com/carlosframework/platform/internal/billing/billingtest	0.083s
ok  	github.com/carlosframework/platform/internal/billingstripe	2.121s
ok  	github.com/carlosframework/platform/internal/boxchoice	0.056s
ok  	github.com/carlosframework/platform/internal/boxid	2.226s
?   	github.com/carlosframework/platform/internal/boxid/boxidtest	[no test files]
?   	github.com/carlosframework/platform/internal/boxid/internal/signtest	[no test files]
ok  	github.com/carlosframework/platform/internal/boxroles	0.013s
ok  	github.com/carlosframework/platform/internal/boxself	0.333s
ok  	github.com/carlosframework/platform/internal/boxvolumes	0.052s
ok  	github.com/carlosframework/platform/internal/caps	0.161s
ok  	github.com/carlosframework/platform/internal/certwarm	0.017s
ok  	github.com/carlosframework/platform/internal/cgroup	1.502s
ok  	github.com/carlosframework/platform/internal/changelog	5.242s
ok  	github.com/carlosframework/platform/internal/clamd	0.113s
?   	github.com/carlosframework/platform/internal/cliflag	[no test files]
ok  	github.com/carlosframework/platform/internal/clireg	0.024s
ok  	github.com/carlosframework/platform/internal/codehealth	18.128s
ok  	github.com/carlosframework/platform/internal/compute	0.010s
?   	github.com/carlosframework/platform/internal/controlname	[no test files]
?   	github.com/carlosframework/platform/internal/controlsock	[no test files]
ok  	github.com/carlosframework/platform/internal/dbdoor	10.986s
ok  	github.com/carlosframework/platform/internal/dbdoor/dbdoortest	0.036s
ok  	github.com/carlosframework/platform/internal/dbquery	0.022s
ok  	github.com/carlosframework/platform/internal/dbreads	3.032s
?   	github.com/carlosframework/platform/internal/dbreads/dbreadstest	[no test files]
ok  	github.com/carlosframework/platform/internal/dbverify	0.036s
ok  	github.com/carlosframework/platform/internal/demo	0.012s
ok  	github.com/carlosframework/platform/internal/demobuild	2.909s
ok  	github.com/carlosframework/platform/internal/democlaim	0.392s
ok  	github.com/carlosframework/platform/internal/devbox	19.109s
ok  	github.com/carlosframework/platform/internal/dnsrec	0.012s
ok  	github.com/carlosframework/platform/internal/docsite	0.106s
ok  	github.com/carlosframework/platform/internal/domainreg	0.043s
ok  	github.com/carlosframework/platform/internal/domains	66.846s
ok  	github.com/carlosframework/platform/internal/doorkey	0.024s
ok  	github.com/carlosframework/platform/internal/economics	0.028s
ok  	github.com/carlosframework/platform/internal/edgefence	0.135s
ok  	github.com/carlosframework/platform/internal/edgeguard	0.472s
?   	github.com/carlosframework/platform/internal/edgeproof	[no test files]
ok  	github.com/carlosframework/platform/internal/edgesfile	0.065s
ok  	github.com/carlosframework/platform/internal/egressaddr	0.016s
ok  	github.com/carlosframework/platform/internal/execsandbox	94.921s
ok  	github.com/carlosframework/platform/internal/fileacl	0.011s
ok  	github.com/carlosframework/platform/internal/fleetapi	2.028s
ok  	github.com/carlosframework/platform/internal/fleetstore	0.010s
ok  	github.com/carlosframework/platform/internal/fxrate	0.038s
ok  	github.com/carlosframework/platform/internal/gate	6.780s
ok  	github.com/carlosframework/platform/internal/genselect	0.150s
ok  	github.com/carlosframework/platform/internal/geo	0.051s
ok  	github.com/carlosframework/platform/internal/geoip	0.132s
ok  	github.com/carlosframework/platform/internal/groupadmission	0.010s
ok  	github.com/carlosframework/platform/internal/grouprollaws	17.463s
ok  	github.com/carlosframework/platform/internal/hadeparture	0.010s
ok  	github.com/carlosframework/platform/internal/hafresh	0.006s
ok  	github.com/carlosframework/platform/internal/hairpin	0.288s
ok  	github.com/carlosframework/platform/internal/historyreadback	1.038s
ok  	github.com/carlosframework/platform/internal/hostactors	23.764s
ok  	github.com/carlosframework/platform/internal/hostbox	22.908s
ok  	github.com/carlosframework/platform/internal/hostclaim	3.487s
ok  	github.com/carlosframework/platform/internal/hostenv	0.022s
ok  	github.com/carlosframework/platform/internal/hostevidence	0.036s
ok  	github.com/carlosframework/platform/internal/hostexec	23.357s
ok  	github.com/carlosframework/platform/internal/hostfence	0.237s
ok  	github.com/carlosframework/platform/internal/hostfiles	28.345s
ok  	github.com/carlosframework/platform/internal/hostfloor	0.065s
ok  	github.com/carlosframework/platform/internal/hostguard	1.856s
ok  	github.com/carlosframework/platform/internal/hostops	8.140s
?   	github.com/carlosframework/platform/internal/hostops/fencerelease	[no test files]
ok  	github.com/carlosframework/platform/internal/hostops/internal/fencerelease	0.021s
ok  	github.com/carlosframework/platform/internal/hostquarantine	0.017s
ok  	github.com/carlosframework/platform/internal/hostrelocate	2.760s
ok  	github.com/carlosframework/platform/internal/hostresolve	0.927s
ok  	github.com/carlosframework/platform/internal/hostwrite	0.018s
ok  	github.com/carlosframework/platform/internal/infraview	0.005s
ok  	github.com/carlosframework/platform/internal/ingresshealth	0.008s
ok  	github.com/carlosframework/platform/internal/ingresshealth/awstg	0.009s
ok  	github.com/carlosframework/platform/internal/instancectl	56.039s
ok  	github.com/carlosframework/platform/internal/instanceexec	9.633s
ok  	github.com/carlosframework/platform/internal/instancefs	0.024s
ok  	github.com/carlosframework/platform/internal/instancekey	0.011s
ok  	github.com/carlosframework/platform/internal/instanceupdates	0.028s
ok  	github.com/carlosframework/platform/internal/interactive	0.705s
ok  	github.com/carlosframework/platform/internal/launchd	0.008s
ok  	github.com/carlosframework/platform/internal/layout	25.809s
ok  	github.com/carlosframework/platform/internal/layout/pubclass	96.592s
ok  	github.com/carlosframework/platform/internal/lbhealth	0.010s
ok  	github.com/carlosframework/platform/internal/lease	148.382s
ok  	github.com/carlosframework/platform/internal/lease/leasetest	1.865s
ok  	github.com/carlosframework/platform/internal/lease/locktest	0.033s
ok  	github.com/carlosframework/platform/internal/ledger	0.079s
ok  	github.com/carlosframework/platform/internal/mail	1.236s
ok  	github.com/carlosframework/platform/internal/mailer	0.852s
ok  	github.com/carlosframework/platform/internal/mailsubmit	1.951s
ok  	github.com/carlosframework/platform/internal/mailwire	0.007s
ok  	github.com/carlosframework/platform/internal/maintenance	0.237s
ok  	github.com/carlosframework/platform/internal/maintenanceexec	8.687s
ok  	github.com/carlosframework/platform/internal/maintenanceguard	0.395s
ok  	github.com/carlosframework/platform/internal/media	1.995s
ok  	github.com/carlosframework/platform/internal/media/mediatest	0.029s
ok  	github.com/carlosframework/platform/internal/mediaaws	63.471s
ok  	github.com/carlosframework/platform/internal/mediahandler	44.184s
ok  	github.com/carlosframework/platform/internal/mediajobs	0.963s
ok  	github.com/carlosframework/platform/internal/medialocal	9.906s
ok  	github.com/carlosframework/platform/internal/metrics	0.133s
ok  	github.com/carlosframework/platform/internal/minorunits	0.006s
ok  	github.com/carlosframework/platform/internal/moves	56.388s
ok  	github.com/carlosframework/platform/internal/moves/archive	3.121s
ok  	github.com/carlosframework/platform/internal/moves/offlinerun	0.127s
ok  	github.com/carlosframework/platform/internal/namedunits	0.060s
ok  	github.com/carlosframework/platform/internal/objstore	0.734s
ok  	github.com/carlosframework/platform/internal/ops	17.884s
ok  	github.com/carlosframework/platform/internal/pageindex	4.055s
ok  	github.com/carlosframework/platform/internal/parity	0.131s
?   	github.com/carlosframework/platform/internal/parity/cmd/parity-doc	[no test files]
ok  	github.com/carlosframework/platform/internal/park	0.930s
ok  	github.com/carlosframework/platform/internal/perf	0.192s
ok  	github.com/carlosframework/platform/internal/plans	0.176s
ok  	github.com/carlosframework/platform/internal/privatefile	0.014s
ok  	github.com/carlosframework/platform/internal/provision	233.974s
ok  	github.com/carlosframework/platform/internal/proxyproto	0.948s
ok  	github.com/carlosframework/platform/internal/publicrelease	0.030s
ok  	github.com/carlosframework/platform/internal/ratelimit	0.233s
ok  	github.com/carlosframework/platform/internal/regionlabel	0.071s
ok  	github.com/carlosframework/platform/internal/regionname	0.024s
ok  	github.com/carlosframework/platform/internal/registrar	0.008s
ok  	github.com/carlosframework/platform/internal/registrar/openprovider	0.262s
?   	github.com/carlosframework/platform/internal/registrar/registrartest	[no test files]
ok  	github.com/carlosframework/platform/internal/registry	84.219s
ok  	github.com/carlosframework/platform/internal/relay	7.750s
ok  	github.com/carlosframework/platform/internal/release	82.353s
ok  	github.com/carlosframework/platform/internal/replicagen	0.010s
ok  	github.com/carlosframework/platform/internal/replicas	0.069s
ok  	github.com/carlosframework/platform/internal/reqrec	8.378s
ok  	github.com/carlosframework/platform/internal/rollout	12.991s
ok  	github.com/carlosframework/platform/internal/rolloutwords	0.026s
ok  	github.com/carlosframework/platform/internal/rootaws	96.288s
ok  	github.com/carlosframework/platform/internal/rootfsimage	0.959s
ok  	github.com/carlosframework/platform/internal/rootparticipation	0.090s
ok  	github.com/carlosframework/platform/internal/rootstate	0.048s
ok  	github.com/carlosframework/platform/internal/runs	1.007s
ok  	github.com/carlosframework/platform/internal/s3compat	0.046s
ok  	github.com/carlosframework/platform/internal/s3fake	1.525s
ok  	github.com/carlosframework/platform/internal/safefile	0.045s
ok  	github.com/carlosframework/platform/internal/schedule	23.200s
ok  	github.com/carlosframework/platform/internal/seeds	0.055s
ok  	github.com/carlosframework/platform/internal/sim/litestreamfacts	4.476s
ok  	github.com/carlosframework/platform/internal/sim/mediajobs	47.175s
ok  	github.com/carlosframework/platform/internal/sim/regionha	23.921s
ok  	github.com/carlosframework/platform/internal/status	0.805s
ok  	github.com/carlosframework/platform/internal/steering	0.233s
ok  	github.com/carlosframework/platform/internal/stopevidence	0.608s
ok  	github.com/carlosframework/platform/internal/storecfg	0.342s
ok  	github.com/carlosframework/platform/internal/svcrole	0.028s
ok  	github.com/carlosframework/platform/internal/systemd	5.814s
?   	github.com/carlosframework/platform/internal/systemdshow	[no test files]
ok  	github.com/carlosframework/platform/internal/team	3.858s
ok  	github.com/carlosframework/platform/internal/teamcontract	0.167s
ok  	github.com/carlosframework/platform/internal/telemetry	0.027s
ok  	github.com/carlosframework/platform/internal/termfence	3.166s
ok  	github.com/carlosframework/platform/internal/timerspec	0.031s
ok  	github.com/carlosframework/platform/internal/tsidentity	4.199s
ok  	github.com/carlosframework/platform/internal/tunnelclient	0.393s
ok  	github.com/carlosframework/platform/internal/unixdial	0.014s
ok  	github.com/carlosframework/platform/internal/updatewords	0.034s
ok  	github.com/carlosframework/platform/internal/upstreamguard	0.017s
?   	github.com/carlosframework/platform/internal/upstreamguard/guardtest	[no test files]
ok  	github.com/carlosframework/platform/internal/usage	0.046s
ok  	github.com/carlosframework/platform/internal/version	0.014s
ok  	github.com/carlosframework/platform/internal/vet	3.138s
ok  	github.com/carlosframework/platform/internal/zonehost	0.016s
ok  	github.com/carlosframework/platform/internal/zonehost/route53zones	0.049s
?   	github.com/carlosframework/platform/internal/zonehost/zonehosttest	[no test files]
?   	github.com/carlosframework/platform/scripts/gitleaks-gate	[no test files]
ok  	github.com/carlosframework/platform/scripts/govulncheck-gate	0.027s
ok  	github.com/carlosframework/platform/scripts/pathmapcheck	0.103s
ok  	github.com/carlosframework/platform/scripts/region-ha-g2/fixture	5.215s
ok  	github.com/carlosframework/platform/scripts/stateless-replicas-drill	1.225s
ok  	github.com/carlosframework/platform/scripts/witness-pointer	0.037s
=== cutover-witness (157 s, from +14 s)
ok  	github.com/carlosframework/platform	2.286s
=== internal_grouproll@0 (273 s, from +74 s)
ok  	github.com/carlosframework/platform/internal/grouproll	271.570s
=== internal_grouproll@1 (275 s, from +74 s)
ok  	github.com/carlosframework/platform/internal/grouproll	273.782s
=== internal_activator@0 (142 s, from +145 s)
ok  	github.com/carlosframework/platform/internal/activator	134.740s
=== internal_activator@1 (135 s, from +145 s)
ok  	github.com/carlosframework/platform/internal/activator	128.019s
=== internal_activator@2 (140 s, from +145 s)
ok  	github.com/carlosframework/platform/internal/activator	132.386s
=== internal_activator@3 (159 s, from +145 s)
ok  	github.com/carlosframework/platform/internal/activator	152.260s
=== root@0 (120 s, from +167 s)
ok  	github.com/carlosframework/platform	109.641s
=== root@1 (108 s, from +167 s)
ok  	github.com/carlosframework/platform	98.904s
=== root@2 (118 s, from +167 s)
ok  	github.com/carlosframework/platform	108.300s
=== root@3 (109 s, from +167 s)
ok  	github.com/carlosframework/platform	99.694s
=== root@4 (97 s, from +167 s)
ok  	github.com/carlosframework/platform	88.260s
=== internal_edge@0 (198 s, from +170 s)
ok  	github.com/carlosframework/platform/internal/edge	187.490s
=== internal_edge@1 (126 s, from +170 s)
ok  	github.com/carlosframework/platform/internal/edge	116.627s
=== internal_edge@2 (213 s, from +170 s)
ok  	github.com/carlosframework/platform/internal/edge	203.634s
=== internal_edge@3 (156 s, from +170 s)
ok  	github.com/carlosframework/platform/internal/edge	147.911s
=== internal_host@0 (130 s, from +210 s)
ok  	github.com/carlosframework/platform/internal/host	125.583s
=== internal_host@1 (143 s, from +210 s)
ok  	github.com/carlosframework/platform/internal/host	138.821s
=== internal_host@2 (278 s, from +210 s)
ok  	github.com/carlosframework/platform/internal/host	273.160s
=== internal_host@3 (193 s, from +210 s)
ok  	github.com/carlosframework/platform/internal/host	188.306s
=== internal_host@4 (207 s, from +210 s)
ok  	github.com/carlosframework/platform/internal/host	202.277s
=== internal_host@5 (200 s, from +210 s)
ok  	github.com/carlosframework/platform/internal/host	195.324s
=== internal_console@0 (185 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	178.206s
=== internal_console@1 (193 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	185.973s
=== internal_console@2 (190 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	184.245s
=== internal_console@3 (243 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	236.664s
=== internal_console@4 (177 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	171.577s
=== internal_console@5 (197 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	191.414s
=== internal_console@6 (197 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	191.584s
=== internal_console@7 (191 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	184.111s
=== internal_console@8 (200 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	193.616s
=== internal_console@9 (201 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	194.842s
=== internal_console@10 (210 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	204.529s
=== internal_console@11 (220 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	213.809s
=== internal_console@12 (271 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	264.541s
=== internal_console@13 (189 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	182.763s
=== internal_console@14 (186 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	179.846s
=== internal_console@15 (236 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	228.781s
=== internal_console@16 (218 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	211.955s
=== internal_console@17 (194 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	188.729s
=== internal_console@18 (197 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	189.623s
=== internal_console@19 (197 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	191.175s
=== internal_console@20 (197 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	190.849s
=== internal_console@21 (216 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	209.679s
=== internal_console@22 (211 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	205.238s
=== internal_console@23 (208 s, from +217 s)
ok  	github.com/carlosframework/platform/internal/console	201.485s
=== lists: internal_console 216 s, internal_edge 169 s, internal_activator 144 s, internal_host 209 s, root 166 s, internal_grouproll 73 s
=== cpu: the gate used 12273 cpu-seconds in 489 s, about 25.1 of 32 cores; the machine as a whole was 84% busy
=== opentofu ===
opentofu: 35 test files in 11 suites, OpenTofu v1.13.9
  initialised in 15 s
  ok      17 s  infra/modules/box-fence-writer/tests/writer.tftest.hcl  Success! 1 passed, 0 failed.
  ok      30 s  infra/modules/deployment-buckets/tests/data_lifecycle.tftest.hcl  Success! 3 passed, 0 failed.
  ok      20 s  infra/modules/deployment-buckets/tests/db_reads.tftest.hcl  Success! 1 passed, 0 failed.
  ok      20 s  infra/modules/deployment-buckets/tests/evidence.tftest.hcl  Success! 1 passed, 0 failed.
  ok      30 s  infra/modules/deployment-buckets/tests/fence_writers.tftest.hcl  Success! 3 passed, 0 failed.
  ok      90 s  infra/modules/media-engine/tests/media_engine.tftest.hcl  Success! 24 passed, 0 failed.
  ok      34 s  infra/modules/pdf-host/tests/computed.tftest.hcl  Success! 2 passed, 0 failed.
  ok      72 s  infra/modules/pdf-host/tests/pdf_host.tftest.hcl  Success! 24 passed, 0 failed.
  ok      45 s  infra/modules/region-group-operator-document/tests/document.tftest.hcl  Success! 12 passed, 0 failed.
  ok      20 s  infra/modules/region-host/ingress/tests/fixed-targets/tests/targets.tftest.hcl  Success! 2 passed, 0 failed.
  ok      70 s  infra/modules/region-host/ingress/tests/group_ingress.tftest.hcl  Success! 30 passed, 0 failed.
  ok      44 s  infra/modules/region-host/tests/alert_publish.tftest.hcl  Success! 18 passed, 0 failed.
  ok      41 s  infra/modules/region-host/tests/alerts_topic.tftest.hcl  Success! 16 passed, 0 failed.
  ok      13 s  infra/modules/region-host/tests/analytics_prune.tftest.hcl  Success! 2 passed, 0 failed.
  ok      17 s  infra/modules/region-host/tests/console_mail.tftest.hcl  Success! 4 passed, 0 failed.
  ok       9 s  infra/modules/region-host/tests/fixed_state_unchanged.tftest.hcl  Success! 1 passed, 0 failed.
  ok      68 s  infra/modules/region-host/tests/group.tftest.hcl  Success! 32 passed, 0 failed.
  ok      11 s  infra/modules/region-host/tests/group_alarms.tftest.hcl  Success! 4 passed, 0 failed.
  ok      11 s  infra/modules/region-host/tests/group_iam.tftest.hcl  Success! 4 passed, 0 failed.
  ok       5 s  infra/modules/region-host/tests/group_isolation.tftest.hcl  Success! 1 passed, 0 failed.
  ok      34 s  infra/modules/region-host/tests/group_operator.tftest.hcl  Success! 13 passed, 0 failed.
  ok      10 s  infra/modules/region-host/tests/group_user_data.tftest.hcl  Success! 3 passed, 0 failed.
  ok      30 s  infra/modules/region-host/tests/health_alarms.tftest.hcl  Success! 10 passed, 0 failed.
  ok      13 s  infra/modules/region-host/tests/ingress_drain_read.tftest.hcl  Success! 4 passed, 0 failed.
  ok       6 s  infra/modules/region-host/tests/instance_metadata.tftest.hcl  Success! 1 passed, 0 failed.
  ok      23 s  infra/modules/region-host/tests/mailer.tftest.hcl  Success! 6 passed, 0 failed.
  ok      12 s  infra/modules/region-host/tests/mailer_group.tftest.hcl  Success! 2 passed, 0 failed.
  ok      14 s  infra/modules/region-host/tests/managed_fleets/group_refusal.tftest.hcl  Success! 2 passed, 0 failed.
  ok     100 s  infra/modules/region-host/tests/managed_fleets/managed_fleets.tftest.hcl  Success! 46 passed, 0 failed.
  ok      73 s  infra/modules/region-host/tests/store_conversion.tftest.hcl  Success! 27 passed, 0 failed.
  ok      15 s  infra/modules/region-host/tests/store_scanning.tftest.hcl  Success! 4 passed, 0 failed.
  ok      16 s  infra/modules/region-host/tests/user_data_ignored.tftest.hcl  Success! 3 passed, 0 failed.
  ok      11 s  infra/modules/region-remote-host/tests/data_lifecycle.tftest.hcl  Success! 3 passed, 0 failed.
  ok      15 s  infra/modules/region-remote-host/tests/no_deployment_bucket.tftest.hcl  Success! 5 passed, 0 failed.
  ok      31 s  infra/modules/scanner-host/tests/scanner_host.tftest.hcl  Success! 14 passed, 0 failed.
opentofu: 35 files in 206 s
opentofu: PASS
=== cross ===
--- shard 0 of 5 ---
go version go1.26.10 linux/arm64
cross-compiling darwin/arm64
--- shard 1 of 5 ---
go version go1.26.10 linux/arm64
cross-compiling darwin/amd64
--- shard 2 of 5 ---
go version go1.26.10 linux/arm64
cross-compiling linux/arm64
linux/arm64 carlos binary: 65667234 bytes (ceiling 70000000)
--- shard 3 of 5 ---
go version go1.26.10 linux/arm64
cross-compiling windows/amd64
--- shard 4 of 5 ---
go version go1.26.10 linux/arm64
cross-compiling windows/arm64
=== minio-contract ===
go version go1.26.10 linux/arm64
minio contract: arm64, minio RELEASE.2025-09-07T16-13-09Z, mc RELEASE.2025-08-13T08-35-41Z
  minio: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/minio/minio.linux-arm64.RELEASE.2025-09-07T16-13-09Z
  minio: downloaded, digest verified
  mc: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/minio/mc.linux-arm64.RELEASE.2025-08-13T08-35-41Z
  mc: downloaded, digest verified
  minio healthy on 127.0.0.1:30117
Added `local` successfully.
Bucket created successfully `local/contract-bucket`.
Bucket created successfully `local/denied-bucket`.
Created policy `contract-only` successfully.
Added user `scopeduser` successfully.
Attached Policies: [contract-only]
To User: scopeduser
  buckets and scoped user ready
=== RUN   TestDeliveredContractMinio
=== RUN   TestDeliveredContractMinio/put
=== RUN   TestDeliveredContractMinio/get_round-trips_the_body
=== RUN   TestDeliveredContractMinio/list_shows_the_key
=== RUN   TestDeliveredContractMinio/head_and_list_agree_on_the_version
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_its_own_object
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/not_by_PutObjectTagging
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/and_not_by_x-amz-tagging_on_upload
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CreateMultipartUpload
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CopyObject_with_a_REPLACE_tagging_directive
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/but_multipart_itself_is_allowed
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_copy_itself_is_allowed
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/a_POST-policy_forged_tag_with_a_matching_version_is_still_not_a_verdict
=== RUN   TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_an_ordinary_tagged-with-something-else_upload_is_allowed
=== RUN   TestDeliveredContractMinio/delete_removes_it
=== RUN   TestDeliveredContractMinio/cross-bucket_denial
--- PASS: TestDeliveredContractMinio (0.03s)
    --- PASS: TestDeliveredContractMinio/put (0.00s)
    --- PASS: TestDeliveredContractMinio/get_round-trips_the_body (0.00s)
    --- PASS: TestDeliveredContractMinio/list_shows_the_key (0.00s)
    --- PASS: TestDeliveredContractMinio/head_and_list_agree_on_the_version (0.00s)
    --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object (0.00s)
        --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/not_by_PutObjectTagging (0.00s)
        --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/and_not_by_x-amz-tagging_on_upload (0.00s)
    --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route (0.02s)
        --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CreateMultipartUpload (0.00s)
        --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CopyObject_with_a_REPLACE_tagging_directive (0.00s)
        --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/but_multipart_itself_is_allowed (0.00s)
        --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_copy_itself_is_allowed (0.00s)
        --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/a_POST-policy_forged_tag_with_a_matching_version_is_still_not_a_verdict (0.00s)
        --- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_an_ordinary_tagged-with-something-else_upload_is_allowed (0.00s)
    --- PASS: TestDeliveredContractMinio/delete_removes_it (0.00s)
    --- PASS: TestDeliveredContractMinio/cross-bucket_denial (0.00s)
PASS
ok  	github.com/carlosframework/platform/internal/objstore	0.039s
=== RUN   TestT4StorageProbeMinio
2026/11/22 11:54:42 moves: T4: STORE: list: operation error S3: ListObjectsV2, https response error StatusCode: 403, RequestID: 18EA5BEECB1176DA, HostID: 80002f7490ada9ae044c9b5521864553aea6a8fa3eab66d61dbd31b1ab7533e5, api error SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
--- PASS: TestT4StorageProbeMinio (0.01s)
PASS
ok  	github.com/carlosframework/platform/internal/host	0.046s
=== RUN   TestS3StoreMinioContract
=== RUN   TestS3StoreMinioContract/conditional_get_and_etag_listing
=== RUN   TestS3StoreMinioContract/bump_through_every_mutation_path
--- PASS: TestS3StoreMinioContract (0.03s)
    --- PASS: TestS3StoreMinioContract/conditional_get_and_etag_listing (0.01s)
    --- PASS: TestS3StoreMinioContract/bump_through_every_mutation_path (0.02s)
PASS
ok  	github.com/carlosframework/platform/internal/release	0.042s
Bucket created successfully `local/analytics-versions`.
local/analytics-versions versioning is enabled
Created policy `analytics-versions` successfully.
Added user `analyticsversions` successfully.
Attached Policies: [analytics-versions]
To User: analyticsversions
=== RUN   TestS3StoreMinioVersions
--- PASS: TestS3StoreMinioVersions (0.03s)
PASS
ok  	github.com/carlosframework/platform/internal/release	0.040s
=== RUN   TestEndToEndMinio
=== RUN   TestEndToEndMinio/plan
=== RUN   TestEndToEndMinio/roll
=== RUN   TestEndToEndMinio/replace
=== RUN   TestEndToEndMinio/remove
--- PASS: TestEndToEndMinio (0.47s)
    --- PASS: TestEndToEndMinio/plan (0.01s)
    --- PASS: TestEndToEndMinio/roll (0.13s)
    --- PASS: TestEndToEndMinio/replace (0.15s)
    --- PASS: TestEndToEndMinio/remove (0.15s)
PASS
ok  	github.com/carlosframework/platform/internal/grouproll	0.478s
Bucket created successfully `local/dbf-deploy`.
Bucket created successfully `local/dbf-data-ie`.
Bucket created successfully `local/dbf-data-uk`.
local/dbf-deploy versioning is enabled
Created policy `dbf-console` successfully.
Created policy `dbf-ukbox` successfully.
Added user `dbfconsole` successfully.
Added user `dbfukbox` successfully.
Attached Policies: [dbf-console]
To User: dbfconsole
Attached Policies: [dbf-ukbox]
To User: dbfukbox
=== RUN   TestDBForwardMinio
2026/11/22 11:54:48 INFO replica sync system=store db=source.db replica=file txid.replica=0000000000000000 txid.db=0000000000000001
2026/11/22 11:54:48 INFO ltx file uploaded system=store db=source.db replica=file level=0 minTXID=0000000000000001 maxTXID=0000000000000001 size=720
2026/11/22 11:54:48 INFO replica sync system=store db=source.db replica=file txid.replica=0000000000000001 txid.db=0000000000000001
2026/11/22 11:54:48 INFO replica sync system=store db=source.db replica=file txid.replica=0000000000000001 txid.db=0000000000000002
2026/11/22 11:54:48 INFO ltx file uploaded system=store db=source.db replica=file level=0 minTXID=0000000000000002 maxTXID=0000000000000002 size=370
2026/11/22 11:54:48 INFO replica sync system=store db=source.db replica=file txid.replica=0000000000000002 txid.db=0000000000000002
2026/11/22 11:54:48 INFO replica sync system=store db=source.db replica=file txid.replica=0000000000000002 txid.db=0000000000000003
2026/11/22 11:54:48 INFO ltx file uploaded system=store db=source.db replica=file level=0 minTXID=0000000000000003 maxTXID=0000000000000003 size=454
2026/11/22 11:54:48 INFO replica sync system=store db=source.db replica=file txid.replica=0000000000000003 txid.db=0000000000000003
2026/11/22 11:54:48 INFO replica sync system=store db=source.db replica=file txid.replica=0000000000000000 txid.db=0000000000000001
2026/11/22 11:54:48 INFO ltx file uploaded system=store db=source.db replica=file level=0 minTXID=0000000000000001 maxTXID=0000000000000001 size=720
2026/11/22 11:54:48 INFO replica sync system=store db=source.db replica=file txid.replica=0000000000000001 txid.db=0000000000000001
2026/11/22 11:54:48 console: CARLOS_SECRETS_PUBKEY is unset, so no region outside the home can be chosen automatically
2026/11/22 11:54:48 console: could not notify member@example.com of a CLI token issue: keymail: lookup member@example.com: keymail: GET /api/federation/lookup?addr=member%40example.com&from=console%40127.0.0.1%3A45969: could not determine target mailbox
    agent.go:136: dbreads: dbr_decl5jgxrzo5bd564xw5hjaz2a: planned 3 files (1544 bytes) and restored to 3 in 14ms
    agent.go:136: dbreads: dbr_decl5jgxrzo5bd564xw5hjaz2a: output 5 bytes in 1 confirmed chunks in 2ms
2026/11/22 11:54:49 console: db read dbr_decl5jgxrzo5bd564xw5hjaz2a: relayed 1 chunks (102 bytes) in 1.005s, ended done
    agent.go:136: dbreads: dbr_bzpbzs252yrwiwn4tfyu2dwjpq: planned 1 files (720 bytes) and restored to 1 in 11ms
    agent.go:136: dbreads: dbr_bzpbzs252yrwiwn4tfyu2dwjpq: output 5 bytes in 1 confirmed chunks in 1ms
2026/11/22 11:54:50 console: db read dbr_bzpbzs252yrwiwn4tfyu2dwjpq: relayed 1 chunks (102 bytes) in 1.005s, ended done
    agent.go:136: dbreads: dbr_rkaplkytruojnibmoso3qzzzja: planned 3 files (1544 bytes) and held through 3 in 12ms
    agent.go:136: dbreads: dbr_rkaplkytruojnibmoso3qzzzja: output 1544 bytes in 1 confirmed chunks in 1ms
2026/11/22 11:54:51 console: db read dbr_rkaplkytruojnibmoso3qzzzja: relayed 1 chunks (1641 bytes) in 1.005s, ended done
=== RUN   TestDBForwardMinio/by_disconnect
=== NAME  TestDBForwardMinio
    agent.go:136: dbreads: dbr_fpyygebs5ik6cmqamben6q3vvu: planned 3 files (1544 bytes) and restored to 3 in 13ms
2026/11/22 11:54:51 console: db read dbr_fpyygebs5ik6cmqamben6q3vvu: relayed 0 chunks (0 bytes) in 17ms, ended client gone
    agent.go:136: dbreads: dbr_fpyygebs5ik6cmqamben6q3vvu: output 5 bytes in 1 confirmed chunks in 105ms
=== RUN   TestDBForwardMinio/by_timeout
=== NAME  TestDBForwardMinio
    agent.go:136: dbreads: dbr_l4z5eflusatrybztntj7ne6ryy: planned 3 files (1544 bytes) and restored to 3 in 15ms
2026/11/22 11:55:12 console: db read dbr_l4z5eflusatrybztntj7ne6ryy: relayed 0 chunks (0 bytes) in 19.893s, ended no-result
    agent.go:136: dbreads: dbr_l4z5eflusatrybztntj7ne6ryy: output 5 bytes in 1 confirmed chunks in 19.865s
--- PASS: TestDBForwardMinio (23.55s)
    --- PASS: TestDBForwardMinio/by_disconnect (0.23s)
    --- PASS: TestDBForwardMinio/by_timeout (20.01s)
PASS
ok  	github.com/carlosframework/platform/internal/console	23.592s
Bucket created successfully `local/media-transfers`.
Bucket created successfully `local/media-transfer-results`.
Created policy `media-transfers` successfully.
Added user `mediatransfers` successfully.
Attached Policies: [media-transfers]
To User: mediatransfers
=== RUN   TestMediaTransfersMinio
    upload.go:117: codec: the store already holds video.mp4
    upload.go:117: codec: the store already holds video.m3u8
    upload.go:117: codec: the store already holds poster.jpg
--- PASS: TestMediaTransfersMinio (0.05s)
PASS
ok  	github.com/carlosframework/platform/internal/mediaaws	0.060s
Bucket created successfully `local/media-local-store`.
Bucket created successfully `local/media-local-results`.
Created policy `media-local` successfully.
Added user `medialocal` successfully.
Attached Policies: [media-local]
To User: medialocal
=== RUN   TestLocalEndToEndMinio
--- PASS: TestLocalEndToEndMinio (0.55s)
PASS
ok  	github.com/carlosframework/platform/internal/medialocal	0.557s
=== RUN   TestHeldHandoverTwoBoxMinio
2026/11/22 11:55:17 edge: mesh key: minted
2026/11/22 11:55:17 provision: minted sidecar route bot0.shop.bac.sidecar.internal (app "shop" acct "bac" args ["work"])
2026/11/22 11:55:17 provision: minted sidecar route bot0.shop.bac.sidecar.internal (app "shop" acct "bac" args ["work"])
2026/11/22 11:55:17 tenant admission is open. accepting tenant work
2026/11/22 11:55:17 activator: HA placement host=shop-02708636.example.test kind=Place ref=annie reason=roomiest generation=2026-11-22T11:55:17Z lock_generation=0
2026/11/22 11:55:17 lease: t8-02708636/shop-02708636.example.test: HA lease acquired in 4ms (first wake)
2026/11/22 11:55:17 activator: shop-02708636.example.test: restored (no-marker): first wake, the prefix proven empty, booting fresh
2026/11/22 11:55:17 activator: shop-02708636.example.test: started carlos-instance@shop\x2d02708636.example.test.service memory.max=536870912 (build 0s, prepare (dirs 0s, admin token 0s, instance key 0s, env 6ms, control socket 0s, key gate 0s, logs 0s) 6ms, launch file 0s, gate 0s, root start 1ms)
2026/11/22 11:55:17 activator: shop-02708636.example.test: carlos-instance@shop\x2d02708636.example.test.service launched in 7ms, healthy 0s later
2026/11/22 11:55:17 activator: shop-02708636.example.test: woke in 22ms: checks 0s, lease 5ms, restore 0s, identity 0s, protect 0s, spawn 8ms, replicate 9ms
2026/11/22 11:55:17 lease: t8-02708636/plain-02708636.example.test: acquired in 1ms (client 0s, lock read and write 1ms)
2026/11/22 11:55:17 activator: no replica for plain-02708636.example.test in s3://contract-bucket/t8-02708636/plain-02708636.example.test — booting fresh
2026/11/22 11:55:17 activator: plain-02708636.example.test: started carlos-instance@plain\x2d02708636.example.test.service memory.max=536870912 (build 0s, prepare (dirs 0s, admin token 1ms, instance key 0s, env 4ms, control socket 0s, key gate 0s, logs 0s) 5ms, launch file 0s, gate 0s, root start 1ms)
2026/11/22 11:55:17 activator: plain-02708636.example.test: carlos-instance@plain\x2d02708636.example.test.service launched in 6ms, healthy 0s later
2026/11/22 11:55:17 activator: plain-02708636.example.test: woke in 42ms: checks 0s, lease 2ms, restore 19ms, identity 0s, protect 0s, spawn 7ms, replicate 15ms
2026/11/22 11:55:17 lease: t8-02708636/bot0.shop.bac.sidecar.internal: HA lease acquired in 5ms (first wake)
2026/11/22 11:55:17 activator: bot0.shop.bac.sidecar.internal: restored (no-marker): first wake, the prefix proven empty, booting fresh
2026/11/22 11:55:17 activator: bot0.shop.bac.sidecar.internal: woke in 21ms: checks 0s, lease 5ms, restore 0s, identity 0s, protect 0s, spawn 7ms, settle 0s, replicate 8ms
2026/11/22 11:55:17 activator: next-due probe plain-02708636.example.test: decode /api/next-due: invalid character 'a' looking for beginning of value — recording none (it sleeps until a request)
2026/11/22 11:55:17 activator: plain-02708636.example.test hibernated
2026/11/22 11:55:17 activator: bot0.shop.bac.sidecar.internal: released with a marker (clean true, txid 1, files 3:f4d36a700d0ba27fcb7331ce2d74c705f6c033a7974d084cb696b58e9f79f8ca) in 8ms: files 1ms, sync 5ms, record 1ms, marker 2ms
2026/11/22 11:55:17 activator: bot0.shop.bac.sidecar.internal hibernated
2026/11/22 11:55:17 activator: next-due probe shop-02708636.example.test: decode /api/next-due: invalid character 'a' looking for beginning of value — recording none (it sleeps until a request)
2026/11/22 11:55:17 activator: shop-02708636.example.test: released with a marker (clean true, txid 1, files 3:91586ea4486a1391dc434df69ae30b5f98385a53d2562e95a7a0624a3bdc9136) in 6ms: files 1ms, sync 3ms, record 1ms, marker 2ms
2026/11/22 11:55:17 activator: shop-02708636.example.test hibernated
2026/11/22 11:55:17 lease: t8-02708636/shop-02708636.example.test: HA lease acquired in 3ms (clean marker)
2026/11/22 11:55:17 activator: shop-02708636.example.test: restored (other-box)
2026/11/22 11:55:17 activator: shop-02708636.example.test: started carlos-instance@shop\x2d02708636.example.test.service memory.max=536870912 (build 0s, prepare (dirs 0s, admin token 0s, instance key 0s, env 1ms, control socket 0s, key gate 0s, logs 0s) 1ms, launch file 0s, gate 0s, root start 1ms)
2026/11/22 11:55:17 activator: shop-02708636.example.test: carlos-instance@shop\x2d02708636.example.test.service launched in 2ms, healthy 0s later
2026/11/22 11:55:17 activator: shop-02708636.example.test: woke in 39ms: checks 0s, lease 4ms, restore 24ms, identity 0s, protect 0s, spawn 2ms, replicate 8ms
2026/11/22 11:55:17 edge: ha-take shop-02708636.example.test from annie (txn t8-witness, marker generation 1): holder betty, generation 2
2026/11/22 11:55:17 edge: forward shop-02708636.example.test: annie handed the request over to betty; sending it there (occurrence #1)
    hadrain_twobox_minio_linux_test.go:1238: drain report: {V:1 Transaction:t8-witness Incarnation:244dad497cb1ad2e814535593261736f Step:move Result:ok Reasons:[] Fence:t8-witness StartedAt:2026-11-22 11:55:17.335666382 +0000 UTC FinishedAt:2026-11-22 11:55:17.483931966 +0000 UTC Acked:[betty carol] Departed:[] Moved:[{Host:shop-02708636.example.test Holder:betty Gen:2 Confirmed:take}] Released:[{Host:plain-02708636.example.test Kind:other Marker:true Clean:true Reason:} {Host:bot0.shop.bac.sidecar.internal Kind:worker Marker:true Clean:true Reason:}] Unclean:[] Left:[] Holds:{LongestMS:100 Todays:0 RefusedAtOnce:1} Closed:0 Quiet:{DrainQuiet:{Waking:0 Stopping:0 Recovering:0 Owed:0} Held:[]}}
    hadrain_twobox_minio_linux_test.go:1239: driver calls: [begin shop-02708636.example.test <nil> stop plain-02708636.example.test marker=true clean=true <nil> stop bot0.shop.bac.sidecar.internal marker=true clean=true <nil> releasing shop-02708636.example.test <nil> stop shop-02708636.example.test marker=true clean=true <nil> taken shop-02708636.example.test betty <nil> end-moves]
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/bot0.shop.bac.sidecar.internal/0001/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/bot0.shop.bac.sidecar.internal/0001/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/bot0.shop.bac.sidecar.internal/0000/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/bot0.shop.bac.sidecar.internal/0002/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/bot0.shop.bac.sidecar.internal/0003/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: PUT /contract-bucket/t8-02708636/bot0.shop.bac.sidecar.internal/0009/0000000000000001-0000000000000001.ltx
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: DELETE /contract-bucket/t8-02708636/plain-02708636.example.test/lock.json
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: PUT /contract-bucket/t8-02708636/bot0.shop.bac.sidecar.internal/lock.json
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: PUT /contract-bucket/t8-02708636/shop-02708636.example.test/0009/0000000000000001-0000000000000001.ltx
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: PUT /contract-bucket/t8-02708636/shop-02708636.example.test/lock.json
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: GET /contract-bucket/t8-02708636/shop-02708636.example.test/lock.json
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: PUT /contract-bucket/t8-02708636/shop-02708636.example.test/lock.json
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: GET /contract-bucket/t8-02708636/shop-02708636.example.test/head.json
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/generations/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0009/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0008/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0007/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0006/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0005/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0004/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0003/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0002/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0001/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0000/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0009/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0008/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0007/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0006/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0005/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0004/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0003/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0002/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0001/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0000/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: GET /contract-bucket/t8-02708636/shop-02708636.example.test/0009/0000000000000001-0000000000000001.ltx
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: GET /contract-bucket/t8-02708636/shop-02708636.example.test/files/0/manifest.json
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: GET /contract-bucket/t8-02708636/shop-02708636.example.test/files/0/objects/0000000000000001-f546590d4cee6a7109907642d5de967a627ac9dbcf0d0b6caa86dc44b31915a3
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: GET /contract-bucket/t8-02708636/shop-02708636.example.test/files/0/objects/0000000000000003-2be1f038b23b0cbc7102fbb1916ce4f284f97c6b03060174ae25977c33d8f2e9
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0000/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: GET /contract-bucket/t8-02708636/shop-02708636.example.test/0000/0000000000000001-0000000000000001.ltx
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0003/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0000/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0002/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: PUT /contract-bucket/t8-02708636/shop-02708636.example.test/0000/0000000000000002-0000000000000002.ltx
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0009/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0009/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0001/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0001/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0002/
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: GET /contract-bucket/t8-02708636/shop-02708636.example.test/lock.json
    hadrain_twobox_minio_linux_test.go:1241: S3 during the drain: LIST /contract-bucket?t8-02708636/shop-02708636.example.test/0003/
    hadrain_twobox_minio_linux_test.go:1243: drain took 194ms; S3 calls 51 (DELETE lock=1 GET files=3 GET head=1 GET lock=2 GET replica=2 LIST replica=36 PUT lock=3 PUT replica=3); deployment store calls 20 (GET edges=14 LIST edges=4 PUT edges=2)
    hadrain_twobox_minio_linux_test.go:1367: the fenced A's start gate answers 503 "This service is unavailable. Try again later.\n" (Retry-After "10")
2026/11/22 11:55:17 lease: t8-02708636/plain-02708636.example.test: acquired in 2ms (client 0s, lock read and write 1ms)
2026/11/22 11:55:17 activator: plain-02708636.example.test: started carlos-instance@plain\x2d02708636.example.test.service memory.max=536870912 (build 0s, prepare (dirs 0s, admin token 0s, instance key 0s, env 0s, control socket 0s, key gate 0s, logs 0s) 0s, launch file 0s, gate 0s, root start 1ms)
2026/11/22 11:55:17 activator: plain-02708636.example.test: carlos-instance@plain\x2d02708636.example.test.service launched in 1ms, healthy 0s later
2026/11/22 11:55:17 lease: /tmp/carlos-minio-contract-Odwc0D/g/dw1073226503/data/instances/plain-02708636.example.test/plain-02708636.example.test.db: continuity with the last clean close not proven; snapshot 1-0000000000000001 written before serving
2026/11/22 11:55:17 activator: plain-02708636.example.test: woke in 8ms: checks 0s, lease 2ms, restore 0s, identity 0s, protect 1ms, spawn 2ms, replicate 4ms
2026/11/22 11:55:17 activator: next-due probe shop-02708636.example.test: decode /api/next-due: invalid character 'b' looking for beginning of value — recording none (it sleeps until a request)
2026/11/22 11:55:17 activator: shop-02708636.example.test: released with a marker (clean true, txid 2, files 3:91586ea4486a1391dc434df69ae30b5f98385a53d2562e95a7a0624a3bdc9136) in 4ms: files 1ms, sync 0s, record 1ms, marker 2ms
2026/11/22 11:55:17 activator: shop-02708636.example.test hibernated
2026/11/22 11:55:17 tenant admission is closed for shutdown
2026/11/22 11:55:17 activator: next-due probe plain-02708636.example.test: decode /api/next-due: invalid character 'a' looking for beginning of value — recording none (it sleeps until a request)
2026/11/22 11:55:17 activator: plain-02708636.example.test hibernated
--- PASS: TestHeldHandoverTwoBoxMinio (0.52s)
=== RUN   TestHeldHandoverLostLeaseMinio
2026/11/22 11:55:17 edge: mesh key: minted
2026/11/22 11:55:17 provision: minted sidecar route bot0.shop.bac.sidecar.internal (app "shop" acct "bac" args ["work"])
2026/11/22 11:55:17 provision: minted sidecar route bot0.shop.bac.sidecar.internal (app "shop" acct "bac" args ["work"])
2026/11/22 11:55:17 tenant admission is open. accepting tenant work
2026/11/22 11:55:17 activator: HA placement host=shop-fcde60c3.example.test kind=Place ref=annie reason=roomiest generation=2026-11-22T11:55:17Z lock_generation=0
2026/11/22 11:55:17 lease: t8-fcde60c3/shop-fcde60c3.example.test: HA lease acquired in 3ms (first wake)
2026/11/22 11:55:17 activator: shop-fcde60c3.example.test: restored (no-marker): first wake, the prefix proven empty, booting fresh
2026/11/22 11:55:17 activator: shop-fcde60c3.example.test: started carlos-instance@shop\x2dfcde60c3.example.test.service memory.max=536870912 (build 0s, prepare (dirs 0s, admin token 0s, instance key 0s, env 5ms, control socket 0s, key gate 0s, logs 0s) 6ms, launch file 0s, gate 0s, root start 1ms)
2026/11/22 11:55:17 activator: shop-fcde60c3.example.test: carlos-instance@shop\x2dfcde60c3.example.test.service launched in 7ms, healthy 0s later
2026/11/22 11:55:17 activator: shop-fcde60c3.example.test: woke in 18ms: checks 0s, lease 4ms, restore 0s, identity 0s, protect 0s, spawn 7ms, replicate 6ms
2026/11/22 11:55:17 activator: next-due probe shop-fcde60c3.example.test: decode /api/next-due: invalid character 'a' looking for beginning of value — recording none (it sleeps until a request)
2026/11/22 11:55:17 activator: final checkpoint shop-fcde60c3.example.test: lease: release marker owed for s3://contract-bucket/t8-fcde60c3/shop-fcde60c3.example.test/lock.json (If-Match "573875c6a8f7cc883325b5e84e09ccd0"): lease: write release marker: operation error S3: PutObject, https response error StatusCode: 503, RequestID: , HostID: , api error ServiceUnavailable: witness: refused
2026/11/22 11:55:17 activator: shop-fcde60c3.example.test hibernated
2026/11/22 11:55:17 activator: handover of shop-fcde60c3.example.test left: released without a marker; its held requests get today's answer
    hadrain_twobox_minio_linux_test.go:1469: the held request's hold ended "shop-fcde60c3.example.test client 4 "
    hadrain_twobox_minio_linux_test.go:1486: driver calls: [begin shop-fcde60c3.example.test <nil> releasing shop-fcde60c3.example.test <nil> stop shop-fcde60c3.example.test marker=false clean=false <nil> left shop-fcde60c3.example.test released without a marker]
    hadrain_twobox_minio_linux_test.go:1487: a request after the loss: 503 "This instance cannot wake right now. Please try again shortly.\n" (Retry-After "10", holder "none", 0s, err <nil>)
2026/11/22 11:55:17 tenant admission is closed for shutdown
2026/11/22 11:55:17 http: proxy error: context canceled
--- PASS: TestHeldHandoverLostLeaseMinio (0.27s)
PASS
ok  	github.com/carlosframework/platform/internal/host	0.836s
Bucket created successfully `local/gen-take`.
local/gen-take versioning is enabled
Created policy `gen-take` successfully.
Added user `gentake` successfully.
Attached Policies: [gen-take]
To User: gentake
=== RUN   TestGenerationTakeMinio
=== RUN   TestGenerationTakeMinio/take
2026/11/22 11:55:19 lease: instances/gen-1795348519068620454.shop.example.com: HA lease acquired in 5ms (first wake)
2026/11/22 11:55:19 lease: instances/gen-1795348519068620454.shop.example.com: HA lease acquired in 3ms (holder terminated)
    gentake_minio_test.go:308: a second create-only copy onto instances/gen-1795348519068620454.shop.example.com/g-00000000000000000002/0000/0000000000000001-0000000000000001.ltx: <nil> (destination condition honoured: false)
2026/11/22 11:55:19 ERROR retention enforcement failed system=store db=w.example.com.db error="enforce snapshot retention: remove ltx files: lease: invalid or changed generation binding"
2026/11/22 11:55:19 ERROR enforce L0 time retention system=store db=w.example.com.db error="fetch l1 files: lease: a write has waited too long to reach storage (write fence)"
2026/11/22 11:55:19 http: proxy error: context canceled
2026/11/22 11:55:19 ERROR retention enforcement failed system=store db=w.example.com.db error="enforce snapshot retention: remove ltx files: lease: a write has waited too long to reach storage (write fence)"
=== RUN   TestGenerationTakeMinio/switch-412
2026/11/22 11:55:19 lease: instances/gen-1795348519192758122.shop.example.com: HA lease acquired in 3ms (first wake)
2026/11/22 11:55:19 ERROR retention enforcement failed system=store db=seed.db error="enforce snapshot retention: fetch ltx files: lease: a write has waited too long to reach storage (write fence)"
2026/11/22 11:55:19 lease: instances/gen-1795348519192758122.shop.example.com: HA lease acquired in 3ms (clean marker)
=== RUN   TestGenerationTakeMinio/copy-version
=== RUN   TestGenerationTakeMinio/store-time
2026/11/22 11:55:19 lease: instances/gen-1795348519239689830.shop.example.com: HA lease acquired in 3ms (first wake)
2026/11/22 11:55:19 ERROR retention enforcement failed system=store db=seed.db error="enforce snapshot retention: remove ltx files: lease: invalid or changed generation binding"
2026/11/22 11:55:19 lease: instances/gen-1795348519239689830.shop.example.com: HA lease acquired in 3ms (clean marker)
2026/11/22 11:55:19 lease: instances/gen-1795348519239689830.shop.example.com: HA lease acquired in 2ms (unclean marker)
2026/11/22 11:55:19 lease: instances/gen-1795348519239689830.shop.example.com: HA lease acquired in 2ms (unclean marker)
2026/11/22 11:55:19 lease: instances/gen-1795348519239689830.shop.example.com: HA lease acquired in 2ms (unclean marker)
2026/11/22 11:55:19 lease: instances/gen-1795348519239689830.shop.example.com: HA lease acquired in 2ms (unclean marker)
=== RUN   TestGenerationTakeMinio/skew
--- PASS: TestGenerationTakeMinio (0.33s)
    --- PASS: TestGenerationTakeMinio/take (0.12s)
    --- PASS: TestGenerationTakeMinio/switch-412 (0.04s)
    --- PASS: TestGenerationTakeMinio/copy-version (0.01s)
    --- PASS: TestGenerationTakeMinio/store-time (0.15s)
    --- PASS: TestGenerationTakeMinio/skew (0.01s)
PASS
ok  	github.com/carlosframework/platform/internal/lease	0.340s
minio contract: PASS
=== staticcheck ===
go version go1.26.10 linux/arm64
go: downloading honnef.co/go/tools v0.8.2
go: downloading golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678
go: downloading github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
go: downloading golang.org/x/sync v0.23.0
go: downloading golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
staticcheck: clean
=== govulncheck ===
go version go1.26.10 linux/arm64
go: downloading golang.org/x/vuln v1.8.0
go: downloading golang.org/x/telemetry v0.0.0-20260908163034-4bcc4b2ee518
go: downloading golang.org/x/tools v0.50.0
govulncheck: scanned github.com/carlosframework/platform, amadan.net/carlos/platform.git/launchctx
GO-2026-6859  called  stdlib@v1.26.10, fixed in v1.26.11
    HTTP/1 server crash due to MaxBytesReader header race in net/http
    excepted until 2027-01-31 (.amadan/govulncheck-exceptions.tsv:9): net/http MaxBytesReader header race, fixed in go1.26.11. CI and releases stay on go1.26.10 because 1.26.11 deadlocks the edge's Expect: 100-continue path (#897, .amadan/go-toolchain.sh); #904 checked every production MaxBytesReader site and found it unreachable.
GO-2026-5932  required  golang.org/x/crypto@v0.58.0, fixed in v0.58.1-0.20261009181718-2f1f834330b2
    The golang.org/x/crypto/openpgp package is unmaintained, unsafe by design, and has known security issues
    not fatal: no call path to the vulnerable code
govulncheck: clean (2 finding(s), none called outside .amadan/govulncheck-exceptions.tsv)
=== code-health ===
go version go1.26.10 linux/arm64
    codehealth_test.go:42: scanned in 1m48.216s
    codehealth_test.go:107: line metrics (code lines, then physical):
          file-lines  5471  7324  internal/activator activator_test.go
          file-lines  4219  7040  internal/console server.go
          file-lines  4184  6365  . apimode.go
          file-lines  3782  7198  internal/activator activator.go
          file-lines  3530  4459  . apimode_test.go
          file-lines  3261  3864  internal/registry registry_test.go
          file-lines  3211  6356  internal/host agent.go
          file-lines  3094  3992  internal/provision reconcile_test.go
          func-lines   870   891  internal/host plan14InstalledClaimLaunch
          func-lines   811  1275  internal/provision Reconcile
          func-lines   769  1242  internal/console (*Server).handleAPIInstanceCreate
          func-lines   688  1232  internal/host runAgent
          func-lines   570   903  internal/activator (*Service).doWakeOnce
          func-lines   538   546  internal/host runServingParkPeerNamespace
          func-lines   519   712  . runRoute
          func-lines   509   569  internal/host TestPagingIsRateLimited
          func-lines   494   809  internal/release adoptHost
          func-lines   441   500  internal/host TestRootInstanceStopExecStop
          func-lines   421   436  internal/host (*ClaimWakeAssembly).Build
          func-lines   421   437  internal/team TestFixture
          func-lines   412   414  internal/console TestDemoProtectionsSourceToLimitAndTakedown
          func-lines   408   485  . TestFleetAppServesThroughTheHub
          func-lines   400   868  internal/provision rootReadArchivedChain
          func-lines   399   732  internal/release PassFilter
          func-lines   390   398  internal/host runFilesSeedPreparationWithLive
          func-lines   384   905  internal/edge (*Edge).ServeHTTP
          func-lines   383   406  internal/console TestDemoSourceToLiveAndUpdate
          func-lines   378   600  internal/console (*Server).handleAPIShip
          func-lines   374   377  internal/host plan14RequiredArtifactsRootRunner
          func-lines   371   417  internal/host TestRootEgressKernelProof
          func-lines   367   635  cmd/console serve
          func-lines   364   371  internal/host testRootMigrationBootstrap
          func-lines   360   362  internal/edge TestDemoAPIAliasBoundary
          func-lines   358   362  internal/registry (*Registry).haJournal
          func-lines   357   358  internal/registry (*Registry).dispatchRemote
          func-lines   355   372  internal/host TestRootSandboxUpdateFromOldBox
          func-lines   343   354  internal/analytics Prune
          func-lines   340   353  internal/host newColdRootHarness
          func-lines   335   557  internal/console (*Store).migrate
          func-lines   334   334  internal/host TestPlan12RecoveryRestoreSourceDatabase
          func-lines   330   371  internal/edge TestRegionalNameNeverLeavesItsRegion
          func-lines   329   471  . runDeploy
          func-lines   329   329  internal/host TestPlan12RecoveryRestoreSourceDatabase.func1
          func-lines   327   369  internal/edge TestTunnelWebSocketEndToEnd
          func-lines   325   455  internal/objstore TestDeliveredContractMinio
          func-lines   320   654  internal/appconfig SyncExecWithCallbacks
          func-lines   315   318  internal/host plan14TimerIntention
          func-lines   311   314  internal/host plan14TimerIntention.func1
          func-lines   310   315  internal/hostbox ColdHandover.Run
          func-lines   308   309  internal/host rootFilesSeedIsolatedWitness
          func-lines   305   323  internal/host hairpinKernelWitness
          func-lines   304   308  internal/console TestHAP2ProductionDoors
          func-lines   302   329  internal/host TestRootG2PoolIngress
        release-importers: . cmd/console internal/activator internal/analytics internal/appconfig internal/apperr internal/applog internal/apppolicy internal/boxid internal/boxvolumes internal/console internal/dbreads internal/dbreads/dbreadstest internal/dbverify internal/demobuild internal/domains internal/doorkey internal/edge internal/edgeproof internal/edgesfile internal/fleetapi internal/grouproll internal/grouprollaws internal/historyreadback internal/host internal/hostactors internal/hostbox internal/hostclaim internal/hostevidence internal/hostexec internal/hostfence internal/hostfiles internal/hostfloor internal/hostguard internal/hostops internal/hostrelocate internal/hostresolve internal/instancectl internal/instanceupdates internal/interactive internal/layout internal/lease internal/ledger internal/mail internal/mailer internal/mailsubmit internal/metrics internal/moves internal/objstore internal/ops internal/park internal/plans internal/provision internal/relay internal/rollout internal/rootfsimage internal/runs internal/s3fake internal/schedule internal/seeds internal/status internal/telemetry internal/usage internal/vet scripts/pathmapcheck scripts/witness-pointer
        not scanned (203 files):
          cmd/carlos-media/drill_other.go: built only for other systems or tags
          cmd/carlos-media/harden_other.go: built only for other systems or tags
          cmd/console/servelock_windows.go: built only for other systems or tags
          cmd/moveprobe/detach_windows.go: built only for other systems or tags
          cmd/rootfswitness/mmap_other.go: built only for other systems or tags
          devbox_acl_other.go: built only for other systems or tags
          devbox_envfile_darwin_test.go: built only for other systems or tags
          devbox_envfile_other.go: built only for other systems or tags
          interactive_term_darwin.go: built only for other systems or tags
          interactive_term_other.go: built only for other systems or tags
          internal/activator/claimprocess_root_other.go: built only for other systems or tags
          internal/activator/escrow_stamp_other.go: built only for other systems or tags
          internal/activator/harecord_other.go: built only for other systems or tags
          internal/activator/ownenv_other.go: built only for other systems or tags
          internal/activator/pty_other.go: built only for other systems or tags
          internal/activator/race_on_test.go: built only for other systems or tags
          internal/activator/rolelaunch_other.go: built only for other systems or tags
          internal/assetcache/statfs_other.go: built only for other systems or tags
          internal/boxself/io_other.go: built only for other systems or tags
          internal/cgroup/cleanup_other.go: built only for other systems or tags
          internal/cgroup/cleanup_other_test.go: built only for other systems or tags
          internal/cgroup/hostprocs_other.go: built only for other systems or tags
          internal/cgroup/recreate_other.go: built only for other systems or tags
          internal/cgroup/role_other.go: built only for other systems or tags
          internal/cgroup/shim_other.go: built only for other systems or tags
          internal/cgroup/strict_other.go: built only for other systems or tags
          internal/cgroup/verify_other.go: built only for other systems or tags
          internal/console/claim_sql_identity_other.go: built only for other systems or tags
          internal/console/geoipverify_other.go: built only for other systems or tags
          internal/console/hostreports_process_other.go: built only for other systems or tags
          internal/console/replicaview_other.go: built only for other systems or tags
          internal/console/restore_sim_nice_other_test.go: built only for other systems or tags
          internal/console/scalecost_other_test.go: built only for other systems or tags
          internal/console/seedscratch_windows.go: built only for other systems or tags
          internal/dbreads/worker_other.go: built only for other systems or tags
          internal/demobuild/security_other.go: built only for other systems or tags
          internal/democlaim/source_other.go: built only for other systems or tags
          internal/devbox/peer_darwin.go: built only for other systems or tags
          internal/devbox/peer_darwin_test.go: built only for other systems or tags
          internal/devbox/peer_other.go: built only for other systems or tags
          internal/devbox/socketcheck_other.go: built only for other systems or tags
          internal/edge/devboxpeer_other.go: built only for other systems or tags
          internal/edge/hairpin_other.go: built only for other systems or tags
          internal/edge/heldbudget_other.go: built only for other systems or tags
          internal/edge/purge_listen_unix.go: built only for other systems or tags
          internal/edge/purge_listen_windows.go: built only for other systems or tags
          internal/edge/race_on_test.go: built only for other systems or tags
          internal/edge/static_artifact_other.go: built only for other systems or tags
          internal/edge/static_recordlock_other.go: built only for other systems or tags
          internal/edge/static_sweep_other.go: built only for other systems or tags
          internal/execsandbox/cleanup_other.go: built only for other systems or tags
          internal/execsandbox/file_other.go: built only for other systems or tags
          internal/execsandbox/oci_other.go: built only for other systems or tags
          internal/fileacl/fileacl_darwin.go: built only for other systems or tags
          internal/fileacl/fileacl_darwin_amd64.s: built only for other systems or tags
          internal/fileacl/fileacl_darwin_arm64.s: built only for other systems or tags
          internal/fileacl/fileacl_darwin_test.go: built only for other systems or tags
          internal/grouproll/state_other.go: built only for other systems or tags
          internal/grouprollaws/pty_darwin.go: built only for other systems or tags
          internal/grouprollaws/pty_other.go: built only for other systems or tags
          internal/hairpin/native_other.go: built only for other systems or tags
          internal/host/applylock_other_test.go: built only for other systems or tags
          internal/host/bootstrapfs_other.go: built only for other systems or tags
          internal/host/boxroles_config_other.go: built only for other systems or tags
          internal/host/claimfilesseed_delegation_other.go: built only for other systems or tags
          internal/host/claimfilesseed_transport_other.go: built only for other systems or tags
          internal/host/claimjournal_containment_other.go: built only for other systems or tags
          internal/host/claimjournal_migration_other.go: built only for other systems or tags
          internal/host/claimlaunch_kernel_other.go: built only for other systems or tags
          internal/host/claimlaunch_rev2_other_test.go: built only for other systems or tags
          internal/host/claimproduction_other.go: built only for other systems or tags
          internal/host/claimready_other.go: built only for other systems or tags
          internal/host/claimroleassembly_other.go: built only for other systems or tags
          internal/host/claimservingartifact_other.go: built only for other systems or tags
          internal/host/claimservinghandover_reboot_other.go: built only for other systems or tags
          internal/host/claimservinghandover_reboot_other_test.go: built only for other systems or tags
          internal/host/claimservingpark_other.go: built only for other systems or tags
          internal/host/claimstate_other.go: built only for other systems or tags
          internal/host/claimstop_kernel_other.go: built only for other systems or tags
          internal/host/claimtoken_inventory_other.go: built only for other systems or tags
          internal/host/claimunit_dropin_other.go: built only for other systems or tags
          internal/host/claimunit_files_other.go: built only for other systems or tags
          internal/host/claimunit_migrate_other.go: built only for other systems or tags
          internal/host/claimunit_ready_other.go: built only for other systems or tags
          internal/host/claimunit_socket_migration_other.go: built only for other systems or tags
          internal/host/dbreads_other.go: built only for other systems or tags
          internal/host/egress_rail_other.go: built only for other systems or tags
          internal/host/fileowner_other.go: built only for other systems or tags
          internal/host/flock_windows.go: built only for other systems or tags
          internal/host/group_config_other.go: built only for other systems or tags
          internal/host/group_maintenance_other.go: built only for other systems or tags
          internal/host/group_maintenance_verbs_other.go: built only for other systems or tags
          internal/host/group_receipt_other.go: built only for other systems or tags
          internal/host/hadrain_call_other.go: built only for other systems or tags
          internal/host/hadrain_socket_other.go: built only for other systems or tags
          internal/host/hadrainfence_other.go: built only for other systems or tags
          internal/host/headroom_other.go: built only for other systems or tags
          internal/host/installchannel_other.go: built only for other systems or tags
          internal/host/metrics_nested_other.go: built only for other systems or tags
          internal/host/movesfloor_other.go: built only for other systems or tags
          internal/host/movesfloorgate_other.go: built only for other systems or tags
          internal/host/movesheldrelease_other.go: built only for other systems or tags
          internal/host/movesmeasure_other.go: built only for other systems or tags
          internal/host/offcloudcredentials_other.go: built only for other systems or tags
          internal/host/registrychild_exec_other.go: built only for other systems or tags
          internal/host/registrychild_other.go: built only for other systems or tags
          internal/host/registryowner_chown_other.go: built only for other systems or tags
          internal/host/registryowner_descriptor_unix.go: built only for other systems or tags
          internal/host/replicahealth_other.go: built only for other systems or tags
          internal/host/rootgeneration_census_other.go: built only for other systems or tags
          internal/host/rootgeneration_kernel_other.go: built only for other systems or tags
          internal/host/rootgeneration_payload_other.go: built only for other systems or tags
          internal/host/rootgeneration_retired_other.go: built only for other systems or tags
          internal/host/rootmigration_production_other.go: built only for other systems or tags
          internal/host/runscset_other.go: built only for other systems or tags
          internal/host/sandboxenv_other.go: built only for other systems or tags
          internal/host/statfs_windows.go: built only for other systems or tags
          internal/host/systemapply_other.go: built only for other systems or tags
          internal/hostbox/census_vendor_other.go: built only for other systems or tags
          internal/hostbox/inventory_identity_other.go: built only for other systems or tags
          internal/hostbox/journalmigration_other.go: built only for other systems or tags
          internal/hostbox/journalnamespace_other.go: built only for other systems or tags
          internal/hostbox/journaltrust_other.go: built only for other systems or tags
          internal/hostbox/migration_census_other.go: built only for other systems or tags
          internal/hostbox/typedpark_other.go: built only for other systems or tags
          internal/hostenv/group_other.go: built only for other systems or tags
          internal/hostenv/write_other.go: built only for other systems or tags
          internal/hostenv/write_other_test.go: built only for other systems or tags
          internal/hostexec/clock_other.go: built only for other systems or tags
          internal/hostexec/clock_other_test.go: built only for other systems or tags
          internal/hostexec/local_other.go: built only for other systems or tags
          internal/hostexec/pending_other.go: built only for other systems or tags
          internal/hostexec/probe_other.go: built only for other systems or tags
          internal/hostexec/rootprocess_other.go: built only for other systems or tags
          internal/hostfiles/dir_other.go: built only for other systems or tags
          internal/hostfiles/refuse_other.go: built only for other systems or tags
          internal/hostfiles/watch_other.go: built only for other systems or tags
          internal/hostfloor/controllers_other.go: built only for other systems or tags
          internal/hostfloor/image_other.go: built only for other systems or tags
          internal/hostguard/flock_other.go: built only for other systems or tags
          internal/hostguard/flock_other_test.go: built only for other systems or tags
          internal/hostguard/record_other.go: built only for other systems or tags
          internal/instancectl/claimexec_other.go: built only for other systems or tags
          internal/instancectl/claimexec_socket_other.go: built only for other systems or tags
          internal/instancectl/claimlaunch_snapshot_other.go: built only for other systems or tags
          internal/instancectl/claimnetwork_other.go: built only for other systems or tags
          internal/instancectl/demo_snapshot_other.go: built only for other systems or tags
          internal/instancectl/egress_cgroup_other.go: built only for other systems or tags
          internal/instancectl/egress_dropin_other.go: built only for other systems or tags
          internal/instancectl/gvisorprobe_other.go: built only for other systems or tags
          internal/instancectl/peer_other.go: built only for other systems or tags
          internal/instancectl/peer_tuple_other.go: built only for other systems or tags
          internal/instancectl/rootfs_identity_other.go: built only for other systems or tags
          internal/instanceexec/claimexec_other.go: built only for other systems or tags
          internal/instanceexec/exec_rootfs_other.go: built only for other systems or tags
          internal/instanceexec/probe_gvisor_other.go: built only for other systems or tags
          internal/instanceexec/probe_hardening_other.go: built only for other systems or tags
          internal/instanceexec/probe_other.go: built only for other systems or tags
          internal/instanceexec/probe_rootfs_other.go: built only for other systems or tags
          internal/instanceexec/sandbox_other.go: built only for other systems or tags
          internal/instanceexec/scope_other.go: built only for other systems or tags
          internal/instanceexec/stop_other.go: built only for other systems or tags
          internal/instanceexec/tty_other.go: built only for other systems or tags
          internal/instancefs/instancefs_other.go: built only for other systems or tags
          internal/launchd/activate_darwin.go: built only for other systems or tags
          internal/launchd/activate_darwin_amd64.s: built only for other systems or tags
          internal/launchd/activate_darwin_arm64.s: built only for other systems or tags
          internal/launchd/activate_darwin_test.go: built only for other systems or tags
          internal/layout/journal_other.go: built only for other systems or tags
          internal/layout/links_other.go: built only for other systems or tags
          internal/mailer/keys_other.go: built only for other systems or tags
          internal/maintenanceexec/run_other.go: built only for other systems or tags
          internal/mediahandler/collect_other.go: built only for other systems or tags
          internal/mediahandler/procs_other.go: built only for other systems or tags
          internal/medialocal/runner_other.go: built only for other systems or tags
          internal/moves/archive/open_other.go: built only for other systems or tags
          internal/moves/archive/sync_other.go: built only for other systems or tags
          internal/ops/flock_windows.go: built only for other systems or tags
          internal/park/local_other.go: built only for other systems or tags
          internal/privatefile/io_other.go: built only for other systems or tags
          internal/proxyproto/peek_other.go: built only for other systems or tags
          internal/relay/race_on_test.go: built only for other systems or tags
          internal/release/consumedfence_other.go: built only for other systems or tags
          internal/release/digestcache_other.go: built only for other systems or tags
          internal/rootaws/credentials_other.go: built only for other systems or tags
          internal/rootaws/open_darwin.go: built only for other systems or tags
          internal/rootfsimage/dir_other.go: built only for other systems or tags
          internal/rootstate/authoritydir_other.go: built only for other systems or tags
          internal/rootstate/authorityfile_other.go: built only for other systems or tags
          internal/rootstate/file_other.go: built only for other systems or tags
          internal/rootstate/link_other.go: built only for other systems or tags
          internal/rootstate/persistent_other.go: built only for other systems or tags
          internal/rootstate/state_other.go: built only for other systems or tags
          internal/safefile/file_other.go: built only for other systems or tags
          internal/safefile/reap_other.go: built only for other systems or tags
          internal/stopevidence/fds_other.go: built only for other systems or tags
          internal/stopevidence/fds_other_test.go: built only for other systems or tags
          internal/stopevidence/holders_other.go: built only for other systems or tags
          internal/stopevidence/reconstruct_other.go: built only for other systems or tags
          internal/team/storelock_other.go: built only for other systems or tags
          internal/team/storelock_windows.go: built only for other systems or tags
          move_offline_run_other.go: built only for other systems or tags
          system_group_other.go: built only for other systems or tags
        
    codehealth_test.go:115: fatal               1094 at  474 sites  log.Fatal*, (*log.Logger).Fatal* and os.Exit in the root package's production files
    codehealth_test.go:115: sleep               1005 at  811 sites  time.Sleep in test files
    codehealth_test.go:115: db-no-context        885 at  703 sites  database calls with no context (dbOpWithoutContext) in production files
    codehealth_test.go:115: host-context         188 at  142 sites  context.Background and context.TODO in internal/host production files
    codehealth_test.go:115: func-lines         18578 at   45 sites  functions over 300 code lines (blank and comment-only lines not counted)
    codehealth_test.go:115: file-lines         30752 at    8 sites  files over 3,000 code lines, counted the same way
    codehealth_test.go:115: release-importers     66 at    1 sites  packages whose production files import internal/release
    codehealth_test.go:119: below the record: file-lines internal/activator activator.go -: 3782 in the code, the record allows 3783 (make code-health-record lowers it)
    codehealth_test.go:119: below the record: file-lines internal/host agent.go -: 3211 in the code, the record allows 3214 (make code-health-record lowers it)
--- PASS: TestCodeHealth (108.22s)
PASS
ok  	github.com/carlosframework/platform/internal/codehealth	109.176s
=== code-health-record ===
go version go1.26.10 linux/arm64

amadan: job cancelled — a newer push superseded it
diff --git a/internal/console/apidemo.go b/internal/console/apidemo.go
index a64dcac11..7798cf976 100644
--- a/internal/console/apidemo.go
+++ b/internal/console/apidemo.go
@@ -354,7 +354,8 @@ func (s *Server) handleDemoPublish(w http.ResponseWriter, r *http.Request) {
demoError(w, ErrDemoToken)
return
}
- row, lookupErr := s.store.LookupDemoToken(r.Context(), parts[1])
+ // Only the update bearer passes here; a claim code is refused.
+ row, lookupErr := s.store.LookupDemoUpdate(r.Context(), parts[1])
if lookupErr != nil {
demoTokenError(w, lookupErr)
return
@@ -461,15 +462,23 @@ func (s *Server) handleDemoPublish(w http.ResponseWriter, r *http.Request) {
}
var row DemoRow
var identity demo.Identity
+ var claimCode string
if update == nil {
sum := sha256.Sum256(src.Archive)
in := DemoAdmission{Config: s.cfg.Demo, IP: clientIP(), Now: time.Now(), SourceSHA256: sum, Client: r.Header.Get("X-Carlos-Client")}
+ // The claim link carries its own code, so handing the person that
+ // link never shows them, or the agent's transcript, the update bearer.
+ if in.ClaimCode, err = randomToken(); err != nil {
+ demoError(w, err)
+ return
+ }
in.job = func(ctx context.Context, tx *sql.Tx, d DemoRow, life AppLife) error {
expiresAt = life.ExpiresAt
_, err := s.insertDemoJob(ctx, tx, d, life, src)
return err
}
row, identity, err = s.reserveFreshDemo(r.Context(), in)
+ claimCode = in.ClaimCode
} else {
row = *update
}
@@ -489,7 +498,7 @@ func (s *Server) handleDemoPublish(w http.ResponseWriter, r *http.Request) {
if update == nil {
response["claimAvailable"] = s.demoClaimEnabled()
response["claimToken"] = identity.Token
- response["claimUrl"] = strings.TrimRight(s.cfg.Origin, "/") + "/demo/claim#" + identity.Token
+ response["claimUrl"] = strings.TrimRight(s.cfg.Origin, "/") + "/demo/claim#" + claimCode
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
diff --git a/internal/console/apidemo_test.go b/internal/console/apidemo_test.go
index a6b9e377f..c66a3bc44 100644
--- a/internal/console/apidemo_test.go
+++ b/internal/console/apidemo_test.go
@@ -107,7 +107,7 @@ func TestDemoUpdateAuthority(t *testing.T) {
if w.Code != 400 {
t.Fatalf("update %d %s", w.Code, w.Body.String())
}
- got, err := s.store.LookupDemoToken(t.Context(), in.Identity.Token)
+ got, err := s.store.LookupDemoUpdate(t.Context(), in.Identity.Token)
if err != nil || got.ID != row.ID || got.UpdateAttempts != 1 {
t.Fatalf("update: %+v %v", got, err)
}
diff --git a/internal/console/demo_api_origin_test.go b/internal/console/demo_api_origin_test.go
index 423a135d7..3b83cf960 100644
--- a/internal/console/demo_api_origin_test.go
+++ b/internal/console/demo_api_origin_test.go
@@ -51,9 +51,14 @@ func TestDemoPublicAPIOrigin(t *testing.T) {
if len(got) != 7 || job == "" || got["statusUrl"] != want+"/api/demo/jobs/"+job {
t.Error("wrong status URL or response shape")
}
- if token == "" || got["claimUrl"] != s.cfg.Origin+"/demo/claim#"+token {
+ link, _ := got["claimUrl"].(string)
+ code, ok := strings.CutPrefix(link, s.cfg.Origin+"/demo/claim#")
+ if token == "" || !ok || code == token {
t.Error("browser claim origin or fragment changed")
}
+ if _, err := s.store.LookupDemoClaim(t.Context(), code); err != nil {
+ t.Errorf("claim link fragment is not the claim code: %v", err)
+ }
})
}
}
diff --git a/internal/console/demo_claim_auth.go b/internal/console/demo_claim_auth.go
index ede96e8c9..7fabb692c 100644
--- a/internal/console/demo_claim_auth.go
+++ b/internal/console/demo_claim_auth.go
@@ -131,7 +131,7 @@ func (s *Server) handleDemoClaimStart(w http.ResponseWriter, r *http.Request) {
if !s.demoClaimGate(w, r) {
return
}
- fields, ok := demoClaimJSON(w, r, "claimToken", "email", "flowToken")
+ fields, ok := demoClaimJSON(w, r, "claimCode", "claimToken", "email", "flowToken")
if !ok {
return
}
@@ -140,7 +140,18 @@ func (s *Server) handleDemoClaimStart(w http.ResponseWriter, r *http.Request) {
jsonError(w, 400, demoClaimBadRequest)
return
}
- d, err := s.store.LookupDemoToken(r.Context(), fields["claimToken"])
+ // claimCode is the claim link's fragment. claimToken is the older name for
+ // the same field and carries the same value; send exactly one of them.
+ // Neither accepts the update bearer, except from a demo created before
+ // claim codes, whose link still carries it.
+ credential, named := fields["claimCode"]
+ if legacy, both := fields["claimToken"]; both == named {
+ jsonError(w, 400, demoClaimBadRequest)
+ return
+ } else if !named {
+ credential = legacy
+ }
+ d, err := s.store.LookupDemoClaim(r.Context(), credential)
if err != nil {
if errors.Is(err, ErrDemoToken) {
demoTokenError(w, err)
@@ -163,7 +174,7 @@ func (s *Server) handleDemoClaimStart(w http.ResponseWriter, r *http.Request) {
}
underCap := s.limits.submit(ip)
if s.keymailAddress(r.Context(), address, underCap) {
- demoClaimReply(w, 200, map[string]any{"state": "browser_required", "claimUrl": s.cfg.Origin + "/demo/claim#" + fields["claimToken"]})
+ demoClaimReply(w, 200, map[string]any{"state": "browser_required", "claimUrl": s.cfg.Origin + "/demo/claim#" + credential})
return
}
if !s.mailReady(r.Context()) {
diff --git a/internal/console/demo_claim_auth_test.go b/internal/console/demo_claim_auth_test.go
index dfd0146d9..df6b70d6d 100644
--- a/internal/console/demo_claim_auth_test.go
+++ b/internal/console/demo_claim_auth_test.go
@@ -16,7 +16,16 @@ import (
"time"
)
+// claimTestServer returns the demo's claim code: the credential its claim
+// link carries. claimTestDemo also returns the admission, whose
+// Identity.Token is the update bearer.
func claimTestServer(t *testing.T) (*Server, *fakeConsoleMail, string) {
+ t.Helper()
+ s, m, in := claimTestDemo(t)
+ return s, m, in.ClaimCode
+}
+
+func claimTestDemo(t *testing.T) (*Server, *fakeConsoleMail, DemoAdmission) {
t.Helper()
s := demoTestServer(t)
s.demoClaimTestEnabled = true
@@ -35,7 +44,7 @@ func claimTestServer(t *testing.T) (*Server, *fakeConsoleMail, string) {
if _, err := s.store.ReserveDemo(t.Context(), in); err != nil {
t.Fatal(err)
}
- return s, m, in.Identity.Token
+ return s, m, in
}
func claimPost(s *Server, path string, fields map[string]string) *httptest.ResponseRecorder {
@@ -112,7 +121,7 @@ func TestDemoClaimProofBinding(t *testing.T) {
if _, err := s.store.ReserveDemo(t.Context(), in); err != nil {
t.Fatal(err)
}
- otherToken = in.Identity.Token
+ otherToken = in.ClaimCode
}
target, _ = claimStart(t, s, otherToken, "shop@example.com", "")
case "signinCode", "stepupCode":
@@ -168,7 +177,7 @@ func TestDemoClaimProofBinding(t *testing.T) {
})
t.Run("resendBindingAndExpiry", func(t *testing.T) {
s, m, token := claimTestServer(t)
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
@@ -190,7 +199,7 @@ func TestDemoClaimProofBinding(t *testing.T) {
if _, err = s.store.ReserveDemo(t.Context(), in); err != nil {
t.Fatal(err)
}
- for _, v := range []struct{ token, email string }{{in.Identity.Token, "shop@example.com"}, {token, "other@example.com"}} {
+ for _, v := range []struct{ token, email string }{{in.ClaimCode, "shop@example.com"}, {token, "other@example.com"}} {
_, r := claimStart(t, s, v.token, v.email, flow)
if r.Code == 202 {
t.Fatal("flow rebound")
diff --git a/internal/console/demo_claim_caps_test.go b/internal/console/demo_claim_caps_test.go
index 024bebc13..a70889f55 100644
--- a/internal/console/demo_claim_caps_test.go
+++ b/internal/console/demo_claim_caps_test.go
@@ -58,7 +58,7 @@ func TestDemoClaimReservationCaps(t *testing.T) {
if !isPlanCap(err) {
t.Fatalf("cap: %v", err)
}
- if _, err := s.store.LookupDemoToken(t.Context(), token); err != nil {
+ if _, err := s.store.LookupDemoClaim(t.Context(), token); err != nil {
t.Fatal(err)
}
return
@@ -105,7 +105,7 @@ func TestDemoClaimAccountsFreeAccountAllowance(t *testing.T) {
if err != nil || len(accounts) != 1 {
t.Fatalf("extra allowance: %v %v", accounts, err)
}
- if _, err := s.store.LookupDemoToken(t.Context(), token); err != nil {
+ if _, err := s.store.LookupDemoClaim(t.Context(), token); err != nil {
t.Fatal("selection refusal consumed source", err)
}
}
diff --git a/internal/console/demo_claim_choice_test.go b/internal/console/demo_claim_choice_test.go
index b8ac8f61c..131899351 100644
--- a/internal/console/demo_claim_choice_test.go
+++ b/internal/console/demo_claim_choice_test.go
@@ -32,7 +32,7 @@ func TestDemoClaimChoiceRendering(t *testing.T) {
claimAccount(t, s, int64(501+i), "shop@example.com", RoleOwner)
}
s.cfg.AppsDomain = "apps.example.com"
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
diff --git a/internal/console/demo_claim_code_test.go b/internal/console/demo_claim_code_test.go
new file mode 100644
index 000000000..894f5fa08
--- /dev/null
+++ b/internal/console/demo_claim_code_test.go
@@ -0,0 +1,267 @@
+package console
+
+import (
+ "bytes"
+ "encoding/json"
+ "errors"
+ "log"
+ "net/http/httptest"
+ "net/url"
+ "strings"
+ "testing"
+ "time"
+)
+
+// A demo carries two secrets. The update bearer (the create response's
+// claimToken) only updates; the claim code (claimUrl's fragment) only starts
+// a claim. These tests hold each door shut to the other's credential.
+
+func demoClaimRefusal(t *testing.T, surface string, w *httptest.ResponseRecorder, code int, reason string) {
+ t.Helper()
+ var got map[string]string
+ if w.Code != code || json.Unmarshal(w.Body.Bytes(), &got) != nil || (reason != "" && got["reason"] != reason) {
+ t.Fatalf("%s: %d %s; want %d %s", surface, w.Code, w.Body, code, reason)
+ }
+}
+
+func demoUpdateAttempts(t *testing.T, s *Server, id string) int {
+ t.Helper()
+ var n int
+ if err := s.store.db.QueryRow(`SELECT update_attempts FROM demo_apps WHERE demo_id=?`, id).Scan(&n); err != nil {
+ t.Fatal(err)
+ }
+ return n
+}
+
+func TestDemoClaimCodeStoredAsHashOnly(t *testing.T) {
+ st, _ := demoTestStore(t)
+ in := demoTestAdmission(t, demoTestConfig(t))
+ if _, err := st.ReserveDemo(t.Context(), in); err != nil {
+ t.Fatal(err)
+ }
+ want, _ := demoSecretHash(in.ClaimCode)
+ var stored []byte
+ var minted int
+ if err := st.db.QueryRow(`SELECT claim_code_hash,claim_code_minted FROM demo_apps WHERE demo_id=?`, in.Identity.ID).Scan(&stored, &minted); err != nil {
+ t.Fatal(err)
+ }
+ if !bytes.Equal(stored, want[:]) || minted != 1 || bytes.Equal(stored, in.Identity.TokenHash[:]) {
+ t.Fatalf("claim code hash %x minted=%d", stored, minted)
+ }
+
+ // A create without a claim code, or with the bearer as its code, is refused:
+ // nothing can mint a row whose link opens the update door.
+ for name, code := range map[string]string{"none": "", "bearer": "", "short": in.ClaimCode[:20]} {
+ bad := demoTestAdmission(t, demoTestConfig(t))
+ bad.ClaimCode = code
+ if name == "bearer" {
+ bad.ClaimCode = bad.Identity.Token
+ }
+ if _, err := st.ReserveDemo(t.Context(), bad); err == nil {
+ t.Fatalf("%s: reserved without a separate claim code", name)
+ }
+ }
+}
+
+func TestDemoClaimCodeDoors(t *testing.T) {
+ s, _, in := claimTestDemo(t)
+ bearer, code := in.Identity.Token, in.ClaimCode
+
+ // The update endpoint refuses the claim code and spends no attempt.
+ demoClaimRefusal(t, "update with claim code", demoRequest(s, "Bearer "+code, "192.0.2.1").ResponseRecorder, 401, "invalid")
+ if n := demoUpdateAttempts(t, s, in.Identity.ID); n != 0 {
+ t.Fatalf("claim code spent an update attempt: %d", n)
+ }
+ if _, err := s.store.LookupDemoUpdate(t.Context(), code); err != ErrDemoToken {
+ t.Fatalf("update lookup of claim code: %v", err)
+ }
+
+ // Both claim entry points refuse the update bearer, under either field name.
+ for _, field := range []string{"claimToken", "claimCode"} {
+ demoClaimRefusal(t, "start with bearer as "+field, claimPost(s, "/api/demo/claims", map[string]string{field: bearer, "email": "shop@example.com"}), 401, "invalid")
+ }
+ b := &claimBrowser{t: t, s: s}
+ b.request("GET", "/demo/claim", nil)
+ demoClaimRefusal(t, "intent with bearer", b.post("/demo/claim/intent", url.Values{"claimToken": {bearer}}), 401, "invalid")
+ if _, err := s.store.LookupDemoClaim(t.Context(), bearer); err != ErrDemoToken {
+ t.Fatalf("claim lookup of bearer: %v", err)
+ }
+ if n := claimBrowserCount(t, s, "demo_claim_flows"); n != 0 {
+ t.Fatalf("bearer created %d claim flows", n)
+ }
+
+ // Sending both names, or neither, is a bad request.
+ demoClaimRefusal(t, "both fields", claimPost(s, "/api/demo/claims", map[string]string{"claimCode": code, "claimToken": code, "email": "shop@example.com"}), 400, "")
+ demoClaimRefusal(t, "neither field", claimPost(s, "/api/demo/claims", map[string]string{"email": "shop@example.com"}), 400, "")
+
+ // The claim code opens both claim entry points, under either field name.
+ w := claimPost(s, "/api/demo/claims", map[string]string{"claimCode": code, "email": "shop@example.com"})
+ var started struct{ State, FlowToken string }
+ if w.Code != 202 || json.Unmarshal(w.Body.Bytes(), &started) != nil || started.State != "email_required" {
+ t.Fatalf("start with claimCode: %d %s", w.Code, w.Body)
+ }
+ if w := claimPost(s, "/api/demo/claims", map[string]string{"claimToken": code, "email": "shop@example.com", "flowToken": started.FlowToken}); w.Code != 202 {
+ t.Fatalf("resend with claimToken carrying the code: %d %s", w.Code, w.Body)
+ }
+ if strings.Contains(w.Body.String(), bearer) {
+ t.Fatal("claim start echoed the update bearer")
+ }
+ if w := b.post("/demo/claim/intent", url.Values{"claimToken": {code}}); w.Code != 303 {
+ t.Fatalf("intent with claim code: %d %s", w.Code, w.Body)
+ }
+
+ // The bearer still updates.
+ if w := demoRequest(s, "Bearer "+bearer, "192.0.2.1"); w.Code != 400 {
+ t.Fatalf("update with bearer: %d %s", w.Code, w.Body)
+ }
+ if n := demoUpdateAttempts(t, s, in.Identity.ID); n != 1 {
+ t.Fatalf("bearer update not admitted: attempts=%d", n)
+ }
+}
+
+// demoMakeLegacy gives a row the shape the migration leaves on a demo created
+// before claim codes: no code, never minted.
+func demoMakeLegacy(t *testing.T, s *Server, id string) {
+ t.Helper()
+ if _, err := s.store.db.Exec(`UPDATE demo_apps SET claim_code_hash=NULL,claim_code_minted=0 WHERE demo_id=?`, id); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestDemoClaimCodeLegacyLinks(t *testing.T) {
+ t.Run("old link keeps working", func(t *testing.T) {
+ s, _, in := claimTestDemo(t)
+ demoMakeLegacy(t, s, in.Identity.ID)
+ bearer := in.Identity.Token
+ if _, w := claimStart(t, s, bearer, "shop@example.com", ""); w.Code != 202 {
+ t.Fatalf("legacy start: %d %s", w.Code, w.Body)
+ }
+ b := &claimBrowser{t: t, s: s}
+ b.request("GET", "/demo/claim", nil)
+ if w := b.post("/demo/claim/intent", url.Values{"claimToken": {bearer}}); w.Code != 303 {
+ t.Fatalf("legacy intent: %d %s", w.Code, w.Body)
+ }
+ if w := demoRequest(s, "Bearer "+bearer, "192.0.2.1"); w.Code != 400 || demoUpdateAttempts(t, s, in.Identity.ID) != 1 {
+ t.Fatalf("legacy update: %d %s", w.Code, w.Body)
+ }
+ demoClaimRefusal(t, "stale code on legacy row", claimPost(s, "/api/demo/claims", map[string]string{"claimCode": in.ClaimCode, "email": "shop@example.com"}), 401, "invalid")
+ })
+ t.Run("gate is the minted flag, not a missing hash", func(t *testing.T) {
+ s, _, in := claimTestDemo(t)
+ if _, err := s.store.db.Exec(`UPDATE demo_apps SET claim_code_hash=NULL WHERE demo_id=?`, in.Identity.ID); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := s.store.LookupDemoClaim(t.Context(), in.Identity.Token); err != ErrDemoToken {
+ t.Fatalf("minted row accepted its bearer at claim: %v", err)
+ }
+ demoClaimRefusal(t, "start", claimPost(s, "/api/demo/claims", map[string]string{"claimToken": in.Identity.Token, "email": "shop@example.com"}), 401, "invalid")
+ })
+ t.Run("a code dies with its bearer", func(t *testing.T) {
+ s, _, in := claimTestDemo(t)
+ if _, err := s.store.db.Exec(`UPDATE demo_apps SET claim_token_hash=NULL WHERE demo_id=?`, in.Identity.ID); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := s.store.LookupDemoClaim(t.Context(), in.ClaimCode); err != ErrDemoToken {
+ t.Fatalf("claim code outlived the bearer: %v", err)
+ }
+ })
+ for _, reason := range []string{"expired", "operator"} {
+ t.Run("legacy spent on "+reason, func(t *testing.T) {
+ s, _, in := claimTestDemo(t)
+ demoMakeLegacy(t, s, in.Identity.ID)
+ d, err := s.store.LookupDemoClaim(t.Context(), in.Identity.Token)
+ if err != nil {
+ t.Fatal(err)
+ }
+ now := time.Now()
+ if reason == "expired" {
+ now = time.Unix(d.CreatedAt+86400, 0)
+ }
+ if err := s.retireDemoLocked(t.Context(), d, now, reason); err != nil {
+ t.Fatal(err)
+ }
+ var kind string
+ var rows int
+ if err := s.store.db.QueryRow(`SELECT (SELECT kind FROM demo_spent_tokens WHERE hash=?),(SELECT count(*) FROM demo_spent_tokens)`, in.Identity.TokenHash[:]).Scan(&kind, &rows); err != nil || kind != "token" || rows != 1 {
+ t.Fatalf("legacy spend: kind=%q rows=%d %v", kind, rows, err)
+ }
+ want := map[string]error{"expired": ErrDemoExpired, "operator": ErrDemoTakenDown}[reason]
+ if _, err := s.store.LookupDemoClaim(t.Context(), in.Identity.Token); !errors.Is(err, want) {
+ t.Fatalf("legacy claim reason: %v", err)
+ }
+ if _, err := s.store.LookupDemoUpdate(t.Context(), in.Identity.Token); !errors.Is(err, want) {
+ t.Fatalf("legacy update reason: %v", err)
+ }
+ })
+ }
+}
+
+func TestDemoClaimCodeMigrationAddsColumnsOnly(t *testing.T) {
+ st, _ := demoTestStore(t)
+ in := demoTestAdmission(t, demoTestConfig(t))
+ if _, err := st.ReserveDemo(t.Context(), in); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := st.db.Exec(`INSERT INTO demo_spent_tokens(hash,reason,spent_at) VALUES(?,'expired',?)`, bytes.Repeat([]byte{7}, 32), time.Now().Unix()); err != nil {
+ t.Fatal(err)
+ }
+ // Recreate the shape a console before this change left behind.
+ for _, q := range []string{
+ `DROP INDEX demo_apps_claim_code`,
+ `ALTER TABLE demo_apps DROP COLUMN claim_code_hash`,
+ `ALTER TABLE demo_apps DROP COLUMN claim_code_minted`,
+ `ALTER TABLE demo_spent_tokens DROP COLUMN kind`,
+ } {
+ if _, err := st.db.Exec(q); err != nil {
+ t.Fatalf("%s: %v", q, err)
+ }
+ }
+ for range 2 {
+ if err := st.migrateDemo(); err != nil {
+ t.Fatal(err)
+ }
+ }
+ var code []byte
+ var minted int
+ var live []byte
+ if err := st.db.QueryRow(`SELECT claim_code_hash,claim_code_minted,claim_token_hash FROM demo_apps WHERE demo_id=?`, in.Identity.ID).Scan(&code, &minted, &live); err != nil {
+ t.Fatal(err)
+ }
+ if code != nil || minted != 0 || !bytes.Equal(live, in.Identity.TokenHash[:]) {
+ t.Fatalf("migrated row: code=%x minted=%d", code, minted)
+ }
+ var kind string
+ if err := st.db.QueryRow(`SELECT kind FROM demo_spent_tokens`).Scan(&kind); err != nil || kind != "token" {
+ t.Fatalf("migrated spent row kind %q %v", kind, err)
+ }
+ // The pre-release demo's link (its bearer) still claims, and still updates.
+ if _, err := st.LookupDemoClaim(t.Context(), in.Identity.Token); err != nil {
+ t.Fatalf("legacy claim after migration: %v", err)
+ }
+ if _, err := st.LookupDemoUpdate(t.Context(), in.Identity.Token); err != nil {
+ t.Fatalf("legacy update after migration: %v", err)
+ }
+}
+
+func TestDemoClaimCodeNeverLogged(t *testing.T) {
+ var logs bytes.Buffer
+ prev := log.Writer()
+ log.SetOutput(&logs)
+ t.Cleanup(func() { log.SetOutput(prev) })
+ s, _, in := claimTestDemo(t)
+ bearer, code := in.Identity.Token, in.ClaimCode
+ claimPost(s, "/api/demo/claims", map[string]string{"claimToken": bearer, "email": "shop@example.com"})
+ claimPost(s, "/api/demo/claims", map[string]string{"claimCode": code, "email": "shop@example.com"})
+ demoRequest(s, "Bearer "+code, "192.0.2.1")
+ demoRequest(s, "Bearer "+bearer, "192.0.2.1")
+ d, err := s.store.LookupDemoUpdate(t.Context(), bearer)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := s.retireDemoLocked(t.Context(), d, time.Now(), "operator"); err != nil {
+ t.Fatal(err)
+ }
+ if out := logs.String(); strings.Contains(out, bearer) || strings.Contains(out, code) {
+ t.Fatal("a demo secret reached the log")
+ }
+}
diff --git a/internal/console/demo_claim_e2e_test.go b/internal/console/demo_claim_e2e_test.go
index fb9910ca5..df22bb9d2 100644
--- a/internal/console/demo_claim_e2e_test.go
+++ b/internal/console/demo_claim_e2e_test.go
@@ -70,7 +70,7 @@ func claimE2ESource(t *testing.T) (*Server, string, DemoRow) {
return lsfile.NewReplicaClient(filepath.Join(dataRoot, prefix)), nil
})
s.seedScratch = newSeedScratch(t.TempDir(), func(string) (int64, error) { return 4 << 30, nil })
- return s, in.Identity.Token, d
+ return s, in.ClaimCode, d
}
// The fake builder returns workstation-built bytes through the existing result
@@ -294,7 +294,7 @@ func TestDemoClaimEmailToPermanent(t *testing.T) {
if err != nil || life.ExpiresAt != 0 {
t.Fatal("not permanent", err)
}
- if _, err = s.store.LookupDemoToken(t.Context(), token); !errors.Is(err, ErrDemoToken) {
+ if _, err = s.store.LookupDemoClaim(t.Context(), token); !errors.Is(err, ErrDemoToken) {
t.Fatal("claim token lives", err)
}
acct, err := s.store.AccountByID(op.Target.AccountID)
@@ -377,7 +377,7 @@ func TestDemoClaimFailureKeepsDemo(t *testing.T) {
return
}
s, m, token := claimTestServer(t)
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
@@ -416,7 +416,7 @@ func TestDemoClaimFailureKeepsDemo(t *testing.T) {
if err != nil || after.ExpiresAt != before.ExpiresAt {
t.Fatal("TTL reset", err)
}
- if _, err = s.store.LookupDemoToken(t.Context(), token); err != nil {
+ if _, err = s.store.LookupDemoClaim(t.Context(), token); err != nil {
t.Fatal("source token lost", err)
}
})
diff --git a/internal/console/demo_claim_kept_test.go b/internal/console/demo_claim_kept_test.go
index 6846d9806..69028e354 100644
--- a/internal/console/demo_claim_kept_test.go
+++ b/internal/console/demo_claim_kept_test.go
@@ -328,7 +328,7 @@ func TestDemoClaimKeptOperationIsolation(t *testing.T) {
if _, err := s.store.ReserveDemo(t.Context(), in); err != nil {
t.Fatal(err)
}
- f, flow2 := claimProved(t, s, in.Identity.Token, op.Person)
+ f, flow2 := claimProved(t, s, in.ClaimCode, op.Person)
w := claimPost(s, "/api/demo/claims/select", map[string]string{"flowToken": flow2, "accountId": op.Target.Sqid})
// Mixed numeric fields require extracting the URL separately.
var response struct {
diff --git a/internal/console/demo_claim_page.go b/internal/console/demo_claim_page.go
index e7d324d12..089a65c08 100644
--- a/internal/console/demo_claim_page.go
+++ b/internal/console/demo_claim_page.go
@@ -376,7 +376,9 @@ func (s *Server) handleDemoClaimBrowserIntent(w http.ResponseWriter, r *http.Req
if !s.demoClaimBrowserGate(w, r) {
return
}
- d, err := s.store.LookupDemoToken(r.Context(), r.PostForm.Get("claimToken"))
+ // The form field keeps its name; it carries the claim link's fragment, a
+ // claim code (or, for a demo created before claim codes, the old token).
+ d, err := s.store.LookupDemoClaim(r.Context(), r.PostForm.Get("claimToken"))
if err != nil {
if errors.Is(err, ErrDemoToken) {
reason, _ := demoTokenRefusal(err)
diff --git a/internal/console/demo_claim_page_test.go b/internal/console/demo_claim_page_test.go
index e03855204..d6bb0b552 100644
--- a/internal/console/demo_claim_page_test.go
+++ b/internal/console/demo_claim_page_test.go
@@ -236,7 +236,7 @@ func TestDemoClaimBrowserNextDemo(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if w := b.post("/demo/claim/intent", url.Values{"claimToken": {in.Identity.Token}}); w.Code != 303 {
+ if w := b.post("/demo/claim/intent", url.Values{"claimToken": {in.ClaimCode}}); w.Code != 303 {
t.Fatalf("next intent: %d %s", w.Code, w.Body)
}
if b.cookie == old.cookie {
diff --git a/internal/console/demo_claim_resume_test.go b/internal/console/demo_claim_resume_test.go
index f070e339d..dc1eab6de 100644
--- a/internal/console/demo_claim_resume_test.go
+++ b/internal/console/demo_claim_resume_test.go
@@ -189,7 +189,7 @@ func TestDemoClaimSelectStepUpWrongDemo(t *testing.T) {
}
staleNonce = b.nonce
}
- if w := b.post("/demo/claim/intent", url.Values{"claimToken": {inB.Identity.Token}}); w.Code != 303 {
+ if w := b.post("/demo/claim/intent", url.Values{"claimToken": {inB.ClaimCode}}); w.Code != 303 {
t.Fatalf("demo B intent: %d %s", w.Code, w.Body)
}
if !afterMarker {
@@ -204,7 +204,7 @@ func TestDemoClaimSelectStepUpWrongDemo(t *testing.T) {
t.Fatal(err)
}
flow, err := s.store.demoClaimFlowByHash(t.Context(), hash, time.Now())
- demoB, lookupErr := s.store.LookupDemoToken(t.Context(), inB.Identity.Token)
+ demoB, lookupErr := s.store.LookupDemoUpdate(t.Context(), inB.Identity.Token)
if err != nil || lookupErr != nil || flow.DemoID != demoB.ID || b.nonce == staleNonce {
t.Fatalf("manual form is not bound to demo B: %+v %v %v", flow, err, lookupErr)
}
diff --git a/internal/console/demo_claim_target_test.go b/internal/console/demo_claim_target_test.go
index 8ec08e781..e2b62b4c1 100644
--- a/internal/console/demo_claim_target_test.go
+++ b/internal/console/demo_claim_target_test.go
@@ -17,7 +17,7 @@ import (
func claimProved(t *testing.T, s *Server, token, person string) (claimFlow, string) {
t.Helper()
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
@@ -184,7 +184,7 @@ func TestDemoClaimReservation(t *testing.T) {
s, _, token := claimTestServer(t)
f, raw := claimProved(t, s, token, "shop@example.com")
a := claimAccount(t, s, 501, f.Person, role)
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
@@ -216,7 +216,7 @@ func TestDemoClaimReservation(t *testing.T) {
if w.Code != 202 || !strings.Contains(w.Body.String(), `"phase":"reserved"`) {
t.Fatalf("status: %d %s", w.Code, w.Body)
}
- if _, err := s.store.LookupDemoToken(t.Context(), token); err != nil {
+ if _, err := s.store.LookupDemoClaim(t.Context(), token); err != nil {
t.Fatalf("source token: %v", err)
}
})
@@ -232,7 +232,7 @@ func TestDemoClaimReservation(t *testing.T) {
if _, err := s.reserveDemoClaim(t.Context(), f, a, regionReq{explicit: "uk", hasExplicit: true}); err == nil {
t.Fatal("cross-region accepted")
}
- if _, err := s.store.LookupDemoToken(t.Context(), token); err != nil {
+ if _, err := s.store.LookupDemoClaim(t.Context(), token); err != nil {
t.Fatal(err)
}
if n, err := s.runningThings(t.Context(), a); err != nil || n != 0 {
@@ -475,7 +475,7 @@ func TestDemoClaimReservationStalePolicy(t *testing.T) {
s, _, token := claimTestServer(t)
f, _ := claimProved(t, s, token, "shop@example.com")
a := claimAccount(t, s, 501, f.Person, RoleOwner)
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
@@ -507,7 +507,7 @@ func TestDemoClaimReservationFlowErasure(t *testing.T) {
if _, err := s.store.ReserveDemo(t.Context(), in); err != nil {
t.Fatal(err)
}
- g, otherRaw := claimProved(t, s, in.Identity.Token, f.Person)
+ g, otherRaw := claimProved(t, s, in.ClaimCode, f.Person)
if _, err := s.reserveDemoClaim(t.Context(), g, a, regionReq{}); err != nil {
t.Fatal(err)
}
diff --git a/internal/console/demo_claim_transfer.go b/internal/console/demo_claim_transfer.go
index 3bce45b0a..11a897452 100644
--- a/internal/console/demo_claim_transfer.go
+++ b/internal/console/demo_claim_transfer.go
@@ -727,8 +727,9 @@ func (s *Server) commitDemoClaim(ctx context.Context, op claimOp) error {
{`UPDATE apps SET claimed_source=? WHERE account_id=? AND app=? AND demo_claim_op=?`, []any{string(descriptor), op.Target.AccountID, op.Target.App, op.ID}},
{`INSERT INTO demo_claim_commits(operation_id,demo_id,committed_at) VALUES(?,?,?)`, []any{op.ID, op.DemoID, snapshot.ClaimedAt.Unix()}},
{`UPDATE demo_claim_ops SET phase='committed' WHERE id=?`, []any{op.ID}},
- {`INSERT INTO demo_spent_tokens(hash,reason,spent_at) SELECT claim_token_hash,'kept',? FROM demo_apps WHERE demo_id=? AND claim_token_hash IS NOT NULL`, []any{time.Now().Unix(), op.DemoID}},
- {`UPDATE demo_apps SET claim_token_hash=NULL WHERE demo_id=?`, []any{op.DemoID}},
+ {`INSERT INTO demo_spent_tokens(hash,reason,spent_at,kind) SELECT claim_token_hash,'kept',?,CASE claim_code_minted WHEN 1 THEN 'update' ELSE 'token' END FROM demo_apps WHERE demo_id=? AND claim_token_hash IS NOT NULL`, []any{time.Now().Unix(), op.DemoID}},
+ {`INSERT INTO demo_spent_tokens(hash,reason,spent_at,kind) SELECT claim_code_hash,'kept',?,'code' FROM demo_apps WHERE demo_id=? AND claim_code_hash IS NOT NULL`, []any{time.Now().Unix(), op.DemoID}},
+ {`UPDATE demo_apps SET claim_token_hash=NULL,claim_code_hash=NULL WHERE demo_id=?`, []any{op.DemoID}},
{`DELETE FROM demo_claim_flows WHERE demo_id=?`, []any{op.DemoID}},
{`INSERT INTO demo_moved_notices(demo_id,host,target_host,expires_at) VALUES(?,?,?,?)`, []any{op.DemoID, d.Host, op.Target.Host, op.SourceExpiresAt}},
{`INSERT INTO demo_claim_outbox(operation_id,step) VALUES(?,'open'),(?,'moved'),(?,'retire')`, []any{op.ID, op.ID, op.ID}},
diff --git a/internal/console/demo_expiry.go b/internal/console/demo_expiry.go
index a2e02d3e4..145a6187c 100644
--- a/internal/console/demo_expiry.go
+++ b/internal/console/demo_expiry.go
@@ -214,11 +214,15 @@ func (s *Server) retireDemoLocked(ctx context.Context, d DemoRow, now time.Time,
return err
}
if reason != "claimed" {
- if _, err = tx.ExecContext(ctx, `INSERT OR IGNORE INTO demo_spent_tokens(hash,reason,spent_at) SELECT claim_token_hash,?,? FROM demo_apps WHERE demo_id=? AND state='anonymous' AND claim_token_hash IS NOT NULL`, reason, now.Unix(), d.ID); err != nil {
+ if _, err = tx.ExecContext(ctx, `INSERT OR IGNORE INTO demo_spent_tokens(hash,reason,spent_at,kind) SELECT claim_token_hash,?,?,CASE claim_code_minted WHEN 1 THEN 'update' ELSE 'token' END FROM demo_apps WHERE demo_id=? AND state='anonymous' AND claim_token_hash IS NOT NULL`, reason, now.Unix(), d.ID); err != nil {
+ return err
+ }
+ if _, err = tx.ExecContext(ctx, `INSERT OR IGNORE INTO demo_spent_tokens(hash,reason,spent_at,kind) SELECT claim_code_hash,?,?,'code' FROM demo_apps WHERE demo_id=? AND state='anonymous' AND claim_code_hash IS NOT NULL`, reason, now.Unix(), d.ID); err != nil {
return err
}
}
- if _, err = tx.ExecContext(ctx, `UPDATE demo_apps SET state='retiring',generation=generation+1,claim_token_hash=NULL,active_job_id='' WHERE demo_id=? AND state='anonymous'`, d.ID); err != nil {
+ // The claim code dies with the update bearer, whatever the reason.
+ if _, err = tx.ExecContext(ctx, `UPDATE demo_apps SET state='retiring',generation=generation+1,claim_token_hash=NULL,claim_code_hash=NULL,active_job_id='' WHERE demo_id=? AND state='anonymous'`, d.ID); err != nil {
return err
}
if _, err = tx.ExecContext(ctx, `UPDATE demo_jobs SET state='failed',publish_stage='retired' WHERE demo_id=?`, d.ID); err != nil {
diff --git a/internal/console/demo_jobs_test.go b/internal/console/demo_jobs_test.go
index 737881514..45ba8dbf9 100644
--- a/internal/console/demo_jobs_test.go
+++ b/internal/console/demo_jobs_test.go
@@ -333,13 +333,19 @@ func TestDemoJobAdmissionWiring(t *testing.T) {
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
t.Fatal(err)
}
- if response.ClaimToken == "" || response.ClaimAvailable || response.ClaimURL != s.cfg.Origin+"/demo/claim#"+response.ClaimToken {
+ // claimToken is the update bearer; claimUrl's fragment is a separate
+ // claim code for the same demo.
+ code, linked := strings.CutPrefix(response.ClaimURL, s.cfg.Origin+"/demo/claim#")
+ if response.ClaimToken == "" || response.ClaimAvailable || !linked || code == "" || code == response.ClaimToken {
t.Fatal("create credential response")
}
- d, err := s.store.LookupDemoToken(t.Context(), response.ClaimToken)
+ d, err := s.store.LookupDemoUpdate(t.Context(), response.ClaimToken)
if err != nil {
t.Fatal(err)
}
+ if claimed, err := s.store.LookupDemoClaim(t.Context(), code); err != nil || claimed.ID != d.ID {
+ t.Fatalf("claim code does not resolve to the created demo: %v", err)
+ }
life, _ := s.store.AppLife(d.AccountID, d.App)
j, err := s.readDemoJob(t.Context(), response.JobID)
if err != nil || j.Job.Generation != 1 || d.ActiveJobID != response.JobID {
@@ -368,7 +374,7 @@ func TestDemoJobAdmissionWiring(t *testing.T) {
if w.Code != 202 || strings.Contains(w.Body.String(), "claimToken") {
t.Fatalf("update: %d %s", w.Code, w.Body.String())
}
- next, err := s.store.LookupDemoToken(t.Context(), response.ClaimToken)
+ next, err := s.store.LookupDemoUpdate(t.Context(), response.ClaimToken)
if err != nil || next.Generation != 2 || next.ActiveJobID == d.ActiveJobID || next.AssignedBox != d.AssignedBox {
t.Fatalf("generation: %+v %v", next, err)
}
@@ -1305,7 +1311,9 @@ func TestDemoAnonymousWireContract(t *testing.T) {
token, _ = got["claimToken"].(string)
firstName = d.Name
firstExpiry = got["expiresAt"].(float64)
- if token == "" || got["claimAvailable"] != false || got["claimUrl"] != s.cfg.Origin+"/demo/claim#"+token {
+ link, _ := got["claimUrl"].(string)
+ code, ok := strings.CutPrefix(link, s.cfg.Origin+"/demo/claim#")
+ if token == "" || got["claimAvailable"] != false || !ok || code == "" || code == token {
t.Fatalf("claim reply: %v", got)
}
} else if got["name"] != firstName || got["expiresAt"] != firstExpiry {
diff --git a/internal/console/demo_spent_token_test.go b/internal/console/demo_spent_token_test.go
index 716ebb37c..8252f80d7 100644
--- a/internal/console/demo_spent_token_test.go
+++ b/internal/console/demo_spent_token_test.go
@@ -20,8 +20,12 @@ import (
func TestDemoSpentTokenSurfaces(t *testing.T) {
for _, state := range []string{"expired", "expired-live", "kept", "taken-down", "invalid", "malformed"} {
t.Run(state, func(t *testing.T) {
- s, m, token := claimTestServer(t)
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ // token is the claim code (the claim link's fragment); bearer is
+ // the update bearer. Each surface sees only its own credential's
+ // spent reason; the other credential reads as plainly invalid.
+ s, m, in := claimTestDemo(t)
+ token, bearer := in.ClaimCode, in.Identity.Token
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
@@ -65,38 +69,58 @@ func TestDemoSpentTokenSurfaces(t *testing.T) {
t.Fatal(err)
}
case "kept":
- if _, err := s.store.db.Exec(`INSERT INTO demo_spent_tokens(hash,reason,spent_at) SELECT claim_token_hash,'kept',? FROM demo_apps WHERE demo_id=?`, time.Now().Unix(), d.ID); err != nil {
- t.Fatal(err)
+ for _, q := range []string{
+ `INSERT INTO demo_spent_tokens(hash,reason,spent_at,kind) SELECT claim_token_hash,'kept',?,'update' FROM demo_apps WHERE demo_id=?`,
+ `INSERT INTO demo_spent_tokens(hash,reason,spent_at,kind) SELECT claim_code_hash,'kept',?,'code' FROM demo_apps WHERE demo_id=?`,
+ } {
+ if _, err := s.store.db.Exec(q, time.Now().Unix(), d.ID); err != nil {
+ t.Fatal(err)
+ }
}
- if _, err := s.store.db.Exec(`UPDATE demo_apps SET claim_token_hash=NULL WHERE demo_id=?`, d.ID); err != nil {
+ if _, err := s.store.db.Exec(`UPDATE demo_apps SET claim_token_hash=NULL,claim_code_hash=NULL WHERE demo_id=?`, d.ID); err != nil {
t.Fatal(err)
}
case "invalid":
- if token[0] == 'A' {
- token = "B" + token[1:]
- } else {
- token = "A" + token[1:]
+ flip := func(v string) string {
+ if v[0] == 'A' {
+ return "B" + v[1:]
+ }
+ return "A" + v[1:]
}
+ token, bearer = flip(token), flip(bearer)
case "malformed":
reason = "invalid"
token += "="
+ bearer += "="
}
- row, err := s.store.LookupDemoToken(t.Context(), token)
typed := map[string]error{"expired": ErrDemoExpired, "kept": ErrDemoKept, "taken-down": ErrDemoTakenDown, "invalid": ErrDemoToken}
- if !errors.Is(err, typed[reason]) {
- t.Errorf("wrong typed error: %v", err)
- }
- if !errors.Is(err, ErrDemoToken) || row != (DemoRow{}) {
- t.Fatalf("lookup authorized: %+v %v", row, err)
+ for _, l := range []struct {
+ name string
+ lookup func(context.Context, string) (DemoRow, error)
+ own string
+ other string
+ }{{"claim", s.store.LookupDemoClaim, token, bearer}, {"update", s.store.LookupDemoUpdate, bearer, token}} {
+ row, err := l.lookup(t.Context(), l.own)
+ if !errors.Is(err, typed[reason]) {
+ t.Errorf("%s: wrong typed error: %v", l.name, err)
+ }
+ if !errors.Is(err, ErrDemoToken) || row != (DemoRow{}) {
+ t.Fatalf("%s lookup authorized: %+v %v", l.name, row, err)
+ }
+ // The other door's credential, spent or not, explains nothing.
+ row, err = l.lookup(t.Context(), l.other)
+ if err != ErrDemoToken || row != (DemoRow{}) {
+ t.Fatalf("%s lookup of the other credential: %+v %v", l.name, row, err)
+ }
}
- check := func(surface string, w *httptest.ResponseRecorder) {
+ check := func(surface string, w *httptest.ResponseRecorder, reason string) {
t.Helper()
var got map[string]string
if w.Code != 401 || json.Unmarshal(w.Body.Bytes(), &got) != nil || got["reason"] != reason {
t.Errorf("%s: %d %s; want %s", surface, w.Code, w.Body, reason)
return
}
- if surface == "intent" {
+ if strings.HasPrefix(surface, "intent") {
if len(got) != 1 {
t.Errorf("intent exposed more than reason: %v", got)
}
@@ -109,10 +133,15 @@ func TestDemoSpentTokenSurfaces(t *testing.T) {
}
b := &claimBrowser{t: t, s: s}
b.request("GET", "/demo/claim", nil)
- check("intent", b.post("/demo/claim/intent", url.Values{"claimToken": {token}}))
+ check("intent", b.post("/demo/claim/intent", url.Values{"claimToken": {token}}), reason)
_, w = claimStart(t, s, token, "other@example.com", "")
- check("start", w)
- check("update", demoRequest(s, "Bearer "+token, "192.0.2.10").ResponseRecorder)
+ check("start", w, reason)
+ check("update", demoRequest(s, "Bearer "+bearer, "192.0.2.10").ResponseRecorder, reason)
+ b.request("GET", "/demo/claim", nil)
+ check("intent with bearer", b.post("/demo/claim/intent", url.Values{"claimToken": {bearer}}), "invalid")
+ _, w = claimStart(t, s, bearer, "other@example.com", "")
+ check("start with bearer", w, "invalid")
+ check("update with code", demoRequest(s, "Bearer "+token, "192.0.2.10").ResponseRecorder, "invalid")
if state != "invalid" && state != "malformed" {
if w := claimVerify(s, flow, code); w.Code < 400 {
t.Fatalf("old flow verified: %d", w.Code)
@@ -151,22 +180,25 @@ func TestDemoSpentTokenClearingPaths(t *testing.T) {
t.Run(reason, func(t *testing.T) {
var s *Server
var d DemoRow
- var token string
+ var token, code string
if reason == "claimed" {
server, op, data := claimTransferFixture(t)
s = server
d, _ = s.store.demoByID(t.Context(), op.DemoID)
token, _ = randomToken()
- raw, _ := base64.RawURLEncoding.DecodeString(token)
- hash := sha256.Sum256(raw)
- if _, err := s.store.db.Exec(`UPDATE demo_apps SET claim_token_hash=? WHERE demo_id=?`, hash[:], d.ID); err != nil {
+ code, _ = randomToken()
+ hash, _ := demoSecretHash(token)
+ codeHash, _ := demoSecretHash(code)
+ if _, err := s.store.db.Exec(`UPDATE demo_apps SET claim_token_hash=?,claim_code_hash=? WHERE demo_id=? AND claim_code_minted=1`, hash[:], codeHash[:], d.ID); err != nil {
t.Fatal(err)
}
claimToVerify(t, s, op, data)
claimAdvance(t, s, op)
} else {
- s, _, token = claimTestServer(t)
- d, _ = s.store.LookupDemoToken(t.Context(), token)
+ var in DemoAdmission
+ s, _, in = claimTestDemo(t)
+ token, code = in.Identity.Token, in.ClaimCode
+ d, _ = s.store.LookupDemoUpdate(t.Context(), token)
now := time.Now()
if reason == "expired" {
now = time.Unix(d.CreatedAt+86400, 0)
@@ -177,19 +209,27 @@ func TestDemoSpentTokenClearingPaths(t *testing.T) {
}
raw, _ := base64.RawURLEncoding.DecodeString(token)
hash := sha256.Sum256(raw)
+ codeHash, _ := demoSecretHash(code)
check := func() {
t.Helper()
- var live, spent []byte
- if err := s.store.db.QueryRow(`SELECT claim_token_hash,(SELECT hash FROM demo_spent_tokens WHERE hash=?) FROM demo_apps WHERE demo_id=?`, hash[:], d.ID).Scan(&live, &spent); err != nil {
+ var live, liveCode, spent, spentCode []byte
+ var kind, codeKind string
+ if err := s.store.db.QueryRow(`SELECT claim_token_hash,claim_code_hash,(SELECT hash FROM demo_spent_tokens WHERE hash=?),(SELECT kind FROM demo_spent_tokens WHERE hash=?),(SELECT hash FROM demo_spent_tokens WHERE hash=?),(SELECT kind FROM demo_spent_tokens WHERE hash=?) FROM demo_apps WHERE demo_id=?`, hash[:], hash[:], codeHash[:], codeHash[:], d.ID).Scan(&live, &liveCode, &spent, &kind, &spentCode, &codeKind); err != nil {
t.Fatal(err)
}
- if len(live) != 0 || !bytes.Equal(spent, hash[:]) {
- t.Fatal("spent hash lost or live token retained")
+ if len(live) != 0 || !bytes.Equal(spent, hash[:]) || kind != "update" {
+ t.Fatalf("spent hash lost or live token retained (kind %q)", kind)
+ }
+ if len(liveCode) != 0 || !bytes.Equal(spentCode, codeHash[:]) || codeKind != "code" {
+ t.Fatalf("spent claim code lost or live code retained (kind %q)", codeKind)
}
want := map[string]error{"expired": ErrDemoExpired, "operator": ErrDemoTakenDown, "claimed": ErrDemoKept}[reason]
- if _, err := s.store.LookupDemoToken(t.Context(), token); !errors.Is(err, want) || !errors.Is(err, ErrDemoToken) {
+ if _, err := s.store.LookupDemoUpdate(t.Context(), token); !errors.Is(err, want) || !errors.Is(err, ErrDemoToken) {
t.Fatalf("spent token reason lost: %v", err)
}
+ if _, err := s.store.LookupDemoClaim(t.Context(), code); !errors.Is(err, want) || !errors.Is(err, ErrDemoToken) {
+ t.Fatalf("spent claim code reason lost: %v", err)
+ }
}
check()
if reason == "claimed" {
@@ -216,9 +256,12 @@ func TestDemoSpentTokenClearingPaths(t *testing.T) {
if err := s.store.WipeDemoAbuse(t.Context(), future); err != nil {
t.Fatal(err)
}
- if _, err := s.store.LookupDemoToken(t.Context(), token); !errors.Is(err, map[string]error{"expired": ErrDemoExpired, "operator": ErrDemoTakenDown, "claimed": ErrDemoKept}[reason]) {
+ if _, err := s.store.LookupDemoUpdate(t.Context(), token); !errors.Is(err, map[string]error{"expired": ErrDemoExpired, "operator": ErrDemoTakenDown, "claimed": ErrDemoKept}[reason]) {
t.Fatalf("spent token reason lost after demo wipe: %v", err)
}
+ if _, err := s.store.LookupDemoClaim(t.Context(), code); !errors.Is(err, map[string]error{"expired": ErrDemoExpired, "operator": ErrDemoTakenDown, "claimed": ErrDemoKept}[reason]) {
+ t.Fatalf("spent claim code reason lost after demo wipe: %v", err)
+ }
if _, err := s.store.demoByID(t.Context(), d.ID); !errors.Is(err, sql.ErrNoRows) {
t.Fatalf("purged demo row retained: %v", err)
}
@@ -255,7 +298,7 @@ func TestDemoSpentTokenMigration(t *testing.T) {
if !bytes.Equal(live, in.Identity.TokenHash[:]) || spent != 0 {
t.Fatal("migration changed live credential")
}
- if _, err := st.LookupDemoToken(t.Context(), in.Identity.Token); err != nil {
+ if _, err := st.LookupDemoUpdate(t.Context(), in.Identity.Token); err != nil {
t.Fatal(err)
}
}
@@ -270,7 +313,7 @@ func TestDemoSpentTokenBrowserHeadless(t *testing.T) {
t.Skip("no installed node")
}
s, _, token := claimTestServer(t)
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
@@ -299,7 +342,7 @@ func TestDemoSpentTokenBrowserHeadless(t *testing.T) {
func TestDemoSpentTokenDecode(t *testing.T) {
s, _, token := claimTestServer(t)
- d, err := s.store.LookupDemoToken(t.Context(), token)
+ d, err := s.store.LookupDemoClaim(t.Context(), token)
if err != nil {
t.Fatal(err)
}
@@ -309,9 +352,11 @@ func TestDemoSpentTokenDecode(t *testing.T) {
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
noncanonical := token[:42] + string(alphabet[strings.IndexByte(alphabet, token[42])|1])
for _, bad := range []string{"", token + "=", token[:42], "!" + token[1:], noncanonical, base64.RawURLEncoding.EncodeToString(make([]byte, 33)), d.ID, d.Name, d.Host} {
- row, err := s.store.LookupDemoToken(t.Context(), bad)
- if err != ErrDemoToken || row != (DemoRow{}) {
- t.Errorf("malformed or non-token lookup: %+v %v", row, err)
+ for _, lookup := range []func(context.Context, string) (DemoRow, error){s.store.LookupDemoClaim, s.store.LookupDemoUpdate} {
+ row, err := lookup(t.Context(), bad)
+ if err != ErrDemoToken || row != (DemoRow{}) {
+ t.Errorf("malformed or non-token lookup: %+v %v", row, err)
+ }
}
}
}
@@ -334,7 +379,7 @@ func TestDemoSpentTokenAtomicClearing(t *testing.T) {
} else {
server, _, token := claimTestServer(t)
s = server
- d, _ = s.store.LookupDemoToken(t.Context(), token)
+ d, _ = s.store.LookupDemoClaim(t.Context(), token)
if _, err := s.store.db.Exec(`CREATE TRIGGER fail_after_spend BEFORE UPDATE ON demo_serving BEGIN SELECT RAISE(ABORT,'injected'); END`); err != nil {
t.Fatal(err)
}
@@ -344,19 +389,22 @@ func TestDemoSpentTokenAtomicClearing(t *testing.T) {
}
clear = func() error { return s.retireDemoLocked(t.Context(), d, now, reason) }
}
- var before []byte
- if err := s.store.db.QueryRow(`SELECT claim_token_hash FROM demo_apps WHERE demo_id=?`, d.ID).Scan(&before); err != nil {
+ var before, beforeCode []byte
+ if err := s.store.db.QueryRow(`SELECT claim_token_hash,claim_code_hash FROM demo_apps WHERE demo_id=?`, d.ID).Scan(&before, &beforeCode); err != nil {
t.Fatal(err)
}
+ if len(beforeCode) != 32 {
+ t.Fatal("fixture demo has no claim code")
+ }
if err := clear(); err == nil {
t.Fatal("missing injected failure")
}
- var live []byte
+ var live, liveCode []byte
var spent, receipts int
- if err := s.store.db.QueryRow(`SELECT claim_token_hash,(SELECT count(*) FROM demo_spent_tokens),(SELECT count(*) FROM demo_claim_commits WHERE demo_id=d.demo_id) FROM demo_apps d WHERE demo_id=?`, d.ID).Scan(&live, &spent, &receipts); err != nil {
+ if err := s.store.db.QueryRow(`SELECT claim_token_hash,claim_code_hash,(SELECT count(*) FROM demo_spent_tokens),(SELECT count(*) FROM demo_claim_commits WHERE demo_id=d.demo_id) FROM demo_apps d WHERE demo_id=?`, d.ID).Scan(&live, &liveCode, &spent, &receipts); err != nil {
t.Fatal(err)
}
- if !bytes.Equal(live, before) || spent != 0 || receipts != 0 {
+ if !bytes.Equal(live, before) || !bytes.Equal(liveCode, beforeCode) || spent != 0 || receipts != 0 {
t.Fatal("partial credential spend survived rollback")
}
})
@@ -388,7 +436,7 @@ func TestDemoSpentTokenRetention(t *testing.T) {
if err := st.WipeDemoAbuse(t.Context(), now); err != nil {
t.Fatal(err)
}
- if _, err := st.LookupDemoToken(t.Context(), token); err != tc.want {
+ if _, err := st.LookupDemoUpdate(t.Context(), token); err != tc.want {
t.Fatalf("lookup: %v; want %v", err, tc.want)
}
var n int
diff --git a/internal/console/demo_store.go b/internal/console/demo_store.go
index ffd1d4af4..d5494ac12 100644
--- a/internal/console/demo_store.go
+++ b/internal/console/demo_store.go
@@ -10,6 +10,7 @@ import (
"encoding/base64"
"errors"
"fmt"
+ "slices"
"strings"
"time"
@@ -51,7 +52,10 @@ type DemoAdmission struct {
Config demo.Config
SourceSHA256 [32]byte
Client string
- job func(context.Context, *sql.Tx, DemoRow, AppLife) error
+ // ClaimCode is the raw claim code claimUrl carries. It can only start a
+ // claim; Identity.Token stays the update bearer. Only its hash is stored.
+ ClaimCode string `json:"-"`
+ job func(context.Context, *sql.Tx, DemoRow, AppLife) error
}
func (s *Store) migrateDemo() error {
@@ -87,6 +91,9 @@ CREATE TABLE IF NOT EXISTS demo_retirements(demo_id TEXT PRIMARY KEY, wire BLOB
if err != nil {
return err
}
+ if err := s.migrateDemoClaimCode(); err != nil {
+ return err
+ }
if err := s.migrateDemoServing(); err != nil {
return err
}
@@ -105,6 +112,28 @@ CREATE TABLE IF NOT EXISTS demo_retirements(demo_id TEXT PRIMARY KEY, wire BLOB
return s.migrateDemoJobs()
}
+// migrateDemoClaimCode only adds columns (and a partial unique index on the
+// new hash). A row created before the claim code existed keeps
+// claim_code_minted=0 and NULL claim_code_hash: its claim link still carries
+// the update bearer, and LookupDemoClaim accepts that bearer for it alone.
+// demo_spent_tokens.kind says which door a spent hash used to open: 'token'
+// is the old dual-purpose bearer (every row before this column), 'update' a
+// bearer whose demo had a separate claim code, 'code' that claim code.
+func (s *Store) migrateDemoClaimCode() error {
+ ctx := context.Background()
+ for _, stmt := range []string{
+ `ALTER TABLE demo_apps ADD COLUMN claim_code_hash BLOB CHECK(claim_code_hash IS NULL OR length(claim_code_hash)=32)`,
+ `ALTER TABLE demo_apps ADD COLUMN claim_code_minted INTEGER NOT NULL DEFAULT 0 CHECK(claim_code_minted IN (0,1))`,
+ `ALTER TABLE demo_spent_tokens ADD COLUMN kind TEXT NOT NULL DEFAULT 'token' CHECK(kind IN ('token','update','code'))`,
+ } {
+ if _, err := s.db.ExecContext(ctx, stmt); err != nil && !strings.Contains(err.Error(), "duplicate column") {
+ return err
+ }
+ }
+ _, err := s.db.ExecContext(ctx, `CREATE UNIQUE INDEX IF NOT EXISTS demo_apps_claim_code ON demo_apps(claim_code_hash) WHERE claim_code_hash IS NOT NULL`)
+ return err
+}
+
// demoTx takes SQLite's writer lock before any admission reads. It serialises
// count-and-reserve even when two Store handles open the same database.
func (s *Store) demoTx(ctx context.Context) (*sql.Tx, error) {
@@ -226,6 +255,10 @@ func (s *Store) ReserveDemo(ctx context.Context, in DemoAdmission) (DemoRow, err
return zero, ErrDemoToken
}
hash := sha256.Sum256(raw)
+ codeHash, ok := demoSecretHash(in.ClaimCode)
+ if !ok || subtle.ConstantTimeCompare(codeHash[:], hash[:]) == 1 {
+ return zero, demo.ErrConfig
+ }
id, err := base64.RawURLEncoding.Strict().DecodeString(in.Identity.ID)
if err != nil || len(id) != 16 || !c.Enabled || !c.EdgeProtections || c.Validate() != nil || in.AccountID == OpsAccountID || in.AccountSqid != c.Account || in.Fleet != c.Fleet || in.Host != in.Identity.Name+"."+c.Domain || !demo.ValidPublicName(in.Identity.Name) || in.Identity.App != demo.AppPrefix+in.Identity.Name || subtle.ConstantTimeCompare(hash[:], in.Identity.TokenHash[:]) != 1 || in.Now.IsZero() {
return zero, demo.ErrConfig
@@ -278,7 +311,7 @@ func (s *Store) ReserveDemo(ctx context.Context, in DemoAdmission) (DemoRow, err
if len(client) > 100 {
client = strings.ToValidUTF8(client[:100], "")
}
- _, err = tx.ExecContext(ctx, `INSERT INTO demo_apps(demo_id,account_id,account_sqid,app,name,host,fleet,claim_token_hash,created_at,creating_ip,source_sha256,client) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)`, in.Identity.ID, in.AccountID, in.AccountSqid, in.Identity.App, in.Identity.Name, in.Host, in.Fleet, hash[:], in.Now.Unix(), ip, in.SourceSHA256[:], client)
+ _, err = tx.ExecContext(ctx, `INSERT INTO demo_apps(demo_id,account_id,account_sqid,app,name,host,fleet,claim_token_hash,claim_code_hash,claim_code_minted,created_at,creating_ip,source_sha256,client) VALUES(?,?,?,?,?,?,?,?,?,1,?,?,?,?)`, in.Identity.ID, in.AccountID, in.AccountSqid, in.Identity.App, in.Identity.Name, in.Host, in.Fleet, hash[:], codeHash[:], in.Now.Unix(), ip, in.SourceSHA256[:], client)
if err != nil {
return zero, err
}
@@ -328,17 +361,29 @@ func (s *Store) demoByID(ctx context.Context, id string) (DemoRow, error) {
return scanDemo(s.db.QueryRowContext(ctx, `SELECT `+demoCols+` FROM demo_apps WHERE demo_id=?`, id))
}
-func (s *Store) LookupDemoToken(ctx context.Context, token string) (DemoRow, error) {
- raw, err := base64.RawURLEncoding.Strict().DecodeString(token)
+// demoSecretHash decodes a 32-byte base64url secret (update bearer or claim
+// code) and returns the SHA-256 the store keeps. The raw value is never stored.
+func demoSecretHash(secret string) ([32]byte, bool) {
+ raw, err := base64.RawURLEncoding.Strict().DecodeString(secret)
if err != nil || len(raw) != 32 {
+ return [32]byte{}, false
+ }
+ return sha256.Sum256(raw), true
+}
+
+// LookupDemoUpdate resolves the update bearer (the create response's
+// claimToken). A claim code is never in claim_token_hash, so it cannot update;
+// a spent claim code explains nothing here either.
+func (s *Store) LookupDemoUpdate(ctx context.Context, token string) (DemoRow, error) {
+ hash, ok := demoSecretHash(token)
+ if !ok {
return DemoRow{}, ErrDemoToken
}
- hash := sha256.Sum256(raw)
var id string
var stored []byte
- err = s.db.QueryRowContext(ctx, `SELECT demo_id,claim_token_hash FROM demo_apps WHERE claim_token_hash=?`, hash[:]).Scan(&id, &stored)
+ err := s.db.QueryRowContext(ctx, `SELECT demo_id,claim_token_hash FROM demo_apps WHERE claim_token_hash=?`, hash[:]).Scan(&id, &stored)
if errors.Is(err, sql.ErrNoRows) {
- return DemoRow{}, s.spentDemoTokenError(ctx, hash[:])
+ return DemoRow{}, s.spentDemoTokenError(ctx, hash[:], "token", "update")
}
if err != nil {
return DemoRow{}, err
@@ -346,6 +391,38 @@ func (s *Store) LookupDemoToken(ctx context.Context, token string) (DemoRow, err
if subtle.ConstantTimeCompare(hash[:], stored) != 1 {
return DemoRow{}, ErrDemoToken
}
+ return s.liveDemo(ctx, id)
+}
+
+// LookupDemoClaim resolves the credential a claim link carries. A demo minted
+// with a claim code accepts only that code, and only while its update bearer
+// is unspent, so the code dies exactly when the bearer does. A demo created
+// before claim codes existed (claim_code_minted=0) has the update bearer in its
+// link, and only such a row accepts the bearer here.
+func (s *Store) LookupDemoClaim(ctx context.Context, credential string) (DemoRow, error) {
+ hash, ok := demoSecretHash(credential)
+ if !ok {
+ return DemoRow{}, ErrDemoToken
+ }
+ var id string
+ var stored []byte
+ err := s.db.QueryRowContext(ctx, `SELECT demo_id,claim_code_hash FROM demo_apps WHERE claim_code_hash=? AND claim_code_minted=1 AND claim_token_hash IS NOT NULL`, hash[:]).Scan(&id, &stored)
+ if errors.Is(err, sql.ErrNoRows) {
+ err = s.db.QueryRowContext(ctx, `SELECT demo_id,claim_token_hash FROM demo_apps WHERE claim_token_hash=? AND claim_code_minted=0 AND claim_code_hash IS NULL`, hash[:]).Scan(&id, &stored)
+ }
+ if errors.Is(err, sql.ErrNoRows) {
+ return DemoRow{}, s.spentDemoTokenError(ctx, hash[:], "token", "code")
+ }
+ if err != nil {
+ return DemoRow{}, err
+ }
+ if subtle.ConstantTimeCompare(hash[:], stored) != 1 {
+ return DemoRow{}, ErrDemoToken
+ }
+ return s.liveDemo(ctx, id)
+}
+
+func (s *Store) liveDemo(ctx context.Context, id string) (DemoRow, error) {
row, err := s.demoByID(ctx, id)
if err != nil {
return DemoRow{}, err
@@ -364,17 +441,20 @@ func (s *Store) LookupDemoToken(ctx context.Context, token string) (DemoRow, err
}
// Spent hashes explain a refusal only; this path never returns a demo row.
-func (s *Store) spentDemoTokenError(ctx context.Context, hash []byte) error {
+// kinds limits the explanation to the credentials the caller's door accepts,
+// so a spent claim code reads as invalid at update and a spent update bearer
+// reads as invalid at claim.
+func (s *Store) spentDemoTokenError(ctx context.Context, hash []byte, kinds ...string) error {
var stored []byte
- var reason string
- err := s.db.QueryRowContext(ctx, `SELECT hash,reason FROM demo_spent_tokens WHERE hash=?`, hash).Scan(&stored, &reason)
+ var reason, kind string
+ err := s.db.QueryRowContext(ctx, `SELECT hash,reason,kind FROM demo_spent_tokens WHERE hash=?`, hash).Scan(&stored, &reason, &kind)
if errors.Is(err, sql.ErrNoRows) {
return ErrDemoToken
}
if err != nil {
return err
}
- if subtle.ConstantTimeCompare(hash, stored) != 1 {
+ if subtle.ConstantTimeCompare(hash, stored) != 1 || !slices.Contains(kinds, kind) {
return ErrDemoToken
}
switch reason {
diff --git a/internal/console/demo_store_test.go b/internal/console/demo_store_test.go
index ebdbc551e..1fad03a3b 100644
--- a/internal/console/demo_store_test.go
+++ b/internal/console/demo_store_test.go
@@ -48,7 +48,11 @@ func demoTestAdmission(t *testing.T, cfg demo.Config) DemoAdmission {
if err != nil {
t.Fatal(err)
}
- return DemoAdmission{Identity: id, AccountID: 42, AccountSqid: "shop", Host: id.Name + "." + cfg.Domain, Fleet: cfg.Fleet, IP: "192.0.2.1", Now: time.Now(), Config: cfg, SourceSHA256: sha256.Sum256([]byte("archive")), Client: strings.Repeat("x", 120)}
+ code, err := randomToken()
+ if err != nil {
+ t.Fatal(err)
+ }
+ return DemoAdmission{Identity: id, ClaimCode: code, AccountID: 42, AccountSqid: "shop", Host: id.Name + "." + cfg.Domain, Fleet: cfg.Fleet, IP: "192.0.2.1", Now: time.Now(), Config: cfg, SourceSHA256: sha256.Sum256([]byte("archive")), Client: strings.Repeat("x", 120)}
}
func TestDemoAdmissionDurableAndAtomic(t *testing.T) {
t.Run("ceiling", func(t *testing.T) {
@@ -162,7 +166,7 @@ func TestDemoIdentityStored(t *testing.T) {
if string(stored) != string(hash[:]) || string(stored) == in.Identity.Token {
t.Fatal("persistedToken != SHA256(rawToken)")
}
- got, err := st.LookupDemoToken(t.Context(), in.Identity.Token)
+ got, err := st.LookupDemoUpdate(t.Context(), in.Identity.Token)
if err != nil || got.ID != row.ID {
t.Fatalf("lookup: %+v %v", got, err)
}
@@ -196,7 +200,7 @@ func TestDemoUpdateAuthorityStore(t *testing.T) {
if life.ExpiresAt != in.Now.Add(24*time.Hour).Unix() {
t.Fatal("update extended expiry")
}
- if _, err := st.LookupDemoToken(t.Context(), "bad"); !errors.Is(err, ErrDemoToken) {
+ if _, err := st.LookupDemoUpdate(t.Context(), "bad"); !errors.Is(err, ErrDemoToken) {
t.Fatalf("invalid token: %v", err)
}
if _, err := st.db.Exec(`UPDATE demo_apps SET update_attempts=0, active_job_id='job' WHERE demo_id=?`, row.ID); err != nil {
@@ -217,7 +221,7 @@ func TestDemoUpdateAuthorityStore(t *testing.T) {
t.Fatalf("lock callback: %v", err)
}
st.db.Exec(`UPDATE apps SET expires_at=? WHERE demo_id=?`, time.Now().Add(-time.Second).Unix(), row.ID)
- if _, err := st.LookupDemoToken(t.Context(), in.Identity.Token); !errors.Is(err, ErrDemoToken) {
+ if _, err := st.LookupDemoUpdate(t.Context(), in.Identity.Token); !errors.Is(err, ErrDemoToken) {
t.Fatalf("expired token: %v", err)
}
}