Skip to content

Commit 29af0e4

Browse files
committed
fix(hosted): restore owner admission size gate
1 parent 6639ff9 commit 29af0e4

2 files changed

Lines changed: 47 additions & 31 deletions

File tree

src/main/composition/hosted/hostedAdmissionSocketIdentity.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,25 @@ export function sameHostedAdmissionSocketIdentity(
4040
left.mode === right.mode
4141
);
4242
}
43+
44+
export function assertSameHostedAdmissionSocketIdentity(
45+
left: OrchestratorSocketIdentity,
46+
right: OrchestratorSocketIdentity
47+
): void {
48+
if (!sameHostedAdmissionSocketIdentity(left, right)) {
49+
throw new TypeError('hosted-lifecycle-owner-admission-socket-substituted');
50+
}
51+
}
52+
53+
export function hostedAdmissionSocketIdentityForPath(
54+
socketPaths: readonly string[],
55+
socketIdentities: readonly OrchestratorSocketIdentity[],
56+
socketPath: string | undefined
57+
): OrchestratorSocketIdentity {
58+
const index = socketPath === undefined ? -1 : socketPaths.indexOf(socketPath);
59+
const identity = index < 0 ? undefined : socketIdentities[index];
60+
if (identity === undefined) {
61+
throw new TypeError('hosted-lifecycle-owner-admission-layout-invalid');
62+
}
63+
return identity;
64+
}

src/main/composition/hosted/hostedLifecycleProductionOwnerAdmission.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { basename, dirname, isAbsolute, normalize, resolve } from 'node:path';
1313

1414
import { readHostedAdmissionExactRecord as readExactRecord } from './hostedAdmissionExactRecord';
1515
import {
16+
assertSameHostedAdmissionSocketIdentity,
17+
hostedAdmissionSocketIdentityForPath,
1618
parseHostedAdmissionSocketIdentity,
17-
sameHostedAdmissionSocketIdentity,
1819
} from './hostedAdmissionSocketIdentity';
1920
import {
2021
type HostedApprovalAdmissionPin,
@@ -224,20 +225,32 @@ export function admitHostedLifecycleProductionOwner(
224225
expectedUid,
225226
expectedGid,
226227
});
227-
assertSameSocketIdentity(
228+
assertSameHostedAdmissionSocketIdentity(
228229
parsed.expectedOwnerBinding.socketIdentity,
229-
socketIdentityForPath(admittedSocketPaths, admittedSocketIdentities, socketPath)
230+
hostedAdmissionSocketIdentityForPath(
231+
admittedSocketPaths,
232+
admittedSocketIdentities,
233+
socketPath
234+
)
230235
);
231236
for (const route of parsed.approvalRoutes) {
232-
assertSameSocketIdentity(
237+
assertSameHostedAdmissionSocketIdentity(
233238
route.socketIdentity,
234-
socketIdentityForPath(admittedSocketPaths, admittedSocketIdentities, route.socketPath)
239+
hostedAdmissionSocketIdentityForPath(
240+
admittedSocketPaths,
241+
admittedSocketIdentities,
242+
route.socketPath
243+
)
235244
);
236245
}
237246
for (const admittedSocketPath of admittedSocketPaths) {
238247
assertSocketStillCurrent(
239248
admittedSocketPath,
240-
socketIdentityForPath(admittedSocketPaths, admittedSocketIdentities, admittedSocketPath)
249+
hostedAdmissionSocketIdentityForPath(
250+
admittedSocketPaths,
251+
admittedSocketIdentities,
252+
admittedSocketPath
253+
)
241254
);
242255
}
243256
assertBootstrapBinding(
@@ -257,9 +270,9 @@ export function admitHostedLifecycleProductionOwner(
257270
expectedGid,
258271
});
259272
for (const [index, identity] of admittedSocketIdentities.entries()) {
260-
assertSameSocketIdentity(
273+
assertSameHostedAdmissionSocketIdentity(
261274
identity,
262-
socketIdentityForPath(
275+
hostedAdmissionSocketIdentityForPath(
263276
admittedSocketPaths,
264277
revalidatedSocketIdentities,
265278
admittedSocketPaths[index]
@@ -443,19 +456,6 @@ function assertOwnerRunDirectoryLayout(input: {
443456
);
444457
}
445458

446-
function socketIdentityForPath(
447-
socketPaths: readonly string[],
448-
socketIdentities: readonly OrchestratorSocketIdentity[],
449-
socketPath: string | undefined
450-
): OrchestratorSocketIdentity {
451-
const index = socketPath === undefined ? -1 : socketPaths.indexOf(socketPath);
452-
const identity = index < 0 ? undefined : socketIdentities[index];
453-
if (identity === undefined) {
454-
throw new TypeError('hosted-lifecycle-owner-admission-layout-invalid');
455-
}
456-
return identity;
457-
}
458-
459459
function assertLifecycleTrustDirectoryLayout(input: {
460460
readonly trustAnchorPath: string;
461461
readonly releasePinPath: string;
@@ -520,7 +520,10 @@ function readSocketIdentity(
520520
}
521521

522522
function assertSocketStillCurrent(path: string, expected: OrchestratorSocketIdentity): void {
523-
assertSameSocketIdentity(expected, readSocketIdentity(path, expected.uid, expected.gid));
523+
assertSameHostedAdmissionSocketIdentity(
524+
expected,
525+
readSocketIdentity(path, expected.uid, expected.gid)
526+
);
524527
}
525528

526529
function parseAdmissionPayload(
@@ -796,12 +799,3 @@ function sameReleasePin(
796799
candidate.protocolVersion === artifact.protocolVersion
797800
);
798801
}
799-
800-
function assertSameSocketIdentity(
801-
left: OrchestratorSocketIdentity,
802-
right: OrchestratorSocketIdentity
803-
): void {
804-
if (!sameHostedAdmissionSocketIdentity(left, right)) {
805-
throw new TypeError('hosted-lifecycle-owner-admission-socket-substituted');
806-
}
807-
}

0 commit comments

Comments
 (0)