feat(core): one-time install tokens that register a host to a team

Installing on a host should be a command a person pastes, not a user
session copied onto a machine. A token is issued for a team, spent by its
first use, expires after an hour and is stored only as a digest, because
it travels in that command and so lands in shell history.

Redeeming is one conditional update inside the registration transaction:
concurrent redemptions of one token register exactly one machine, and a
registration that fails leaves the token unspent.
This commit is contained in:
Wanjohi
2026-09-28 08:36:09 +03:00
parent 451b495de6
commit f691b56c0c
7 changed files with 3910 additions and 124 deletions
@@ -0,0 +1,18 @@
CREATE TABLE "install_token" (
"id" char(30) PRIMARY KEY NOT NULL,
"time_created" timestamp with time zone DEFAULT now() NOT NULL,
"time_updated" timestamp with time zone DEFAULT now() NOT NULL,
"time_deleted" timestamp with time zone,
"team_id" char(30) NOT NULL,
"created_by_user_id" char(30) NOT NULL,
"token_hash" text NOT NULL,
"expires_at" timestamp with time zone NOT NULL,
"redeemed_at" timestamp with time zone,
"machine_id" char(30)
);
--> statement-breakpoint
ALTER TABLE "install_token" ADD CONSTRAINT "install_token_team_id_team_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."team"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "install_token" ADD CONSTRAINT "install_token_created_by_user_id_user_id_fk" FOREIGN KEY ("created_by_user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "install_token" ADD CONSTRAINT "install_token_machine_id_machine_id_fk" FOREIGN KEY ("machine_id") REFERENCES "public"."machine"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "install_token_hash_unique" ON "install_token" USING btree ("token_hash");--> statement-breakpoint
CREATE INDEX "install_token_team_idx" ON "install_token" USING btree ("team_id");
File diff suppressed because it is too large Load Diff
+131 -124
View File
@@ -1,125 +1,132 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1784801002476,
"tag": "0000_quick_dark_phoenix",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1785312635128,
"tag": "0001_opposite_senator_kelly",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1785379712946,
"tag": "0002_light_mesmero",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1785382013687,
"tag": "0003_many_pyro",
"breakpoints": true
},
{
"idx": 4,
"version": "7",
"when": 1785588097470,
"tag": "0004_remove_user_download_add_game_download",
"breakpoints": true
},
{
"idx": 5,
"version": "7",
"when": 1785909838801,
"tag": "0005_flaky_may_parker",
"breakpoints": true
},
{
"idx": 6,
"version": "7",
"when": 1786205230097,
"tag": "0006_waitlist_verification_game_aliases",
"breakpoints": true
},
{
"idx": 7,
"version": "7",
"when": 1788460224524,
"tag": "0007_box_session_team_notnull",
"breakpoints": true
},
{
"idx": 8,
"version": "7",
"when": 1788547836146,
"tag": "0008_session_one_active_run_per_box",
"breakpoints": true
},
{
"idx": 9,
"version": "7",
"when": 1788555252186,
"tag": "0009_email_is_the_root_identity",
"breakpoints": true
},
{
"idx": 10,
"version": "7",
"when": 1788590292860,
"tag": "0010_device_authorization_grant",
"breakpoints": true
},
{
"idx": 11,
"version": "7",
"when": 1788607804606,
"tag": "0011_auth_state_in_postgres",
"breakpoints": true
},
{
"idx": 12,
"version": "7",
"when": 1788691753961,
"tag": "0012_steam_enrolment_without_a_token",
"breakpoints": true
},
{
"idx": 13,
"version": "7",
"when": 1788725541386,
"tag": "0013_machine_endpoint_id",
"breakpoints": true
},
{
"idx": 14,
"version": "7",
"when": 1789680491539,
"tag": "0014_machine_public_label",
"breakpoints": true
},
{
"idx": 15,
"version": "7",
"when": 1789762221718,
"tag": "0015_organisation_owns_fleet_hardware",
"breakpoints": true
},
{
"idx": 16,
"version": "7",
"when": 1789765075037,
"tag": "0016_burn_counters_and_rate_segments",
"breakpoints": true
}
]
}
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1784801002476,
"tag": "0000_quick_dark_phoenix",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1785312635128,
"tag": "0001_opposite_senator_kelly",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1785379712946,
"tag": "0002_light_mesmero",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1785382013687,
"tag": "0003_many_pyro",
"breakpoints": true
},
{
"idx": 4,
"version": "7",
"when": 1785588097470,
"tag": "0004_remove_user_download_add_game_download",
"breakpoints": true
},
{
"idx": 5,
"version": "7",
"when": 1785909838801,
"tag": "0005_flaky_may_parker",
"breakpoints": true
},
{
"idx": 6,
"version": "7",
"when": 1786205230097,
"tag": "0006_waitlist_verification_game_aliases",
"breakpoints": true
},
{
"idx": 7,
"version": "7",
"when": 1788460224524,
"tag": "0007_box_session_team_notnull",
"breakpoints": true
},
{
"idx": 8,
"version": "7",
"when": 1788547836146,
"tag": "0008_session_one_active_run_per_box",
"breakpoints": true
},
{
"idx": 9,
"version": "7",
"when": 1788555252186,
"tag": "0009_email_is_the_root_identity",
"breakpoints": true
},
{
"idx": 10,
"version": "7",
"when": 1788590292860,
"tag": "0010_device_authorization_grant",
"breakpoints": true
},
{
"idx": 11,
"version": "7",
"when": 1788607804606,
"tag": "0011_auth_state_in_postgres",
"breakpoints": true
},
{
"idx": 12,
"version": "7",
"when": 1788691753961,
"tag": "0012_steam_enrolment_without_a_token",
"breakpoints": true
},
{
"idx": 13,
"version": "7",
"when": 1788725541386,
"tag": "0013_machine_endpoint_id",
"breakpoints": true
},
{
"idx": 14,
"version": "7",
"when": 1789680491539,
"tag": "0014_machine_public_label",
"breakpoints": true
},
{
"idx": 15,
"version": "7",
"when": 1789762221718,
"tag": "0015_organisation_owns_fleet_hardware",
"breakpoints": true
},
{
"idx": 16,
"version": "7",
"when": 1789765075037,
"tag": "0016_burn_counters_and_rate_segments",
"breakpoints": true
},
{
"idx": 17,
"version": "7",
"when": 1790573670492,
"tag": "0017_install_token",
"breakpoints": true
}
]
}