@rathnasgala2/adapter-github-pages 0.1.0 → 0.1.1
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/CHANGELOG.md +39 -0
- package/LICENSE +201 -0
- package/README.md +24 -9
- package/package.json +32 -12
- package/src/artifact-projection.js +12 -5
- package/src/capability.js +8 -3
- package/src/carrier.js +77 -33
- package/src/constants.js +7 -3
- package/src/deployment.js +61 -56
- package/src/errors.js +32 -0
- package/src/index.js +40 -36
- package/src/marker.js +4 -2
- package/src/oidc.js +97 -8
- package/src/public-read.js +4 -2
- package/src/recovery.js +6 -4
- package/src/redaction.js +8 -4
- package/src/request-catalog.js +7 -4
- package/src/rest.js +63 -24
- package/types/artifact-projection.d.ts +48 -0
- package/types/capability.d.ts +23 -0
- package/types/carrier.d.ts +49 -0
- package/types/constants.d.ts +86 -0
- package/types/deployment.d.ts +107 -0
- package/types/errors.d.ts +28 -0
- package/types/index.d.ts +299 -0
- package/types/marker.d.ts +26 -0
- package/types/oidc.d.ts +108 -0
- package/types/public-read.d.ts +33 -0
- package/types/recovery.d.ts +175 -0
- package/types/redaction.d.ts +38 -0
- package/types/request-catalog.d.ts +106 -0
- package/types/rest.d.ts +159 -0
- package/types/store.d.ts +66 -0
- package/src/index.d.ts +0 -246
package/src/constants.js
CHANGED
|
@@ -32,11 +32,13 @@ export const ADAPTER_VERSION = /** @type {string} */ (
|
|
|
32
32
|
export const GENERATION_MARKER_PATH = '.well-known/gala-generation.json';
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* The exact
|
|
36
|
-
* status values (brief section 6.2
|
|
37
|
-
*
|
|
35
|
+
* The exact twelve accepted `GET /repos/{owner}/{repo}/pages/deployments/{id}`
|
|
36
|
+
* status values (brief section 6.2, plus `deployment_queued`, which GitHub's
|
|
37
|
+
* REST reference lists and a real run returned on 2026-10-06). Anything else
|
|
38
|
+
* is unknown and can never release the destination fence.
|
|
38
39
|
*/
|
|
39
40
|
export const PAGES_DEPLOYMENT_STATUSES = Object.freeze([
|
|
41
|
+
'deployment_queued',
|
|
40
42
|
'deployment_in_progress',
|
|
41
43
|
'syncing_files',
|
|
42
44
|
'finished_file_sync',
|
|
@@ -52,10 +54,12 @@ export const PAGES_DEPLOYMENT_STATUSES = Object.freeze([
|
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* Temporary statuses: polling continues and the fence stays held.
|
|
57
|
+
* `deployment_queued` is the state before `deployment_in_progress`, and
|
|
55
58
|
* `deployment_attempt_error` is temporary because GitHub retries it
|
|
56
59
|
* automatically (brief section 6.2).
|
|
57
60
|
*/
|
|
58
61
|
export const TEMPORARY_STATUSES = Object.freeze([
|
|
62
|
+
'deployment_queued',
|
|
59
63
|
'deployment_in_progress',
|
|
60
64
|
'syncing_files',
|
|
61
65
|
'finished_file_sync',
|
package/src/deployment.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Pages deployment call sequence: the `pagesBuildVersion` projection,
|
|
3
3
|
* the exact `gala-pages-create-deployment-jcs-v2` request entity, the single
|
|
4
|
-
* create call, and the bounded poll loop over the exact
|
|
4
|
+
* create call, and the bounded poll loop over the exact twelve accepted
|
|
5
5
|
* statuses (DEC-097 sections 6.2 and 7).
|
|
6
6
|
*
|
|
7
7
|
* The create body is the one place either credential is allowed to meet the
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { PagesAdapterError } from './errors.js';
|
|
17
|
+
import { canonicalizeJson } from '@rathnasgala2/adapter-protocol';
|
|
17
18
|
|
|
18
19
|
import {
|
|
19
|
-
DOMAIN_PAGES_BUILD_VERSION,
|
|
20
20
|
POLL_BUDGET_SECONDS,
|
|
21
21
|
POLL_SCHEDULE_SECONDS,
|
|
22
22
|
POLL_TAIL_SECONDS,
|
|
@@ -43,36 +43,24 @@ export const MAXIMUM_ARTIFACT_ID = 9007199254740991;
|
|
|
43
43
|
const BUILD_VERSION_PATTERN = /^[0-9a-f]{40}$/u;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
* the
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* The `pagesBuildVersion`: the workflow run's head commit SHA (`GITHUB_SHA`,
|
|
47
|
+
* the OIDC `sha` claim). GitHub validates `pages_build_version` as a commit
|
|
48
|
+
* of the repository (measured on 2026-10-04: any other 40-hex value, such as
|
|
49
|
+
* a synthetic hash, answers 404), so a synthetic derivation can never deploy.
|
|
50
|
+
* `pagesDeploymentId` must equal it exactly.
|
|
50
51
|
*
|
|
51
|
-
* @param {{
|
|
52
|
-
* destinationKey: string,
|
|
53
|
-
* operationId: string,
|
|
54
|
-
* attemptId: string,
|
|
55
|
-
* runId?: string,
|
|
56
|
-
* runAttempt?: number,
|
|
57
|
-
* artifactId: string,
|
|
58
|
-
* artifactDigest: string,
|
|
59
|
-
* generationId: string
|
|
60
|
-
* }} projection the closed projection inputs
|
|
52
|
+
* @param {{headSha?: string | undefined}} projection the run's head commit
|
|
61
53
|
* @returns {string} the 40-character lowercase hexadecimal build version
|
|
62
54
|
*/
|
|
63
55
|
export function derivePagesBuildVersion(projection) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
generationId: projection.generationId,
|
|
73
|
-
})
|
|
74
|
-
.slice('sha256:'.length)
|
|
75
|
-
.slice(0, 40);
|
|
56
|
+
const value = projection.headSha;
|
|
57
|
+
if (typeof value !== 'string' || !BUILD_VERSION_PATTERN.test(value)) {
|
|
58
|
+
throw new PagesAdapterError(
|
|
59
|
+
'PAGES_HEAD_SHA_INVALID',
|
|
60
|
+
'the destination must carry the run head commit SHA (headSha) as exactly 40 lowercase hexadecimal characters',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
76
64
|
}
|
|
77
65
|
|
|
78
66
|
/**
|
|
@@ -89,13 +77,15 @@ export function assertCanonicalCreateBody(bodyText) {
|
|
|
89
77
|
try {
|
|
90
78
|
parsed = JSON.parse(bodyText);
|
|
91
79
|
} catch {
|
|
92
|
-
throw new
|
|
93
|
-
'PAGES_CREATE_BODY_NONCANONICAL
|
|
80
|
+
throw new PagesAdapterError(
|
|
81
|
+
'PAGES_CREATE_BODY_NONCANONICAL',
|
|
82
|
+
'the create request entity is not JSON',
|
|
94
83
|
);
|
|
95
84
|
}
|
|
96
85
|
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
97
|
-
throw new
|
|
98
|
-
'PAGES_CREATE_BODY_NONCANONICAL
|
|
86
|
+
throw new PagesAdapterError(
|
|
87
|
+
'PAGES_CREATE_BODY_NONCANONICAL',
|
|
88
|
+
'the create request entity is not a JSON object',
|
|
99
89
|
);
|
|
100
90
|
}
|
|
101
91
|
const keys = Object.keys(/** @type {Record<string, unknown>} */ (parsed));
|
|
@@ -103,13 +93,15 @@ export function assertCanonicalCreateBody(bodyText) {
|
|
|
103
93
|
keys.length !== CREATE_BODY_MEMBERS.length ||
|
|
104
94
|
!CREATE_BODY_MEMBERS.every((name, index) => keys[index] === name)
|
|
105
95
|
) {
|
|
106
|
-
throw new
|
|
107
|
-
`PAGES_CREATE_BODY_NONCANONICAL
|
|
96
|
+
throw new PagesAdapterError(
|
|
97
|
+
`PAGES_CREATE_BODY_NONCANONICAL`,
|
|
98
|
+
`the create request entity must have exactly the three members ${CREATE_BODY_MEMBERS.join(', ')} in JCS order`,
|
|
108
99
|
);
|
|
109
100
|
}
|
|
110
101
|
if (canonicalizeJson(parsed) !== bodyText) {
|
|
111
|
-
throw new
|
|
112
|
-
'PAGES_CREATE_BODY_NONCANONICAL
|
|
102
|
+
throw new PagesAdapterError(
|
|
103
|
+
'PAGES_CREATE_BODY_NONCANONICAL',
|
|
104
|
+
'the create request entity is not compact RFC 8785 JCS',
|
|
113
105
|
);
|
|
114
106
|
}
|
|
115
107
|
}
|
|
@@ -134,18 +126,21 @@ export function buildCreateDeploymentBody(input) {
|
|
|
134
126
|
artifactId > MAXIMUM_ARTIFACT_ID ||
|
|
135
127
|
String(artifactId) !== String(input.pagesArtifactId)
|
|
136
128
|
) {
|
|
137
|
-
throw new
|
|
138
|
-
`PAGES_ARTIFACT_ID_INVALID
|
|
129
|
+
throw new PagesAdapterError(
|
|
130
|
+
`PAGES_ARTIFACT_ID_INVALID`,
|
|
131
|
+
`${JSON.stringify(String(input.pagesArtifactId))} is not a JSON integer in 1..${MAXIMUM_ARTIFACT_ID}; a string artifact id, a non-integer and an unsafe integer are all refused`,
|
|
139
132
|
);
|
|
140
133
|
}
|
|
141
134
|
if (!BUILD_VERSION_PATTERN.test(input.pagesBuildVersion)) {
|
|
142
|
-
throw new
|
|
143
|
-
'PAGES_BUILD_VERSION_INVALID
|
|
135
|
+
throw new PagesAdapterError(
|
|
136
|
+
'PAGES_BUILD_VERSION_INVALID',
|
|
137
|
+
'pages_build_version must be exactly 40 lowercase hexadecimal characters',
|
|
144
138
|
);
|
|
145
139
|
}
|
|
146
140
|
if (typeof input.oidcToken !== 'string' || input.oidcToken === '') {
|
|
147
|
-
throw new
|
|
148
|
-
'PAGES_OIDC_TOKEN_REQUIRED
|
|
141
|
+
throw new PagesAdapterError(
|
|
142
|
+
'PAGES_OIDC_TOKEN_REQUIRED',
|
|
143
|
+
'oidc_token is a mandatory member of the create request entity',
|
|
149
144
|
);
|
|
150
145
|
}
|
|
151
146
|
const bodyText = canonicalizeJson({
|
|
@@ -155,8 +150,9 @@ export function buildCreateDeploymentBody(input) {
|
|
|
155
150
|
});
|
|
156
151
|
assertCanonicalCreateBody(bodyText);
|
|
157
152
|
if (bodyText.includes(input.githubToken)) {
|
|
158
|
-
throw new
|
|
159
|
-
'PAGES_SECRET_LEAK_DETECTED
|
|
153
|
+
throw new PagesAdapterError(
|
|
154
|
+
'PAGES_SECRET_LEAK_DETECTED',
|
|
155
|
+
'the GitHub token reached the create request body; DEC-097 section 7 forbids it',
|
|
160
156
|
);
|
|
161
157
|
}
|
|
162
158
|
return Object.freeze({
|
|
@@ -211,8 +207,9 @@ export async function createDeployment(context, input) {
|
|
|
211
207
|
const parsed = /** @type {Record<string, unknown>} */ (response.body ?? {});
|
|
212
208
|
const observedId = parsed.id === undefined ? undefined : String(parsed.id);
|
|
213
209
|
if (observedId !== input.pagesBuildVersion) {
|
|
214
|
-
throw new
|
|
215
|
-
`PAGES_DEPLOYMENT_ID_MISMATCH
|
|
210
|
+
throw new PagesAdapterError(
|
|
211
|
+
`PAGES_DEPLOYMENT_ID_MISMATCH`,
|
|
212
|
+
`provider returned deployment id ${JSON.stringify(observedId)} for requested pages_build_version ${JSON.stringify(input.pagesBuildVersion)}`,
|
|
216
213
|
);
|
|
217
214
|
}
|
|
218
215
|
|
|
@@ -223,8 +220,9 @@ export async function createDeployment(context, input) {
|
|
|
223
220
|
: undefined;
|
|
224
221
|
const pollUrl = buildPollUrl(context, input.pagesBuildVersion);
|
|
225
222
|
if (observedStatusUrl === pollUrl) {
|
|
226
|
-
throw new
|
|
227
|
-
'PAGES_STATUS_URL_EQUALS_POLL_URL
|
|
223
|
+
throw new PagesAdapterError(
|
|
224
|
+
'PAGES_STATUS_URL_EQUALS_POLL_URL',
|
|
225
|
+
'DEC-097 section 7 forbids equality between the create response status_url and the independently constructed poll URL',
|
|
228
226
|
);
|
|
229
227
|
}
|
|
230
228
|
|
|
@@ -294,8 +292,9 @@ export async function pollDeployment(context, pagesDeploymentId, options) {
|
|
|
294
292
|
observedStatuses.push(status);
|
|
295
293
|
|
|
296
294
|
if (!PAGES_DEPLOYMENT_STATUSES.includes(status)) {
|
|
297
|
-
throw new
|
|
298
|
-
`PAGES_DEPLOYMENT_STATUS_UNKNOWN
|
|
295
|
+
throw new PagesAdapterError(
|
|
296
|
+
`PAGES_DEPLOYMENT_STATUS_UNKNOWN`,
|
|
297
|
+
`${JSON.stringify(status)} is outside the twelve accepted statuses; the destination fence stays held`,
|
|
299
298
|
);
|
|
300
299
|
}
|
|
301
300
|
if (status === SUCCESS_STATUS) {
|
|
@@ -305,15 +304,17 @@ export async function pollDeployment(context, pagesDeploymentId, options) {
|
|
|
305
304
|
return { status, succeeded: false, observedStatuses, waitedSeconds };
|
|
306
305
|
}
|
|
307
306
|
if (!TEMPORARY_STATUSES.includes(status)) {
|
|
308
|
-
throw new
|
|
309
|
-
`PAGES_DEPLOYMENT_STATUS_UNPARTITIONED
|
|
307
|
+
throw new PagesAdapterError(
|
|
308
|
+
`PAGES_DEPLOYMENT_STATUS_UNPARTITIONED`,
|
|
309
|
+
`${JSON.stringify(status)} is neither temporary nor terminal`,
|
|
310
310
|
);
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
const wait = POLL_SCHEDULE_SECONDS[attempt] ?? POLL_TAIL_SECONDS;
|
|
314
314
|
if (spent + wait > budget) {
|
|
315
|
-
throw new
|
|
316
|
-
`PAGES_DEPLOYMENT_POLL_BUDGET_EXHAUSTED
|
|
315
|
+
throw new PagesAdapterError(
|
|
316
|
+
`PAGES_DEPLOYMENT_POLL_BUDGET_EXHAUSTED`,
|
|
317
|
+
`${pagesDeploymentId} was still ${status} after ${spent} seconds; the outcome is ambiguous and the destination fence stays held`,
|
|
317
318
|
);
|
|
318
319
|
}
|
|
319
320
|
spent += wait;
|
|
@@ -328,6 +329,10 @@ export async function pollDeployment(context, pagesDeploymentId, options) {
|
|
|
328
329
|
*/
|
|
329
330
|
function defaultSleep(seconds) {
|
|
330
331
|
return new Promise((resolve) => {
|
|
331
|
-
|
|
332
|
+
// Referenced on purpose: an unreferenced timer let the event loop drain while
|
|
333
|
+
// the only pending work was this sleep, and Node exited with code 13
|
|
334
|
+
// ("unsettled top-level await") mid-poll on a real run. The poll budget
|
|
335
|
+
// bounds the wait; nothing else keeps the process alive during it.
|
|
336
|
+
setTimeout(resolve, seconds * 1000);
|
|
332
337
|
});
|
|
333
338
|
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This adapter's one typed failure class (PUB-H6). Every refusal this
|
|
3
|
+
* package raises -- OIDC verification, the Pages REST catalog, the request
|
|
4
|
+
* catalog, carrier construction, capability declaration, recovery --
|
|
5
|
+
* throws `PagesAdapterError`, which carries a stable `code` as a real
|
|
6
|
+
* property so a consumer can discriminate
|
|
7
|
+
* `error.code === 'PAGES_OIDC_SUBJECT_MISMATCH'` without parsing
|
|
8
|
+
* `.message`. `.message` is `${code}: ${detail}`, so a log line or the
|
|
9
|
+
* credential-hygiene scan still matches a code inside the message.
|
|
10
|
+
*
|
|
11
|
+
* The closed code vocabulary this class carries is documented in
|
|
12
|
+
* `README.md`.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A typed failure this adapter raises, carrying a stable `code`
|
|
19
|
+
* alongside the ordinary `Error` message.
|
|
20
|
+
*/
|
|
21
|
+
export class PagesAdapterError extends Error {
|
|
22
|
+
/**
|
|
23
|
+
* @param {string} code stable, machine-readable failure code
|
|
24
|
+
* @param {string} detail human-readable detail (never a token byte)
|
|
25
|
+
*/
|
|
26
|
+
constructor(code, detail) {
|
|
27
|
+
super(`${code}: ${detail}`);
|
|
28
|
+
this.name = 'PagesAdapterError';
|
|
29
|
+
/** @type {string} */
|
|
30
|
+
this.code = code;
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/index.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* @module
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { PagesAdapterError } from './errors.js';
|
|
24
25
|
import {
|
|
25
26
|
fenceDisagrees,
|
|
26
27
|
fenceFor,
|
|
@@ -56,15 +57,17 @@ import {
|
|
|
56
57
|
} from './recovery.js';
|
|
57
58
|
import { GITHUB_API_ORIGIN, buildRequestTemplates } from './request-catalog.js';
|
|
58
59
|
import { bindIdentity, callProvider } from './rest.js';
|
|
59
|
-
import {
|
|
60
|
+
import { stateFor } from './store.js';
|
|
60
61
|
|
|
61
62
|
export {
|
|
62
63
|
EXPECT_NOTHING_SERVED,
|
|
63
64
|
fenceFor,
|
|
64
65
|
generateUuidV7,
|
|
65
66
|
} from '@rathnasgala2/adapter-protocol';
|
|
67
|
+
export { PagesAdapterError } from './errors.js';
|
|
66
68
|
export { computeArtifactDigest } from './artifact-projection.js';
|
|
67
69
|
export { decodeCarrier, encodeCarrier } from './carrier.js';
|
|
70
|
+
export { buildValidatedMarker } from './marker.js';
|
|
68
71
|
export { GENERATION_MARKER_PATH } from './constants.js';
|
|
69
72
|
export { forgetDestination } from './store.js';
|
|
70
73
|
export { ADAPTER_VERSION, NORMAL_MODE, RECOVERY_MODE } from './constants.js';
|
|
@@ -114,7 +117,8 @@ export {
|
|
|
114
117
|
* publicFetch?: typeof globalThis.fetch,
|
|
115
118
|
* sleep?: (seconds: number) => Promise<void>,
|
|
116
119
|
* runId?: string,
|
|
117
|
-
* runAttempt?: number
|
|
120
|
+
* runAttempt?: number,
|
|
121
|
+
* headSha?: string
|
|
118
122
|
* }>} PagesDestination
|
|
119
123
|
*/
|
|
120
124
|
|
|
@@ -378,8 +382,9 @@ export async function stage(input) {
|
|
|
378
382
|
continue;
|
|
379
383
|
}
|
|
380
384
|
if (existing.artifactDigest !== input.artifactDigest) {
|
|
381
|
-
throw new
|
|
382
|
-
`IDEMPOTENCY_KEY_REUSE_CONFLICT
|
|
385
|
+
throw new PagesAdapterError(
|
|
386
|
+
`IDEMPOTENCY_KEY_REUSE_CONFLICT`,
|
|
387
|
+
`idempotency key ${JSON.stringify(input.idempotencyKey)} was already used for a different artifact digest`,
|
|
383
388
|
);
|
|
384
389
|
}
|
|
385
390
|
return Object.freeze({
|
|
@@ -407,8 +412,9 @@ export async function stage(input) {
|
|
|
407
412
|
];
|
|
408
413
|
const carrierBytes = encodeCarrier(carrierFiles);
|
|
409
414
|
if (carrierBytes.byteLength > MAXIMUM_PAGES_CARRIER_BYTES) {
|
|
410
|
-
throw new
|
|
411
|
-
`PAGES_CARRIER_TOO_LARGE
|
|
415
|
+
throw new PagesAdapterError(
|
|
416
|
+
`PAGES_CARRIER_TOO_LARGE`,
|
|
417
|
+
`${carrierBytes.byteLength} bytes exceed the ${MAXIMUM_PAGES_CARRIER_BYTES}-byte Pages artifact ceiling`,
|
|
412
418
|
);
|
|
413
419
|
}
|
|
414
420
|
const carrierDigest = sha256Hex(carrierBytes);
|
|
@@ -423,8 +429,9 @@ export async function stage(input) {
|
|
|
423
429
|
published.artifactDigest !== undefined &&
|
|
424
430
|
published.artifactDigest !== carrierDigest
|
|
425
431
|
) {
|
|
426
|
-
throw new
|
|
427
|
-
`PAGES_CARRIER_HANDOFF_MISMATCH
|
|
432
|
+
throw new PagesAdapterError(
|
|
433
|
+
`PAGES_CARRIER_HANDOFF_MISMATCH`,
|
|
434
|
+
`the artifact publisher reported digest ${published.artifactDigest} for a carrier whose bytes digest to ${carrierDigest}`,
|
|
428
435
|
);
|
|
429
436
|
}
|
|
430
437
|
|
|
@@ -507,8 +514,9 @@ export async function recoverPriorAttempt(input) {
|
|
|
507
514
|
function requirePagesOidc(destination, input) {
|
|
508
515
|
const token = input.pagesOidcToken ?? destination.oidcToken;
|
|
509
516
|
if (typeof token !== 'string' || token === '') {
|
|
510
|
-
throw new
|
|
511
|
-
'PAGES_OIDC_TOKEN_REQUIRED
|
|
517
|
+
throw new PagesAdapterError(
|
|
518
|
+
'PAGES_OIDC_TOKEN_REQUIRED',
|
|
519
|
+
'oidc_token is a mandatory member of the create request entity (DEC-097 section 7). Supply it as input.pagesOidcToken or destination.oidcToken; this repository never mints a credential.',
|
|
512
520
|
);
|
|
513
521
|
}
|
|
514
522
|
const claims = requireOidcExpectation(
|
|
@@ -518,8 +526,9 @@ function requirePagesOidc(destination, input) {
|
|
|
518
526
|
destination.repositoryId === undefined ||
|
|
519
527
|
destination.repositoryOwnerId === undefined
|
|
520
528
|
) {
|
|
521
|
-
throw new
|
|
522
|
-
'PAGES_OIDC_EXPECTATION_INVALID
|
|
529
|
+
throw new PagesAdapterError(
|
|
530
|
+
'PAGES_OIDC_EXPECTATION_INVALID',
|
|
531
|
+
'destination.repositoryId and destination.repositoryOwnerId are required so the two admitted subject forms can be recomputed from the verified claims',
|
|
523
532
|
);
|
|
524
533
|
}
|
|
525
534
|
return {
|
|
@@ -577,13 +586,15 @@ export async function activate(input) {
|
|
|
577
586
|
);
|
|
578
587
|
const mode = input.mode ?? NORMAL_MODE;
|
|
579
588
|
if (!AUTHORITY_MODES.includes(mode)) {
|
|
580
|
-
throw new
|
|
581
|
-
`PAGES_AUTHORITY_MODE_INVALID
|
|
589
|
+
throw new PagesAdapterError(
|
|
590
|
+
`PAGES_AUTHORITY_MODE_INVALID`,
|
|
591
|
+
`${JSON.stringify(mode)} is not one of ${AUTHORITY_MODES.join(', ')}`,
|
|
582
592
|
);
|
|
583
593
|
}
|
|
584
594
|
if (mode === NORMAL_MODE && input.pagesRecovery !== undefined) {
|
|
585
|
-
throw new
|
|
586
|
-
'PAGES_RECOVERY_RECORD_FORBIDDEN
|
|
595
|
+
throw new PagesAdapterError(
|
|
596
|
+
'PAGES_RECOVERY_RECORD_FORBIDDEN',
|
|
597
|
+
'normal mode forbids pagesRecovery and every recovery-prior call',
|
|
587
598
|
);
|
|
588
599
|
}
|
|
589
600
|
const oidc = requirePagesOidc(input.destination, input);
|
|
@@ -673,8 +684,9 @@ export async function activate(input) {
|
|
|
673
684
|
|
|
674
685
|
const record = state.stages.get(input.stageToken);
|
|
675
686
|
if (record === undefined) {
|
|
676
|
-
throw new
|
|
677
|
-
`PAGES_STAGE_NOT_FOUND
|
|
687
|
+
throw new PagesAdapterError(
|
|
688
|
+
`PAGES_STAGE_NOT_FOUND`,
|
|
689
|
+
`stage token ${JSON.stringify(input.stageToken)} has no staged carrier in this run`,
|
|
678
690
|
);
|
|
679
691
|
}
|
|
680
692
|
|
|
@@ -689,8 +701,9 @@ export async function activate(input) {
|
|
|
689
701
|
.map((file) => projectEntry(file.path, file.bytes)),
|
|
690
702
|
);
|
|
691
703
|
if (recomputed !== input.expectedArtifactDigest) {
|
|
692
|
-
throw new
|
|
693
|
-
`STAGE_INTEGRITY_MISMATCH
|
|
704
|
+
throw new PagesAdapterError(
|
|
705
|
+
`STAGE_INTEGRITY_MISMATCH`,
|
|
706
|
+
`staged carrier digests to ${recomputed}, which disagrees with the expected artifact digest ${input.expectedArtifactDigest}; refusing to promote a partial or tampered stage`,
|
|
694
707
|
);
|
|
695
708
|
}
|
|
696
709
|
}
|
|
@@ -703,18 +716,7 @@ export async function activate(input) {
|
|
|
703
716
|
}
|
|
704
717
|
|
|
705
718
|
const pagesBuildVersion = derivePagesBuildVersion({
|
|
706
|
-
|
|
707
|
-
operationId: record.operationId,
|
|
708
|
-
attemptId: record.attemptId,
|
|
709
|
-
...(input.destination.runId === undefined
|
|
710
|
-
? {}
|
|
711
|
-
: { runId: input.destination.runId }),
|
|
712
|
-
...(input.destination.runAttempt === undefined
|
|
713
|
-
? {}
|
|
714
|
-
: { runAttempt: input.destination.runAttempt }),
|
|
715
|
-
artifactId: record.artifactId,
|
|
716
|
-
artifactDigest: record.artifactDigest,
|
|
717
|
-
generationId: input.generationId,
|
|
719
|
+
headSha: input.destination.headSha,
|
|
718
720
|
});
|
|
719
721
|
|
|
720
722
|
const context = bindIdentity(baseContext, {
|
|
@@ -740,8 +742,9 @@ export async function activate(input) {
|
|
|
740
742
|
state.inFlight.delete(input.generationId);
|
|
741
743
|
|
|
742
744
|
if (!polled.succeeded) {
|
|
743
|
-
throw new
|
|
744
|
-
`PAGES_DEPLOYMENT_FAILED
|
|
745
|
+
throw new PagesAdapterError(
|
|
746
|
+
`PAGES_DEPLOYMENT_FAILED`,
|
|
747
|
+
`deployment ${pagesBuildVersion} reached terminal status ${polled.status}`,
|
|
745
748
|
);
|
|
746
749
|
}
|
|
747
750
|
|
|
@@ -931,8 +934,9 @@ export async function rollback(input) {
|
|
|
931
934
|
(candidate) => candidate.generationId === input.targetGenerationId,
|
|
932
935
|
);
|
|
933
936
|
if (record === undefined) {
|
|
934
|
-
throw new
|
|
935
|
-
`ROLLBACK_INPUT_UNAVAILABLE
|
|
937
|
+
throw new PagesAdapterError(
|
|
938
|
+
`ROLLBACK_INPUT_UNAVAILABLE`,
|
|
939
|
+
`generation ${JSON.stringify(input.targetGenerationId)} was not staged by this run and GitHub Pages cannot read a historical artifact back; supply its bytes through "files"`,
|
|
936
940
|
);
|
|
937
941
|
}
|
|
938
942
|
files = decodeCarrier(record.carrierBytes).filter(
|
package/src/marker.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { PagesAdapterError } from './errors.js';
|
|
13
14
|
import { validateGalaDocument } from '@rathnasgala2/schemas';
|
|
14
15
|
|
|
15
16
|
/** The exact schema identity every marker is validated against. */
|
|
@@ -34,8 +35,9 @@ export function buildValidatedMarker(identity) {
|
|
|
34
35
|
});
|
|
35
36
|
const validation = validateGalaDocument(MARKER_SCHEMA_ID, marker);
|
|
36
37
|
if (!validation.valid) {
|
|
37
|
-
throw new
|
|
38
|
-
`PAGES_MARKER_INVALID
|
|
38
|
+
throw new PagesAdapterError(
|
|
39
|
+
`PAGES_MARKER_INVALID`,
|
|
40
|
+
`${JSON.stringify(validation.diagnostics)}`,
|
|
39
41
|
);
|
|
40
42
|
}
|
|
41
43
|
return marker;
|
package/src/oidc.js
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
* environment job, which calls the GitHub-hosted runner URL from
|
|
11
11
|
* `ACTIONS_ID_TOKEN_REQUEST_URL` exactly once with
|
|
12
12
|
* `ACTIONS_ID_TOKEN_REQUEST_TOKEN` (that is what the job's `id-token: write`
|
|
13
|
-
* permission is for), against an origin that must
|
|
14
|
-
*
|
|
13
|
+
* permission is for), against an origin that must match the closed
|
|
14
|
+
* capability-authorized `githubActionsOidcOriginCatalog` grammar (one
|
|
15
|
+
* lowercase label under `.actions.githubusercontent.com`).
|
|
15
16
|
*
|
|
16
17
|
* For this in-job, single-use credential the trust boundary is therefore
|
|
17
18
|
* that exact catalog-authorized, DNS/TLS-authenticated runner token endpoint
|
|
@@ -36,13 +37,18 @@
|
|
|
36
37
|
* from the separately verified `repository`, `repository_owner`,
|
|
37
38
|
* `repository_id` and `repository_owner_id` claims, `environment`, and the
|
|
38
39
|
* caller-supplied ref/SHA/run id/run attempt/`job_workflow_ref`/
|
|
39
|
-
* `job_workflow_sha` expectations
|
|
40
|
+
* `job_workflow_sha` expectations; and (PUB-L5, belt-and-braces) `exp`,
|
|
41
|
+
* `iat` and, when present, `nbf`, each within
|
|
42
|
+
* {@link PAGES_OIDC_CLOCK_SKEW_SECONDS} of the check's own clock -- Pages
|
|
43
|
+
* remains the authoritative check for token staleness, per the trust
|
|
44
|
+
* boundary above.
|
|
40
45
|
*
|
|
41
46
|
* No error raised here ever contains a token byte.
|
|
42
47
|
*
|
|
43
48
|
* @module
|
|
44
49
|
*/
|
|
45
50
|
|
|
51
|
+
import { PagesAdapterError } from './errors.js';
|
|
46
52
|
/** The closed credential-source profile this module implements. */
|
|
47
53
|
export const PAGES_OIDC_PROFILE = 'gala-pages-oidc-v2';
|
|
48
54
|
|
|
@@ -54,8 +60,22 @@ export const PAGES_OIDC_ENVIRONMENT = 'github-pages';
|
|
|
54
60
|
|
|
55
61
|
/** Inclusive byte bounds on the compact JWT (DEC-097 section 7). */
|
|
56
62
|
export const PAGES_OIDC_MINIMUM_BYTES = 1;
|
|
57
|
-
/**
|
|
58
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Inclusive upper byte bound on the compact JWT: a memory bound with headroom,
|
|
65
|
+
* not an expected size. GitHub controls the actual token size.
|
|
66
|
+
*/
|
|
67
|
+
export const PAGES_OIDC_MAXIMUM_BYTES = 32768;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* PUB-L5: clock-skew tolerance, in seconds, for the belt-and-braces
|
|
71
|
+
* `exp`/`iat`/`nbf` checks below. GitHub Pages is the relying party that
|
|
72
|
+
* authoritatively rejects a stale or not-yet-valid token (this module's own
|
|
73
|
+
* header explains why that is the real trust boundary); this check exists
|
|
74
|
+
* only to fail closed earlier, with a clearer diagnostic, when it costs
|
|
75
|
+
* nothing to do so. 300 seconds is generous enough to absorb ordinary
|
|
76
|
+
* runner/host clock drift without weakening the check.
|
|
77
|
+
*/
|
|
78
|
+
export const PAGES_OIDC_CLOCK_SKEW_SECONDS = 300;
|
|
59
79
|
|
|
60
80
|
const BASE64URL_SEGMENT = /^[A-Za-z0-9_-]+$/u;
|
|
61
81
|
const CANONICAL_DECIMAL = /^(?:0|[1-9][0-9]*)$/u;
|
|
@@ -83,7 +103,7 @@ const CANONICAL_DECIMAL = /^(?:0|[1-9][0-9]*)$/u;
|
|
|
83
103
|
* @returns {never} never returns
|
|
84
104
|
*/
|
|
85
105
|
function refuse(code, detail) {
|
|
86
|
-
throw new
|
|
106
|
+
throw new PagesAdapterError(code, detail);
|
|
87
107
|
}
|
|
88
108
|
|
|
89
109
|
/**
|
|
@@ -269,6 +289,66 @@ function requireCanonicalDecimal(value, name) {
|
|
|
269
289
|
return /** @type {string} */ (text);
|
|
270
290
|
}
|
|
271
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Read one required numeric claim (a JWT `NumericDate`: seconds since the
|
|
294
|
+
* epoch, per RFC 7519 section 2).
|
|
295
|
+
*
|
|
296
|
+
* @param {Record<string, unknown>} payload the parsed payload
|
|
297
|
+
* @param {string} name the claim name
|
|
298
|
+
* @returns {number} the claim value
|
|
299
|
+
*/
|
|
300
|
+
function requireNumericClaim(payload, name) {
|
|
301
|
+
const value = payload[name];
|
|
302
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
303
|
+
refuse(
|
|
304
|
+
'PAGES_OIDC_CLAIM_MISSING',
|
|
305
|
+
`the ${JSON.stringify(name)} claim is absent or not a finite number`,
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
return /** @type {number} */ (value);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Belt-and-braces temporal validity: `exp` and `iat` are required and
|
|
313
|
+
* checked with a {@link PAGES_OIDC_CLOCK_SKEW_SECONDS} tolerance; `nbf` is
|
|
314
|
+
* checked the same way when present, since RFC 7519 makes it optional.
|
|
315
|
+
* Failing here is never the last word -- Pages independently rejects a
|
|
316
|
+
* stale token when it validates the signature -- but it produces a far
|
|
317
|
+
* clearer diagnostic than a Pages-side rejection, at zero verification cost.
|
|
318
|
+
*
|
|
319
|
+
* @param {Record<string, unknown>} payload the parsed payload
|
|
320
|
+
* @param {() => number} now the clock source, in epoch milliseconds
|
|
321
|
+
* (injectable so a test can pin "now" instead of racing the wall clock at
|
|
322
|
+
* the 300-second skew boundary; defaults to the real `Date.now`)
|
|
323
|
+
* @returns {void}
|
|
324
|
+
*/
|
|
325
|
+
function requireTemporalValidity(payload, now) {
|
|
326
|
+
const nowSeconds = now() / 1000;
|
|
327
|
+
const expiresAt = requireNumericClaim(payload, 'exp');
|
|
328
|
+
if (nowSeconds > expiresAt + PAGES_OIDC_CLOCK_SKEW_SECONDS) {
|
|
329
|
+
refuse(
|
|
330
|
+
'PAGES_OIDC_TOKEN_EXPIRED',
|
|
331
|
+
`the token's "exp" claim (${expiresAt}) is in the past beyond the ${PAGES_OIDC_CLOCK_SKEW_SECONDS}s skew tolerance`,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
const issuedAt = requireNumericClaim(payload, 'iat');
|
|
335
|
+
if (issuedAt > nowSeconds + PAGES_OIDC_CLOCK_SKEW_SECONDS) {
|
|
336
|
+
refuse(
|
|
337
|
+
'PAGES_OIDC_TOKEN_NOT_YET_VALID',
|
|
338
|
+
`the token's "iat" claim (${issuedAt}) is in the future beyond the ${PAGES_OIDC_CLOCK_SKEW_SECONDS}s skew tolerance`,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
if (payload.nbf !== undefined) {
|
|
342
|
+
const notBefore = requireNumericClaim(payload, 'nbf');
|
|
343
|
+
if (notBefore > nowSeconds + PAGES_OIDC_CLOCK_SKEW_SECONDS) {
|
|
344
|
+
refuse(
|
|
345
|
+
'PAGES_OIDC_TOKEN_NOT_YET_VALID',
|
|
346
|
+
`the token's "nbf" claim (${notBefore}) is in the future beyond the ${PAGES_OIDC_CLOCK_SKEW_SECONDS}s skew tolerance`,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
272
352
|
/**
|
|
273
353
|
* Compare one claim against its expectation without echoing either value's
|
|
274
354
|
* observed bytes where the claim could carry caller content.
|
|
@@ -281,9 +361,12 @@ function requireCanonicalDecimal(value, name) {
|
|
|
281
361
|
*/
|
|
282
362
|
function requireClaimEquals(observed, expected, name, code) {
|
|
283
363
|
if (observed !== expected) {
|
|
364
|
+
// Every claim compared here is a public identity string (ref, sha, run id,
|
|
365
|
+
// workflow path), never a credential, so the observed value is named: a
|
|
366
|
+
// production refusal that hides it costs a full publish cycle to diagnose.
|
|
284
367
|
refuse(
|
|
285
368
|
code,
|
|
286
|
-
`the ${JSON.stringify(name)} claim does not byte-equal the expected ${JSON.stringify(expected)}`,
|
|
369
|
+
`the ${JSON.stringify(name)} claim ${JSON.stringify(String(observed))} does not byte-equal the expected ${JSON.stringify(expected)}`,
|
|
287
370
|
);
|
|
288
371
|
}
|
|
289
372
|
}
|
|
@@ -315,6 +398,10 @@ export function buildSubjectForms(identity) {
|
|
|
315
398
|
*
|
|
316
399
|
* @param {unknown} token the caller-supplied compact JWT
|
|
317
400
|
* @param {PagesOidcExpectation} expected the expected bindings
|
|
401
|
+
* @param {() => number} [now] the clock source used for the `exp`/`iat`/`nbf`
|
|
402
|
+
* checks, in epoch milliseconds. Defaults to `Date.now`; a test supplies a
|
|
403
|
+
* fixed function to check the {@link PAGES_OIDC_CLOCK_SKEW_SECONDS}
|
|
404
|
+
* boundary deterministically instead of racing the real clock.
|
|
318
405
|
* @returns {Readonly<{
|
|
319
406
|
* profile: string,
|
|
320
407
|
* subjectForm: 'name' | 'identifier',
|
|
@@ -322,7 +409,7 @@ export function buildSubjectForms(identity) {
|
|
|
322
409
|
* tokenByteCount: number
|
|
323
410
|
* }>} non-secret evidence about the accepted token
|
|
324
411
|
*/
|
|
325
|
-
export function verifyPagesOidcToken(token, expected) {
|
|
412
|
+
export function verifyPagesOidcToken(token, expected, now = Date.now) {
|
|
326
413
|
if (typeof token !== 'string' || token === '') {
|
|
327
414
|
refuse(
|
|
328
415
|
'PAGES_OIDC_TOKEN_REQUIRED',
|
|
@@ -363,6 +450,8 @@ export function verifyPagesOidcToken(token, expected) {
|
|
|
363
450
|
'JWT payload',
|
|
364
451
|
);
|
|
365
452
|
|
|
453
|
+
requireTemporalValidity(payload, now);
|
|
454
|
+
|
|
366
455
|
const repositoryOwner = requireStringClaim(payload, 'repository_owner');
|
|
367
456
|
const repositoryClaim = requireStringClaim(payload, 'repository');
|
|
368
457
|
const repositoryId = requireCanonicalDecimal(
|