feat(deploy): register L1 credential provenance successor
This commit is contained in:
parent
c19b0789c7
commit
a9fe5f44e3
|
|
@ -0,0 +1,162 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { createHash } from "node:crypto";
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
import { copyFile, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { dirname, join, resolve } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const workspaceRoot = resolve(scriptDir, "../../..");
|
||||||
|
const engineRoot = resolve(
|
||||||
|
process.env.NODEDC_ENGINE_SOURCE_ROOT || join(workspaceRoot, "NODEDC_ENGINE_INFRA"),
|
||||||
|
);
|
||||||
|
const artifactDir = resolve(
|
||||||
|
process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(scriptDir, "../deploy-artifacts"),
|
||||||
|
);
|
||||||
|
const [patchId = "engine-mcp-l1-credential-provenance-20260724-044", ...extra] =
|
||||||
|
process.argv.slice(2);
|
||||||
|
|
||||||
|
if (
|
||||||
|
extra.length
|
||||||
|
|| !/^engine-mcp-l1-credential-provenance-\d{8}-\d{3}$/.test(patchId)
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
"usage: build-engine-mcp-l1-credential-provenance-artifact.mjs "
|
||||||
|
+ "[engine-mcp-l1-credential-provenance-YYYYMMDD-NNN]",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const expectedSha256 = Object.freeze({
|
||||||
|
"nodedc-source/server/routes/n8n.js":
|
||||||
|
"af07edcf784c420855134ab9178f020d259a1cac703cd643418ab7b4eb94dbd3",
|
||||||
|
"nodedc-source/server/deployTransitions/l1CredentialProvenanceV2.json":
|
||||||
|
"5887da6e5cb611450e03a110be9786acbe47ae1b00217b8bf09e0967f71f6a3d",
|
||||||
|
});
|
||||||
|
const files = Object.freeze(Object.keys(expectedSha256));
|
||||||
|
const artifact = join(artifactDir, `nodedc-${patchId}.tgz`);
|
||||||
|
const checksum = `${artifact}.sha256`;
|
||||||
|
const stage = await mkdtemp(join(tmpdir(), "nodedc-engine-l1-credential-provenance-"));
|
||||||
|
|
||||||
|
await assertFresh(artifact);
|
||||||
|
await assertExactSources();
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const relativePath of files) {
|
||||||
|
const destination = join(stage, "payload", relativePath);
|
||||||
|
await mkdir(dirname(destination), { recursive: true });
|
||||||
|
await copyFile(join(engineRoot, relativePath), destination);
|
||||||
|
}
|
||||||
|
await writeFile(
|
||||||
|
join(stage, "manifest.env"),
|
||||||
|
`id=${patchId}\ncomponent=engine\ntype=app-overlay\n`,
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
|
await writeFile(join(stage, "files.txt"), `${files.join("\n")}\n`, "utf8");
|
||||||
|
await mkdir(artifactDir, { recursive: true });
|
||||||
|
run("python3", ["-c", canonicalTarScript(), artifact, stage]);
|
||||||
|
const sha256 = digest(await readFile(artifact));
|
||||||
|
await writeFile(checksum, `${sha256} ${artifact.split("/").at(-1)}\n`, "utf8");
|
||||||
|
console.log(JSON.stringify({
|
||||||
|
ok: true,
|
||||||
|
patchId,
|
||||||
|
artifact,
|
||||||
|
checksum,
|
||||||
|
sha256,
|
||||||
|
services: ["nodedc-backend"],
|
||||||
|
mcpVersion: "0.11.0",
|
||||||
|
tool: "engine_list_l2_credential_refs",
|
||||||
|
credentialScope: "same-l1-workflow",
|
||||||
|
localProvenanceSources: ["manual", "workflow-ref", "credentials-file"],
|
||||||
|
referencedSourceRequiresSyncPayload: true,
|
||||||
|
crossL1Sharing: false,
|
||||||
|
managedGrants: "target-local",
|
||||||
|
credentialValuesIncluded: false,
|
||||||
|
files,
|
||||||
|
}, null, 2));
|
||||||
|
} finally {
|
||||||
|
await rm(stage, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function assertExactSources() {
|
||||||
|
for (const [relativePath, expected] of Object.entries(expectedSha256)) {
|
||||||
|
const sourcePath = join(engineRoot, relativePath);
|
||||||
|
const info = await lstat(sourcePath);
|
||||||
|
if (!info.isFile() || info.isSymbolicLink()) {
|
||||||
|
throw new Error(`engine_l1_credential_provenance_source_unsafe:${relativePath}`);
|
||||||
|
}
|
||||||
|
const actual = digest(await readFile(sourcePath));
|
||||||
|
if (actual !== expected) {
|
||||||
|
throw new Error(
|
||||||
|
`engine_l1_credential_provenance_target_mismatch:${relativePath}:`
|
||||||
|
+ `expected=${expected}:actual=${actual}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const route = await readFile(
|
||||||
|
join(engineRoot, "nodedc-source/server/routes/n8n.js"),
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
|
const descriptor = JSON.parse(await readFile(
|
||||||
|
join(
|
||||||
|
engineRoot,
|
||||||
|
"nodedc-source/server/deployTransitions/l1CredentialProvenanceV2.json",
|
||||||
|
),
|
||||||
|
"utf8",
|
||||||
|
));
|
||||||
|
if (
|
||||||
|
!route.includes("function engineAgentCredentialMayProveL1Provenance")
|
||||||
|
|| !route.includes("return isGlobalRegistryEntryAllowed(entry)")
|
||||||
|
|| !route.includes("engineAgentCredentialMayProveL1Provenance(item)")
|
||||||
|
|| descriptor?.id !== "engine-mcp-l1-credential-provenance-v2"
|
||||||
|
|| descriptor?.visibilityProof?.referencedSourceRequiresSyncPayload !== true
|
||||||
|
|| descriptor?.visibilityProof?.logicalKeyEqualityRequired !== true
|
||||||
|
|| descriptor?.binding?.applyOperation !== "assignCredentialRef"
|
||||||
|
|| descriptor?.crossL1Sharing !== false
|
||||||
|
|| descriptor?.candidateBoundary?.managedGrants !== "target-local"
|
||||||
|
) {
|
||||||
|
throw new Error("engine_l1_credential_provenance_runtime_boundary_invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function assertFresh(path) {
|
||||||
|
try {
|
||||||
|
await lstat(path);
|
||||||
|
} catch (error) {
|
||||||
|
if (error?.code === "ENOENT") return;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
throw new Error("artifact_already_exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
function canonicalTarScript() {
|
||||||
|
return [
|
||||||
|
"import gzip,io,pathlib,sys,tarfile",
|
||||||
|
"root=pathlib.Path(sys.argv[2])",
|
||||||
|
"with open(sys.argv[1],'xb') as out:",
|
||||||
|
" with gzip.GzipFile(filename='',mode='wb',fileobj=out,compresslevel=9,mtime=0) as gz:",
|
||||||
|
" with tarfile.open(fileobj=gz,mode='w',format=tarfile.PAX_FORMAT) as tar:",
|
||||||
|
" for top in ('manifest.env','files.txt','payload'):",
|
||||||
|
" p=root/top; paths=[p]+(sorted(p.rglob('*')) if p.is_dir() else [])",
|
||||||
|
" for x in paths:",
|
||||||
|
" info=tar.gettarinfo(str(x),arcname=x.relative_to(root).as_posix())",
|
||||||
|
" info.uid=info.gid=0; info.uname=info.gname='root'; info.mtime=0; info.mode=0o755 if info.isdir() else 0o644",
|
||||||
|
" with (open(x,'rb') if info.isfile() else io.BytesIO()) as src: tar.addfile(info,src if info.isfile() else None)",
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function digest(value) {
|
||||||
|
return createHash("sha256").update(value).digest("hex");
|
||||||
|
}
|
||||||
|
|
||||||
|
function run(command, args) {
|
||||||
|
const result = spawnSync(command, args, {
|
||||||
|
encoding: "utf8",
|
||||||
|
maxBuffer: 128 * 1024 * 1024,
|
||||||
|
});
|
||||||
|
if (result.status !== 0) {
|
||||||
|
throw new Error(`${command}_failed:${result.stderr || result.stdout}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -787,6 +787,36 @@ ENGINE_MCP_L1_CREDENTIAL_REUSE_TARGET_SHA256 = {
|
||||||
ENGINE_MCP_L1_CREDENTIAL_REUSE_NEW_PATHS = (
|
ENGINE_MCP_L1_CREDENTIAL_REUSE_NEW_PATHS = (
|
||||||
ENGINE_MCP_L1_CREDENTIAL_REUSE_DESCRIPTOR_REL,
|
ENGINE_MCP_L1_CREDENTIAL_REUSE_DESCRIPTOR_REL,
|
||||||
)
|
)
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_DESCRIPTOR_REL = (
|
||||||
|
"nodedc-source/server/deployTransitions/l1CredentialProvenanceV2.json"
|
||||||
|
)
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_ARTIFACT_ENTRIES = (
|
||||||
|
"nodedc-source/server/routes/n8n.js",
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_DESCRIPTOR_REL,
|
||||||
|
)
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_PREDECESSOR_SHA256 = {
|
||||||
|
"nodedc-source/server/routes/n8n.js":
|
||||||
|
"6620e4bdd573e9f6b636a4b059eafef76d59da2fdb2183038fa5ec95357d8478",
|
||||||
|
}
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_FOUNDATION_SHA256 = {
|
||||||
|
"nodedc-source/server/routes/engineAgentGateway.js":
|
||||||
|
"4a9524fd954320277042c783b7b19cbb2172f075f27652c0eebfd743ffc47872",
|
||||||
|
ENGINE_MCP_NORMALIZED_IDENTITY_SEARCH_DESCRIPTOR_REL:
|
||||||
|
"41738185fe103642912b0aa1c29c51860970c38f9f916cc3725e79e258b9ea7e",
|
||||||
|
ENGINE_NODE_INTELLIGENCE_DESCRIPTOR_REL:
|
||||||
|
"3e7aeb1d28eb291461f79cd656ece6488bc6d372124088e92f53bf89c3373f61",
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_REUSE_DESCRIPTOR_REL:
|
||||||
|
"2ada49ef8bb2f146a9ea8d3c9ab5ee55f6a4e1b17e0f4b62a16f27368bd0eb05",
|
||||||
|
}
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_TARGET_SHA256 = {
|
||||||
|
"nodedc-source/server/routes/n8n.js":
|
||||||
|
"af07edcf784c420855134ab9178f020d259a1cac703cd643418ab7b4eb94dbd3",
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_DESCRIPTOR_REL:
|
||||||
|
"5887da6e5cb611450e03a110be9786acbe47ae1b00217b8bf09e0967f71f6a3d",
|
||||||
|
}
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_NEW_PATHS = (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_DESCRIPTOR_REL,
|
||||||
|
)
|
||||||
ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES = (
|
ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES = (
|
||||||
ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL,
|
ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL,
|
||||||
)
|
)
|
||||||
|
|
@ -4854,6 +4884,48 @@ process.stdout.write('engine-mcp-l1-credential-reuse:0.11.0:same-l1:opaque-ref:v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def accept_engine_mcp_l1_credential_provenance_runtime():
|
||||||
|
root = component_root("engine")
|
||||||
|
validate_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
root,
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_ARTIFACT_ENTRIES,
|
||||||
|
)
|
||||||
|
live = run_engine_backend_probe(
|
||||||
|
(
|
||||||
|
"node",
|
||||||
|
"--input-type=module",
|
||||||
|
"-e",
|
||||||
|
"""
|
||||||
|
const route=await import('file:///app/server/routes/n8n.js');
|
||||||
|
const slot='httpBearerAuth';
|
||||||
|
const common={nodeDcCredentialId:'credential-provider',n8nCredentialId:'runtime-provider',type:slot,name:'Provider read access',source:'manual',status:'ok',data:{token:'synthetic'}};
|
||||||
|
const workflowRef={...common,source:'workflow-ref'};
|
||||||
|
const workflowRefWithoutSync={...workflowRef,data:{}};
|
||||||
|
const sameL1=new Set([common.nodeDcCredentialId]);
|
||||||
|
const graph={nodes:[{id:'source-reader',data:{n8n:{type:'n8n-nodes-base.httpRequest',parameters:{url:'https://api.provider.example/v1/items'},credentials:{[slot]:{id:common.n8nCredentialId,name:common.name,nodeDcCredentialId:common.nodeDcCredentialId}}}}}]};
|
||||||
|
const target={type:'n8n-nodes-base.httpRequest',parameters:{url:'https://api.provider.example/v1/identity'}};
|
||||||
|
const allowed=route.buildEngineAgentCredentialTransportPolicy({...common,data:{allowedHttpRequestDomains:'all'}},graph,slot,target);
|
||||||
|
if(!route.engineAgentCredentialMayProveL1Provenance(workflowRef)||route.engineAgentCredentialMayProveL1Provenance(workflowRefWithoutSync)||route.engineAgentCredentialMayReuseWithinL1(workflowRef)||route.engineAgentCandidateScope(common,{localEntries:[]},sameL1)!=='l1'||!allowed.bindable||allowed.policy?.allowedHosts?.join(',')!=='api.provider.example')process.exit(2);
|
||||||
|
process.stdout.write('engine-mcp-l1-credential-provenance:0.11.0:workflow-ref-sync-proof:v2');
|
||||||
|
""".strip(),
|
||||||
|
),
|
||||||
|
"Engine MCP L1 credential provenance",
|
||||||
|
container_id=engine_backend_container_id(),
|
||||||
|
)
|
||||||
|
expected = (
|
||||||
|
"engine-mcp-l1-credential-provenance:"
|
||||||
|
"0.11.0:workflow-ref-sync-proof:v2"
|
||||||
|
)
|
||||||
|
if live != expected:
|
||||||
|
die("Engine MCP L1 credential provenance live acceptance mismatch")
|
||||||
|
return {
|
||||||
|
"target_sha256": dict(
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_TARGET_SHA256
|
||||||
|
),
|
||||||
|
"live": live,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def validate_no_lifecycle_scripts(payload_dir, label):
|
def validate_no_lifecycle_scripts(payload_dir, label):
|
||||||
forbidden = ("preinstall", "install", "postinstall", "prepare", "prepack", "postpack")
|
forbidden = ("preinstall", "install", "postinstall", "prepare", "prepack", "postpack")
|
||||||
for package_path in payload_dir.rglob("package.json"):
|
for package_path in payload_dir.rglob("package.json"):
|
||||||
|
|
@ -6262,6 +6334,90 @@ def validate_engine_mcp_l1_credential_reuse_slice(payload_dir, entries):
|
||||||
die("Engine MCP L1 credential reuse managed-grant boundary missing")
|
die("Engine MCP L1 credential reuse managed-grant boundary missing")
|
||||||
|
|
||||||
|
|
||||||
|
def validate_engine_mcp_l1_credential_provenance_slice(payload_dir, entries):
|
||||||
|
if tuple(entries) != ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_ARTIFACT_ENTRIES:
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance files.txt exact set/order "
|
||||||
|
"mismatch"
|
||||||
|
)
|
||||||
|
for rel, expected_sha256 in (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_TARGET_SHA256.items()
|
||||||
|
):
|
||||||
|
path = payload_dir / rel
|
||||||
|
try:
|
||||||
|
path_stat = path.lstat()
|
||||||
|
except FileNotFoundError:
|
||||||
|
die(f"Engine MCP L1 credential provenance target is missing: {rel}")
|
||||||
|
if (
|
||||||
|
stat.S_ISLNK(path_stat.st_mode)
|
||||||
|
or not stat.S_ISREG(path_stat.st_mode)
|
||||||
|
or sha256_file(path) != expected_sha256
|
||||||
|
):
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance target sha256 mismatch: "
|
||||||
|
f"{rel}"
|
||||||
|
)
|
||||||
|
|
||||||
|
descriptor = read_strict_json(
|
||||||
|
payload_dir / ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_DESCRIPTOR_REL,
|
||||||
|
"Engine MCP L1 credential provenance descriptor",
|
||||||
|
max_bytes=32 * 1024,
|
||||||
|
)
|
||||||
|
expected_descriptor = {
|
||||||
|
"schemaVersion": "nodedc.engine.deploy-transition/v1",
|
||||||
|
"id": "engine-mcp-l1-credential-provenance-v2",
|
||||||
|
"component": "engine",
|
||||||
|
"scope": "external-mcp-l2-authoring",
|
||||||
|
"mcpVersion": "0.11.0",
|
||||||
|
"sourcePath": "nodedc-source/server/routes/n8n.js",
|
||||||
|
"predecessor": "engine-mcp-l1-credential-reuse-v1",
|
||||||
|
"visibilityProof": {
|
||||||
|
"scope": "same-l1-workflow",
|
||||||
|
"localSources": ["manual", "workflow-ref", "credentials-file"],
|
||||||
|
"referencedSourceRequiresSyncPayload": True,
|
||||||
|
"logicalKeyEqualityRequired": True,
|
||||||
|
},
|
||||||
|
"candidateBoundary": {
|
||||||
|
"commonEntryMustBeReusable": True,
|
||||||
|
"managedEntriesAllowed": False,
|
||||||
|
"managedGrants": "target-local",
|
||||||
|
},
|
||||||
|
"binding": {
|
||||||
|
"listTool": "engine_list_l2_credential_refs",
|
||||||
|
"applyOperation": "assignCredentialRef",
|
||||||
|
"opaqueRefOnly": True,
|
||||||
|
"credentialIdsReturned": False,
|
||||||
|
"credentialValuesReturned": False,
|
||||||
|
},
|
||||||
|
"transportPolicy": {
|
||||||
|
"httpsRequired": True,
|
||||||
|
"redirectsDisabled": True,
|
||||||
|
"hostAuthority": [
|
||||||
|
"credential-allowlist",
|
||||||
|
"same-l1-observed-host",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"crossL1Sharing": False,
|
||||||
|
}
|
||||||
|
if descriptor != expected_descriptor:
|
||||||
|
die("Engine MCP L1 credential provenance descriptor contract mismatch")
|
||||||
|
|
||||||
|
route_source = (
|
||||||
|
payload_dir / "nodedc-source/server/routes/n8n.js"
|
||||||
|
).read_text(encoding="utf-8")
|
||||||
|
for marker in (
|
||||||
|
"function engineAgentCredentialMayProveL1Provenance",
|
||||||
|
"return isGlobalRegistryEntryAllowed(entry)",
|
||||||
|
"engineAgentCredentialMayProveL1Provenance(item)",
|
||||||
|
"The common candidate itself is",
|
||||||
|
):
|
||||||
|
if marker not in route_source:
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance route marker missing: "
|
||||||
|
f"{marker}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_engine_agent_full_grant_migration_slice(payload_dir, entries):
|
def validate_engine_agent_full_grant_migration_slice(payload_dir, entries):
|
||||||
if tuple(entries) != ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES:
|
if tuple(entries) != ENGINE_AGENT_FULL_GRANT_MIGRATION_ARTIFACT_ENTRIES:
|
||||||
die("Engine agent full grant migration files.txt exact set/order mismatch")
|
die("Engine agent full grant migration files.txt exact set/order mismatch")
|
||||||
|
|
@ -6770,6 +6926,14 @@ def load_artifact(artifact, work_dir):
|
||||||
payload_dir,
|
payload_dir,
|
||||||
entries,
|
entries,
|
||||||
)
|
)
|
||||||
|
if is_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
manifest["component"],
|
||||||
|
entries,
|
||||||
|
):
|
||||||
|
validate_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
payload_dir,
|
||||||
|
entries,
|
||||||
|
)
|
||||||
if is_engine_provider_security_catalog_slice(manifest["component"], entries):
|
if is_engine_provider_security_catalog_slice(manifest["component"], entries):
|
||||||
validate_engine_provider_security_catalog_payload(payload_dir, entries)
|
validate_engine_provider_security_catalog_payload(payload_dir, entries)
|
||||||
if touches_engine_credential_sink(manifest["component"], entries):
|
if touches_engine_credential_sink(manifest["component"], entries):
|
||||||
|
|
@ -6811,6 +6975,10 @@ def load_artifact(artifact, work_dir):
|
||||||
manifest["component"],
|
manifest["component"],
|
||||||
entries,
|
entries,
|
||||||
)
|
)
|
||||||
|
and not is_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
manifest["component"],
|
||||||
|
entries,
|
||||||
|
)
|
||||||
and (
|
and (
|
||||||
touches_engine_data_product_publish_grant(entries)
|
touches_engine_data_product_publish_grant(entries)
|
||||||
or ENGINE_DATA_PRODUCT_PUBLISH_GRANT_OVERRIDE_REL in entries
|
or ENGINE_DATA_PRODUCT_PUBLISH_GRANT_OVERRIDE_REL in entries
|
||||||
|
|
@ -7049,6 +7217,15 @@ def is_engine_mcp_l1_credential_reuse_slice(component, entries):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_engine_mcp_l1_credential_provenance_slice(component, entries):
|
||||||
|
return (
|
||||||
|
component == "engine"
|
||||||
|
and entries is not None
|
||||||
|
and tuple(entries)
|
||||||
|
== ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_ARTIFACT_ENTRIES
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_engine_agent_full_grant_migration_slice(component, entries):
|
def is_engine_agent_full_grant_migration_slice(component, entries):
|
||||||
return (
|
return (
|
||||||
component == "engine"
|
component == "engine"
|
||||||
|
|
@ -7943,6 +8120,83 @@ def preflight_engine_mcp_l1_credential_reuse_predecessor():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def preflight_engine_mcp_l1_credential_provenance_predecessor():
|
||||||
|
root = component_root("engine")
|
||||||
|
actual = {}
|
||||||
|
for rel, expected_sha256 in (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_PREDECESSOR_SHA256.items()
|
||||||
|
):
|
||||||
|
path = root / rel
|
||||||
|
try:
|
||||||
|
path_stat = path.lstat()
|
||||||
|
except FileNotFoundError:
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance predecessor is missing: "
|
||||||
|
f"{rel}"
|
||||||
|
)
|
||||||
|
if stat.S_ISLNK(path_stat.st_mode) or not stat.S_ISREG(path_stat.st_mode):
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance predecessor is unsafe: "
|
||||||
|
f"{rel}"
|
||||||
|
)
|
||||||
|
actual_sha256 = sha256_file(path)
|
||||||
|
if actual_sha256 != expected_sha256:
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance predecessor drift "
|
||||||
|
f"detected: path={rel} expected={expected_sha256} "
|
||||||
|
f"actual={actual_sha256}"
|
||||||
|
)
|
||||||
|
actual[rel] = actual_sha256
|
||||||
|
|
||||||
|
foundation = {}
|
||||||
|
for rel, expected_sha256 in (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_FOUNDATION_SHA256.items()
|
||||||
|
):
|
||||||
|
path = root / rel
|
||||||
|
try:
|
||||||
|
path_stat = path.lstat()
|
||||||
|
except FileNotFoundError:
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance foundation is missing: "
|
||||||
|
f"{rel}"
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
stat.S_ISLNK(path_stat.st_mode)
|
||||||
|
or not stat.S_ISREG(path_stat.st_mode)
|
||||||
|
or sha256_file(path) != expected_sha256
|
||||||
|
):
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance foundation drift "
|
||||||
|
f"detected: {rel}"
|
||||||
|
)
|
||||||
|
foundation[rel] = expected_sha256
|
||||||
|
|
||||||
|
for rel in ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_NEW_PATHS:
|
||||||
|
path = root / rel
|
||||||
|
if path.exists() or path.is_symlink():
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance new path already exists: "
|
||||||
|
f"{rel}"
|
||||||
|
)
|
||||||
|
|
||||||
|
backend = preflight_engine_credential_backend_runtime()
|
||||||
|
if backend["mode"] != "verified-derived-retry":
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance requires the active "
|
||||||
|
"immutable backend"
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"mode": "l1-credential-reuse-v1-to-provenance-v2",
|
||||||
|
"predecessor_sha256": actual,
|
||||||
|
"foundation_sha256": foundation,
|
||||||
|
"target_sha256": dict(
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_TARGET_SHA256
|
||||||
|
),
|
||||||
|
"new_paths": tuple(ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_NEW_PATHS),
|
||||||
|
"backend_mode": backend["mode"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def preflight_engine_agent_full_grant_migration_predecessor():
|
def preflight_engine_agent_full_grant_migration_predecessor():
|
||||||
root = component_root("engine")
|
root = component_root("engine")
|
||||||
store_path = root / ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL
|
store_path = root / ENGINE_AGENT_FULL_GRANT_MIGRATION_STORE_REL
|
||||||
|
|
@ -8003,6 +8257,7 @@ def component_services(component, entries=None):
|
||||||
or is_engine_mcp_execution_plan_module_ownership_slice(component, entries)
|
or is_engine_mcp_execution_plan_module_ownership_slice(component, entries)
|
||||||
or is_engine_mcp_normalized_identity_search_slice(component, entries)
|
or is_engine_mcp_normalized_identity_search_slice(component, entries)
|
||||||
or is_engine_mcp_l1_credential_reuse_slice(component, entries)
|
or is_engine_mcp_l1_credential_reuse_slice(component, entries)
|
||||||
|
or is_engine_mcp_l1_credential_provenance_slice(component, entries)
|
||||||
or is_engine_provider_security_catalog_slice(component, entries)
|
or is_engine_provider_security_catalog_slice(component, entries)
|
||||||
):
|
):
|
||||||
# This slice updates only the existing Engine backend control plane.
|
# This slice updates only the existing Engine backend control plane.
|
||||||
|
|
@ -10218,6 +10473,7 @@ def plan_artifact(artifact):
|
||||||
mcp_execution_plan_module_ownership_preflight = None
|
mcp_execution_plan_module_ownership_preflight = None
|
||||||
mcp_normalized_identity_search_preflight = None
|
mcp_normalized_identity_search_preflight = None
|
||||||
mcp_l1_credential_reuse_preflight = None
|
mcp_l1_credential_reuse_preflight = None
|
||||||
|
mcp_l1_credential_provenance_preflight = None
|
||||||
provider_catalog_preflight = None
|
provider_catalog_preflight = None
|
||||||
with tempfile.TemporaryDirectory(prefix="plan-", dir=TMP_DIR) as tmp:
|
with tempfile.TemporaryDirectory(prefix="plan-", dir=TMP_DIR) as tmp:
|
||||||
manifest, entries, payload_dir = load_artifact(artifact, Path(tmp))
|
manifest, entries, payload_dir = load_artifact(artifact, Path(tmp))
|
||||||
|
|
@ -10318,6 +10574,13 @@ def plan_artifact(artifact):
|
||||||
mcp_l1_credential_reuse_preflight = (
|
mcp_l1_credential_reuse_preflight = (
|
||||||
preflight_engine_mcp_l1_credential_reuse_predecessor()
|
preflight_engine_mcp_l1_credential_reuse_predecessor()
|
||||||
)
|
)
|
||||||
|
if is_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
manifest["component"],
|
||||||
|
entries,
|
||||||
|
):
|
||||||
|
mcp_l1_credential_provenance_preflight = (
|
||||||
|
preflight_engine_mcp_l1_credential_provenance_predecessor()
|
||||||
|
)
|
||||||
if is_engine_provider_security_catalog_slice(manifest["component"], entries):
|
if is_engine_provider_security_catalog_slice(manifest["component"], entries):
|
||||||
provider_catalog_preflight = preflight_engine_provider_security_catalog_predecessor()
|
provider_catalog_preflight = preflight_engine_provider_security_catalog_predecessor()
|
||||||
|
|
||||||
|
|
@ -10387,6 +10650,9 @@ def plan_artifact(artifact):
|
||||||
touches_mcp_l1_credential_reuse = (
|
touches_mcp_l1_credential_reuse = (
|
||||||
is_engine_mcp_l1_credential_reuse_slice(component, entries)
|
is_engine_mcp_l1_credential_reuse_slice(component, entries)
|
||||||
)
|
)
|
||||||
|
touches_mcp_l1_credential_provenance = (
|
||||||
|
is_engine_mcp_l1_credential_provenance_slice(component, entries)
|
||||||
|
)
|
||||||
touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice(
|
touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice(
|
||||||
component,
|
component,
|
||||||
entries,
|
entries,
|
||||||
|
|
@ -10409,6 +10675,7 @@ def plan_artifact(artifact):
|
||||||
or touches_mcp_execution_plan_module_ownership
|
or touches_mcp_execution_plan_module_ownership
|
||||||
or touches_mcp_normalized_identity_search
|
or touches_mcp_normalized_identity_search
|
||||||
or touches_mcp_l1_credential_reuse
|
or touches_mcp_l1_credential_reuse
|
||||||
|
or touches_mcp_l1_credential_provenance
|
||||||
or touches_agent_grant_migration
|
or touches_agent_grant_migration
|
||||||
):
|
):
|
||||||
credential_backend_preflight = preflight_engine_credential_backend_runtime()
|
credential_backend_preflight = preflight_engine_credential_backend_runtime()
|
||||||
|
|
@ -10505,6 +10772,14 @@ def plan_artifact(artifact):
|
||||||
"Engine MCP L1 credential reuse requires the active immutable "
|
"Engine MCP L1 credential reuse requires the active immutable "
|
||||||
"credential backend"
|
"credential backend"
|
||||||
)
|
)
|
||||||
|
if touches_mcp_l1_credential_provenance:
|
||||||
|
if mcp_l1_credential_provenance_preflight is None:
|
||||||
|
die("Engine MCP L1 credential provenance preflight is missing")
|
||||||
|
if credential_backend_preflight["mode"] != "verified-derived-retry":
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance requires the active "
|
||||||
|
"immutable credential backend"
|
||||||
|
)
|
||||||
if touches_agent_grant_migration:
|
if touches_agent_grant_migration:
|
||||||
agent_grant_migration_predecessor_sha256 = (
|
agent_grant_migration_predecessor_sha256 = (
|
||||||
preflight_engine_agent_full_grant_migration_predecessor()
|
preflight_engine_agent_full_grant_migration_predecessor()
|
||||||
|
|
@ -11234,6 +11509,80 @@ def plan_artifact(artifact):
|
||||||
print("credentials=preserved")
|
print("credentials=preserved")
|
||||||
print("mcp_nginx=untouched")
|
print("mcp_nginx=untouched")
|
||||||
print("embedded_ai_workspace=untouched")
|
print("embedded_ai_workspace=untouched")
|
||||||
|
if mcp_l1_credential_provenance_preflight:
|
||||||
|
print(
|
||||||
|
"engine_mcp_l1_credential_provenance_transition="
|
||||||
|
f"{mcp_l1_credential_provenance_preflight['mode']}"
|
||||||
|
)
|
||||||
|
print("engine_mcp_version=0.11.0")
|
||||||
|
print("engine_mcp_surface=external-codex")
|
||||||
|
print("engine_mcp_tool=engine_list_l2_credential_refs")
|
||||||
|
print("engine_mcp_apply_operation=assignCredentialRef")
|
||||||
|
print("engine_mcp_credential_scope=same-l1-workflow")
|
||||||
|
print(
|
||||||
|
"engine_mcp_local_provenance_sources="
|
||||||
|
"manual,workflow-ref,credentials-file"
|
||||||
|
)
|
||||||
|
print("engine_mcp_referenced_source_requires_sync_payload=yes")
|
||||||
|
print("engine_mcp_logical_key_equality_required=yes")
|
||||||
|
print("engine_mcp_cross_l1_sharing=no")
|
||||||
|
print("engine_mcp_managed_grants=target-local")
|
||||||
|
print("engine_mcp_credential_ids_included=no")
|
||||||
|
print("engine_mcp_credential_values_included=no")
|
||||||
|
for foundation_path, foundation_sha256 in (
|
||||||
|
mcp_l1_credential_provenance_preflight[
|
||||||
|
"foundation_sha256"
|
||||||
|
].items()
|
||||||
|
):
|
||||||
|
print(
|
||||||
|
"engine_mcp_l1_credential_provenance_foundation_sha256"
|
||||||
|
f"[{foundation_path}]={foundation_sha256}"
|
||||||
|
)
|
||||||
|
for changed_path in (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_ARTIFACT_ENTRIES
|
||||||
|
):
|
||||||
|
print(
|
||||||
|
"engine_mcp_l1_credential_provenance_changed_path="
|
||||||
|
f"{changed_path}"
|
||||||
|
)
|
||||||
|
if changed_path in mcp_l1_credential_provenance_preflight[
|
||||||
|
"predecessor_sha256"
|
||||||
|
]:
|
||||||
|
print(
|
||||||
|
"engine_mcp_l1_credential_provenance_predecessor_sha256"
|
||||||
|
f"[{changed_path}]="
|
||||||
|
f"{mcp_l1_credential_provenance_preflight['predecessor_sha256'][changed_path]}"
|
||||||
|
)
|
||||||
|
elif changed_path in mcp_l1_credential_provenance_preflight[
|
||||||
|
"new_paths"
|
||||||
|
]:
|
||||||
|
print(
|
||||||
|
"engine_mcp_l1_credential_provenance_predecessor_state"
|
||||||
|
f"[{changed_path}]=absent"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance plan has no "
|
||||||
|
f"predecessor state: {changed_path}"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"engine_mcp_l1_credential_provenance_target_sha256"
|
||||||
|
f"[{changed_path}]="
|
||||||
|
f"{mcp_l1_credential_provenance_preflight['target_sha256'][changed_path]}"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"backend_current_barrier="
|
||||||
|
f"{mcp_l1_credential_provenance_preflight['backend_mode']}"
|
||||||
|
)
|
||||||
|
print("backend_force_recreate=yes")
|
||||||
|
print("backend_pull=never")
|
||||||
|
print("l2_graph=untouched")
|
||||||
|
print("n8n_l1=untouched")
|
||||||
|
print("engine_ui=untouched")
|
||||||
|
print("engine_databases=untouched")
|
||||||
|
print("credentials=preserved")
|
||||||
|
print("mcp_nginx=untouched")
|
||||||
|
print("embedded_ai_workspace=untouched")
|
||||||
if transition_descriptor:
|
if transition_descriptor:
|
||||||
print(f"n8n_transition={transition_descriptor['action']}")
|
print(f"n8n_transition={transition_descriptor['action']}")
|
||||||
print(f"n8n_version={transition_descriptor['n8nVersion']}")
|
print(f"n8n_version={transition_descriptor['n8nVersion']}")
|
||||||
|
|
@ -12369,6 +12718,10 @@ def component_healthchecks(component, entries=None, services=None):
|
||||||
entries,
|
entries,
|
||||||
)
|
)
|
||||||
or is_engine_mcp_l1_credential_reuse_slice(component, entries)
|
or is_engine_mcp_l1_credential_reuse_slice(component, entries)
|
||||||
|
or is_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
component,
|
||||||
|
entries,
|
||||||
|
)
|
||||||
or is_engine_agent_full_grant_migration_slice(component, entries)
|
or is_engine_agent_full_grant_migration_slice(component, entries)
|
||||||
or is_engine_mcp_control_plane_slice(component, entries)
|
or is_engine_mcp_control_plane_slice(component, entries)
|
||||||
or is_engine_mcp_ontology_sdk_slice(component, entries)
|
or is_engine_mcp_ontology_sdk_slice(component, entries)
|
||||||
|
|
@ -12813,6 +13166,9 @@ def run_healthchecks(component, entries=None, services=None):
|
||||||
touches_mcp_l1_credential_reuse = (
|
touches_mcp_l1_credential_reuse = (
|
||||||
is_engine_mcp_l1_credential_reuse_slice(component, entries)
|
is_engine_mcp_l1_credential_reuse_slice(component, entries)
|
||||||
)
|
)
|
||||||
|
touches_mcp_l1_credential_provenance = (
|
||||||
|
is_engine_mcp_l1_credential_provenance_slice(component, entries)
|
||||||
|
)
|
||||||
touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice(
|
touches_agent_grant_migration = is_engine_agent_full_grant_migration_slice(
|
||||||
component,
|
component,
|
||||||
entries,
|
entries,
|
||||||
|
|
@ -12836,6 +13192,7 @@ def run_healthchecks(component, entries=None, services=None):
|
||||||
or touches_mcp_execution_plan_module_ownership
|
or touches_mcp_execution_plan_module_ownership
|
||||||
or touches_mcp_normalized_identity_search
|
or touches_mcp_normalized_identity_search
|
||||||
or touches_mcp_l1_credential_reuse
|
or touches_mcp_l1_credential_reuse
|
||||||
|
or touches_mcp_l1_credential_provenance
|
||||||
or touches_agent_grant_migration
|
or touches_agent_grant_migration
|
||||||
or touches_mcp_control_plane
|
or touches_mcp_control_plane
|
||||||
or touches_mcp_ontology_sdk
|
or touches_mcp_ontology_sdk
|
||||||
|
|
@ -12863,6 +13220,7 @@ def run_healthchecks(component, entries=None, services=None):
|
||||||
or touches_mcp_execution_plan_module_ownership
|
or touches_mcp_execution_plan_module_ownership
|
||||||
or touches_mcp_normalized_identity_search
|
or touches_mcp_normalized_identity_search
|
||||||
or touches_mcp_l1_credential_reuse
|
or touches_mcp_l1_credential_reuse
|
||||||
|
or touches_mcp_l1_credential_provenance
|
||||||
or touches_agent_grant_migration
|
or touches_agent_grant_migration
|
||||||
or touches_mcp_control_plane
|
or touches_mcp_control_plane
|
||||||
or touches_mcp_ontology_sdk
|
or touches_mcp_ontology_sdk
|
||||||
|
|
@ -13218,6 +13576,48 @@ def run_healthchecks(component, entries=None, services=None):
|
||||||
"Engine MCP L1 credential reuse installed state is neither "
|
"Engine MCP L1 credential reuse installed state is neither "
|
||||||
"target nor rollback predecessor"
|
"target nor rollback predecessor"
|
||||||
)
|
)
|
||||||
|
if touches_mcp_l1_credential_provenance:
|
||||||
|
root = component_root("engine")
|
||||||
|
target_state = all(
|
||||||
|
(root / rel).is_file()
|
||||||
|
and not (root / rel).is_symlink()
|
||||||
|
and sha256_file(root / rel) == expected
|
||||||
|
for rel, expected in (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_TARGET_SHA256.items()
|
||||||
|
)
|
||||||
|
) and all(
|
||||||
|
(root / rel).is_file()
|
||||||
|
and not (root / rel).is_symlink()
|
||||||
|
and sha256_file(root / rel) == expected
|
||||||
|
for rel, expected in (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_FOUNDATION_SHA256.items()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
predecessor_state = all(
|
||||||
|
(root / rel).is_file()
|
||||||
|
and not (root / rel).is_symlink()
|
||||||
|
and sha256_file(root / rel) == expected
|
||||||
|
for rel, expected in (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_PREDECESSOR_SHA256.items()
|
||||||
|
)
|
||||||
|
) and all(
|
||||||
|
(root / rel).is_file()
|
||||||
|
and not (root / rel).is_symlink()
|
||||||
|
and sha256_file(root / rel) == expected
|
||||||
|
for rel, expected in (
|
||||||
|
ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_FOUNDATION_SHA256.items()
|
||||||
|
)
|
||||||
|
) and all(
|
||||||
|
not (root / rel).exists() and not (root / rel).is_symlink()
|
||||||
|
for rel in ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_NEW_PATHS
|
||||||
|
)
|
||||||
|
if target_state:
|
||||||
|
accept_engine_mcp_l1_credential_provenance_runtime()
|
||||||
|
elif not predecessor_state:
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance installed state is "
|
||||||
|
"neither target nor rollback predecessor"
|
||||||
|
)
|
||||||
container_name = COMPONENTS[component].get("health_container")
|
container_name = COMPONENTS[component].get("health_container")
|
||||||
if container_name:
|
if container_name:
|
||||||
healthcheck_container(container_name)
|
healthcheck_container(container_name)
|
||||||
|
|
@ -13415,6 +13815,22 @@ def apply_artifact(artifact):
|
||||||
"Engine MCP L1 credential reuse requires the "
|
"Engine MCP L1 credential reuse requires the "
|
||||||
"active immutable credential backend"
|
"active immutable credential backend"
|
||||||
)
|
)
|
||||||
|
if is_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
component,
|
||||||
|
entries,
|
||||||
|
):
|
||||||
|
preflight_engine_mcp_l1_credential_provenance_predecessor()
|
||||||
|
l1_credential_provenance_backend_preflight = (
|
||||||
|
preflight_engine_credential_backend_runtime()
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
l1_credential_provenance_backend_preflight["mode"]
|
||||||
|
!= "verified-derived-retry"
|
||||||
|
):
|
||||||
|
die(
|
||||||
|
"Engine MCP L1 credential provenance requires the "
|
||||||
|
"active immutable credential backend"
|
||||||
|
)
|
||||||
if is_engine_agent_full_grant_migration_slice(component, entries):
|
if is_engine_agent_full_grant_migration_slice(component, entries):
|
||||||
preflight_engine_agent_full_grant_migration_predecessor()
|
preflight_engine_agent_full_grant_migration_predecessor()
|
||||||
migration_backend_preflight = preflight_engine_credential_backend_runtime()
|
migration_backend_preflight = preflight_engine_credential_backend_runtime()
|
||||||
|
|
@ -13692,6 +14108,10 @@ def apply_artifact(artifact):
|
||||||
component,
|
component,
|
||||||
entries,
|
entries,
|
||||||
)
|
)
|
||||||
|
or is_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
component,
|
||||||
|
entries,
|
||||||
|
)
|
||||||
or is_engine_agent_full_grant_migration_slice(component, entries)
|
or is_engine_agent_full_grant_migration_slice(component, entries)
|
||||||
or is_engine_mcp_control_plane_slice(component, entries)
|
or is_engine_mcp_control_plane_slice(component, entries)
|
||||||
or is_engine_mcp_ontology_sdk_slice(component, entries)
|
or is_engine_mcp_ontology_sdk_slice(component, entries)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,349 @@
|
||||||
|
import hashlib
|
||||||
|
import importlib.machinery
|
||||||
|
import importlib.util
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import tarfile
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
from contextlib import redirect_stdout
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
|
||||||
|
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||||
|
RUNNER_PATH = SCRIPT_DIR / "nodedc-deploy"
|
||||||
|
BUILDER_PATH = (
|
||||||
|
SCRIPT_DIR / "build-engine-mcp-l1-credential-provenance-artifact.mjs"
|
||||||
|
)
|
||||||
|
ENGINE_ROOT = SCRIPT_DIR.parent.parent.parent / "NODEDC_ENGINE_INFRA"
|
||||||
|
PATCH_ID = "engine-mcp-l1-credential-provenance-20991231-999"
|
||||||
|
|
||||||
|
|
||||||
|
def load_runner():
|
||||||
|
loader = importlib.machinery.SourceFileLoader(
|
||||||
|
"nodedc_engine_mcp_l1_credential_provenance",
|
||||||
|
str(RUNNER_PATH),
|
||||||
|
)
|
||||||
|
spec = importlib.util.spec_from_loader(loader.name, loader)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
RUNNER = load_runner()
|
||||||
|
|
||||||
|
|
||||||
|
class EngineMcpL1CredentialProvenanceTest(unittest.TestCase):
|
||||||
|
def require_current_target_source(self):
|
||||||
|
for relative_path, expected in (
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_TARGET_SHA256.items()
|
||||||
|
):
|
||||||
|
path = ENGINE_ROOT / relative_path
|
||||||
|
if (
|
||||||
|
not path.is_file()
|
||||||
|
or hashlib.sha256(path.read_bytes()).hexdigest() != expected
|
||||||
|
):
|
||||||
|
self.skipTest("L1 credential provenance source has advanced")
|
||||||
|
|
||||||
|
def build(self, artifact_dir, engine_root=ENGINE_ROOT):
|
||||||
|
environment = os.environ.copy()
|
||||||
|
environment["NODEDC_ENGINE_SOURCE_ROOT"] = str(engine_root)
|
||||||
|
environment["NODEDC_DEPLOY_ARTIFACT_DIR"] = str(artifact_dir)
|
||||||
|
completed = subprocess.run(
|
||||||
|
["node", str(BUILDER_PATH), PATCH_ID],
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
env=environment,
|
||||||
|
)
|
||||||
|
return json.loads(completed.stdout)
|
||||||
|
|
||||||
|
def test_builder_is_deterministic_exact_and_backend_only(self):
|
||||||
|
self.require_current_target_source()
|
||||||
|
with tempfile.TemporaryDirectory(
|
||||||
|
prefix="nodedc-engine-mcp-l1-credential-provenance-"
|
||||||
|
) as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
first = self.build(root / "first")
|
||||||
|
second = self.build(root / "second")
|
||||||
|
first_artifact = Path(first["artifact"])
|
||||||
|
second_artifact = Path(second["artifact"])
|
||||||
|
self.assertEqual(first_artifact.read_bytes(), second_artifact.read_bytes())
|
||||||
|
self.assertEqual(first["services"], ["nodedc-backend"])
|
||||||
|
self.assertEqual(first["mcpVersion"], "0.11.0")
|
||||||
|
self.assertEqual(first["credentialScope"], "same-l1-workflow")
|
||||||
|
self.assertEqual(
|
||||||
|
first["localProvenanceSources"],
|
||||||
|
["manual", "workflow-ref", "credentials-file"],
|
||||||
|
)
|
||||||
|
self.assertTrue(first["referencedSourceRequiresSyncPayload"])
|
||||||
|
self.assertFalse(first["crossL1Sharing"])
|
||||||
|
self.assertFalse(first["credentialValuesIncluded"])
|
||||||
|
|
||||||
|
extract = root / "extract"
|
||||||
|
with tarfile.open(first_artifact, "r:gz") as archive:
|
||||||
|
archive.extractall(extract, filter="data")
|
||||||
|
entries = tuple(
|
||||||
|
(extract / "files.txt").read_text(encoding="utf-8").splitlines()
|
||||||
|
)
|
||||||
|
payload = extract / "payload"
|
||||||
|
self.assertEqual(
|
||||||
|
entries,
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_ARTIFACT_ENTRIES,
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
RUNNER.is_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
"engine",
|
||||||
|
entries,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
RUNNER.component_services("engine", entries),
|
||||||
|
("nodedc-backend",),
|
||||||
|
)
|
||||||
|
RUNNER.validate_engine_mcp_l1_credential_provenance_slice(
|
||||||
|
payload,
|
||||||
|
entries,
|
||||||
|
)
|
||||||
|
(root / "load").mkdir()
|
||||||
|
manifest, loaded_entries, _ = RUNNER.load_artifact(
|
||||||
|
first_artifact,
|
||||||
|
root / "load",
|
||||||
|
)
|
||||||
|
self.assertEqual(manifest["component"], "engine")
|
||||||
|
self.assertEqual(tuple(loaded_entries), entries)
|
||||||
|
|
||||||
|
def test_builder_rejects_source_drift(self):
|
||||||
|
self.require_current_target_source()
|
||||||
|
with tempfile.TemporaryDirectory(
|
||||||
|
prefix="nodedc-engine-mcp-l1-credential-provenance-drift-"
|
||||||
|
) as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
engine_copy = root / "engine"
|
||||||
|
for relative_path in (
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_ARTIFACT_ENTRIES
|
||||||
|
):
|
||||||
|
source = ENGINE_ROOT / relative_path
|
||||||
|
destination = engine_copy / relative_path
|
||||||
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
destination.write_bytes(source.read_bytes())
|
||||||
|
route = engine_copy / "nodedc-source/server/routes/n8n.js"
|
||||||
|
route.write_text(
|
||||||
|
route.read_text(encoding="utf-8") + "\n// drift\n",
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
with self.assertRaises(subprocess.CalledProcessError):
|
||||||
|
self.build(root / "artifact", engine_copy)
|
||||||
|
|
||||||
|
def test_descriptor_requires_sync_proof_and_keeps_cross_l1_closed(self):
|
||||||
|
self.require_current_target_source()
|
||||||
|
descriptor = json.loads(
|
||||||
|
(
|
||||||
|
ENGINE_ROOT
|
||||||
|
/ RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_DESCRIPTOR_REL
|
||||||
|
).read_text(encoding="utf-8")
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
descriptor["predecessor"],
|
||||||
|
"engine-mcp-l1-credential-reuse-v1",
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
descriptor["visibilityProof"][
|
||||||
|
"referencedSourceRequiresSyncPayload"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
descriptor["visibilityProof"]["logicalKeyEqualityRequired"]
|
||||||
|
)
|
||||||
|
self.assertFalse(descriptor["crossL1Sharing"])
|
||||||
|
self.assertFalse(
|
||||||
|
descriptor["candidateBoundary"]["managedEntriesAllowed"]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_preflight_requires_043_foundation_and_absent_v2_descriptor(self):
|
||||||
|
with tempfile.TemporaryDirectory(
|
||||||
|
prefix="nodedc-engine-mcp-l1-credential-provenance-preflight-"
|
||||||
|
) as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
hashes = {}
|
||||||
|
for mapping in (
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_PREDECESSOR_SHA256,
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_FOUNDATION_SHA256,
|
||||||
|
):
|
||||||
|
for relative_path, expected in mapping.items():
|
||||||
|
path = root / relative_path
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_text("installed\n", encoding="utf-8")
|
||||||
|
hashes[path] = expected
|
||||||
|
with (
|
||||||
|
mock.patch.object(RUNNER, "component_root", return_value=root),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"sha256_file",
|
||||||
|
side_effect=lambda path: hashes[Path(path)],
|
||||||
|
),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"preflight_engine_credential_backend_runtime",
|
||||||
|
return_value={"mode": "verified-derived-retry"},
|
||||||
|
),
|
||||||
|
):
|
||||||
|
result = (
|
||||||
|
RUNNER
|
||||||
|
.preflight_engine_mcp_l1_credential_provenance_predecessor()
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
result["mode"],
|
||||||
|
"l1-credential-reuse-v1-to-provenance-v2",
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_REUSE_DESCRIPTOR_REL,
|
||||||
|
result["foundation_sha256"],
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_plan_renders_exact_provenance_boundary(self):
|
||||||
|
self.require_current_target_source()
|
||||||
|
with tempfile.TemporaryDirectory(
|
||||||
|
prefix="nodedc-engine-mcp-l1-credential-provenance-plan-"
|
||||||
|
) as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
artifact = Path(self.build(root / "artifacts")["artifact"])
|
||||||
|
live_root = root / "live"
|
||||||
|
live_root.mkdir()
|
||||||
|
preflight = {
|
||||||
|
"mode": "l1-credential-reuse-v1-to-provenance-v2",
|
||||||
|
"predecessor_sha256": dict(
|
||||||
|
RUNNER
|
||||||
|
.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_PREDECESSOR_SHA256
|
||||||
|
),
|
||||||
|
"foundation_sha256": dict(
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_FOUNDATION_SHA256
|
||||||
|
),
|
||||||
|
"target_sha256": dict(
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_TARGET_SHA256
|
||||||
|
),
|
||||||
|
"new_paths": tuple(
|
||||||
|
RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_NEW_PATHS
|
||||||
|
),
|
||||||
|
"backend_mode": "verified-derived-retry",
|
||||||
|
}
|
||||||
|
output = io.StringIO()
|
||||||
|
with (
|
||||||
|
mock.patch.object(RUNNER, "validate_artifact_location"),
|
||||||
|
mock.patch.object(RUNNER, "ensure_layout"),
|
||||||
|
mock.patch.object(RUNNER, "TMP_DIR", root),
|
||||||
|
mock.patch.object(RUNNER, "component_root", return_value=live_root),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"component_compose_root",
|
||||||
|
return_value=live_root,
|
||||||
|
),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"preflight_engine_mcp_l1_credential_provenance_predecessor",
|
||||||
|
return_value=preflight,
|
||||||
|
),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"preflight_engine_credential_backend_runtime",
|
||||||
|
return_value={"mode": "verified-derived-retry"},
|
||||||
|
),
|
||||||
|
mock.patch.object(RUNNER, "state_has_sha", return_value=False),
|
||||||
|
mock.patch.object(RUNNER, "state_has_patch_id", return_value=False),
|
||||||
|
redirect_stdout(output),
|
||||||
|
):
|
||||||
|
RUNNER.plan_artifact(artifact)
|
||||||
|
plan = output.getvalue()
|
||||||
|
self.assertIn("services=nodedc-backend", plan)
|
||||||
|
self.assertIn(
|
||||||
|
"engine_mcp_local_provenance_sources="
|
||||||
|
"manual,workflow-ref,credentials-file",
|
||||||
|
plan,
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
"engine_mcp_referenced_source_requires_sync_payload=yes",
|
||||||
|
plan,
|
||||||
|
)
|
||||||
|
self.assertIn("engine_mcp_logical_key_equality_required=yes", plan)
|
||||||
|
self.assertIn("engine_mcp_cross_l1_sharing=no", plan)
|
||||||
|
self.assertIn("l2_graph=untouched", plan)
|
||||||
|
self.assertIn("state=new", plan)
|
||||||
|
|
||||||
|
def test_healthchecks_dispatch_provenance_acceptance(self):
|
||||||
|
entries = RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_ARTIFACT_ENTRIES
|
||||||
|
with tempfile.TemporaryDirectory(
|
||||||
|
prefix="nodedc-engine-mcp-l1-credential-provenance-health-"
|
||||||
|
) as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
all_hashes = {
|
||||||
|
**RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_TARGET_SHA256,
|
||||||
|
**RUNNER.ENGINE_MCP_L1_CREDENTIAL_PROVENANCE_FOUNDATION_SHA256,
|
||||||
|
}
|
||||||
|
for relative_path in all_hashes:
|
||||||
|
path = root / relative_path
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_text("target\n", encoding="utf-8")
|
||||||
|
|
||||||
|
def target_hash(path):
|
||||||
|
relative_path = Path(path).relative_to(root).as_posix()
|
||||||
|
return all_hashes[relative_path]
|
||||||
|
|
||||||
|
with (
|
||||||
|
mock.patch.object(RUNNER, "component_root", return_value=root),
|
||||||
|
mock.patch.object(RUNNER, "sha256_file", side_effect=target_hash),
|
||||||
|
mock.patch.object(RUNNER, "healthcheck_compose_service"),
|
||||||
|
mock.patch.object(RUNNER, "component_healthchecks", return_value=()),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"preflight_engine_credential_backend_runtime",
|
||||||
|
return_value={"mode": "verified-derived-retry"},
|
||||||
|
),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"accept_engine_mcp_l1_credential_provenance_runtime",
|
||||||
|
return_value={"live": "accepted"},
|
||||||
|
) as acceptance,
|
||||||
|
mock.patch.object(RUNNER, "healthcheck_container"),
|
||||||
|
):
|
||||||
|
RUNNER.run_healthchecks(
|
||||||
|
"engine",
|
||||||
|
entries,
|
||||||
|
("nodedc-backend",),
|
||||||
|
)
|
||||||
|
acceptance.assert_called_once_with()
|
||||||
|
|
||||||
|
def test_live_acceptance_proves_workflow_ref_sync_boundary(self):
|
||||||
|
expected_live = (
|
||||||
|
"engine-mcp-l1-credential-provenance:"
|
||||||
|
"0.11.0:workflow-ref-sync-proof:v2"
|
||||||
|
)
|
||||||
|
with (
|
||||||
|
mock.patch.object(RUNNER, "component_root", return_value=ENGINE_ROOT),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"validate_engine_mcp_l1_credential_provenance_slice",
|
||||||
|
),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"engine_backend_container_id",
|
||||||
|
return_value="backend",
|
||||||
|
),
|
||||||
|
mock.patch.object(
|
||||||
|
RUNNER,
|
||||||
|
"run_engine_backend_probe",
|
||||||
|
return_value=expected_live,
|
||||||
|
) as backend_probe,
|
||||||
|
):
|
||||||
|
result = RUNNER.accept_engine_mcp_l1_credential_provenance_runtime()
|
||||||
|
self.assertEqual(result["live"], expected_live)
|
||||||
|
probe_source = backend_probe.call_args.args[0][-1]
|
||||||
|
self.assertIn("engineAgentCredentialMayProveL1Provenance", probe_source)
|
||||||
|
self.assertIn("workflowRefWithoutSync", probe_source)
|
||||||
|
self.assertIn("engineAgentCredentialMayReuseWithinL1", probe_source)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main(verbosity=2)
|
||||||
Loading…
Reference in New Issue