diff --git a/.github/workflows/hgsp2-security.yml b/.github/workflows/hgsp2-security.yml index 2e0cf84e..17522ac8 100644 --- a/.github/workflows/hgsp2-security.yml +++ b/.github/workflows/hgsp2-security.yml @@ -6,6 +6,9 @@ on: - 'OpenSim/Framework/HGSP2Authorization.cs' - 'OpenSim/Server/Handlers/Inventory/**' - 'OpenSim/Data/IPresenceData.cs' + - 'OpenSim/Data/*/Resources/HGTravelStore.migrations' + - 'tools/ci/verify_hgsp2_travel_schema.py' + - 'tools/ci/smoke_hypergrid_login.sh' - 'OpenSim/Data/MySQL/MySQLPresenceData.cs' - 'OpenSim/Services/PresenceService/PresenceService.cs' - 'tools/ci/HGSP2PresenceRegression/**' @@ -31,6 +34,8 @@ jobs: dotnet-version: '10.0.x' - name: Verify isolated ES256 signed authorization and rejection paths run: dotnet run --project tools/ci/HGSP2SecurityRegression/HGSP2SecurityRegression.csproj -c Release + - name: Verify versioned HGSP2 travel migrations and legacy compatibility + run: python3 tools/ci/verify_hgsp2_travel_schema.py - name: Generate existing OpenGenesisLINK server projects run: bash runprebuild.sh - name: Compile full .NET 10 server including Hypergrid public handlers diff --git a/OpenSim/Data/MySQL/Resources/HGTravelStore.migrations b/OpenSim/Data/MySQL/Resources/HGTravelStore.migrations index 62b99870..43b87a33 100644 --- a/OpenSim/Data/MySQL/Resources/HGTravelStore.migrations +++ b/OpenSim/Data/MySQL/Resources/HGTravelStore.migrations @@ -22,3 +22,6 @@ ALTER TABLE `hg_traveling_data` MODIFY `TMStamp` timestamp NOT NULL default CURR COMMIT; +:VERSION 3 # HGSP2 travel binding (legacy sessions keep empty value) + +ALTER TABLE `hg_traveling_data` ADD COLUMN `HGSP2Trip` VARCHAR(36) NOT NULL DEFAULT ''; diff --git a/OpenSim/Data/PGSQL/Resources/HGTravelStore.migrations b/OpenSim/Data/PGSQL/Resources/HGTravelStore.migrations index adf126d7..528082d7 100644 --- a/OpenSim/Data/PGSQL/Resources/HGTravelStore.migrations +++ b/OpenSim/Data/PGSQL/Resources/HGTravelStore.migrations @@ -15,3 +15,6 @@ CREATE TABLE hg_traveling_data ( COMMIT; +:VERSION 2 # HGSP2 travel binding (legacy sessions keep empty value) + +ALTER TABLE hg_traveling_data ADD COLUMN "HGSP2Trip" VARCHAR(36) NOT NULL DEFAULT ''; diff --git a/OpenSim/Data/SQLite/Resources/HGTravelStore.migrations b/OpenSim/Data/SQLite/Resources/HGTravelStore.migrations index 02612ce1..eb01a1bc 100644 --- a/OpenSim/Data/SQLite/Resources/HGTravelStore.migrations +++ b/OpenSim/Data/SQLite/Resources/HGTravelStore.migrations @@ -16,3 +16,6 @@ CREATE TABLE hg_traveling_data( COMMIT; +:VERSION 3 # HGSP2 travel binding (legacy sessions keep empty value) + +ALTER TABLE hg_traveling_data ADD COLUMN HGSP2Trip VARCHAR(36) NOT NULL DEFAULT ""; diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs index b846aeeb..88117f39 100644 --- a/OpenSim/Services/HypergridService/UserAgentService.cs +++ b/OpenSim/Services/HypergridService/UserAgentService.cs @@ -840,11 +840,16 @@ namespace OpenSim.Services.HypergridService { ["GridExternalName"] = travel.GridExternalName, ["ServiceToken"] = travel.ServiceToken, - ["ClientIPAddress"] = travel.ClientIPAddress, - ["HGSP2Trip"] = travel.HGSP2Trip + ["ClientIPAddress"] = travel.ClientIPAddress } }; + // Legacy HG sessions never require the new column on their write path. + // Secure travel always binds a persisted trip identifier so the + // inventory guard can reject grants for other/replaced sessions. + if (!String.IsNullOrEmpty(travel.HGSP2Trip)) + hgt.Data["HGSP2Trip"] = travel.HGSP2Trip; + m_Database.Store(hgt); } #endregion diff --git a/doc/OpenGenesisLINK/HGSP2_TRAVEL_SCHEMA.md b/doc/OpenGenesisLINK/HGSP2_TRAVEL_SCHEMA.md new file mode 100644 index 00000000..0b2951eb --- /dev/null +++ b/doc/OpenGenesisLINK/HGSP2_TRAVEL_SCHEMA.md @@ -0,0 +1,15 @@ +# HGSP2 travel binding – regression and migration + +The HGSP2 security branch originally added `HGSP2Trip` to the `HGTravelingData.Data` map without a corresponding database column. Existing `hg_traveling_data` tables rejected every HomeAgent login with HTTP 500 (`no column named HGSP2Trip`). This is a server-side migration regression, unrelated to the Viewer. + +The schema is upgraded **forward** in each supported provider with `HGSP2Trip VARCHAR(36) NOT NULL DEFAULT ''`: + +- SQLite: `HGTravelStore.migrations` version 3 (following version 2). +- MariaDB/MySQL: version 3 (following version 2). +- PostgreSQL: version 2 (following version 1). + +Existing rows retain a blank trip ID, which **cannot** pass HGSP2 inventory authorization. Legacy HomeAgent/Gatekeeper connections write only the original columns. A successful pinned-peer HGSP2 travel writes its signed, random trip ID and the inventory guard requires the stored ID to match the grant's trip, session, avatar and destination. No fallback from a failed authenticated request to unauthenticated inventory access is permitted. + +Tests: `python3 tools/ci/verify_hgsp2_travel_schema.py` and `bash tools/ci/smoke_hypergrid_login.sh` (in disposable CI instances only). The latter checks the migrated column and verifies that legacy sessions remain unbound. The `HGSP2 security and no-downgrade regression` job covers cryptographic grants separately. + +**Deployment restriction:** The source change is not a production migration instruction. Never deploy a migration to live HG databases without a tested transaction/backup, migration dry run, rollback plan and operator approval. HGSP2 remains disabled in production until all CI, peer interoperability and database upgrades have been accepted. The existing PR #448 is still a draft until that occurs. diff --git a/tools/ci/smoke_hypergrid_login.sh b/tools/ci/smoke_hypergrid_login.sh index c4c761ce..44ba9c59 100644 --- a/tools/ci/smoke_hypergrid_login.sh +++ b/tools/ci/smoke_hypergrid_login.sh @@ -147,6 +147,19 @@ if [ "$HG_OK" -ne 1 ]; then exit 1 fi +# The HGSP2 extension must migrate the existing HG travel table while +# retaining the legacy HomeAgent/Gatekeeper login and its empty trip binding. +python3 - "$SOURCE_DB" <<'PYSQL' +import sqlite3 +import sys +with sqlite3.connect(sys.argv[1], timeout=3) as db: + columns = {row[1] for row in db.execute("PRAGMA table_info(hg_traveling_data)")} + assert "HGSP2Trip" in columns, "HGSP2 travel-id migration missing" + rows = db.execute("SELECT HGSP2Trip FROM hg_traveling_data").fetchall() + assert rows and all(row[0] == "" for row in rows), "Legacy travel unexpectedly bound to HGSP2" +print("HGSP2 travel-schema migration + legacy session default: OK") +PYSQL + grep -F "[USER AGENT SERVICE]: Request to login user NexVerseCI Resident" "$SOURCE_LOG" grep -F "desired grid: http://127.0.0.1:19300/" "$SOURCE_LOG" grep -F "[GATEKEEPER SERVICE]: Login request for NexVerseCI Resident" "$DEST_LOG" diff --git a/tools/ci/verify_hgsp2_travel_schema.py b/tools/ci/verify_hgsp2_travel_schema.py new file mode 100644 index 00000000..f72ddc5c --- /dev/null +++ b/tools/ci/verify_hgsp2_travel_schema.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +"""Regression contract: HGSP2 travel-id migration across all SQL providers.""" +from pathlib import Path +root = Path(__file__).resolve().parents[2] +for backend, version in (("SQLite", 3), ("MySQL", 3), ("PGSQL", 2)): + file = root / f"OpenSim/Data/{backend}/Resources/HGTravelStore.migrations" + schema = file.read_text(encoding="utf-8-sig") + assert f":VERSION {version}" in schema, backend + assert "ADD COLUMN" in schema and "HGSP2Trip" in schema, backend + assert "NOT NULL DEFAULT" in schema, backend + print(f"{backend}: versioned HGSP2Trip migration present") +service = (root / "OpenSim/Services/HypergridService/UserAgentService.cs").read_text() +assert 'if (!String.IsNullOrEmpty(travel.HGSP2Trip))' in service +assert 'hgt.Data["HGSP2Trip"] = travel.HGSP2Trip;' in service +guard = (root / "OpenSim/Server/Handlers/Inventory/HGSP2InventoryGuard.cs").read_text() +assert 'record.Data.TryGetValue("HGSP2Trip"' in guard +smoke = (root / "tools/ci/smoke_hypergrid_login.sh").read_text() +assert 'PRAGMA table_info(hg_traveling_data)' in smoke +assert 'SELECT HGSP2Trip FROM hg_traveling_data' in smoke +print("HGSP2 travel schema, legacy safety and inventory session binding: PASS")