Admit checked restricted artifacts without individual code approvals
This commit is contained in:
@@ -23,6 +23,39 @@ export interface ImportFinding {
|
||||
readonly detail: string;
|
||||
readonly line: number | null;
|
||||
}
|
||||
export const restrictedSDKSpecifier = "quixos:restricted-sdk/v1";
|
||||
export const restrictedSDKPath = "share/quixos/restricted/core.mjs";
|
||||
|
||||
/** Mechanical candidate checks, not authorization or an engine-safety proof.
|
||||
* The caller must first verify the manifest and all declared file digests. */
|
||||
export async function inspectRestrictedImplementation(
|
||||
revision: string,
|
||||
implementation: ArtifactImplementation,
|
||||
read: ArtifactReader,
|
||||
qualifiedSDKDigest?: string,
|
||||
): Promise<ImportFinding[]> {
|
||||
const entry = implementation.files.find((file) => file.path === implementation.path);
|
||||
const sdk = implementation.files.find((file) => file.path === restrictedSDKPath);
|
||||
if (
|
||||
implementation.compatibility !== "quixos-restricted-module-v1" ||
|
||||
implementation.target !== "server" ||
|
||||
implementation.files.length !== 2 ||
|
||||
!entry ||
|
||||
!sdk ||
|
||||
entry === sdk ||
|
||||
entry.mediaType !== "text/javascript" ||
|
||||
sdk.mediaType !== "text/javascript" ||
|
||||
!/^[$A-Z_a-z][$\w]*$/.test(implementation.registryExport ?? "")
|
||||
)
|
||||
return [{ code: "RESTRICTED_CLOSURE", detail: "Expected one closed module and the restricted SDK", line: null }];
|
||||
if (qualifiedSDKDigest && sdk.digest !== qualifiedSDKDigest)
|
||||
return [{ code: "RESTRICTED_SDK_UNSUPPORTED", detail: "SDK differs from the qualified host profile", line: null }];
|
||||
if (entry.bytes > 1024 * 1024 || sdk.bytes > 2 * 1024 * 1024)
|
||||
return [{ code: "ANALYSIS_LIMIT", detail: "Restricted closure exceeds the source budget", line: null }];
|
||||
return inspectJavaScriptSurface(Buffer.from(await read(revision, entry.path, entry.bytes)).toString("utf8"), [
|
||||
restrictedSDKSpecifier,
|
||||
]);
|
||||
}
|
||||
const nativeImports = new Set(builtinModules.flatMap((name) => [name, name.replace(/^node:/, "")]));
|
||||
const ambient = new Set([
|
||||
"process",
|
||||
@@ -136,10 +169,8 @@ export function inspectJavaScriptSurface(source: string, checkedSDKImports: read
|
||||
return findings;
|
||||
}
|
||||
|
||||
/** Derived metadata only. Browser/server portability and available targets say
|
||||
* nothing about sandbox eligibility. Build reports have no platform approval
|
||||
* catalog, so they conservatively require VM placement. A host can override
|
||||
* placement only for independently reviewed, exact restricted-code approvals. */
|
||||
/** Derived metadata only. A build report can describe a closed candidate but
|
||||
* cannot qualify the host's engine, SDK, OS sandbox or resource controller. */
|
||||
export async function reportExecutionPlacement(
|
||||
plan: ExecutionPlan,
|
||||
installation: ExecutionInstallation,
|
||||
@@ -156,11 +187,13 @@ export async function reportExecutionPlacement(
|
||||
const packages = await Promise.all(
|
||||
installation.packages.map(async (pkg) => {
|
||||
const implementations: { id: string; digest: string; compatibility: string; findings: ImportFinding[] }[] = [];
|
||||
for (const implementation of [pkg.service, pkg.module].filter(
|
||||
for (const implementation of [pkg.service, pkg.module, pkg.restricted].filter(
|
||||
(entry): entry is ArtifactImplementation => !!entry,
|
||||
)) {
|
||||
let findings: ImportFinding[];
|
||||
if (implementation.compatibility === "quixos-js-module-v1") {
|
||||
if (implementation.compatibility === "quixos-restricted-module-v1")
|
||||
findings = await inspectRestrictedImplementation(pkg.revision, implementation, read);
|
||||
else if (implementation.compatibility === "quixos-js-module-v1") {
|
||||
const file = implementation.files.find((file) => file.path === implementation.path)!;
|
||||
if (!file || file.bytes > 1024 * 1024)
|
||||
findings = [
|
||||
@@ -192,7 +225,14 @@ export async function reportExecutionPlacement(
|
||||
revision: pkg.revision,
|
||||
requiresVM: implementations.length > 0,
|
||||
restrictedEligible: false as const,
|
||||
reason: "NO_QUALIFIED_RESTRICTED_RUNTIME",
|
||||
reason: pkg.restricted ? "HOST_PROFILE_QUALIFICATION_REQUIRED" : "NO_RESTRICTED_IMPLEMENTATION",
|
||||
restrictedCandidate: pkg.restricted
|
||||
? {
|
||||
digest: pkg.restricted.contentDigest,
|
||||
exports: pkg.restricted.exports,
|
||||
compatible: implementations.find((entry) => entry.id === pkg.restricted!.id)!.findings.length === 0,
|
||||
}
|
||||
: null,
|
||||
implementations,
|
||||
};
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user