@bongos/core 1.21.93 → 1.21.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bongos-core.json +55 -35
- package/clients/bongos-client/README.md +1 -1
- package/clients/bongos-client/bongos-client.global.js +2 -0
- package/clients/bongos-client/index.cjs +2 -0
- package/clients/bongos-client/index.d.ts +4 -2
- package/clients/bongos-client/index.mjs +2 -0
- package/docs/api/openapi.json +38 -7
- package/docs/api-reference.md +4 -3
- package/docs/copy-inventory.md +354 -354
- package/docs/copy-registry.json +420 -420
- package/docs/design/project-startup-direction.md +7 -0
- package/docs/module-api-changelog.md +2 -0
- package/docs/page-readings.json +963 -992
- package/modules/provisioning/github-setup.js +129 -0
- package/modules/provisioning/module.json +2 -1
- package/modules/provisioning/provisioning.js +3 -0
- package/modules/provisioning/routes/callback-page.js +66 -1
- package/modules/provisioning/routes/github-setup.js +113 -0
- package/modules/provisioning/routes/provisioning.js +11 -45
- package/modules/public-landing/public/projects.html +105 -57
- package/package-lock.json +2 -2
- package/package.json +1 -1
- package/release-notes.json +6 -0
- package/scripts/gds/oauth-secret.js +4 -2
- package/scripts/gds/provision-github-setup.js +148 -0
- package/scripts/gds/provision.js +19 -5
- package/src/module-api.js +1 -1
- package/tests/github_one_trip.mjs +297 -0
- package/tests/projects_hub_dns_ready.mjs +2 -1
- package/tests/projects_hub_pre_uat.mjs +17 -9
- package/tests/provision.mjs +51 -9
- package/tests/provisioning_github_app_routes.mjs +94 -8
- package/tests/wizard_github_feedback.mjs +8 -5
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// modules/provisioning/github-setup.js — "Connect GitHub" in one trip, and the checklist
|
|
4
|
+
// that ticks itself (task 1004649; the design of record is docs/design/mocks/day-night-rooms/
|
|
5
|
+
// part 03: Approve the <name> app on GitHub · Install it on your repo · Builders can sign in ·
|
|
6
|
+
// Command-line sign-in is on).
|
|
7
|
+
//
|
|
8
|
+
// WHY. A founder used to make three separate trips to github.com after Create (approve the
|
|
9
|
+
// app, tick "Enable Device Flow", install the app on the repo), and nothing ever checked the
|
|
10
|
+
// last two. Now the manifest carries a setup_url, so GitHub sends the founder from "app
|
|
11
|
+
// created" straight on to "install it on your repo" and then back to the project page — and
|
|
12
|
+
// every tick on the checklist is a fact the SERVER has seen, never a click the page assumed:
|
|
13
|
+
//
|
|
14
|
+
// approve — GitHub created the app AND the runner placed its credentials (the runner
|
|
15
|
+
// records the app's slug only after the placement write, provision.js).
|
|
16
|
+
// install — the runner, holding the app's own key, asked GitHub whether the app is
|
|
17
|
+
// installed on the project's repo and GitHub said yes ('github-app-installed').
|
|
18
|
+
// The installation_id GitHub appends to the setup_url is NOT trusted: GitHub's
|
|
19
|
+
// docs warn it can be spoofed, so that redirect only records that the founder
|
|
20
|
+
// SAYS they installed it ('github-app-install-reported'), which makes the
|
|
21
|
+
// runner look again.
|
|
22
|
+
// sign_in — the runner saw the project report auth_configured (the manifest row 'done').
|
|
23
|
+
// device — the runner started a device-flow sign-in with the app's client id and GitHub
|
|
24
|
+
// did not refuse it with device_flow_disabled ('github-app-device-flow').
|
|
25
|
+
// GitHub offers no manifest field and no API to switch device flow on (the
|
|
26
|
+
// spike in this task, written up in docs/design/project-startup-direction.md),
|
|
27
|
+
// so this step is OPTIONAL: it reads 'later' until the founder ticks the box on
|
|
28
|
+
// GitHub, and it never holds the project back from being alive.
|
|
29
|
+
//
|
|
30
|
+
// No new columns (ADR 0083 §5 additive rule; this task carries no migration): the verified
|
|
31
|
+
// facts are rows of the existing append-only provisioning_events ledger, read since the
|
|
32
|
+
// latest attempt began. The db is injected.
|
|
33
|
+
|
|
34
|
+
// The provisioning_events names this leg writes. One table, so the runner (which writes the
|
|
35
|
+
// verified ones), the setup redirect (which writes the reported one) and the reader agree.
|
|
36
|
+
const SETUP_EVENTS = Object.freeze({
|
|
37
|
+
installReported: 'github-app-install-reported',
|
|
38
|
+
installed: 'github-app-installed',
|
|
39
|
+
deviceFlow: 'github-app-device-flow',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// How long after an attempt settles the runner keeps checking for the install and the
|
|
43
|
+
// device-flow tick. Past it the checklist stops promising a self-tick for device flow
|
|
44
|
+
// (the step says "turn it on later"); a fresh install report re-opens the window.
|
|
45
|
+
const VERIFY_WINDOW_MS = 2 * 60 * 60 * 1000;
|
|
46
|
+
|
|
47
|
+
// The one-trip install page for the app GitHub just created, carrying the attempt's state
|
|
48
|
+
// so GitHub hands it back on the setup_url redirect. null until the app's slug is known.
|
|
49
|
+
// PURE. (The callback page narrows it to the repo with /permissions?suggested_target_id
|
|
50
|
+
// when it can learn the numeric ids — see callback-page.js.)
|
|
51
|
+
function installUrlFor({ appSlug, state } = {}) {
|
|
52
|
+
if (!appSlug) return null;
|
|
53
|
+
const q = state ? `?state=${encodeURIComponent(state)}` : '';
|
|
54
|
+
return `https://github.com/apps/${encodeURIComponent(appSlug)}/installations/new${q}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// owner/repo from the instance's target_ref, or null. Strict — this string reaches a
|
|
58
|
+
// public read and the callback page's GitHub lookup.
|
|
59
|
+
const REPO_REF_RE = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/;
|
|
60
|
+
function targetRepo(inst) {
|
|
61
|
+
const ref = String((inst && inst.target_ref) || '').trim().replace(/\.git$/, '');
|
|
62
|
+
return REPO_REF_RE.test(ref) ? ref : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The verified facts for one instance since `since` (the attempt's created_at): when each
|
|
66
|
+
// setup event was first seen, or null. One indexed read (idx_provisioning_events_instance).
|
|
67
|
+
async function githubSetupFacts(db, instanceId, since) {
|
|
68
|
+
const { rows } = await db.query(
|
|
69
|
+
`SELECT event, min(created_at) AS at FROM provisioning_events
|
|
70
|
+
WHERE instance_id = $1 AND event = ANY($2) AND created_at >= $3
|
|
71
|
+
GROUP BY event`,
|
|
72
|
+
[instanceId, Object.values(SETUP_EVENTS), since || new Date(0).toISOString()]);
|
|
73
|
+
const at = (name) => {
|
|
74
|
+
const r = rows.find((x) => x.event === name);
|
|
75
|
+
return r && r.at ? new Date(r.at).toISOString() : null;
|
|
76
|
+
};
|
|
77
|
+
return { installReportedAt: at(SETUP_EVENTS.installReported), installedAt: at(SETUP_EVENTS.installed), deviceFlowAt: at(SETUP_EVENTS.deviceFlow) };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Each checklist step's state, from the latest attempt's EFFECTIVE status (manifest-truth's
|
|
81
|
+
// vocabulary) + the facts above. A closed vocabulary the page turns into words:
|
|
82
|
+
// 'done' · 'now' (waiting on GitHub, the founder or the platform) · 'todo' (not reached)
|
|
83
|
+
// · 'stopped' (this attempt failed at this step) · 'later' (device flow only: optional, off).
|
|
84
|
+
// PURE.
|
|
85
|
+
function githubChecklist(status, appSlug, facts = {}) {
|
|
86
|
+
const s = String(status || '');
|
|
87
|
+
const inFlight = s === 'pending' || s === 'code_received' || s === 'converting';
|
|
88
|
+
const failed = s === 'error' || s === 'expired';
|
|
89
|
+
const approve = appSlug ? 'done' : inFlight ? 'now' : failed ? 'stopped' : 'todo';
|
|
90
|
+
const install = facts.installedAt ? 'done' : appSlug ? 'now' : 'todo';
|
|
91
|
+
const signIn = s === 'done' ? 'done' : appSlug && failed ? 'stopped' : appSlug ? 'now' : 'todo';
|
|
92
|
+
const device = facts.deviceFlowAt ? 'done' : s === 'done' ? 'later' : 'todo';
|
|
93
|
+
return {
|
|
94
|
+
approve, install, sign_in: signIn, device_flow: device,
|
|
95
|
+
// what "is alive" waits for — device flow is optional by design
|
|
96
|
+
connected: approve === 'done' && install === 'done' && signIn === 'done',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Is the runner still checking this attempt? While it is, an install or a 'later'
|
|
101
|
+
// device-flow step can still tick itself, so the page keeps polling. PURE.
|
|
102
|
+
function stillVerifying(row, facts = {}, now = Date.now()) {
|
|
103
|
+
const settled = row && (row.resolved_at || row.updated_at);
|
|
104
|
+
const last = Math.max(settled ? new Date(settled).getTime() : 0, facts.installReportedAt ? new Date(facts.installReportedAt).getTime() : 0);
|
|
105
|
+
return last > 0 && now - last < VERIFY_WINDOW_MS;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// What the public status poll and the owner's instance read add for this leg: the checklist,
|
|
109
|
+
// the install link (until the install is verified), the repo it belongs on, and whether the
|
|
110
|
+
// runner is still checking. `status` is manifest-truth's EFFECTIVE status. Never the raw row.
|
|
111
|
+
// `withState` false (the owner's instance read) leaves the state token off the install
|
|
112
|
+
// link: that read never carries the token (task 1003235), and a stateless install still
|
|
113
|
+
// lands on the setup page, which sends the founder back to their projects.
|
|
114
|
+
// A failed facts read is "nothing verified yet" — the honest 'now' states, never a 500.
|
|
115
|
+
async function githubSetupRead(db, inst, row, status, { now = Date.now(), withState = true } = {}) {
|
|
116
|
+
if (!row) return { checklist: githubChecklist(null, null), install_url: null, repo: targetRepo(inst), verifying: false };
|
|
117
|
+
let facts = {};
|
|
118
|
+
// through module.exports so a route test can stub the one DB read on the cached module
|
|
119
|
+
try { facts = await module.exports.githubSetupFacts(db, row.instance_id, row.created_at); } catch (_) { facts = {}; }
|
|
120
|
+
const checklist = githubChecklist(status, row.app_slug, facts);
|
|
121
|
+
return {
|
|
122
|
+
checklist,
|
|
123
|
+
install_url: checklist.install === 'done' ? null : installUrlFor({ appSlug: row.app_slug, state: withState ? row.state : null }),
|
|
124
|
+
repo: targetRepo(inst),
|
|
125
|
+
verifying: stillVerifying(row, facts, now),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = { SETUP_EVENTS, VERIFY_WINDOW_MS, installUrlFor, targetRepo, githubSetupFacts, githubChecklist, stillVerifying, githubSetupRead };
|
|
@@ -754,6 +754,9 @@ function buildGithubAppManifest({ instanceName, slug, instanceDomain, mothership
|
|
|
754
754
|
// is never called while inactive; point it at the mothership so it's a real host.
|
|
755
755
|
hook_attributes: { url: `${String(mothershipOrigin || '').replace(/\/+$/, '')}/api/bongos/provisioning/github-app/webhook`, active: false },
|
|
756
756
|
redirect_url: redirectUrl,
|
|
757
|
+
// One trip (task 1004649): after the install GitHub sends the founder here with the
|
|
758
|
+
// attempt's state, and the route hands them back to the project page.
|
|
759
|
+
setup_url: redirectUrl.replace(/\/callback$/, '/setup'), setup_on_update: true,
|
|
757
760
|
callback_urls: [
|
|
758
761
|
`${instOrigin}/api/gds/auth/web/callback`,
|
|
759
762
|
`${instOrigin}/api/bongos/auth/web/callback`,
|
|
@@ -82,13 +82,65 @@ const HANDBACK_SCRIPT = `
|
|
|
82
82
|
})();
|
|
83
83
|
`;
|
|
84
84
|
|
|
85
|
+
// Client script for the ONE-TRIP variant (task 1004649). GitHub just created the app and
|
|
86
|
+
// sent the founder here; the runner now turns GitHub's code into credentials and names the
|
|
87
|
+
// app. This page waits for that name on the state-keyed status poll, then sends the founder
|
|
88
|
+
// straight on to installing the app — narrowed to the project's own repo when GitHub will
|
|
89
|
+
// tell an anonymous caller the repo's numeric ids (a public repo; a private one falls back
|
|
90
|
+
// to the plain install page, where GitHub asks which account). GitHub's setup_url brings
|
|
91
|
+
// them back to the checklist afterwards. Already installed, or the attempt stopped → back
|
|
92
|
+
// to the checklist at once, which says what happened. A wait past five minutes stops and
|
|
93
|
+
// says so; the way back is always on the page. Same no-backtick / no-${...} rule as above.
|
|
94
|
+
const INSTALL_SCRIPT = `
|
|
95
|
+
(function(){
|
|
96
|
+
var cfg=window.__CB_SETUP__||{};
|
|
97
|
+
var back=cfg.back||'/projects?view=new';
|
|
98
|
+
if(cfg.state)back+='#ghstate='+encodeURIComponent(cfg.state);
|
|
99
|
+
var link=document.getElementById('back');if(link)link.href=back;
|
|
100
|
+
var note=document.getElementById('note');
|
|
101
|
+
var say=function(t){if(note)note.textContent=t;};
|
|
102
|
+
var tries=0,MAX=150;
|
|
103
|
+
function narrow(base,ownerId,repoId){
|
|
104
|
+
var parts=String(base).split('?');
|
|
105
|
+
return parts[0]+'/permissions?'+(parts[1]?parts[1]+'&':'')+'suggested_target_id='+encodeURIComponent(ownerId)+'&repository_ids[]='+encodeURIComponent(repoId);
|
|
106
|
+
}
|
|
107
|
+
function go(url){say('Opening the install page on GitHub…');location.replace(url);}
|
|
108
|
+
function toInstall(d){
|
|
109
|
+
if(!d.repo){go(d.install_url);return;}
|
|
110
|
+
fetch('https://api.github.com/repos/'+d.repo,{headers:{Accept:'application/vnd.github+json'}})
|
|
111
|
+
.then(function(r){return r.ok?r.json():null;})
|
|
112
|
+
.then(function(j){go(j&&j.id&&j.owner&&j.owner.id?narrow(d.install_url,j.owner.id,j.id):d.install_url);})
|
|
113
|
+
.catch(function(){go(d.install_url);});
|
|
114
|
+
}
|
|
115
|
+
function tick(){
|
|
116
|
+
tries++;
|
|
117
|
+
fetch('/api/bongos/provisioning/github-app/status?state='+encodeURIComponent(cfg.state||''))
|
|
118
|
+
.then(function(r){return r.ok?r.json():null;})
|
|
119
|
+
.then(function(d){
|
|
120
|
+
if(d&&d.checklist&&d.checklist.install==='done'){location.replace(back);return;}
|
|
121
|
+
if(d&&(d.status==='error'||d.status==='expired')){location.replace(back);return;}
|
|
122
|
+
if(d&&d.install_url){toInstall(d);return;}
|
|
123
|
+
again();
|
|
124
|
+
})
|
|
125
|
+
.catch(again);
|
|
126
|
+
}
|
|
127
|
+
function again(){
|
|
128
|
+
if(tries>=MAX){say('This is taking longer than usual. Go back to your project: the install step waits for you there.');return;}
|
|
129
|
+
setTimeout(tick,2000);
|
|
130
|
+
}
|
|
131
|
+
tick();
|
|
132
|
+
})();
|
|
133
|
+
`;
|
|
134
|
+
|
|
85
135
|
// The standalone landing page for the public GitHub redirect (the mothership serves it;
|
|
86
136
|
// it is NOT the hall shell). Two variants share the Cloud Bongos brand shell (task 2096):
|
|
87
137
|
// • hand-back — ok + state + domain: a brief "GitHub app created" that returns the
|
|
88
138
|
// founder to their setup checklist, where the wait is shown (task 1004548).
|
|
139
|
+
// • install — the hand-back's inputs + next:'install' (task 1004649): "GitHub app
|
|
140
|
+
// created", then straight on to installing it on the repo (INSTALL_SCRIPT).
|
|
89
141
|
// • message — everything else (errors + the no-domain success fallback): a calm badge
|
|
90
142
|
// + `body` (server-authored, trusted HTML).
|
|
91
|
-
function callbackPage({ ok, title, body, state, domain }) {
|
|
143
|
+
function callbackPage({ ok, title, body, state, domain, next }) {
|
|
92
144
|
const handback = !!(ok && state && domain);
|
|
93
145
|
const cfgJson = JSON.stringify({ state: state || '', domain: domain || '', back: '/projects?view=new' }).replace(/</g, '\\u003c');
|
|
94
146
|
const head = `<!doctype html><html lang="en"><head><meta charset="utf-8">
|
|
@@ -98,6 +150,19 @@ function callbackPage({ ok, title, body, state, domain }) {
|
|
|
98
150
|
<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
99
151
|
<link href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;700;800&family=Quicksand:wght@400;500;600;700&family=Fira+Code&display=swap" rel="stylesheet">
|
|
100
152
|
<style>${PAGE_STYLE}</style></head><body>`;
|
|
153
|
+
if (handback && next === 'install') {
|
|
154
|
+
return `${head}
|
|
155
|
+
<main class="card">
|
|
156
|
+
<div class="badge-warn">✓</div>
|
|
157
|
+
<h1>${esc(title)}</h1>
|
|
158
|
+
<p class="sub">Next, install it on your repo. Taking you there now.</p>
|
|
159
|
+
<p class="muted" id="note" role="status" aria-live="polite">Waiting for GitHub to hand over the app…</p>
|
|
160
|
+
<div class="cta"><a class="btn" id="back" href="/projects?view=new">Back to my project</a></div>
|
|
161
|
+
</main>
|
|
162
|
+
<script>window.__CB_SETUP__=${cfgJson};</script>
|
|
163
|
+
<script>${INSTALL_SCRIPT}</script>
|
|
164
|
+
</body></html>`;
|
|
165
|
+
}
|
|
101
166
|
if (handback) {
|
|
102
167
|
return `${head}
|
|
103
168
|
<main class="card">
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// modules/provisioning/routes/github-setup.js — the GitHub leg's two PUBLIC, state-keyed
|
|
2
|
+
// routes: the progress poll the project page and the callback page read, and the setup_url
|
|
3
|
+
// GitHub sends the founder to after installing the app (task 1004649 — "Connect GitHub in
|
|
4
|
+
// one trip"; ADR 0133 is the manifest design).
|
|
5
|
+
//
|
|
6
|
+
// Its own routes file (declared in module.json) because routes/provisioning.js sits at the
|
|
7
|
+
// 1500-line size ratchet; the status poll moved here from it unchanged in key and contract.
|
|
8
|
+
// Both routes are public by the same model as the manifest callback: the unguessable,
|
|
9
|
+
// single-use `state` minted for the signed-in owner is the only key, and neither route
|
|
10
|
+
// reveals a secret or changes authority. The checklist they report is derived in
|
|
11
|
+
// ../github-setup.js from what the control-plane runner has VERIFIED.
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
const express = require('express');
|
|
15
|
+
const api = require('../../../src/module-api');
|
|
16
|
+
const { pool } = api;
|
|
17
|
+
const provisioning = require('../provisioning');
|
|
18
|
+
const githubSetup = require('../github-setup');
|
|
19
|
+
const { makeAskRateLimiter } = require('../rate-limit');
|
|
20
|
+
const { callbackPage } = require('./callback-page');
|
|
21
|
+
|
|
22
|
+
const log = api.logger('provisioning');
|
|
23
|
+
|
|
24
|
+
// GitHub's installation id is digits; anything else is dropped before it reaches a log line.
|
|
25
|
+
function installationIdOf(q) {
|
|
26
|
+
const s = String((q && q.installation_id) || '');
|
|
27
|
+
return /^\d{1,20}$/.test(s) ? s : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = function buildGithubSetupRouter() {
|
|
31
|
+
const router = express.Router();
|
|
32
|
+
// the page polls every few seconds, the callback page every two — per-IP, in-module
|
|
33
|
+
const statusRateLimit = makeAskRateLimiter({ max: 120 });
|
|
34
|
+
const setupRateLimit = makeAskRateLimiter({ max: 30 });
|
|
35
|
+
|
|
36
|
+
// GET /provisioning/github-app/status?state=<> — the PUBLIC progress read (task 1004548;
|
|
37
|
+
// the checklist since task 1004649). Reveals the manifest lifecycle status, the
|
|
38
|
+
// instance's own (already-public) domain and repo, the App's public slug, and the
|
|
39
|
+
// four-step checklist with the one-trip install link — never a secret. `ready` is true
|
|
40
|
+
// iff sign-in is verified (the auto-open signal). `terminal` now waits for the install
|
|
41
|
+
// too: a finished sign-in with the app not yet installed is not the end of the trip.
|
|
42
|
+
// rank: public — no session, no mutation, no secret; an unknown state is a 404 no-op.
|
|
43
|
+
router.get('/provisioning/github-app/status', statusRateLimit, async (req, res) => {
|
|
44
|
+
try {
|
|
45
|
+
const state = String(req.query.state || '');
|
|
46
|
+
if (!state) return res.status(400).json({ ok: false, error: 'missing_state' });
|
|
47
|
+
const row = await provisioning.getOAuthManifestByState(pool, state);
|
|
48
|
+
if (!row) return res.status(404).json({ ok: false, error: 'unknown_state' });
|
|
49
|
+
const inst = await provisioning.getInstanceById(pool, row.instance_id).catch(() => null);
|
|
50
|
+
// EFFECTIVE status + how far a failure got (task 1004572, manifest-truth.js)
|
|
51
|
+
const { status, failure } = provisioning.publicGithubApp(row);
|
|
52
|
+
const setup = await githubSetup.githubSetupRead(pool, inst, row, status);
|
|
53
|
+
const failed = status === 'error' || status === 'expired';
|
|
54
|
+
return res.json({
|
|
55
|
+
ok: true,
|
|
56
|
+
status,
|
|
57
|
+
failure,
|
|
58
|
+
ready: status === 'done',
|
|
59
|
+
terminal: failed || (setup.checklist.connected && (setup.checklist.device_flow === 'done' || !setup.verifying)),
|
|
60
|
+
domain: inst && inst.domain ? inst.domain : null,
|
|
61
|
+
instance_status: inst ? inst.status : null,
|
|
62
|
+
// The App's public slug (task 1003049) — its GitHub page is public by design.
|
|
63
|
+
app_slug: row.app_slug || null,
|
|
64
|
+
checklist: setup.checklist,
|
|
65
|
+
install_url: setup.install_url,
|
|
66
|
+
repo: setup.repo,
|
|
67
|
+
verifying: setup.verifying,
|
|
68
|
+
});
|
|
69
|
+
} catch (err) {
|
|
70
|
+
log.error('[provisioning] GET /provisioning/github-app/status', err);
|
|
71
|
+
return res.status(500).json({ ok: false, error: 'status_check_failed' });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// GET /provisioning/github-app/setup?installation_id=&setup_action=&state= — the App's
|
|
76
|
+
// setup_url (task 1004649). GitHub sends the founder's BROWSER here after they install
|
|
77
|
+
// the app (or change its repos), carrying the state we put on the install link. GitHub's
|
|
78
|
+
// own docs warn the installation_id can be spoofed, so this route trusts NOTHING it is
|
|
79
|
+
// handed: it records only that an install was REPORTED for the attempt — which makes the
|
|
80
|
+
// runner ask GitHub, with the app's own key, whether the app really is on the repo — and
|
|
81
|
+
// hands the founder back to the project page. A missing or unknown state gets the same
|
|
82
|
+
// way back, without the attempt. rank: public — a browser redirect with no session; no
|
|
83
|
+
// secret revealed, no authority changed, the only write an audit row.
|
|
84
|
+
router.get('/provisioning/github-app/setup', setupRateLimit, async (req, res) => {
|
|
85
|
+
const sendPage = (status, page) => res.status(status).type('html').send(page);
|
|
86
|
+
try {
|
|
87
|
+
const state = String(req.query.state || '');
|
|
88
|
+
const row = /^[0-9a-f]{16,128}$/i.test(state) ? await provisioning.getOAuthManifestByState(pool, state) : null;
|
|
89
|
+
if (!row) {
|
|
90
|
+
return sendPage(200, callbackPage({ ok: true, title: 'Installed on GitHub',
|
|
91
|
+
body: '<p>GitHub has installed the app. Go back to your project’s page: it checks the install itself.</p><p><a class="btn" href="/projects?view=mine">Back to my projects →</a></p>' }));
|
|
92
|
+
}
|
|
93
|
+
const id = installationIdOf(req.query);
|
|
94
|
+
const action = String(req.query.setup_action || '') === 'update' ? 'update' : 'install';
|
|
95
|
+
await provisioning.recordEvent(pool, {
|
|
96
|
+
instanceId: row.instance_id, ownerBuilderId: row.requested_by, event: githubSetup.SETUP_EVENTS.installReported,
|
|
97
|
+
detail: `GitHub returned from the app ${action}${id ? ` (installation ${id}, unverified)` : ''}; awaiting the runner's check`, actor: 'github',
|
|
98
|
+
}).catch(() => {});
|
|
99
|
+
const inst = await provisioning.getInstanceById(pool, row.instance_id).catch(() => null);
|
|
100
|
+
const domain = inst && inst.domain ? inst.domain : null;
|
|
101
|
+
return sendPage(200, domain
|
|
102
|
+
? callbackPage({ ok: true, title: 'Installed on GitHub', state, domain })
|
|
103
|
+
: callbackPage({ ok: true, title: 'Installed on GitHub',
|
|
104
|
+
body: '<p>GitHub has installed the app. We check it on your project’s page.</p><p><a class="btn" href="/projects?view=mine">Back to my projects →</a></p>' }));
|
|
105
|
+
} catch (err) {
|
|
106
|
+
log.error('[provisioning] GET /provisioning/github-app/setup', err);
|
|
107
|
+
return sendPage(500, callbackPage({ ok: false, title: 'Something went wrong',
|
|
108
|
+
body: '<p>We couldn’t record GitHub’s response. Your project’s page checks the install itself.</p><p><a class="btn" href="/projects?view=mine">Back to my projects →</a></p>' }));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return router;
|
|
113
|
+
};
|
|
@@ -62,7 +62,7 @@ const { requireRoomOnBox } = require('../capacity-gate'); // a full box refuse
|
|
|
62
62
|
const { adoptCredentialFault } = require('../credential-preflight'); const { termsAcknowledgement } = require('../terms-ack');
|
|
63
63
|
const catalogBridge = require('../catalog-bridge');
|
|
64
64
|
const capacity = require('../capacity'); // the box's slot ceiling (ADR 0285, task 1003927)
|
|
65
|
-
const { callbackPage } = require('./callback-page');
|
|
65
|
+
const { callbackPage } = require('./callback-page'); const githubSetup = require('../github-setup');
|
|
66
66
|
// the LOUD body validators (task 1003504) — lifted out when this file hit the size ratchet
|
|
67
67
|
const { badProjectDetail, badModuleSelection, badProjectType, screenedOut } = require('./body-validators'); const demo = require('../demo'); const birth = require('../birth');
|
|
68
68
|
const { failFrom } = require('../public-refusal'); // every catch: a declared refusal reaches the owner, anything else stays opaque (task 1004126)
|
|
@@ -171,11 +171,7 @@ module.exports = function provisioningRoutes() {
|
|
|
171
171
|
const router = express.Router();
|
|
172
172
|
// Per-IP limiter for the public tls-check `ask` endpoint (SEC review, task 1945).
|
|
173
173
|
const askRateLimit = makeAskRateLimiter();
|
|
174
|
-
//
|
|
175
|
-
// 2096): the onboarding page polls it every ~3s while it waits, so legitimate volume is
|
|
176
|
-
// higher than tls-check's one-shot ask. 120/min/IP gives comfortable headroom while
|
|
177
|
-
// still shedding a flood; in-memory, own bucket (does not share tls-check's budget).
|
|
178
|
-
const statusRateLimit = makeAskRateLimiter({ max: 120 });
|
|
174
|
+
// (The public status poll and its own limiter moved to ./github-setup.js, task 1004649.)
|
|
179
175
|
// Limiter for the slug-availability check (task 1002898 N10). Signed-in-only, but a
|
|
180
176
|
// session is cheap and the route answers a yes/no about EVERY project slug on the
|
|
181
177
|
// instance — an enumeration oracle if left unthrottled. A wizard debouncing one handle
|
|
@@ -675,6 +671,9 @@ module.exports = function provisioningRoutes() {
|
|
|
675
671
|
instance: ownerInstance(inst),
|
|
676
672
|
open_intent: open ? { action: open.action, state: open.state } : null,
|
|
677
673
|
github_app: provisioning.publicGithubApp(manifest),
|
|
674
|
+
// the four-step checklist from what the runner verified (task 1004649) — the
|
|
675
|
+
// install link rides WITHOUT the state token this read never carries
|
|
676
|
+
github_setup: await githubSetup.githubSetupRead(pool, inst, manifest, manifest ? provisioning.publicGithubApp(manifest).status : null, { withState: false }),
|
|
678
677
|
});
|
|
679
678
|
} catch (err) {
|
|
680
679
|
log.error('[provisioning] GET /provisioning/instances/:id', err);
|
|
@@ -1392,41 +1391,8 @@ module.exports = function provisioningRoutes() {
|
|
|
1392
1391
|
}
|
|
1393
1392
|
});
|
|
1394
1393
|
|
|
1395
|
-
// GET /provisioning/github-app/status
|
|
1396
|
-
//
|
|
1397
|
-
// Same public-by-state model as the callback: the unguessable, single-use `state` token
|
|
1398
|
-
// is the only key, and the response reveals only the manifest lifecycle status + the
|
|
1399
|
-
// instance's own (already-public) domain — never a secret. Per-IP rate-limited because
|
|
1400
|
-
// the page polls it every ~3s. `ready` is true iff the manifest reached 'done' (creds
|
|
1401
|
-
// placed + /healthz verified) — the setup checklist then opens https://<domain>.
|
|
1402
|
-
// rank: public — no session, no mutation, no secret; an unknown state is a 404 no-op.
|
|
1403
|
-
router.get('/provisioning/github-app/status', statusRateLimit, async (req, res) => {
|
|
1404
|
-
try {
|
|
1405
|
-
const state = String(req.query.state || '');
|
|
1406
|
-
if (!state) return res.status(400).json({ ok: false, error: 'missing_state' });
|
|
1407
|
-
const row = await provisioning.getOAuthManifestByState(pool, state);
|
|
1408
|
-
if (!row) return res.status(404).json({ ok: false, error: 'unknown_state' });
|
|
1409
|
-
const inst = await provisioning.getInstanceById(pool, row.instance_id).catch(() => null);
|
|
1410
|
-
// EFFECTIVE status + how far a failure got (task 1004572, manifest-truth.js)
|
|
1411
|
-
const { status, failure } = provisioning.publicGithubApp(row);
|
|
1412
|
-
return res.json({
|
|
1413
|
-
ok: true,
|
|
1414
|
-
status,
|
|
1415
|
-
failure,
|
|
1416
|
-
ready: status === 'done',
|
|
1417
|
-
terminal: status === 'done' || status === 'error' || status === 'expired',
|
|
1418
|
-
domain: inst && inst.domain ? inst.domain : null,
|
|
1419
|
-
instance_status: inst ? inst.status : null,
|
|
1420
|
-
// The App's public slug (task 1003049): lets the wizard render the one-click
|
|
1421
|
-
// install link (github.com/apps/<slug>/installations/new) for the app-install
|
|
1422
|
-
// step. Public info — the App's page is public by design (task 1003048).
|
|
1423
|
-
app_slug: row.app_slug || null,
|
|
1424
|
-
});
|
|
1425
|
-
} catch (err) {
|
|
1426
|
-
log.error('[provisioning] GET /provisioning/github-app/status', err);
|
|
1427
|
-
return res.status(500).json({ ok: false, error: 'status_check_failed' });
|
|
1428
|
-
}
|
|
1429
|
-
});
|
|
1394
|
+
// GET /provisioning/github-app/status + /setup — the state-keyed poll and the App's
|
|
1395
|
+
// setup_url — live in ./github-setup.js (task 1004649).
|
|
1430
1396
|
|
|
1431
1397
|
// GET /provisioning/github-app/callback?code=&state= — GitHub redirects the owner's
|
|
1432
1398
|
// BROWSER here after they approve the App Manifest (task 2080, ADR 0133). It is a
|
|
@@ -1465,11 +1431,11 @@ module.exports = function provisioningRoutes() {
|
|
|
1465
1431
|
}).catch(() => {});
|
|
1466
1432
|
const inst = await provisioning.getInstanceById(pool, row.instance_id).catch(() => null);
|
|
1467
1433
|
const domain = inst && inst.domain ? inst.domain : null;
|
|
1468
|
-
//
|
|
1469
|
-
//
|
|
1470
|
-
//
|
|
1434
|
+
// One trip (task 1004649): the page waits for the runner to name the app, then sends
|
|
1435
|
+
// the founder on to installing it on their repo; GitHub's setup_url brings them back
|
|
1436
|
+
// to the checklist. Falls back to a static success if we have no domain to point at.
|
|
1471
1437
|
return sendPage(200, domain
|
|
1472
|
-
? callbackPage({ ok: true, title: 'GitHub app created', state, domain })
|
|
1438
|
+
? callbackPage({ ok: true, title: 'GitHub app created', state, domain, next: 'install' })
|
|
1473
1439
|
: callbackPage({ ok: true, title: 'GitHub app created',
|
|
1474
1440
|
body: '<p>Nice — GitHub created the app. We’re placing its credentials on your instance now; this finishes on its own within a few minutes.</p><p class="muted">You can close this tab.</p>' }));
|
|
1475
1441
|
} catch (err) {
|