@bongos/core 1.19.663 → 1.19.664
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 +24 -14
- package/docs/module-api-changelog.md +12 -0
- package/modules/provisioning/credential-preflight.js +170 -0
- package/modules/provisioning/routes/provisioning.js +16 -11
- package/package-lock.json +2 -2
- package/package.json +1 -1
- package/src/module-api.js +15 -1
- package/tests/module_api.mjs +1 -0
- package/tests/provisioning_credential_preflight.mjs +153 -0
- package/tests/provisioning_onboard_mode.mjs +13 -0
package/.bongos-core.json
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
"artifact": "bongos-core",
|
|
3
3
|
"manifest_schema": 1,
|
|
4
4
|
"generator": "scripts/gds/package-core.js",
|
|
5
|
-
"core_version": "1.19.
|
|
6
|
-
"core_contract": "1.19.
|
|
7
|
-
"source_commit": "
|
|
5
|
+
"core_version": "1.19.664",
|
|
6
|
+
"core_contract": "1.19.664",
|
|
7
|
+
"source_commit": "22eade9fabde0d50dd8dc441b6ad82659c3925af",
|
|
8
8
|
"source_ref": "HEAD",
|
|
9
|
-
"built_at": "2026-09-11T03:
|
|
9
|
+
"built_at": "2026-09-11T03:34:10.888Z",
|
|
10
10
|
"redaction": {
|
|
11
11
|
"model": "docs-redacted+functional-verbatim",
|
|
12
12
|
"docs_redacted": 473,
|
|
13
13
|
"agent_docs_stubbed": 24,
|
|
14
|
-
"functional_verbatim":
|
|
14
|
+
"functional_verbatim": 2115,
|
|
15
15
|
"rules": 3,
|
|
16
16
|
"gate_literals": 3,
|
|
17
17
|
"gate": "passed"
|
|
18
18
|
},
|
|
19
|
-
"file_count":
|
|
20
|
-
"tree_sha256": "
|
|
19
|
+
"file_count": 2612,
|
|
20
|
+
"tree_sha256": "84b0905b27f747599562fc3a649df36296c71ea7f08e863fb7f2d886bc788a6f",
|
|
21
21
|
"files": [
|
|
22
22
|
{
|
|
23
23
|
"path": ".claude/skills/ask-for-help/SKILL.md",
|
|
@@ -2787,7 +2787,7 @@
|
|
|
2787
2787
|
{
|
|
2788
2788
|
"path": "docs/module-api-changelog.md",
|
|
2789
2789
|
"mode": "0000644",
|
|
2790
|
-
"sha256": "
|
|
2790
|
+
"sha256": "5e2db4fa846a72ed355864eb5df81abb6c1dc2833c239d1d6200d5b23eeb67fa"
|
|
2791
2791
|
},
|
|
2792
2792
|
{
|
|
2793
2793
|
"path": "docs/modules-contract.md",
|
|
@@ -6374,6 +6374,11 @@
|
|
|
6374
6374
|
"mode": "0000644",
|
|
6375
6375
|
"sha256": "dae214682f6115b3a4e11ac3bcd120460b07c2a517155ba0b7ec690f1db9f3ea"
|
|
6376
6376
|
},
|
|
6377
|
+
{
|
|
6378
|
+
"path": "modules/provisioning/credential-preflight.js",
|
|
6379
|
+
"mode": "0000644",
|
|
6380
|
+
"sha256": "83e174333fbe6a2e9d11b46bfd5755fbd6314b1ccd09d8b8cefb01973a69fc37"
|
|
6381
|
+
},
|
|
6377
6382
|
{
|
|
6378
6383
|
"path": "modules/provisioning/migrations/provisioning_001_tables.sql",
|
|
6379
6384
|
"mode": "0000644",
|
|
@@ -6492,7 +6497,7 @@
|
|
|
6492
6497
|
{
|
|
6493
6498
|
"path": "modules/provisioning/routes/provisioning.js",
|
|
6494
6499
|
"mode": "0000644",
|
|
6495
|
-
"sha256": "
|
|
6500
|
+
"sha256": "14fda38bbfd01404c16e48c626247cbfacd956889e25aab6c65cf1b746b5e3e7"
|
|
6496
6501
|
},
|
|
6497
6502
|
{
|
|
6498
6503
|
"path": "modules/provisioning/starter-bundles.js",
|
|
@@ -7752,12 +7757,12 @@
|
|
|
7752
7757
|
{
|
|
7753
7758
|
"path": "package-lock.json",
|
|
7754
7759
|
"mode": "0000644",
|
|
7755
|
-
"sha256": "
|
|
7760
|
+
"sha256": "9f5ffaf4b6733ee29b44799f6911ccec28806c1c89a191d015e14dfa8777723a"
|
|
7756
7761
|
},
|
|
7757
7762
|
{
|
|
7758
7763
|
"path": "package.json",
|
|
7759
7764
|
"mode": "0000644",
|
|
7760
|
-
"sha256": "
|
|
7765
|
+
"sha256": "51248222358e2c56acfb51ce7fab9cf83ea1750edb7aa51e2998fdfa29cae0d0"
|
|
7761
7766
|
},
|
|
7762
7767
|
{
|
|
7763
7768
|
"path": "public-docs/index.html",
|
|
@@ -9512,7 +9517,7 @@
|
|
|
9512
9517
|
{
|
|
9513
9518
|
"path": "src/module-api.js",
|
|
9514
9519
|
"mode": "0000644",
|
|
9515
|
-
"sha256": "
|
|
9520
|
+
"sha256": "b81fd10bc6c7db853fee7809a05275836f743a32b167778d83e9b5f40eec8fc2"
|
|
9516
9521
|
},
|
|
9517
9522
|
{
|
|
9518
9523
|
"path": "src/module-loader/catalog.js",
|
|
@@ -11632,7 +11637,7 @@
|
|
|
11632
11637
|
{
|
|
11633
11638
|
"path": "tests/module_api.mjs",
|
|
11634
11639
|
"mode": "0000644",
|
|
11635
|
-
"sha256": "
|
|
11640
|
+
"sha256": "4055467ff3bb8f5bcb79a87db12a649d90545986a3f8217a743934a6a50e8b5f"
|
|
11636
11641
|
},
|
|
11637
11642
|
{
|
|
11638
11643
|
"path": "tests/module_api_lazy.mjs",
|
|
@@ -12044,6 +12049,11 @@
|
|
|
12044
12049
|
"mode": "0000644",
|
|
12045
12050
|
"sha256": "74d53ae7f3c93883bdc6db5187c904cc6c641267233d70bfef1a25d5b2a4ca05"
|
|
12046
12051
|
},
|
|
12052
|
+
{
|
|
12053
|
+
"path": "tests/provisioning_credential_preflight.mjs",
|
|
12054
|
+
"mode": "0000644",
|
|
12055
|
+
"sha256": "851e89c4b8d14030fde9ff23f710ce335498c1a215eb7d52d6a6582d4dd0a5c7"
|
|
12056
|
+
},
|
|
12047
12057
|
{
|
|
12048
12058
|
"path": "tests/provisioning_default_domain.mjs",
|
|
12049
12059
|
"mode": "0000644",
|
|
@@ -12067,7 +12077,7 @@
|
|
|
12067
12077
|
{
|
|
12068
12078
|
"path": "tests/provisioning_onboard_mode.mjs",
|
|
12069
12079
|
"mode": "0000644",
|
|
12070
|
-
"sha256": "
|
|
12080
|
+
"sha256": "3a76bb14f9dc12ce4fff703b14a9802b1a612e726c77cfe219505743643bca9f"
|
|
12071
12081
|
},
|
|
12072
12082
|
{
|
|
12073
12083
|
"path": "tests/provisioning_paid_shape_gate.mjs",
|
|
@@ -1775,5 +1775,17 @@ is load-bearing: the script throws rather than guess if it is missing, and
|
|
|
1775
1775
|
landed since 1.19.661 with no explicit bump. run 34553965204. (task 1002620)
|
|
1776
1776
|
1.19.663 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
|
|
1777
1777
|
landed since 1.19.662 with no explicit bump. run 34557840364. (task 1002620)
|
|
1778
|
+
(next carrier) — grantedScopeCoversRepos re-exported (task 1002909, goal 1000106).
|
|
1779
|
+
The provisioning module's create-route credential preflight must tell "that
|
|
1780
|
+
repo does not exist" apart from "it is private and your pre-ADR-0155 token
|
|
1781
|
+
cannot see it" — GitHub answers 404 to both — so it needs the canonical scope
|
|
1782
|
+
read. Shared rather than re-implemented because `public_repo` CONTAINS the
|
|
1783
|
+
substring "repo", so a naive match accepts exactly the stale token it guards
|
|
1784
|
+
against. auth-config.js is KERNEL (ADR 0091 §1), so this stays inside the
|
|
1785
|
+
kernel-imports-only rule; db.getGithubToken and github-repos are DOMAIN and
|
|
1786
|
+
deliberately did NOT come through the doorway — the module reaches those via
|
|
1787
|
+
the already-exposed `pool` + `secretBox` and its own one-field repo client.
|
|
1788
|
+
1.19.664 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
|
|
1789
|
+
landed since 1.19.663 with no explicit bump. run 34558906002. (task 1002620)
|
|
1778
1790
|
---------------------------------------------------------------------------
|
|
1779
1791
|
```
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// modules/provisioning/credential-preflight.js — does the caller hold a credential
|
|
2
|
+
// that can actually stand up the repo they are adopting? (task 1002909, 1002898 N3)
|
|
3
|
+
//
|
|
4
|
+
// THE GAP THIS CLOSES. `POST /provisioning/instances` validated that an `adopt`
|
|
5
|
+
// carried a target_ref, but never that the owner could READ it — so an API caller
|
|
6
|
+
// could queue a standup that was doomed at request time and only learned about it
|
|
7
|
+
// ~2 minutes later, as raw git stderr on the runner (the task-1002697 acceptance
|
|
8
|
+
// walk did exactly that). The web wizard was only incidentally protected: it 403s
|
|
9
|
+
// earlier on its own repo picker. The API had nothing.
|
|
10
|
+
//
|
|
11
|
+
// WHY IT WAITED FOR ADR 0176 (task 1002735). A preflight is only as good as its
|
|
12
|
+
// definition of "usable credential", and 1002898 carved this out rather than guess
|
|
13
|
+
// at one: written against the wrong definition it would either refuse valid creates
|
|
14
|
+
// or keep admitting doomed ones. 1002735 settled it, so this file encodes THAT
|
|
15
|
+
// definition and nothing else — what `ensurePrivateRepoAccess` (scripts/gds/
|
|
16
|
+
// provision-repo.js) will demand at standup time, asked one round-trip earlier:
|
|
17
|
+
//
|
|
18
|
+
// public target_ref → any readable credential is enough. The recurring deploy
|
|
19
|
+
// pull rides the shared SSH alias, which reads public repos
|
|
20
|
+
// without being registered on them.
|
|
21
|
+
// private target_ref → the runner must register a READ-ONLY deploy key on the
|
|
22
|
+
// repo, and GitHub requires repository ADMIN for that. A
|
|
23
|
+
// credential that can merely read a private repo is NOT
|
|
24
|
+
// enough, and discovering that mid-standup is the loud
|
|
25
|
+
// version of this same refusal.
|
|
26
|
+
//
|
|
27
|
+
// GREENFIELD IS EXEMPT, and that exemption is load-bearing (the constraint carried
|
|
28
|
+
// over from 1002898): the platform CREATES that repo itself, so there is no
|
|
29
|
+
// pre-existing repo for a credential to cover and nothing here to check.
|
|
30
|
+
//
|
|
31
|
+
// A TRANSIENT GITHUB FAILURE ADMITS. This refuses only on POSITIVE evidence that a
|
|
32
|
+
// standup cannot succeed. GitHub being unreachable is not that evidence — and the
|
|
33
|
+
// runner takes the same posture (`skipped: 'github_unreachable'` continues rather
|
|
34
|
+
// than throwing), so a GitHub hiccup must not become an outage of project creation.
|
|
35
|
+
//
|
|
36
|
+
// WHY IT READS THE TOKEN ITSELF rather than calling core's db.getGithubToken /
|
|
37
|
+
// github-repos.getUserRepo. `src/module-api.js` is a KERNEL file (ADR 0091 §1) and
|
|
38
|
+
// may depend only on kernel files; `src/bongos/db.js` and `src/bongos/github-repos.js`
|
|
39
|
+
// are domain, so routing either through the doorway fails the boundary check in
|
|
40
|
+
// scripts/gds/fitness.js. Modules own their data access through the exposed `pool`
|
|
41
|
+
// (the module contract's own rule), so the two small reads below are that ownership,
|
|
42
|
+
// not a shortcut around it. Both are DELIBERATE TWINS of core's versions and say so;
|
|
43
|
+
// `grantedScopeCoversRepos` is reached through the doorway instead of re-implemented
|
|
44
|
+
// because it is kernel (src/bongos/auth-config.js) AND because its subtlety —
|
|
45
|
+
// `public_repo` CONTAINS "repo", so a substring match accepts exactly the stale
|
|
46
|
+
// pre-ADR-0155 token this guards against — is the kind that must never be re-typed.
|
|
47
|
+
//
|
|
48
|
+
// Its own file, like ../paid-shape-gate.js, for the same two mechanical reasons:
|
|
49
|
+
// `routes/provisioning.js` sits at its 1500-line fitness ratchet, and every
|
|
50
|
+
// dependency here is INJECTED so the check is exercisable without standing up the
|
|
51
|
+
// auth stack or touching the network.
|
|
52
|
+
'use strict';
|
|
53
|
+
|
|
54
|
+
// Mirrors scripts/gds/provision-repo.js parseTargetRef EXACTLY. The preflight and
|
|
55
|
+
// the runner must agree on what a target_ref means, or this admits refs the runner
|
|
56
|
+
// cannot parse (and refuses ones it can) — a divergence that would be silent.
|
|
57
|
+
function parseTargetRef(ref) {
|
|
58
|
+
const m = String(ref || '').trim()
|
|
59
|
+
.replace(/^git@[^:]+:/, '')
|
|
60
|
+
.replace(/^https?:\/\/[^/]+\//, '')
|
|
61
|
+
.match(/^([A-Za-z0-9][A-Za-z0-9_.-]*)\/([A-Za-z0-9][A-Za-z0-9_.-]*?)(?:\.git)?$/);
|
|
62
|
+
return m ? { owner: m[1], name: m[2] } : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Twin of src/bongos/db.js getGithubToken, kept in step with it deliberately (see
|
|
66
|
+
// the header). Returns { token, scope } or null when there is none, it expired, or
|
|
67
|
+
// the blob will not decrypt under the current master key. Unlike core's version it
|
|
68
|
+
// does NOT lazily delete an expired row — a read-only preflight must not mutate, and
|
|
69
|
+
// core's own reaper still runs on the endpoints that own that table.
|
|
70
|
+
async function readOwnerRepoToken({ builderId }, { pool, secretBox }) {
|
|
71
|
+
if (!secretBox.isConfigured()) return null;
|
|
72
|
+
const { rows } = await pool.query(
|
|
73
|
+
`SELECT token_enc, scope, expires_at FROM github_oauth_tokens WHERE builder_id = $1`,
|
|
74
|
+
[builderId],
|
|
75
|
+
);
|
|
76
|
+
const row = rows[0];
|
|
77
|
+
if (!row) return null;
|
|
78
|
+
if (new Date(row.expires_at).getTime() <= Date.now()) return null;
|
|
79
|
+
try { return { token: secretBox.decrypt(row.token_enc), scope: row.scope }; }
|
|
80
|
+
catch { return null; } // a blob that won't decrypt reads as "none", as in core
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Twin of src/bongos/github-repos.js getUserRepo, narrowed to the two fields this
|
|
84
|
+
// decision needs. Throws { code } on the cases the caller branches on; every other
|
|
85
|
+
// status is a transient the caller admits on.
|
|
86
|
+
async function fetchRepoVisibility(token, { owner, name, fetchImpl, userAgent }) {
|
|
87
|
+
const res = await (fetchImpl || fetch)(
|
|
88
|
+
`https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`,
|
|
89
|
+
{ headers: { Authorization: `Bearer ${token}`, 'User-Agent': userAgent, Accept: 'application/vnd.github+json' } },
|
|
90
|
+
);
|
|
91
|
+
if (res.status === 401) throw Object.assign(new Error('github rejected the token'), { code: 'github_unauthorized' });
|
|
92
|
+
if (res.status === 404) throw Object.assign(new Error('repo not found'), { code: 'repo_not_found' });
|
|
93
|
+
if (!res.ok) throw Object.assign(new Error(`github ${res.status}`), { code: 'github_error' });
|
|
94
|
+
const r = await res.json();
|
|
95
|
+
return { private: !!r.private, admin: !!(r.permissions && r.permissions.admin) };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// adoptCredentialFault — null to ADMIT the create, or the refusal the route should
|
|
99
|
+
// send: { code, status, message }. Returning a value rather than writing to `res`
|
|
100
|
+
// keeps this directly testable and leaves the HTTP shape with the route that owns it.
|
|
101
|
+
//
|
|
102
|
+
// deps: { pool, secretBox, grantedScopeCoversRepos, userAgent, fetchImpl?,
|
|
103
|
+
// readToken?, fetchRepo? } — the last two are test seams.
|
|
104
|
+
async function adoptCredentialFault({ builderId, onboardMode, targetRef }, deps) {
|
|
105
|
+
if (onboardMode !== 'adopt') return null; // greenfield: nothing to check
|
|
106
|
+
const { grantedScopeCoversRepos, secretBox, fetchImpl, userAgent } = deps;
|
|
107
|
+
const readToken = deps.readToken || readOwnerRepoToken;
|
|
108
|
+
const fetchRepo = deps.fetchRepo || fetchRepoVisibility;
|
|
109
|
+
|
|
110
|
+
// An unparseable ref cannot be checked, and the runner's identical parse would
|
|
111
|
+
// fail on it too — so this is a doomed standup, refused for the reason it is
|
|
112
|
+
// doomed rather than admitted because the credential question never got asked.
|
|
113
|
+
const repo = parseTargetRef(targetRef);
|
|
114
|
+
if (!repo) {
|
|
115
|
+
return { code: 'bad_target_ref', status: 400,
|
|
116
|
+
message: 'Name the repository to adopt as owner/repo.' };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// No secret-box means no token can be STORED at all, so every adopt would fail at
|
|
120
|
+
// the push. 503, not 403: the fault is the server's configuration, not the caller's.
|
|
121
|
+
if (!secretBox.isConfigured()) {
|
|
122
|
+
return { code: 'github_credential_unavailable', status: 503,
|
|
123
|
+
message: 'Repo access is not configured on this server, so an existing repository cannot be adopted yet.' };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const row = await readToken({ builderId }, deps);
|
|
127
|
+
if (!row || !row.token) {
|
|
128
|
+
return { code: 'repo_scope_required', status: 403,
|
|
129
|
+
message: 'Connect your GitHub account before adopting an existing repository.' };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let info;
|
|
133
|
+
try {
|
|
134
|
+
info = await fetchRepo(row.token, { owner: repo.owner, name: repo.name, fetchImpl, userAgent });
|
|
135
|
+
} catch (e) {
|
|
136
|
+
const code = e && e.code;
|
|
137
|
+
if (code === 'github_unauthorized') {
|
|
138
|
+
return { code: 'repo_scope_required', status: 403,
|
|
139
|
+
message: 'GitHub rejected your stored credential — reconnect your GitHub account and try again.' };
|
|
140
|
+
}
|
|
141
|
+
if (code === 'repo_not_found') {
|
|
142
|
+
// A `public_repo`-scoped token cannot SEE a private repo: GitHub answers 404
|
|
143
|
+
// for "absent" and for "private and invisible to you" identically. So the
|
|
144
|
+
// message covers both honestly rather than asserting the repo does not exist —
|
|
145
|
+
// a pre-ADR-0155 token reaching its own private repo lands exactly here, which
|
|
146
|
+
// is the hermeslines-marketing failure told at request time instead of at the pull.
|
|
147
|
+
if (!grantedScopeCoversRepos(row.scope)) {
|
|
148
|
+
return { code: 'repo_scope_required', status: 403,
|
|
149
|
+
message: `We cannot see ${repo.owner}/${repo.name}. If it is private, reconnect GitHub to include your private repositories; if it is public, check the name.` };
|
|
150
|
+
}
|
|
151
|
+
return { code: 'target_repo_not_found', status: 404,
|
|
152
|
+
message: `GitHub has no repository ${repo.owner}/${repo.name} that your account can reach — check the name, or that you still have access.` };
|
|
153
|
+
}
|
|
154
|
+
return null; // unreachable / 5xx: no positive evidence of doom, so admit
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Private repos need repository ADMIN, because the runner registers a read-only
|
|
158
|
+
// deploy key to keep the deploy pull working after the one-shot OAuth token dies
|
|
159
|
+
// (ADR 0176). Read-only collaborator access passes the read above and then fails at
|
|
160
|
+
// key registration — the exact "looked like it worked" shape this exists to end.
|
|
161
|
+
// The sentence matches the runner's own so the two can never disagree.
|
|
162
|
+
if (info.private && !info.admin) {
|
|
163
|
+
return { code: 'repo_admin_required', status: 403,
|
|
164
|
+
message: `Your GitHub account can read ${repo.owner}/${repo.name}, but adopting a private repository needs repository ADMIN so its deploy key can be registered. Ask a repository admin to raise your access, or make the repository public.` };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = { adoptCredentialFault, parseTargetRef, readOwnerRepoToken, fetchRepoVisibility };
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
// POST /provisioning/instances — request a new instance
|
|
15
15
|
// (a `dedicated` shape ALSO needs
|
|
16
16
|
// provisioning.fleet.manage — it is the
|
|
17
|
-
// only shape that bills; ../paid-shape-gate.js
|
|
17
|
+
// only shape that bills; ../paid-shape-gate.js.
|
|
18
|
+
// An `adopt` ALSO passes the credential
|
|
19
|
+
// preflight — ../credential-preflight.js,
|
|
20
|
+
// task 1002909; greenfield is exempt)
|
|
18
21
|
// GET /provisioning/instances — list the caller's instances
|
|
19
22
|
// GET /provisioning/instances/:id — read one of the caller's instances
|
|
20
23
|
// (also SELF-HEALS its catalog projection,
|
|
@@ -49,6 +52,7 @@ const { ALWAYS_ON_CORE, OPTIONAL_MODULES, starterBundleAnswerTable, optionalModu
|
|
|
49
52
|
const { recommendationsForDetails } = require('../recommendations');
|
|
50
53
|
const { makeAskRateLimiter, clientIp } = require('../rate-limit');
|
|
51
54
|
const { requireAuthorityForMeteredShape } = require('../paid-shape-gate');
|
|
55
|
+
const { adoptCredentialFault } = require('../credential-preflight');
|
|
52
56
|
const catalogBridge = require('../catalog-bridge');
|
|
53
57
|
const { callbackPage } = require('./callback-page');
|
|
54
58
|
// task 1003208: structured logging (pino via the doorway) — was console.*.
|
|
@@ -409,17 +413,18 @@ module.exports = function provisioningRoutes() {
|
|
|
409
413
|
reason: 'adopt layers onto an existing repo, so target_ref (owner/repo) is required',
|
|
410
414
|
});
|
|
411
415
|
}
|
|
412
|
-
// KNOWN GAP — the credential preflight belongs HERE, and is deliberately absent.
|
|
413
|
-
// This route validates that target_ref is PRESENT but never that the owner holds a
|
|
414
|
-
// usable repo credential for it, so an API caller can queue a standup that dies
|
|
415
|
-
// ~2 minutes later in raw git stderr (the task-1002697 walk did exactly that; the
|
|
416
|
-
// web wizard is only incidentally protected because it 403s earlier). Carved out of
|
|
417
|
-
// task 1002898 as N3 and tracked by task 1002909, which is BLOCKED on task 1002735
|
|
418
|
-
// deciding what credential a private-repo standup actually needs: written against
|
|
419
|
-
// the wrong definition, a preflight would refuse valid creates or keep admitting
|
|
420
|
-
// doomed ones. Greenfield must stay exempt when it lands — the platform creates
|
|
421
|
-
// that repo itself, so there is no pre-existing repo to hold a credential for.
|
|
422
416
|
try {
|
|
417
|
+
// The credential preflight (task 1002909, 1002898 N3). An `adopt` names a repo
|
|
418
|
+
// the platform must read forever, so ask ONE round-trip early whether this
|
|
419
|
+
// caller's credential can actually carry that standup — rather than queueing a
|
|
420
|
+
// doomed intent the runner discovers two minutes later as raw git stderr (the
|
|
421
|
+
// task-1002697 walk). Greenfield is exempt by construction. Encodes ADR 0176's
|
|
422
|
+
// definition of a usable credential; ../credential-preflight.js says why.
|
|
423
|
+
const credFault = await adoptCredentialFault(
|
|
424
|
+
{ builderId: req.builder.id, onboardMode, targetRef: body.target_ref },
|
|
425
|
+
{ pool, secretBox: api.secretBox, grantedScopeCoversRepos: api.grantedScopeCoversRepos, userAgent: api.userAgent() },
|
|
426
|
+
);
|
|
427
|
+
if (credFault) return res.fail(credFault.code, { status: credFault.status, message: credFault.message });
|
|
423
428
|
// A re-request must not re-litigate the address: createInstance never updates
|
|
424
429
|
// an existing row's domain, so for one the guards below could only misfire —
|
|
425
430
|
// a "Try again" on a pre-existing reserved-label row, or domain_taken fired
|
package/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bongos/core",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.664",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@bongos/core",
|
|
9
|
-
"version": "1.19.
|
|
9
|
+
"version": "1.19.664",
|
|
10
10
|
"license": "AGPL-3.0-or-later",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"express": "^4.21.2",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bongos/core",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.664",
|
|
4
4
|
"description": "Cloud Bongos — the AI-first build platform core (GDS + platform surfaces + module system), installed as a versioned dependency (ADR 0108).",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"main": "src/platform-server.js",
|
package/src/module-api.js
CHANGED
|
@@ -71,7 +71,7 @@ const { responsibilityFor, ROLE_RESPONSIBILITIES } = require('./role-responsibil
|
|
|
71
71
|
// there. scripts/gds/bump-version.js still rewrites the literal below; it appends
|
|
72
72
|
// the entry to that file. Look for a version's history there, not here.
|
|
73
73
|
// ---------------------------------------------------------------------------
|
|
74
|
-
const CORE_VERSION = '1.19.
|
|
74
|
+
const CORE_VERSION = '1.19.664'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
|
|
75
75
|
|
|
76
76
|
// A namespaced logger so a module's log lines are attributable + consistent.
|
|
77
77
|
// Usage: const log = api.logger('dev-box'); log.info('mounted');
|
|
@@ -197,6 +197,20 @@ module.exports = {
|
|
|
197
197
|
// isConfigured/encrypt/decrypt/provisionMasterKey without reaching core.
|
|
198
198
|
get secretBox() { return require('./bongos/secret-box'); },
|
|
199
199
|
|
|
200
|
+
// --- grantedScopeCoversRepos(scope) — does a scope string GitHub ACTUALLY
|
|
201
|
+
// GRANTED still reach private repos? Exposed for the provisioning module's
|
|
202
|
+
// create-route credential preflight (task 1002909), which must tell "that
|
|
203
|
+
// repo does not exist" apart from "it is private and your pre-ADR-0155 token
|
|
204
|
+
// cannot see it" — GitHub answers 404 to both.
|
|
205
|
+
//
|
|
206
|
+
// Shared rather than re-implemented because the subtlety is a trap:
|
|
207
|
+
// `public_repo` CONTAINS the substring "repo", so a naive match accepts
|
|
208
|
+
// exactly the stale token this guards against. auth-config.js is KERNEL
|
|
209
|
+
// (ADR 0091 §1), so this stays inside the kernel-imports-only rule — unlike
|
|
210
|
+
// db.getGithubToken / github-repos, which are domain and which a module
|
|
211
|
+
// therefore reaches via the exposed `pool` and its own client instead.
|
|
212
|
+
get grantedScopeCoversRepos() { return require('./bongos/auth-config').grantedScopeCoversRepos; },
|
|
213
|
+
|
|
200
214
|
// --- KERNEL trust classifiers (ADR 0091 §1, KERNEL_FILES) — the deterministic
|
|
201
215
|
// route→rank + protected-path matchers. They are KERNEL (the trust
|
|
202
216
|
// boundary, never "called" by a domain), exposed so a module that runs the
|
package/tests/module_api.mjs
CHANGED
|
@@ -24,6 +24,7 @@ const PUBLISHED_SURFACE = [
|
|
|
24
24
|
'requirePermission', // BV1.R105: the authority-atom gate module routes migrate onto (1.19.0; ADR 0151)
|
|
25
25
|
'pool', 'getPool', 'instanceDbName', 'withTx', 'getBuilderById',
|
|
26
26
|
'secretBox', // Gemini-key storage relocated to modules/art-pipeline + its 'art.getBuilderGeminiKeyRow' port (ADR 0102)
|
|
27
|
+
'grantedScopeCoversRepos', // the create-route credential preflight's scope read (task 1002909); kernel (auth-config.js), unlike db/github-repos which the module reaches via `pool` + its own client
|
|
27
28
|
'accountExistenceReadRateLimit', // task 1003339 (ADR 0209): the shared per-IP budget both account-existence probes spend from — one instance, not a factory, so the budget is genuinely shared
|
|
28
29
|
'publicProjectFeedRateLimit', // task 1002327 (ADR 0252 §5.3): the per-IP ceiling on GET /projects/featured — the platform's most expensive anonymous read (a cold call fans out to up to 500 third-party origins). One instance for the same reason as its neighbour
|
|
29
30
|
'routeRankCheck', 'permissionPathCheck', // BV1.R73: kernel trust classifiers (1.6.0)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// tests/provisioning_credential_preflight.mjs
|
|
2
|
+
//
|
|
3
|
+
// The create-route credential preflight (task 1002909, 1002898 N3).
|
|
4
|
+
//
|
|
5
|
+
// Before this, POST /provisioning/instances checked that an `adopt` NAMED a repo but
|
|
6
|
+
// never that the caller could read it, so the API admitted standups that were doomed at
|
|
7
|
+
// request time and surfaced ~2 minutes later as raw git stderr on the runner (the
|
|
8
|
+
// task-1002697 acceptance walk). The preflight asks ADR 0176's question one round-trip
|
|
9
|
+
// early: can this builder's credential carry THIS repo's standup?
|
|
10
|
+
//
|
|
11
|
+
// The two properties that matter, and the two ways this can be got wrong:
|
|
12
|
+
// 1. it must never refuse a create that would have SUCCEEDED (greenfield, public repos,
|
|
13
|
+
// admin-on-private, and — deliberately — a GitHub outage), and
|
|
14
|
+
// 2. it must refuse the ones that cannot (no credential, stale public_repo scope on a
|
|
15
|
+
// private repo, read-only access to a private repo).
|
|
16
|
+
// 1002898 carved this task out rather than guess at the definition precisely because a
|
|
17
|
+
// preflight written against the wrong one fails in one of those two directions.
|
|
18
|
+
//
|
|
19
|
+
// DB-free and network-free: readToken and fetchRepo are injected seams.
|
|
20
|
+
//
|
|
21
|
+
// Run: node tests/provisioning_credential_preflight.mjs
|
|
22
|
+
|
|
23
|
+
import { strict as assert } from 'node:assert';
|
|
24
|
+
import { createRequire } from 'node:module';
|
|
25
|
+
|
|
26
|
+
const require = createRequire(import.meta.url);
|
|
27
|
+
|
|
28
|
+
const { adoptCredentialFault, parseTargetRef } = require('../modules/provisioning/credential-preflight.js');
|
|
29
|
+
// The REAL scope helper, not a stand-in: its whole point is that `public_repo` contains
|
|
30
|
+
// the substring "repo", so a test double would hide the bug it exists to prevent.
|
|
31
|
+
const { grantedScopeCoversRepos } = require('../src/bongos/auth-config.js');
|
|
32
|
+
|
|
33
|
+
let passed = 0, failed = 0;
|
|
34
|
+
async function ta(name, fn) {
|
|
35
|
+
try { await fn(); passed++; console.log(` PASS ${name}`); }
|
|
36
|
+
catch (e) { failed++; console.log(` FAIL ${name}\n ${e.message}`); }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// A deps bundle with every leg stubbed; each test overrides only what it is about.
|
|
40
|
+
function deps({ configured = true, token = { token: 't', scope: 'repo' }, repo = { private: false, admin: false }, throws = null } = {}) {
|
|
41
|
+
return {
|
|
42
|
+
secretBox: { isConfigured: () => configured },
|
|
43
|
+
grantedScopeCoversRepos,
|
|
44
|
+
userAgent: 'test-agent',
|
|
45
|
+
readToken: async () => token,
|
|
46
|
+
fetchRepo: async () => { if (throws) throw Object.assign(new Error('x'), { code: throws }); return repo; },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const adopt = (targetRef = 'octo-owner/demo') => ({ builderId: 7, onboardMode: 'adopt', targetRef });
|
|
50
|
+
|
|
51
|
+
// ── the exemption that is load-bearing ──────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
await ta('greenfield is EXEMPT — the platform creates that repo, so nothing is checked', async () => {
|
|
54
|
+
// Asserted via the seams: a greenfield create must not even read the token, or a
|
|
55
|
+
// builder with no GitHub connection could no longer make a fresh project at all.
|
|
56
|
+
let touched = false;
|
|
57
|
+
const d = deps();
|
|
58
|
+
d.readToken = async () => { touched = true; return null; };
|
|
59
|
+
assert.equal(await adoptCredentialFault({ builderId: 7, onboardMode: 'greenfield', targetRef: null }, d), null);
|
|
60
|
+
assert.equal(touched, false, 'greenfield must not consult the credential at all');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// ── the refusals ────────────────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
await ta('no stored credential → 403 repo_scope_required, and the message says what to do', async () => {
|
|
66
|
+
const f = await adoptCredentialFault(adopt(), deps({ token: null }));
|
|
67
|
+
assert.equal(f.code, 'repo_scope_required');
|
|
68
|
+
assert.equal(f.status, 403);
|
|
69
|
+
assert.match(f.message, /Connect your GitHub account/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await ta('secret-box unconfigured → 503, not 403 — the fault is the server config, not the caller', async () => {
|
|
73
|
+
const f = await adoptCredentialFault(adopt(), deps({ configured: false }));
|
|
74
|
+
assert.equal(f.code, 'github_credential_unavailable');
|
|
75
|
+
assert.equal(f.status, 503);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await ta('THE HERMESLINES SHAPE: a stale public_repo token 404ing on a private repo re-prompts for scope', async () => {
|
|
79
|
+
// GitHub answers 404 identically for "absent" and "private and invisible to you", so a
|
|
80
|
+
// pre-ADR-0155 token reaching its owner's own private repo lands here. Asserting the
|
|
81
|
+
// repo does not exist would be a lie; the message must offer both readings.
|
|
82
|
+
const f = await adoptCredentialFault(adopt(), deps({ token: { token: 't', scope: 'public_repo,read:user' }, throws: 'repo_not_found' }));
|
|
83
|
+
assert.equal(f.code, 'repo_scope_required');
|
|
84
|
+
assert.equal(f.status, 403);
|
|
85
|
+
assert.match(f.message, /private/i);
|
|
86
|
+
assert.match(f.message, /reconnect/i);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await ta('a repo-scoped token that still 404s → 404 target_repo_not_found (it really is absent)', async () => {
|
|
90
|
+
const f = await adoptCredentialFault(adopt(), deps({ token: { token: 't', scope: 'repo' }, throws: 'repo_not_found' }));
|
|
91
|
+
assert.equal(f.code, 'target_repo_not_found');
|
|
92
|
+
assert.equal(f.status, 404);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
await ta('private repo WITHOUT admin → 403: the runner could read it and then fail registering the deploy key', async () => {
|
|
96
|
+
const f = await adoptCredentialFault(adopt(), deps({ repo: { private: true, admin: false } }));
|
|
97
|
+
assert.equal(f.code, 'repo_admin_required');
|
|
98
|
+
assert.equal(f.status, 403);
|
|
99
|
+
assert.match(f.message, /ADMIN/);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
await ta('a rejected token → 403 telling the caller to reconnect, not a raw 401', async () => {
|
|
103
|
+
const f = await adoptCredentialFault(adopt(), deps({ throws: 'github_unauthorized' }));
|
|
104
|
+
assert.equal(f.code, 'repo_scope_required');
|
|
105
|
+
assert.match(f.message, /reconnect/i);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
await ta('an unparseable target_ref is refused for THAT reason, not admitted unchecked', async () => {
|
|
109
|
+
const f = await adoptCredentialFault(adopt('not a repo ref!!'), deps());
|
|
110
|
+
assert.equal(f.code, 'bad_target_ref');
|
|
111
|
+
assert.equal(f.status, 400);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// ── the admissions (the half a bad preflight breaks) ────────────────────────────
|
|
115
|
+
|
|
116
|
+
await ta('public repo + any readable credential → ADMITTED, admin irrelevant', async () => {
|
|
117
|
+
// The deploy pull rides the shared SSH alias for a public repo, so no deploy key and
|
|
118
|
+
// therefore no admin is needed. Demanding admin here would refuse valid creates.
|
|
119
|
+
assert.equal(await adoptCredentialFault(adopt(), deps({ repo: { private: false, admin: false } })), null);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
await ta('private repo WITH admin → ADMITTED — this is exactly what ADR 0176 needs', async () => {
|
|
123
|
+
assert.equal(await adoptCredentialFault(adopt(), deps({ repo: { private: true, admin: true } })), null);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
await ta('GitHub unreachable → ADMITTED, matching the runner: an outage must not stop project creation', async () => {
|
|
127
|
+
// No positive evidence of doom. The runner takes the same posture
|
|
128
|
+
// (ensurePrivateRepoAccess returns skipped:'github_unreachable' rather than throwing),
|
|
129
|
+
// so refusing here would turn a GitHub hiccup into an outage of the create route.
|
|
130
|
+
assert.equal(await adoptCredentialFault(adopt(), deps({ throws: 'github_error' })), null);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// ── the parse must not drift from the runner's ──────────────────────────────────
|
|
134
|
+
|
|
135
|
+
await ta('parseTargetRef accepts every form the runner accepts, and rejects what it rejects', async () => {
|
|
136
|
+
// A divergence from scripts/gds/provision-repo.js parseTargetRef would be silent: this
|
|
137
|
+
// would admit refs the runner cannot parse, or refuse ones it can.
|
|
138
|
+
for (const ref of ['octo-owner/demo', 'git@github.com:octo-owner/demo.git', 'https://github.com/octo-owner/demo', 'https://github.com/octo-owner/demo.git']) {
|
|
139
|
+
assert.deepEqual(parseTargetRef(ref), { owner: 'octo-owner', name: 'demo' }, `should parse ${ref}`);
|
|
140
|
+
}
|
|
141
|
+
for (const ref of ['', null, 'demo', 'a/b/c', 'not a repo ref!!']) {
|
|
142
|
+
assert.equal(parseTargetRef(ref), null, `should reject ${JSON.stringify(ref)}`);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
await ta('the real scope helper is used, so public_repo never passes as repo', async () => {
|
|
147
|
+
// The trap this guards: 'public_repo'.includes('repo') is true.
|
|
148
|
+
assert.equal(grantedScopeCoversRepos('public_repo,read:user'), false);
|
|
149
|
+
assert.equal(grantedScopeCoversRepos('repo'), true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
console.log(`\nprovisioning_credential_preflight: ${passed} passed, ${failed} failed`);
|
|
153
|
+
process.exit(failed ? 1 : 0);
|
|
@@ -101,6 +101,19 @@ provisioning.getInstanceBySlug = async () => null;
|
|
|
101
101
|
const api = require('../src/module-api.js');
|
|
102
102
|
api.requireBuilder = (req, _res, next) => { req.builder = { id: 7, github_login: 'owner' }; next(); };
|
|
103
103
|
|
|
104
|
+
// An `adopt` create now also passes the credential preflight (task 1002909), which is a
|
|
105
|
+
// REAL precondition and not test scaffolding: the route refuses a standup whose owner
|
|
106
|
+
// holds no usable credential for the repo it is about to queue a push to. So give this
|
|
107
|
+
// harness a passing one — a `repo`-scoped token over a PUBLIC repo, the cheapest shape
|
|
108
|
+
// that admits — and leave the preflight's own branch matrix to
|
|
109
|
+
// tests/provisioning_credential_preflight.mjs, which owns it.
|
|
110
|
+
api.secretBox = { isConfigured: () => true };
|
|
111
|
+
api.pool = {
|
|
112
|
+
query: async () => ({ rows: [{ token_enc: 'enc', scope: 'repo', expires_at: new Date(Date.now() + 3600e3) }] }),
|
|
113
|
+
};
|
|
114
|
+
api.secretBox.decrypt = () => 'tok';
|
|
115
|
+
globalThis.fetch = async () => ({ status: 200, ok: true, json: async () => ({ private: false, permissions: { admin: true } }) });
|
|
116
|
+
|
|
104
117
|
const express = require('express');
|
|
105
118
|
const provisioningRoutes = require('../modules/provisioning/routes/provisioning.js');
|
|
106
119
|
const app = express();
|