agl 41.1.0 → 42.0.0
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 +48 -0
- package/dist_serve/bundle.js +2190 -2193
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +3 -68
- package/dist_serve/bundle.js.third-party-notices.txt +4 -137
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +4 -4
- package/dist_ts/classes.authmodels.d.ts +2 -8
- package/dist_ts/classes.authmodels.js +60 -23
- package/dist_ts/classes.authstore.d.ts +22 -0
- package/dist_ts/classes.authstore.js +152 -23
- package/dist_ts/classes.cli.d.ts +3 -6
- package/dist_ts/classes.cli.js +38 -51
- package/dist_ts/classes.config.d.ts +17 -3
- package/dist_ts/classes.config.js +55 -18
- package/dist_ts/classes.controller.d.ts +12 -12
- package/dist_ts/classes.controller.js +46 -117
- package/dist_ts/classes.controllermanagement.d.ts +42 -9
- package/dist_ts/classes.controllermanagement.js +72 -23
- package/dist_ts/classes.controllerservice.d.ts +3 -31
- package/dist_ts/classes.controllerservice.js +3 -47
- package/dist_ts/classes.inferencegateway.js +4 -3
- package/dist_ts/classes.inferenceusage.d.ts +19 -7
- package/dist_ts/classes.inferenceusage.js +49 -13
- package/dist_ts/classes.inferenceusagetap.d.ts +15 -3
- package/dist_ts/classes.inferenceusagetap.js +16 -9
- package/dist_ts/classes.mcpcontrollerhost.js +9 -3
- package/dist_ts/classes.processinspection.d.ts +8 -1
- package/dist_ts/classes.processinspection.js +92 -2
- package/dist_ts/classes.proxycontrol.js +6 -1
- package/dist_ts/classes.proxydaemon.d.ts +2 -2
- package/dist_ts/classes.proxydaemon.js +1 -1
- package/dist_ts/classes.proxystore.d.ts +2 -11
- package/dist_ts/classes.proxystore.js +3 -25
- package/dist_ts/classes.tpmsecretcodec.d.ts +13 -0
- package/dist_ts/classes.tpmsecretcodec.js +28 -0
- package/dist_ts/classes.trustedproxysecrets.d.ts +91 -0
- package/dist_ts/classes.trustedproxysecrets.js +338 -0
- package/dist_ts/classes.upgradecoordinator.d.ts +14 -1
- package/dist_ts/classes.upgradecoordinator.js +21 -3
- package/dist_ts/classes.upgradetransaction.d.ts +32 -0
- package/dist_ts/classes.upgradetransaction.js +101 -4
- package/dist_ts/classes.usagefeed.js +3 -2
- package/dist_ts/functions.controlleradmission.d.ts +67 -0
- package/dist_ts/functions.controlleradmission.js +127 -0
- package/dist_ts/functions.remotecli.d.ts +27 -0
- package/dist_ts/functions.remotecli.js +236 -0
- package/dist_ts/functions.retiredenvironment.d.ts +11 -2
- package/dist_ts/functions.retiredenvironment.js +22 -5
- package/dist_ts/index.d.ts +1 -0
- package/dist_ts/index.js +2 -1
- package/dist_ts/interfaces.auth.d.ts +29 -4
- package/dist_ts/interfaces.auth.js +5 -1
- package/dist_ts/interfaces.config.d.ts +14 -0
- package/dist_ts/interfaces.config.js +9 -2
- package/dist_ts/interfaces.lifecycle.d.ts +3 -0
- package/dist_ts_authswitch/classes.authoritydaemon.js +6 -1
- package/dist_ts_interfaces/interfaces.d.ts +2 -2
- package/dist_ts_interfaces/interfaces.js +1 -1
- package/dist_ts_interfaces/management.d.ts +2 -2
- package/dist_ts_interfaces/management.js +2 -2
- package/dist_ts_interfaces/metrics.d.ts +29 -7
- package/dist_ts_interfaces/metrics.js +14 -1
- package/dist_ts_interfaces/requests.d.ts +1 -2
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/requests.upgrade.d.ts +0 -12
- package/package.json +12 -11
- package/readme.md +99 -28
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +3 -3
- package/ts/classes.authmodels.ts +68 -25
- package/ts/classes.authstore.ts +151 -24
- package/ts/classes.cli.ts +38 -61
- package/ts/classes.config.ts +70 -21
- package/ts/classes.controller.ts +50 -163
- package/ts/classes.controllermanagement.ts +123 -49
- package/ts/classes.controllerservice.ts +3 -56
- package/ts/classes.inferencegateway.ts +3 -2
- package/ts/classes.inferenceusage.ts +58 -19
- package/ts/classes.inferenceusagetap.ts +27 -8
- package/ts/classes.mcpcontrollerhost.ts +10 -5
- package/ts/classes.processinspection.ts +84 -3
- package/ts/classes.proxycontrol.ts +2 -0
- package/ts/classes.proxydaemon.ts +3 -2
- package/ts/classes.proxystore.ts +4 -25
- package/ts/classes.tpmsecretcodec.ts +26 -0
- package/ts/classes.trustedproxysecrets.ts +317 -0
- package/ts/classes.upgradecoordinator.ts +33 -3
- package/ts/classes.upgradetransaction.ts +130 -1
- package/ts/classes.usagefeed.ts +2 -1
- package/ts/functions.controlleradmission.ts +168 -0
- package/ts/functions.remotecli.ts +264 -0
- package/ts/functions.retiredenvironment.ts +25 -3
- package/ts/index.ts +1 -0
- package/ts/interfaces.auth.ts +36 -3
- package/ts/interfaces.config.ts +15 -0
- package/ts/interfaces.lifecycle.ts +3 -0
- package/ts_authswitch/classes.authoritydaemon.ts +2 -0
- package/ts_interfaces/interfaces.ts +2 -2
- package/ts_interfaces/management.ts +2 -2
- package/ts_interfaces/metrics.ts +34 -7
- package/ts_interfaces/requests.ts +0 -10
- package/ts_interfaces/requests.upgrade.ts +0 -16
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/classes.controllersocketclient.ts +5 -2
- package/ts_web/elements.metricsboard.ts +68 -18
package/ts/classes.config.ts
CHANGED
|
@@ -9,10 +9,12 @@ import type {
|
|
|
9
9
|
IControllerRuntimeOverrides,
|
|
10
10
|
TControllerTlsMode,
|
|
11
11
|
} from './interfaces.config.js';
|
|
12
|
+
import { canonicalGatewaySources } from './functions.controlleradmission.js';
|
|
12
13
|
|
|
13
14
|
export const defaultControllerPort = 4097;
|
|
14
15
|
export const defaultOpenCodePort = 4098;
|
|
15
|
-
|
|
16
|
+
/** Where an initialized port's origin, RP ID, TLS mode and gateway sources change. */
|
|
17
|
+
const remoteMoveRemedy = 'Change it with `agl remote set` or `agl remote unset` while the controller is stopped.';
|
|
16
18
|
|
|
17
19
|
export interface IControllerDataDirectoryOptions extends IAGLHomeOptions {}
|
|
18
20
|
|
|
@@ -133,21 +135,6 @@ export const readDatabaseConfig = (
|
|
|
133
135
|
};
|
|
134
136
|
};
|
|
135
137
|
|
|
136
|
-
export const readTrustedProxySecret = (tlsModeArg: TControllerTlsMode): string | undefined => {
|
|
137
|
-
if (tlsModeArg === 'local') return undefined;
|
|
138
|
-
const secret = process.env[trustedProxySecretEnvironmentVariable]?.trim();
|
|
139
|
-
if (
|
|
140
|
-
!secret
|
|
141
|
-
|| !/^[A-Za-z0-9_-]{43}$/u.test(secret)
|
|
142
|
-
|| Buffer.from(secret, 'base64url').byteLength !== 32
|
|
143
|
-
) {
|
|
144
|
-
throw new Error(
|
|
145
|
-
`${trustedProxySecretEnvironmentVariable} must be a 32-byte base64url secret in proxy mode.`,
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
return secret;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
138
|
export const resolveInitialRuntimeConfig = async (
|
|
152
139
|
overridesArg: IControllerRuntimeOverrides,
|
|
153
140
|
): Promise<IControllerRuntimeConfig> => {
|
|
@@ -216,16 +203,24 @@ export const resolveStoredRuntimeConfig = async (
|
|
|
216
203
|
if (storedArg.tlsMode !== 'proxy' && effectivePort(storedOrigin) !== storedArg.controllerPort) {
|
|
217
204
|
throw new Error('Stored local public-origin port does not match the controller port.');
|
|
218
205
|
}
|
|
206
|
+
if (storedArg.gatewaySources !== undefined && (
|
|
207
|
+
storedArg.tlsMode !== 'proxy'
|
|
208
|
+
|| !Array.isArray(storedArg.gatewaySources)
|
|
209
|
+
|| storedArg.gatewaySources.length === 0
|
|
210
|
+
|| canonicalGatewaySources(storedArg.gatewaySources).join(',') !== storedArg.gatewaySources.join(',')
|
|
211
|
+
)) {
|
|
212
|
+
throw new Error('Stored gateway sources are invalid.');
|
|
213
|
+
}
|
|
219
214
|
if (overridesArg.publicOrigin !== undefined) {
|
|
220
215
|
const requestedOrigin = normalizeOrigin(overridesArg.publicOrigin).origin;
|
|
221
216
|
if (requestedOrigin !== storedArg.publicOrigin) {
|
|
222
|
-
throw new Error(
|
|
217
|
+
throw new Error(`publicOrigin is immutable after controller initialization. ${remoteMoveRemedy}`);
|
|
223
218
|
}
|
|
224
219
|
}
|
|
225
220
|
if (overridesArg.rpId !== undefined) {
|
|
226
221
|
const requestedRpId = normalizeRpId(overridesArg.rpId, storedOrigin.hostname);
|
|
227
222
|
if (requestedRpId !== storedArg.rpId) {
|
|
228
|
-
throw new Error(
|
|
223
|
+
throw new Error(`rpId is immutable after controller initialization. ${remoteMoveRemedy}`);
|
|
229
224
|
}
|
|
230
225
|
}
|
|
231
226
|
if (overridesArg.opencodePort !== undefined && overridesArg.opencodePort !== storedArg.opencodePort) {
|
|
@@ -233,11 +228,11 @@ export const resolveStoredRuntimeConfig = async (
|
|
|
233
228
|
}
|
|
234
229
|
if (storedArg.tlsMode === 'proxy') {
|
|
235
230
|
if (overridesArg.behindTlsProxy === false) {
|
|
236
|
-
throw new Error(
|
|
231
|
+
throw new Error(`Stored TLS proxy mode is immutable. ${remoteMoveRemedy}`);
|
|
237
232
|
}
|
|
238
233
|
} else {
|
|
239
234
|
if (overridesArg.behindTlsProxy) {
|
|
240
|
-
throw new Error(
|
|
235
|
+
throw new Error(`Stored localhost mode cannot be changed to TLS mode. ${remoteMoveRemedy}`);
|
|
241
236
|
}
|
|
242
237
|
}
|
|
243
238
|
if (
|
|
@@ -252,5 +247,59 @@ export const resolveStoredRuntimeConfig = async (
|
|
|
252
247
|
throw new Error('The projects root is immutable after it has been adopted.');
|
|
253
248
|
}
|
|
254
249
|
}
|
|
255
|
-
return
|
|
250
|
+
return cloneRuntimeConfig(storedArg);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const cloneRuntimeConfig = (configArg: IControllerRuntimeConfig): IControllerRuntimeConfig => ({
|
|
254
|
+
controllerPort: configArg.controllerPort,
|
|
255
|
+
publicOrigin: configArg.publicOrigin,
|
|
256
|
+
rpId: configArg.rpId,
|
|
257
|
+
projectsRoot: configArg.projectsRoot,
|
|
258
|
+
opencodePort: configArg.opencodePort,
|
|
259
|
+
tlsMode: configArg.tlsMode,
|
|
260
|
+
...(configArg.gatewaySources === undefined ? {} : { gatewaySources: [...configArg.gatewaySources] }),
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
/** The public origin `agl remote set` moves a port to, behind a TLS reverse proxy. */
|
|
264
|
+
export interface IControllerRemoteTarget {
|
|
265
|
+
publicOrigin: string;
|
|
266
|
+
/** The origin's hostname when absent. */
|
|
267
|
+
rpId?: string;
|
|
268
|
+
/** May be empty: then only a reverse proxy on this host reaches the controller. */
|
|
269
|
+
gatewaySources: readonly string[];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The runtime configuration an initialized port moves to: `agl remote set` (a public origin behind a TLS reverse
|
|
274
|
+
* proxy) or `agl remote unset` (`local`: back to `http://localhost:<port>`, RP ID `localhost`). The port, projects root
|
|
275
|
+
* and OpenCode port stay. `storedArg` must already be a validated stored configuration
|
|
276
|
+
* (`resolveStoredRuntimeConfig`). The only path that changes these settings once a port is initialized; a starting
|
|
277
|
+
* controller never does.
|
|
278
|
+
*/
|
|
279
|
+
export const resolveMovedRuntimeConfig = (
|
|
280
|
+
storedArg: IControllerRuntimeConfig,
|
|
281
|
+
targetArg: IControllerRemoteTarget | 'local',
|
|
282
|
+
): IControllerRuntimeConfig => {
|
|
283
|
+
const kept = {
|
|
284
|
+
controllerPort: storedArg.controllerPort,
|
|
285
|
+
projectsRoot: storedArg.projectsRoot,
|
|
286
|
+
opencodePort: storedArg.opencodePort,
|
|
287
|
+
};
|
|
288
|
+
if (targetArg === 'local') {
|
|
289
|
+
return { ...kept, publicOrigin: `http://localhost:${storedArg.controllerPort}`, rpId: 'localhost', tlsMode: 'local' };
|
|
290
|
+
}
|
|
291
|
+
const origin = normalizeOrigin(targetArg.publicOrigin);
|
|
292
|
+
if (origin.protocol !== 'https:') {
|
|
293
|
+
throw new Error('agl remote set takes an HTTPS public origin; `agl remote unset` moves back to localhost.');
|
|
294
|
+
}
|
|
295
|
+
const tlsMode = resolveTlsMode(origin, true);
|
|
296
|
+
const rpId = normalizeRpId(targetArg.rpId ?? origin.hostname, origin.hostname);
|
|
297
|
+
const gatewaySources = canonicalGatewaySources(targetArg.gatewaySources);
|
|
298
|
+
return {
|
|
299
|
+
...kept,
|
|
300
|
+
publicOrigin: origin.origin,
|
|
301
|
+
rpId,
|
|
302
|
+
tlsMode,
|
|
303
|
+
...(gatewaySources.length === 0 ? {} : { gatewaySources }),
|
|
304
|
+
};
|
|
256
305
|
};
|
package/ts/classes.controller.ts
CHANGED
|
@@ -314,7 +314,6 @@ import {
|
|
|
314
314
|
type IReq_ControllerSetupFinish,
|
|
315
315
|
type IReq_ControllerStatus,
|
|
316
316
|
type IReq_ControllerUpgradeLaunch,
|
|
317
|
-
type IReq_ControllerUpgradePrepare,
|
|
318
317
|
type IReq_ControllerUpgradePrepareBegin,
|
|
319
318
|
type IReq_ControllerUpgradeFinalize,
|
|
320
319
|
type IReq_ControllerFailureDetailGet,
|
|
@@ -347,11 +346,12 @@ import {
|
|
|
347
346
|
parseFlexAuthorityConnectionId,
|
|
348
347
|
} from '../ts_interfaces/index.js';
|
|
349
348
|
import {
|
|
350
|
-
readTrustedProxySecret,
|
|
351
349
|
resolveInitialRuntimeConfig,
|
|
352
350
|
resolveStoredRuntimeConfig,
|
|
353
351
|
} from './classes.config.js';
|
|
354
|
-
import {
|
|
352
|
+
import { controllerListenerOptions } from './functions.controlleradmission.js';
|
|
353
|
+
import { ControllerTrustedProxySecrets } from './classes.trustedproxysecrets.js';
|
|
354
|
+
import { TpmSecretCodec } from './classes.tpmsecretcodec.js';
|
|
355
355
|
import { resolveAGLHomePaths } from './classes.aglhome.js';
|
|
356
356
|
import { selectControllerBrowserPaint } from './functions.browserpaintartifact.js';
|
|
357
357
|
import { ControllerBrowserViewerAssets } from './functions.browserpaintassets.js';
|
|
@@ -795,7 +795,6 @@ const currentRuntimeName = currentCliName === upgradePackageTransitionTarget.cli
|
|
|
795
795
|
const authenticatedPeerStateKey = '__opencodeControllerAuthenticatedCredentialId';
|
|
796
796
|
const terminalPeerLifecycleStateKey = '__harnessControllerTerminalPeerLifecycle';
|
|
797
797
|
const operationAbortControllerPeerStateKey = '__harnessControllerOperationAbortController';
|
|
798
|
-
const trustedProxySecretHeader = 'x-harness-controller-proxy-secret';
|
|
799
798
|
// Generous for a local single-user deployment: transcripts and inline
|
|
800
799
|
// attachments are legitimately multi-megabyte, and an undersized limit
|
|
801
800
|
// fail-closes the connection (and with it the per-connection auth).
|
|
@@ -2846,17 +2845,9 @@ const asTypedResponseError = (
|
|
|
2846
2845
|
const hashResumeToken = (tokenArg: string): string =>
|
|
2847
2846
|
plugins.crypto.createHash('sha256').update(tokenArg, 'utf8').digest('base64url');
|
|
2848
2847
|
|
|
2849
|
-
const headerSecretsEqual = (candidateArg: string | null, expectedArg: string): boolean => {
|
|
2850
|
-
if (candidateArg === null) return false;
|
|
2851
|
-
const candidate = Buffer.from(candidateArg, 'utf8');
|
|
2852
|
-
const expected = Buffer.from(expectedArg, 'utf8');
|
|
2853
|
-
return candidate.byteLength === expected.byteLength
|
|
2854
|
-
&& plugins.crypto.timingSafeEqual(candidate, expected);
|
|
2855
|
-
};
|
|
2856
|
-
|
|
2857
2848
|
const assertControllerUpgradePreparationRequest: (
|
|
2858
2849
|
requestArg: unknown,
|
|
2859
|
-
) => asserts requestArg is
|
|
2850
|
+
) => asserts requestArg is IReq_ControllerUpgradePrepareBegin['request'] = (requestArg) => {
|
|
2860
2851
|
if (
|
|
2861
2852
|
!requestArg
|
|
2862
2853
|
|| typeof requestArg !== 'object'
|
|
@@ -2873,24 +2864,6 @@ const assertControllerUpgradePreparationRequest: (
|
|
|
2873
2864
|
);
|
|
2874
2865
|
};
|
|
2875
2866
|
|
|
2876
|
-
export const isControllerWebSocketRequestAllowed = (
|
|
2877
|
-
headersArg: Headers,
|
|
2878
|
-
publicOriginArg: string,
|
|
2879
|
-
tlsModeArg: 'local' | 'proxy',
|
|
2880
|
-
trustedProxySecretArg?: string,
|
|
2881
|
-
): boolean => {
|
|
2882
|
-
const origin = headersArg.get('origin');
|
|
2883
|
-
if (origin === null) return true;
|
|
2884
|
-
if (origin !== publicOriginArg) return false;
|
|
2885
|
-
if (tlsModeArg === 'local') return true;
|
|
2886
|
-
return headersArg.get('x-forwarded-proto') === 'https'
|
|
2887
|
-
&& trustedProxySecretArg !== undefined
|
|
2888
|
-
&& headerSecretsEqual(
|
|
2889
|
-
headersArg.get(trustedProxySecretHeader),
|
|
2890
|
-
trustedProxySecretArg,
|
|
2891
|
-
);
|
|
2892
|
-
};
|
|
2893
|
-
|
|
2894
2867
|
interface IControllerHarnessSessionEnumeration {
|
|
2895
2868
|
openCode: PromiseSettledResult<IControllerSession[]>;
|
|
2896
2869
|
flex: PromiseSettledResult<IControllerSession[]>;
|
|
@@ -3371,6 +3344,8 @@ export class OpenCodeController {
|
|
|
3371
3344
|
return this.ticketStore.applyFleetEvent(eventArg, signalArg, originArg);
|
|
3372
3345
|
}
|
|
3373
3346
|
private passkeyManager?: PasskeyManager;
|
|
3347
|
+
/** TLS-proxy mode only: the secret admission accepts from the reverse proxy, and its rotation. */
|
|
3348
|
+
private trustedProxySecrets?: ControllerTrustedProxySecrets;
|
|
3374
3349
|
private openCodeSupervisor?: OpenCodeSupervisor;
|
|
3375
3350
|
private openCodeClient?: OpenCodeClientAdapter;
|
|
3376
3351
|
private flexSupervisor?: FlexSupervisor;
|
|
@@ -4150,6 +4125,17 @@ export class OpenCodeController {
|
|
|
4150
4125
|
}
|
|
4151
4126
|
}
|
|
4152
4127
|
|
|
4128
|
+
/**
|
|
4129
|
+
* The trusted-proxy secret of a running controller in TLS-proxy mode, for its gateway client: the secret its route
|
|
4130
|
+
* carries (`routeSecret`), `rotate` and `confirm` once the route carries the new one. Refused in local mode.
|
|
4131
|
+
*/
|
|
4132
|
+
public requireTrustedProxySecrets(): ControllerTrustedProxySecrets {
|
|
4133
|
+
if (!this.trustedProxySecrets) {
|
|
4134
|
+
throw new Error('This controller runs no trusted reverse proxy: it is in local mode or not running.');
|
|
4135
|
+
}
|
|
4136
|
+
return this.trustedProxySecrets;
|
|
4137
|
+
}
|
|
4138
|
+
|
|
4153
4139
|
public getStatus(): IControllerStatus {
|
|
4154
4140
|
const openCodeStatus = this.openCodeSupervisor?.getStatus() ?? {
|
|
4155
4141
|
state: 'stopped' as const,
|
|
@@ -10064,9 +10050,6 @@ export class OpenCodeController {
|
|
|
10064
10050
|
? await resolveStoredRuntimeConfig(storedConfig, this.options.runtimeOverrides)
|
|
10065
10051
|
: await resolveInitialRuntimeConfig(this.options.runtimeOverrides);
|
|
10066
10052
|
this.assertStartActive();
|
|
10067
|
-
if (this.options.serviceUnit !== undefined) {
|
|
10068
|
-
assertControllerServiceTlsMode({ stored: runtimeConfig.tlsMode, remedy: controllerServiceDetachedRemedy });
|
|
10069
|
-
}
|
|
10070
10053
|
const authDocument = await authStore.resolveOrCreateRuntimeConfig(runtimeConfig);
|
|
10071
10054
|
await authStore.migrateTicketOwnerPrincipal();
|
|
10072
10055
|
this.assertStartActive();
|
|
@@ -10113,7 +10096,15 @@ export class OpenCodeController {
|
|
|
10113
10096
|
this.assertStartActive();
|
|
10114
10097
|
|
|
10115
10098
|
const router = this.createRouter(runtimeConfig.publicOrigin);
|
|
10116
|
-
|
|
10099
|
+
if (runtimeConfig.tlsMode === 'proxy') {
|
|
10100
|
+
this.trustedProxySecrets = await ControllerTrustedProxySecrets.open({
|
|
10101
|
+
controllerId: authDocument.id,
|
|
10102
|
+
issuerId: issuerIdentity.issuerId,
|
|
10103
|
+
codec: this.options.trustedProxySecretCodec ?? new TpmSecretCodec(),
|
|
10104
|
+
});
|
|
10105
|
+
this.assertStartActive();
|
|
10106
|
+
}
|
|
10107
|
+
const trustedProxySecrets = this.trustedProxySecrets;
|
|
10117
10108
|
const publicHostname = new URL(runtimeConfig.publicOrigin).hostname;
|
|
10118
10109
|
const hostnames = [...new Set([publicHostname, 'localhost', '127.0.0.1'])];
|
|
10119
10110
|
const serveDirectory = plugins.path.resolve(
|
|
@@ -10137,11 +10128,11 @@ export class OpenCodeController {
|
|
|
10137
10128
|
this.assertStartActive();
|
|
10138
10129
|
const typedServer = new plugins.typedserver.TypedServer({
|
|
10139
10130
|
port: runtimeConfig.controllerPort,
|
|
10140
|
-
//
|
|
10141
|
-
//
|
|
10142
|
-
//
|
|
10143
|
-
//
|
|
10144
|
-
|
|
10131
|
+
// One listener: loopback unless a gateway reaches this controller from another address, and then every
|
|
10132
|
+
// interface, where admission refuses every address off loopback that is not a gateway source sending the
|
|
10133
|
+
// trusted-proxy secret, on every surface alike. The host firewall must still let only the gateways reach the
|
|
10134
|
+
// port (readme, "Remote Browser Access").
|
|
10135
|
+
...controllerListenerOptions(runtimeConfig, (valueArg) => trustedProxySecrets?.accepts(valueArg) === true),
|
|
10145
10136
|
cors: false,
|
|
10146
10137
|
websocketMaxPayloadBytes: websocketPayloadLimit,
|
|
10147
10138
|
connectionTimeout: 120_000,
|
|
@@ -10180,12 +10171,6 @@ export class OpenCodeController {
|
|
|
10180
10171
|
headers: { Allow: 'GET, HEAD' },
|
|
10181
10172
|
});
|
|
10182
10173
|
},
|
|
10183
|
-
websocketAdmission: (contextArg) => isControllerWebSocketRequestAllowed(
|
|
10184
|
-
contextArg.headers,
|
|
10185
|
-
runtimeConfig.publicOrigin,
|
|
10186
|
-
runtimeConfig.tlsMode,
|
|
10187
|
-
trustedProxySecret,
|
|
10188
|
-
),
|
|
10189
10174
|
securityHeaders,
|
|
10190
10175
|
},
|
|
10191
10176
|
],
|
|
@@ -13444,6 +13429,8 @@ export class OpenCodeController {
|
|
|
13444
13429
|
await authStore.close();
|
|
13445
13430
|
if (this.authStore === authStore) {
|
|
13446
13431
|
this.authStore = undefined;
|
|
13432
|
+
this.trustedProxySecrets?.close();
|
|
13433
|
+
this.trustedProxySecrets = undefined;
|
|
13447
13434
|
this.passkeyManager = undefined;
|
|
13448
13435
|
this.controllerId = undefined;
|
|
13449
13436
|
this.openCodeRuntimeDirectory = undefined;
|
|
@@ -13561,7 +13548,6 @@ export class OpenCodeController {
|
|
|
13561
13548
|
});
|
|
13562
13549
|
|
|
13563
13550
|
this.registerStatusHandlers(publicRouter);
|
|
13564
|
-
this.registerUpgradeHandlers(publicRouter);
|
|
13565
13551
|
|
|
13566
13552
|
this.registerAuthHandlers(browserAuthRouter, publicOriginArg);
|
|
13567
13553
|
this.registerSignInHandlers(protectedRouter);
|
|
@@ -13601,22 +13587,12 @@ export class OpenCodeController {
|
|
|
13601
13587
|
publicRouterArg.addTypedHandler(this.createStatusHandler());
|
|
13602
13588
|
}
|
|
13603
13589
|
|
|
13604
|
-
/**
|
|
13605
|
-
* Public scope: the caller is the upgrade command, which holds no passkey session.
|
|
13606
|
-
* Every handler here authorises itself against the upgrade token it is handed.
|
|
13607
|
-
*/
|
|
13608
|
-
private registerUpgradeHandlers(publicRouterArg: plugins.typedrequest.TypedRouter): void {
|
|
13609
|
-
publicRouterArg.addTypedHandler(this.createUpgradeLaunchHandler());
|
|
13610
|
-
publicRouterArg.addTypedHandler(this.createUpgradePrepareHandler());
|
|
13611
|
-
publicRouterArg.addTypedHandler(this.createUpgradePrepareBeginHandler());
|
|
13612
|
-
publicRouterArg.addTypedHandler(this.createUpgradeFinalizeHandler());
|
|
13613
|
-
}
|
|
13614
|
-
|
|
13615
13590
|
/**
|
|
13616
13591
|
* The router of the loopback management endpoint (`controllerManagementMethods`): the status read and the upgrade
|
|
13617
|
-
* methods the CLI and an upgrade worker of this or another release call
|
|
13618
|
-
* controller socket
|
|
13619
|
-
*
|
|
13592
|
+
* methods the CLI and an upgrade worker of this or another release call, which only this endpoint serves (the
|
|
13593
|
+
* controller socket keeps the status read for the browser). The status handler is the one the socket's public scope
|
|
13594
|
+
* uses, and each upgrade handler authorises itself against the upgrade token and one-time grant it is handed; the
|
|
13595
|
+
* endpoint's admission grants a request only its own peer. No other method is reachable through it.
|
|
13620
13596
|
*/
|
|
13621
13597
|
private createManagementRouter(): plugins.typedrequest.TypedRouter {
|
|
13622
13598
|
const router = new plugins.typedrequest.TypedRouter();
|
|
@@ -13727,52 +13703,6 @@ export class OpenCodeController {
|
|
|
13727
13703
|
);
|
|
13728
13704
|
}
|
|
13729
13705
|
|
|
13730
|
-
/** The synchronous preparation an upgrade worker of an earlier release asks for; served on the socket only. */
|
|
13731
|
-
private createUpgradePrepareHandler(): plugins.typedrequest.TypedHandler<IReq_ControllerUpgradePrepare> {
|
|
13732
|
-
return new plugins.typedrequest.TypedHandler<IReq_ControllerUpgradePrepare>(
|
|
13733
|
-
'controller.upgrade.prepare',
|
|
13734
|
-
async (requestArg, toolsArg) => {
|
|
13735
|
-
const peer = peerFromLocalData(toolsArg?.localData);
|
|
13736
|
-
this.recordUnauthenticatedPreflightOperation(peer.id);
|
|
13737
|
-
assertControllerUpgradePreparationRequest(requestArg);
|
|
13738
|
-
return this.runOperation(peer, async (signalArg) => (
|
|
13739
|
-
this.runUpgradePreparationAdmission(async () => {
|
|
13740
|
-
const installation = await resolveCurrentPnpmGlobalInstallation();
|
|
13741
|
-
const coordinator = this.coordinatorForUpgradeToken(
|
|
13742
|
-
requestArg.token,
|
|
13743
|
-
installation.globalRoot,
|
|
13744
|
-
);
|
|
13745
|
-
const status = this.getStatus();
|
|
13746
|
-
await coordinator.consumeControllerActionGrant({
|
|
13747
|
-
token: requestArg.token,
|
|
13748
|
-
action: 'prepare',
|
|
13749
|
-
packageVersion: commitinfo.version,
|
|
13750
|
-
controller: {
|
|
13751
|
-
pid: status.controllerPid,
|
|
13752
|
-
processGroupId: status.processGroupId,
|
|
13753
|
-
processFingerprint: status.processFingerprint,
|
|
13754
|
-
},
|
|
13755
|
-
});
|
|
13756
|
-
await coordinator.recordController(requestArg.token, {
|
|
13757
|
-
pid: status.controllerPid,
|
|
13758
|
-
processGroupId: status.processGroupId,
|
|
13759
|
-
fingerprint: status.processFingerprint,
|
|
13760
|
-
cliPath: installation.cliPath,
|
|
13761
|
-
command: this.options.processMode === 'detached' ? '__serve' : 'foreground',
|
|
13762
|
-
});
|
|
13763
|
-
return await this.prepareUpgrade(
|
|
13764
|
-
coordinator,
|
|
13765
|
-
requestArg.token,
|
|
13766
|
-
requestArg.targetVersion,
|
|
13767
|
-
requestArg.gracePeriodMs,
|
|
13768
|
-
signalArg,
|
|
13769
|
-
);
|
|
13770
|
-
})
|
|
13771
|
-
));
|
|
13772
|
-
},
|
|
13773
|
-
);
|
|
13774
|
-
}
|
|
13775
|
-
|
|
13776
13706
|
private createUpgradePrepareBeginHandler(): plugins.typedrequest.TypedHandler<IReq_ControllerUpgradePrepareBegin> {
|
|
13777
13707
|
return new plugins.typedrequest.TypedHandler<IReq_ControllerUpgradePrepareBegin>(
|
|
13778
13708
|
'controller.upgrade.prepare.begin',
|
|
@@ -35325,7 +35255,6 @@ export class OpenCodeController {
|
|
|
35325
35255
|
|
|
35326
35256
|
private async persistUpgradePreparation(
|
|
35327
35257
|
contextArg: IUpgradePreparationContext,
|
|
35328
|
-
asynchronousArg: boolean,
|
|
35329
35258
|
): Promise<void> {
|
|
35330
35259
|
await contextArg.coordinator.mutateTransaction(contextArg.token, (current) => {
|
|
35331
35260
|
if (current.version === upgradePackageTransitionTransactionVersion) {
|
|
@@ -35341,12 +35270,8 @@ export class OpenCodeController {
|
|
|
35341
35270
|
sessionId: { ...session.sessionId },
|
|
35342
35271
|
stopState: 'pending' as const,
|
|
35343
35272
|
})),
|
|
35344
|
-
|
|
35345
|
-
|
|
35346
|
-
preparationAcceptedAt: contextArg.acceptedAt,
|
|
35347
|
-
preparationDeadlineAt: contextArg.deadline,
|
|
35348
|
-
}
|
|
35349
|
-
: {}),
|
|
35273
|
+
preparationAcceptedAt: contextArg.acceptedAt,
|
|
35274
|
+
preparationDeadlineAt: contextArg.deadline,
|
|
35350
35275
|
};
|
|
35351
35276
|
}
|
|
35352
35277
|
return {
|
|
@@ -35359,12 +35284,8 @@ export class OpenCodeController {
|
|
|
35359
35284
|
sessionId: { ...session.sessionId },
|
|
35360
35285
|
stopState: 'pending' as const,
|
|
35361
35286
|
})),
|
|
35362
|
-
|
|
35363
|
-
|
|
35364
|
-
preparationAcceptedAt: contextArg.acceptedAt,
|
|
35365
|
-
preparationDeadlineAt: contextArg.deadline,
|
|
35366
|
-
}
|
|
35367
|
-
: {}),
|
|
35287
|
+
preparationAcceptedAt: contextArg.acceptedAt,
|
|
35288
|
+
preparationDeadlineAt: contextArg.deadline,
|
|
35368
35289
|
};
|
|
35369
35290
|
});
|
|
35370
35291
|
}
|
|
@@ -35388,7 +35309,7 @@ export class OpenCodeController {
|
|
|
35388
35309
|
*/
|
|
35389
35310
|
private async completeUpgradePreparation(
|
|
35390
35311
|
contextArg: IUpgradePreparationContext,
|
|
35391
|
-
): Promise<
|
|
35312
|
+
): Promise<void> {
|
|
35392
35313
|
const {
|
|
35393
35314
|
barrier,
|
|
35394
35315
|
coordinator,
|
|
@@ -35497,7 +35418,6 @@ export class OpenCodeController {
|
|
|
35497
35418
|
if (Date.now() > deadline) {
|
|
35498
35419
|
throw new Error('The upgrade preparation deadline expired before completion.');
|
|
35499
35420
|
}
|
|
35500
|
-
return { prepared: true, sessionCount: barrier.sessions.length };
|
|
35501
35421
|
}
|
|
35502
35422
|
|
|
35503
35423
|
private async updateUpgradeBlockers(
|
|
@@ -35538,7 +35458,6 @@ export class OpenCodeController {
|
|
|
35538
35458
|
private async compensateUpgradePreparationFailure(
|
|
35539
35459
|
contextArg: IUpgradePreparationContext,
|
|
35540
35460
|
errorArg: unknown,
|
|
35541
|
-
finishTransactionArg: boolean,
|
|
35542
35461
|
): Promise<void> {
|
|
35543
35462
|
let errorMessage = errorArg instanceof Error ? errorArg.message : String(errorArg);
|
|
35544
35463
|
try {
|
|
@@ -35551,44 +35470,12 @@ export class OpenCodeController {
|
|
|
35551
35470
|
} finally {
|
|
35552
35471
|
this.clearUpgradePreparationAbortController(contextArg);
|
|
35553
35472
|
}
|
|
35554
|
-
|
|
35555
|
-
|
|
35556
|
-
|
|
35557
|
-
|
|
35558
|
-
|
|
35559
|
-
|
|
35560
|
-
).catch(() => undefined);
|
|
35561
|
-
}
|
|
35562
|
-
}
|
|
35563
|
-
|
|
35564
|
-
private async prepareUpgrade(
|
|
35565
|
-
coordinatorArg: UpgradeCoordinator,
|
|
35566
|
-
tokenArg: string,
|
|
35567
|
-
targetVersionArg: string,
|
|
35568
|
-
gracePeriodMsArg: number,
|
|
35569
|
-
operationSignalArg: AbortSignal,
|
|
35570
|
-
): Promise<IReq_ControllerUpgradePrepare['response']> {
|
|
35571
|
-
const context = this.createUpgradePreparationContext(
|
|
35572
|
-
coordinatorArg,
|
|
35573
|
-
tokenArg,
|
|
35574
|
-
targetVersionArg,
|
|
35575
|
-
gracePeriodMsArg,
|
|
35576
|
-
operationSignalArg,
|
|
35577
|
-
);
|
|
35578
|
-
const operation = Promise.resolve().then(async () => {
|
|
35579
|
-
try {
|
|
35580
|
-
await this.persistUpgradePreparation(context, false);
|
|
35581
|
-
this.pushUpgradePreparationEvent();
|
|
35582
|
-
const response = await this.completeUpgradePreparation(context);
|
|
35583
|
-
this.clearUpgradePreparationAbortController(context);
|
|
35584
|
-
return response;
|
|
35585
|
-
} catch (errorArg) {
|
|
35586
|
-
await this.compensateUpgradePreparationFailure(context, errorArg, false);
|
|
35587
|
-
throw errorArg;
|
|
35588
|
-
}
|
|
35589
|
-
});
|
|
35590
|
-
this.upgradePreparationTask = operation.then(() => undefined, () => undefined);
|
|
35591
|
-
return await operation;
|
|
35473
|
+
await contextArg.coordinator.finishTransaction(
|
|
35474
|
+
contextArg.token,
|
|
35475
|
+
false,
|
|
35476
|
+
'Upgrade preparation failed.',
|
|
35477
|
+
errorMessage,
|
|
35478
|
+
).catch(() => undefined);
|
|
35592
35479
|
}
|
|
35593
35480
|
|
|
35594
35481
|
private async beginUpgradePreparation(
|
|
@@ -35644,13 +35531,13 @@ export class OpenCodeController {
|
|
|
35644
35531
|
this.clearUpgradePreparationAbortController(context);
|
|
35645
35532
|
return;
|
|
35646
35533
|
}
|
|
35647
|
-
await this.compensateUpgradePreparationFailure(context, errorArg
|
|
35534
|
+
await this.compensateUpgradePreparationFailure(context, errorArg);
|
|
35648
35535
|
}
|
|
35649
35536
|
})();
|
|
35650
35537
|
const trackedBackground = this.trackOperationPromise(background);
|
|
35651
35538
|
this.upgradePreparationTask = trackedBackground;
|
|
35652
35539
|
try {
|
|
35653
|
-
await this.persistUpgradePreparation(context
|
|
35540
|
+
await this.persistUpgradePreparation(context);
|
|
35654
35541
|
releaseGate();
|
|
35655
35542
|
this.pushUpgradePreparationEvent();
|
|
35656
35543
|
return { accepted: true };
|