Skip to content

Commit e1c0dd8

Browse files
committed
fix(selfhost): use ORB_WEBHOOK_SECRET/ORB_APP_ID in Orb collector + drop AUTOINCREMENT from Orb migrations
Use the Orb-specific env vars (ORB_WEBHOOK_SECRET, ORB_APP_ID) in exportOrbBatch and instanceId() instead of the main app's GITHUB_WEBHOOK_SECRET/GITHUB_APP_ID — prevents empty-string HMAC signing when only the Orb secret is set. Drop AUTOINCREMENT from orb_events/orb_installations DDL so the Postgres migration adapter accepts both tables (it translates INTEGER PRIMARY KEY but not AUTOINCREMENT).
1 parent 7d692b7 commit e1c0dd8

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

migrations/0056_orb_events.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- export job to batch-send calibration signals to the central collector (opt-in) or
44
-- to keep them local for operator-only analysis (ORB_AIR_GAP=true).
55
CREATE TABLE IF NOT EXISTS orb_events (
6-
id INTEGER PRIMARY KEY AUTOINCREMENT,
6+
id INTEGER PRIMARY KEY,
77
repo TEXT NOT NULL,
88
pr_number INTEGER NOT NULL,
99
head_sha TEXT NOT NULL,

migrations/0057_orb_installations.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Gittensory Orb (#1219): tracks which repos have the Orb GitHub App installed.
22
-- `removed_at IS NULL` = currently installed; set on uninstall/removal events.
33
CREATE TABLE IF NOT EXISTS orb_installations (
4-
id INTEGER PRIMARY KEY AUTOINCREMENT,
4+
id INTEGER PRIMARY KEY,
55
installation_id INTEGER NOT NULL,
66
repo TEXT NOT NULL,
77
installed_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),

src/selfhost/orb-collector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ interface OrbExportPayload {
4646
}>;
4747
}
4848

49-
/** Stable instance identifier (hash of the App ID — no PII). */
49+
/** Stable instance identifier (hash of the Orb App ID — no PII). */
5050
function instanceId(): string {
51-
return createHash("sha256").update(process.env.GITHUB_APP_ID ?? "unknown").digest("hex").slice(0, 16);
51+
return createHash("sha256").update(process.env.ORB_APP_ID ?? "unknown").digest("hex").slice(0, 16);
5252
}
5353

5454
/** HMAC a string with the webhook secret for anonymized export. */
@@ -93,7 +93,7 @@ export async function exportOrbBatch(
9393
if ((process.env.ORB_AIR_GAP ?? "").toLowerCase() === "true") return 0;
9494

9595
const collectorUrl = process.env.ORB_COLLECTOR_URL ?? "https://orb.gittensory.app/v1/ingest";
96-
const secret = process.env.GITHUB_WEBHOOK_SECRET ?? "";
96+
const secret = process.env.ORB_WEBHOOK_SECRET ?? "";
9797
const anonymize = (process.env.ORB_ANONYMIZE ?? "true").toLowerCase() !== "false";
9898

9999
const { results } = await db

test/unit/selfhost-orb-collector.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ describe("exportOrbBatch()", () => {
116116
beforeEach(() => {
117117
resetMetrics();
118118
process.env.ORB_ENABLED = "true";
119-
process.env.GITHUB_WEBHOOK_SECRET = "test-secret";
119+
process.env.ORB_WEBHOOK_SECRET = "test-secret";
120120
process.env.ORB_ANONYMIZE = "true";
121121
delete process.env.ORB_AIR_GAP;
122122
delete process.env.ORB_COLLECTOR_URL;
123123
});
124124
afterEach(() => {
125125
delete process.env.ORB_ENABLED;
126-
process.env.GITHUB_WEBHOOK_SECRET = undefined as unknown as string;
126+
process.env.ORB_WEBHOOK_SECRET = undefined as unknown as string;
127127
delete process.env.ORB_ANONYMIZE;
128128
delete process.env.ORB_AIR_GAP;
129129
delete process.env.ORB_COLLECTOR_URL;
@@ -228,8 +228,8 @@ describe("exportOrbBatch()", () => {
228228
expect(sigHeader).toMatch(/^sha256=[a-f0-9]{64}$/);
229229
});
230230

231-
it("uses empty-string HMAC key when GITHUB_WEBHOOK_SECRET is unset (covers ?? '' branch)", async () => {
232-
delete (process.env as NodeJS.Dict<string>)["GITHUB_WEBHOOK_SECRET"];
231+
it("uses empty-string HMAC key when ORB_WEBHOOK_SECRET is unset (covers ?? '' branch)", async () => {
232+
delete (process.env as NodeJS.Dict<string>)["ORB_WEBHOOK_SECRET"];
233233
const db = makeDb();
234234
await recordOrbEvent(db, { repo: "o/r", pr_number: 1, head_sha: "sha", outcome: "merged" });
235235
let sigHeader: string | undefined;

0 commit comments

Comments
 (0)