Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/openshell-sdk-package-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
id: package
env:
NEMOCLAW_OPEN_SHELL_SDK_OUTPUT_DIRECTORY: ${{ runner.temp }}/openshell-sdk
NEMOCLAW_OPEN_SHELL_SDK_INCLUDE_REPLACEMENT: "1"
NODE_AUTH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
Expand Down
7 changes: 7 additions & 0 deletions ci/reviewed-npm-audit.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"integrity": "sha512-dB4mLex23Pnw61caGMR2CMHQihy9bj7IK2elJJd718k3yevm+fOt/vG6dJg8/5us4la2BwcOdRwLvOia3tdwFw==",
"tarballUrl": "https://npm.pkg.github.com/download/@nvidia/openshell-sdk/0.0.106/dc32180ba1d658fc4ec309bdf89d2b162196928d"
},
"sourceRegistryPackageReplacement": {
"artifactName": "nvidia-openshell-sdk-0.0.116.tgz",
"label": "OpenShell TypeScript SDK 0.0.116",
"packageSpec": "@nvidia/openshell-sdk@0.0.116",
"integrity": "sha512-MFnyX2vs47f/yVJRUXKmA7C6wZDH03ZGFFg+R5gZME+yMQDg9WF6G4Kdz/APM7nCUpaoGk2bwNEdUUmR60J54A==",
"tarballUrl": "https://npm.pkg.github.com/download/@nvidia/openshell-sdk/0.0.116/3380652847354127ed1bb8010490f8815040ada3"
},
"sourceNestedShrinkwrapPackages": ["@earendil-works/pi-coding-agent@0.80.6"],
"sourceRegistryPackagesWithoutIntegrity": [
{
Expand Down
80 changes: 52 additions & 28 deletions scripts/audit-reviewed-npm-graph.mts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type AuditConfig = Readonly<{
severityThreshold: Severity;
sourceNestedShrinkwrapPackages: readonly string[];
sourceRegistryPackage: SourceRegistryPackage;
sourceRegistryPackageReplacement?: SourceRegistryPackage;
sourceRegistryPackagesWithoutIntegrity: readonly PackageWithoutIntegrity[];
}>;
type ReviewedAuditReport = Readonly<{
Expand Down Expand Up @@ -93,6 +94,28 @@ const SOURCE_GRAPH = {
id: "nemoclaw-cli",
label: "NemoClaw CLI locked production graph",
} as const;

function isSourceRegistryPackage(value: unknown): value is SourceRegistryPackage {
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
const candidate = value as Partial<SourceRegistryPackage>;
return (
typeof candidate.artifactName === "string" &&
/^[a-z0-9][a-z0-9._-]*\.tgz$/.test(candidate.artifactName) &&
typeof candidate.label === "string" &&
candidate.label.length > 0 &&
typeof candidate.packageSpec === "string" &&
EXACT_NPM_PACKAGE_SPEC.test(candidate.packageSpec) &&
typeof candidate.integrity === "string" &&
candidate.integrity.length > 0 &&
typeof candidate.tarballUrl === "string" &&
candidate.tarballUrl.length > 0
);
}

function exactPackageName(packageSpec: string): string {
const separator = packageSpec.lastIndexOf("@");
return packageSpec.slice(0, separator);
}
const OPENCLAW_DOMEXCEPTION_ALIAS = {
actualName: "@nolyfill/domexception",
aliasPackagePath: "node_modules/openclaw/node_modules/node-domexception",
Expand Down Expand Up @@ -202,19 +225,15 @@ export function parseAuditConfig(contents: string): AuditConfig {
) ||
new Set(parsed.sourceRegistryPackagesWithoutIntegrity.map(({ packageSpec }) => packageSpec))
.size !== parsed.sourceRegistryPackagesWithoutIntegrity.length ||
typeof parsed.sourceRegistryPackage !== "object" ||
parsed.sourceRegistryPackage === null ||
Array.isArray(parsed.sourceRegistryPackage) ||
typeof parsed.sourceRegistryPackage.artifactName !== "string" ||
!/^[a-z0-9][a-z0-9._-]*\.tgz$/.test(parsed.sourceRegistryPackage.artifactName) ||
typeof parsed.sourceRegistryPackage.label !== "string" ||
!parsed.sourceRegistryPackage.label ||
typeof parsed.sourceRegistryPackage.packageSpec !== "string" ||
!EXACT_NPM_PACKAGE_SPEC.test(parsed.sourceRegistryPackage.packageSpec) ||
typeof parsed.sourceRegistryPackage.integrity !== "string" ||
!parsed.sourceRegistryPackage.integrity ||
typeof parsed.sourceRegistryPackage.tarballUrl !== "string" ||
!parsed.sourceRegistryPackage.tarballUrl ||
!isSourceRegistryPackage(parsed.sourceRegistryPackage) ||
(parsed.sourceRegistryPackageReplacement !== undefined &&
(!isSourceRegistryPackage(parsed.sourceRegistryPackageReplacement) ||
exactPackageName(parsed.sourceRegistryPackageReplacement.packageSpec) !==
exactPackageName(parsed.sourceRegistryPackage.packageSpec) ||
parsed.sourceRegistryPackageReplacement.packageSpec ===
parsed.sourceRegistryPackage.packageSpec ||
parsed.sourceRegistryPackageReplacement.artifactName ===
parsed.sourceRegistryPackage.artifactName)) ||
parsed.lockedGraphs.some(
(graph) =>
typeof graph.id !== "string" ||
Expand Down Expand Up @@ -472,26 +491,33 @@ export function materializeSourceGraph(
sourceRegistryPackage?: ReviewedPackage,
sourceNestedShrinkwrapPackages: readonly string[] = [],
sourceRegistryPackagesWithoutIntegrity: readonly PackageWithoutIntegrity[] = [],
sourceRegistryPackageReplacements: readonly ReviewedPackage[] = [],
): string {
assertRegularFile(sourcePackage, "NemoClaw CLI package manifest");
assertRegularFile(sourceLock, "NemoClaw CLI lockfile");
verifyReviewedNpmLockPackages({
const reviewedSourcePackages = [
sourceRegistryPackage,
...sourceRegistryPackageReplacements,
].filter((reviewed): reviewed is ReviewedPackage => reviewed !== undefined);
const lockedPackages = verifyReviewedNpmLockPackages({
allowedNestedShrinkwrapPackages: sourceNestedShrinkwrapPackages,
lockfilePath: sourceLock,
omitDev: true,
registryOrigin,
reviewedRegistryPackages: sourceRegistryPackage
? [
{
expectedIntegrity: sourceRegistryPackage.integrity,
label: sourceRegistryPackage.label,
packageSpec: sourceRegistryPackage.packageSpec,
tarballUrl: sourceRegistryPackage.tarballUrl,
},
]
: [],
reviewedRegistryPackages: reviewedSourcePackages.map((reviewed) => ({
expectedIntegrity: reviewed.integrity,
label: reviewed.label,
packageSpec: reviewed.packageSpec,
tarballUrl: reviewed.tarballUrl,
})),
reviewedPackagesWithoutIntegrity: sourceRegistryPackagesWithoutIntegrity,
});
if (
reviewedSourcePackages.filter(({ packageSpec }) => lockedPackages.includes(packageSpec))
.length > 1
) {
throw new Error("reviewed npm lock uses conflicting OpenShell SDK identities");
}
const lockSha256 = createHash("sha256").update(fs.readFileSync(sourceLock)).digest("hex");
fs.mkdirSync(destination);
fs.copyFileSync(sourcePackage, path.join(destination, "package.json"));
Expand Down Expand Up @@ -748,6 +774,7 @@ function auditSourceGraph(
config.sourceRegistryPackage,
config.sourceNestedShrinkwrapPackages,
config.sourceRegistryPackagesWithoutIntegrity,
config.sourceRegistryPackageReplacement ? [config.sourceRegistryPackageReplacement] : [],
);
return auditMaterializedSourceGraph({
directory,
Expand Down Expand Up @@ -1008,10 +1035,7 @@ function isMainModule(): boolean {
if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
throw error;
}
return (
fs.realpathSync.native(fileURLToPath(import.meta.url)) ===
invokedPath
);
return fs.realpathSync.native(fileURLToPath(import.meta.url)) === invokedPath;
}

if (isMainModule()) {
Expand Down
8 changes: 6 additions & 2 deletions scripts/checks/extract-installer-pins.mts
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,14 @@ const TRUSTED_OPENSHELL_RELEASES: readonly OpenShellReleaseTrust[] = [
url: "https://github.com/NVIDIA/OpenShell/releases/download/v0.0.116/openshell.rb",
},
// The v0.0.116 release publishes only MUSL standalone sandbox archives.
// Trust only the prospective installer template whose stable Linux path
// selects that ABI. The v0.0.106 record retains the active GNU templates.
// Trust only the reviewed prospective installer templates whose stable
// Linux path selects that ABI. The second digest is the exact full-cutover
// template consumed by #11251; keeping this approval in a separate base
// prerequisite prevents the activation PR from authorizing its own bytes.
// The v0.0.106 record retains the active GNU templates.
installerTemplateSha256: [
"243f607a1b9a67c116f80844d5cd6e7185d63537e74fb08b3994652f79cb00e9",
"2b6ad3e0730d3220da05d13b88fdba4458de46840bad57942ecad26a5d606017",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
],
manifests: [
{
Expand Down
50 changes: 36 additions & 14 deletions scripts/checks/package-openshell-sdk-for-pr.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,45 @@ import { packReviewedNpmArchive, removeReviewedNpmArchive } from "../lib/reviewe

const TRUSTED_REPOSITORY_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../..");

export function packageReviewedOpenShellSdk(outputDirectory: string): string {
export function packageReviewedOpenShellSdk(
outputDirectory: string,
includeReplacement = false,
dependencies: Readonly<{
pack?: typeof packReviewedNpmArchive;
remove?: typeof removeReviewedNpmArchive;
}> = {},
): string {
if (!outputDirectory) {
throw new Error("reviewed OpenShell SDK output directory is required");
}
const config = parseAuditConfig(
readFileSync(join(TRUSTED_REPOSITORY_ROOT, "ci/reviewed-npm-audit.json"), "utf8"),
);
const reviewed = config.sourceRegistryPackage;
const archive = packReviewedNpmArchive({
env: process.env,
expectedIntegrity: reviewed.integrity,
label: reviewed.label,
packageSpec: reviewed.packageSpec,
tarballUrl: reviewed.tarballUrl,
});
const reviewedPackages =
includeReplacement && config.sourceRegistryPackageReplacement
? [config.sourceRegistryPackage, config.sourceRegistryPackageReplacement]
: [config.sourceRegistryPackage];
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const archives: ReturnType<typeof packReviewedNpmArchive>[] = [];
const pack = dependencies.pack ?? packReviewedNpmArchive;
const remove = dependencies.remove ?? removeReviewedNpmArchive;
const output = resolve(outputDirectory);
try {
rmSync(output, { force: true, recursive: true });
mkdirSync(output, { recursive: true });
const artifact = join(output, reviewed.artifactName);
copyFileSync(archive.archivePath, artifact);
return artifact;
for (const reviewed of reviewedPackages) {
const archive = pack({
env: process.env,
expectedIntegrity: reviewed.integrity,
label: reviewed.label,
packageSpec: reviewed.packageSpec,
tarballUrl: reviewed.tarballUrl,
});
archives.push(archive);
copyFileSync(archive.archivePath, join(output, reviewed.artifactName));
}
return reviewedPackages.length === 1 ? join(output, reviewedPackages[0]!.artifactName) : output;
} finally {
removeReviewedNpmArchive(archive);
for (const archive of archives) remove(archive);
}
}

Expand All @@ -44,8 +59,15 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
console.error("NEMOCLAW_OPEN_SHELL_SDK_OUTPUT_DIRECTORY is required");
process.exit(1);
}
const includeReplacementValue = process.env.NEMOCLAW_OPEN_SHELL_SDK_INCLUDE_REPLACEMENT;
if (includeReplacementValue !== undefined && includeReplacementValue !== "1") {
console.error("NEMOCLAW_OPEN_SHELL_SDK_INCLUDE_REPLACEMENT must be 1 when set");
process.exit(1);
}
try {
process.stdout.write(`${packageReviewedOpenShellSdk(outputDirectory)}\n`);
process.stdout.write(
`${packageReviewedOpenShellSdk(outputDirectory, includeReplacementValue === "1")}\n`,
);
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exit(1);
Expand Down
38 changes: 29 additions & 9 deletions scripts/checks/prepare-ci-npm-install.mts
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,22 @@ function readTrustedAuditConfig(): AuditConfig {
);
}

function reviewedSourceRegistryPackages(
config: AuditConfig,
): readonly ReviewedSourceRegistryPackage[] {
return config.sourceRegistryPackageReplacement
? [config.sourceRegistryPackage, config.sourceRegistryPackageReplacement]
: [config.sourceRegistryPackage];
}

function inspectReviewedLocks(targetRoot: string, config: AuditConfig) {
const reviewed = config.sourceRegistryPackage;
const reviewedRegistryPackages = [
{
expectedIntegrity: reviewed.integrity,
label: reviewed.label,
packageSpec: reviewed.packageSpec,
tarballUrl: reviewed.tarballUrl,
},
];
const reviewedPackages = reviewedSourceRegistryPackages(config);
const reviewedRegistryPackages = reviewedPackages.map((reviewed) => ({
expectedIntegrity: reviewed.integrity,
label: reviewed.label,
packageSpec: reviewed.packageSpec,
tarballUrl: reviewed.tarballUrl,
}));
const lockfiles = ["package-lock.json", "nemoclaw/package-lock.json"].map((relativePath) => {
const lockfilePath = join(targetRoot, relativePath);
const packages = verifyReviewedNpmLockPackages({
Expand All @@ -210,6 +216,20 @@ function inspectReviewedLocks(targetRoot: string, config: AuditConfig) {
});
return { lockfilePath, packages };
});
const lockedReviewedSpecs = new Set(
lockfiles.flatMap(({ packages }) =>
reviewedPackages
.map(({ packageSpec }) => packageSpec)
.filter((packageSpec) => packages.includes(packageSpec)),
),
);
if (lockedReviewedSpecs.size > 1) {
throw new Error("reviewed npm locks use conflicting OpenShell SDK identities");
}
const selectedSpec = [...lockedReviewedSpecs][0];
const reviewed =
reviewedPackages.find(({ packageSpec }) => packageSpec === selectedSpec) ??
config.sourceRegistryPackage;
return {
config,
reviewed,
Expand Down
10 changes: 3 additions & 7 deletions test/automation/pull-requests/pr-workflow-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,7 @@ describe("pull request and main workflow contracts", () => {
) as TypeScriptConfig;
const sharedActions = {
staticChecks: readYaml<CompositeAction>(".github/actions/ci-static-checks/action.yaml"),
compileArtifacts: readYaml<CompositeAction>(
".github/actions/ci-compile-artifacts/action.yaml",
),
compileArtifacts: readYaml<CompositeAction>(".github/actions/ci-compile-artifacts/action.yaml"),
buildTypecheck: readYaml<CompositeAction>(".github/actions/ci-build-typecheck/action.yaml"),
cliCoverageShard: readYaml<CompositeAction>(
".github/actions/ci-cli-coverage-shard/action.yaml",
Expand All @@ -493,10 +491,7 @@ describe("pull request and main workflow contracts", () => {
it("verifies changed Hugging Face catalog references without credentials", () => {
const job = prWorkflow.jobs["hugging-face-models"];
const filterStep = prWorkflow.jobs.changes.steps?.find((step) => step.id === "filter");
const filters = YAML.parse(String(filterStep?.with?.filters ?? "")) as Record<
string,
string[]
>;
const filters = YAML.parse(String(filterStep?.with?.filters ?? "")) as Record<string, string[]>;
const huggingFaceModelFilters = filters.hugging_face_models ?? [];

expect(
Expand Down Expand Up @@ -922,6 +917,7 @@ describe("pull request and main workflow contracts", () => {
);
expect(fetch.env).toEqual({
NEMOCLAW_OPEN_SHELL_SDK_OUTPUT_DIRECTORY: "${{ runner.temp }}/openshell-sdk",
NEMOCLAW_OPEN_SHELL_SDK_INCLUDE_REPLACEMENT: "1",
NODE_AUTH_TOKEN: "${{ github.token }}",
});
expect(fetch.run).toContain(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ describe("trusted reviewed npm audit workflow (#5896)", () => {
);
});

// source-shape-contract: security -- One reviewed package field prevents a second package identity from bypassing the credential-isolation workflow
// source-shape-contract: security -- One active package plus one same-package replacement prevents an open-ended identity list from bypassing the credential-isolation workflow
it("rejects the removed plural source-registry package shape", () => {
const configFile = path.join(REPO_ROOT, "ci", "reviewed-npm-audit.json");
const config = JSON.parse(fs.readFileSync(configFile, "utf-8")) as Record<string, unknown>;
Expand Down
Loading
Loading