Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions docs/china-regions.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
China target fails with an explicit message. Those `add` subcommands say "not available in
China regions" in their help, and the `agentcore add` menu warns when the project has a China
deployment target.
- **PUBLIC filesystem mounts:** The EFS and S3 Files access-point PUBLIC-mode preview is
available only in commercial regions. `agentcore add runtime` rejects PUBLIC EFS or S3 Files
mounts when the project targets China, and `agentcore deploy` rechecks the saved runtime
configuration.
- **Telemetry** is always disabled when the ambient AWS region or any deployment target is a
China region.
119 changes: 119 additions & 0 deletions src/core/project/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
credentialProviderNameEnvVarName,
} from "../../projectSchemas/credential";
import { ProjectSpecSchema } from "../../projectSchemas/project";
import type { FilesystemConfiguration } from "../../projectSchemas/runtime";
import { ENV_LOCAL_RELATIVE_PATH } from "./envLocal";
import { readEnvFile } from "../../io/envFile";
import {
Expand All @@ -29,6 +30,7 @@ import {
LITELLM_MODEL_ID_REQUIRED_CN_MESSAGE,
MEMORY_STRIPPED_CN_MESSAGE,
MODEL_PROVIDER_RUNTIMES_CN_MESSAGE,
PUBLIC_BYO_ACCESS_POINT_MOUNTS_CN_MESSAGE,
chinaModelProviderRestriction,
modelProviderOverridableCnMessage,
} from "./manager";
Expand Down Expand Up @@ -939,6 +941,26 @@ describe("FsProjectManager.addResource", () => {
describe("China (aws-cn) deployment targets", () => {
const MCP_PYTHON_FASTMCP = resolveRuntimeTemplateShortcut("mcp-python-fastmcp");

const EFS_ACCESS_POINT_MOUNT: FilesystemConfiguration = {
efsAccessPoint: {
accessPointArn:
"arn:aws:elasticfilesystem:cn-north-1:111122223333:access-point/fsap-0123456789abcdef0",
mountPath: "/mnt/efs",
},
};
const S3_FILES_ACCESS_POINT_MOUNT: FilesystemConfiguration = {
s3FilesAccessPoint: {
accessPointArn:
"arn:aws:s3files:cn-north-1:111122223333:file-system/fs-0123456789abcdef0/access-point/fsap-0123456789abcdef0",
mountPath: "/mnt/s3files",
},
};
// Both the add and deploy China guards cover EFS and S3 Files access-point mounts.
const PUBLIC_ACCESS_POINT_MOUNTS: [string, FilesystemConfiguration][] = [
["EFS", EFS_ACCESS_POINT_MOUNT],
["S3 Files", S3_FILES_ACCESS_POINT_MOUNT],
];

async function projectWithTarget(
region: string,
missingToolAfterCreate?: string,
Expand Down Expand Up @@ -987,6 +1009,55 @@ describe("FsProjectManager.addResource", () => {
return { subject, project, checkedTools, deployCalls };
}

test.each(PUBLIC_ACCESS_POINT_MOUNTS)(
"rejects a public %s access-point mount before scaffolding",
async (_label, mount) => {
await inTempDirectory();
const { subject, project, checkedTools } = await projectWithTarget(
"cn-north-1",
undefined,
MCP_PYTHON_FASTMCP,
);

await expect(
runAdd(subject, project, {
resourceType: "runtime",
resourceConfig: {
name: "cn_public_mount",
networkMode: "PUBLIC",
platformVersion: "V2",
filesystemConfigurations: [mount],
scaffoldRuntimeInput: { ...MCP_PYTHON_FASTMCP, runtimeName: "cn_public_mount" },
},
}),
).rejects.toThrow(
new RegionUnsupportedFeatureError(PUBLIC_BYO_ACCESS_POINT_MOUNTS_CN_MESSAGE),
);

expect(checkedTools).toEqual([]);
},
);

test("lets a VPC-mode EFS access-point mount past the China gate at add", async () => {
await inTempDirectory();
const { subject, project } = await projectWithTarget("cn-north-1", "uv", MCP_PYTHON_FASTMCP);

// The China guard blocks only PUBLIC access-point mounts; a VPC mount gets past it to the
// dependency checks, which stop on the injected missing tool rather than the region gate.
await expect(
runAdd(subject, project, {
resourceType: "runtime",
resourceConfig: {
name: "cn_vpc_mount",
networkMode: "VPC",
networkConfig: { subnets: ["subnet-12345678"], securityGroups: ["sg-12345678"] },
filesystemConfigurations: [EFS_ACCESS_POINT_MOUNT],
scaffoldRuntimeInput: { ...MCP_PYTHON_FASTMCP, runtimeName: "cn_vpc_mount" },
},
}),
).rejects.toThrow("uv is missing");
});

test("rejects a model-provider template before scaffolding", async () => {
await inTempDirectory();
const { subject, project, checkedTools } = await projectWithTarget("cn-north-1");
Expand Down Expand Up @@ -1203,6 +1274,10 @@ describe("FsProjectManager.addResource", () => {
bedrockManagedAgents?: boolean;
tags?: Record<string, string>;
additionalPolicies?: string[];
networkMode?: string;
networkConfig?: unknown;
platformVersion?: string;
filesystemConfigurations?: unknown[];
}[];
harnesses: unknown[];
memories?: unknown[];
Expand Down Expand Up @@ -1234,6 +1309,50 @@ describe("FsProjectManager.addResource", () => {
}
}

test.each(PUBLIC_ACCESS_POINT_MOUNTS)(
"deploy to a China target rejects a public %s access-point mount",
async (_label, mount) => {
await inTempDirectory();
const { subject, project, deployCalls } = await projectWithTarget(
"cn-north-1",
undefined,
MCP_PYTHON_FASTMCP,
);
await editSpec(project, (spec) => {
spec.runtimes[0]!.networkMode = "PUBLIC";
spec.runtimes[0]!.platformVersion = "V2";
spec.runtimes[0]!.filesystemConfigurations = [mount];
});

const { error } = await deployOutcome(subject, project);
expect(error).toBeInstanceOf(RegionUnsupportedFeatureError);
expect(String(error)).toContain("runtime 'mcp_python_fastmcp'");
expect(String(error)).toContain(PUBLIC_BYO_ACCESS_POINT_MOUNTS_CN_MESSAGE);
expect(deployCalls).toEqual([]);
},
);

test("deploy to a China target allows a VPC-mode EFS access-point mount", async () => {
await inTempDirectory();
const { subject, project, deployCalls } = await projectWithTarget(
"cn-north-1",
undefined,
MCP_PYTHON_FASTMCP,
);
await editSpec(project, (spec) => {
spec.runtimes[0]!.networkMode = "VPC";
spec.runtimes[0]!.networkConfig = {
subnets: ["subnet-12345678"],
securityGroups: ["sg-12345678"],
};
spec.runtimes[0]!.filesystemConfigurations = [EFS_ACCESS_POINT_MOUNT];
});

const { error } = await deployOutcome(subject, project);
expect(error).toBeUndefined();
expect(deployCalls).toHaveLength(1);
});

test("deploy to a China target hard-fails on a persisted commercial model provider", async () => {
await inTempDirectory();
const { subject, project, deployCalls } = await projectWithTarget("cn-north-1");
Expand Down
40 changes: 39 additions & 1 deletion src/core/project/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { EvaluatorSchema } from "../../projectSchemas/evaluator";
import { OnlineEvalConfigSchema } from "../../projectSchemas/online-eval-config";
import { PaymentConnectorSchema, PaymentManagerSchema } from "../../projectSchemas/payment";
import { PolicyEngineSchema, PolicySchema } from "../../projectSchemas/policy";
import { RuntimeEndpointSchema } from "../../projectSchemas/runtime";
import { RuntimeEndpointSchema, type ProjectRuntime } from "../../projectSchemas/runtime";
import { defaultExportProjectName, enclosingProjectRoot, projectSpecPath } from "./fsUtils";
import { parseArn } from "../arn";
import {
Expand Down Expand Up @@ -260,6 +260,24 @@ export function isAddableInChina(kind: ChinaAddKind): boolean {
return CN_SUPPORTED_ADD_KINDS.has(kind);
}

/**
* Returns true when a runtime uses the PUBLIC Preview path for EFS or S3 Files access-point mounts.
* China blocks this path because the preview is unavailable there; VPC access-point mounts remain valid.
* It deliberately does not re-check platformVersion: the runtime schema (projectSchemas/runtime.ts)
* only accepts a PUBLIC access-point mount when platformVersion is V2, so PUBLIC + such a mount
* already implies V2.
*/
function hasPublicByoAccessPointMount(
runtime: Pick<ProjectRuntime, "networkMode" | "filesystemConfigurations">,
): boolean {
return (
runtime.networkMode === "PUBLIC" &&
(runtime.filesystemConfigurations ?? []).some(
(mount) => "efsAccessPoint" in mount || "s3FilesAccessPoint" in mount,
)
);
}

/**
* The project spec collections deployable to a China region — the spec-file
* counterpart of {@link CN_SUPPORTED_RESOURCE_TYPES} (toolRuntimes render as
Expand All @@ -273,6 +291,15 @@ const CN_SUPPORTED_SPEC_COLLECTIONS = new Set([
"toolRuntimes",
]);

/**
* Shown when a runtime's PUBLIC EFS or S3 Files access-point mount is added to, or deployed
* to, a China (aws-cn) region. The PUBLIC-mode access-point preview is not available there;
* the VPC route to the same mounts keeps working.
*/
export const PUBLIC_BYO_ACCESS_POINT_MOUNTS_CN_MESSAGE =
"PUBLIC EFS and S3 Files access-point mounts are not available in China regions " +
"(cn-north-1, cn-northwest-1). Use VPC mode or deploy to a supported commercial region.";

/**
* Shown when a Gateway Target of type `connector` is added to, or deployed from, a
* project with a China (aws-cn) target. The curated connectors are a static CLI
Expand Down Expand Up @@ -674,6 +701,9 @@ export class FsProjectManager implements ProjectManager {
if (input.resourceType === "harness") {
throw new RegionUnsupportedFeatureError(HARNESS_CN_MESSAGE);
}
if (input.resourceType === "runtime" && hasPublicByoAccessPointMount(input.resourceConfig)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall placement is right, and I checked it properly rather than assuming.

Two guards rather than one is the correct call — a user can add the runtime before adding a China target, so an add-time check alone would leak.

I also traced every path a runtime spec can enter a project: add runtime (both flags and the TUI wizard, which funnel through the same addResource), add runtime --agent-id (Bedrock Agent import), export harness --arn, create/init templates, a hand-edited agentcore.json, a spec written by an older CLI, and migrate. The deploy guard covers all of them. I found no route by which a PUBLIC access-point mount reaches a China deploy.

One low-severity gap worth knowing about: export harness --arn bypasses addResource entirely and has no region guard of any kind, while templates/export.ts:274 copies networkMode and never sets platformVersion. Exporting a deployed PUBLIC harness that carries mounts therefore yields a spec rejected later with the generic mount message, giving no hint that the exporter dropped platformVersion. It's the one path where the config is machine-generated rather than user-typed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d61d330. Exported PUBLIC access-point harness configurations now receive platformVersion V2, and a contract test proves the emitted runtime validates. VPC exports remain unchanged.

throw new RegionUnsupportedFeatureError(PUBLIC_BYO_ACCESS_POINT_MOUNTS_CN_MESSAGE);
}
// One allowlist decides what is refused (CN_SUPPORTED_ADD_KINDS); the
// input decides which message: a connector-backed Gateway Target gets
// its own, every other blocked kind the generic one.
Expand Down Expand Up @@ -1635,6 +1665,14 @@ export class FsProjectManager implements ProjectManager {
// modelProvider (BYO, provider-free, hand-edited, or scaffolded by an
// older CLI) cannot be classified and only get an informational note.
if (isChinaRegion(target.region)) {
const publicByoMountRuntimes = project.spec.runtimes.filter(hasPublicByoAccessPointMount);
if (publicByoMountRuntimes.length > 0) {
throw new RegionUnsupportedFeatureError(
`Cannot deploy to China region ${target.region}: ` +
`${publicByoMountRuntimes.map((runtime) => `runtime '${runtime.name}'`).join(", ")} uses ` +
`PUBLIC EFS or S3 Files access-point mounts. ${PUBLIC_BYO_ACCESS_POINT_MOUNTS_CN_MESSAGE}`,
);
}
const bmaRuntimes = project.spec.runtimes.filter(
(runtime) => runtime.bedrockManagedAgents === true,
);
Expand Down
29 changes: 29 additions & 0 deletions src/core/project/templates/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,35 @@ describe("mapHarnessToExportPlan runtime spec entry", () => {
expect(result.runtime.executionRoleArn).toBeUndefined();
});

test("stamps platformVersion V2 for a PUBLIC access-point mount so the runtime validates", () => {
// A deployed PUBLIC harness carrying access-point mounts reaches the mapper as a HarnessSpec.
// The harness spec has no platformVersion, and a PUBLIC access-point mount is invalid without
// V2, so the exporter must stamp it or the exported runtime is rejected later.
const vpcSpec = harness({
networkMode: "VPC",
networkConfig: { subnets: ["subnet-12345678"], securityGroups: ["sg-12345678"] },
efsAccessPoints: [
{
accessPointArn:
"arn:aws:elasticfilesystem:us-east-1:111122223333:access-point/fsap-0123456789abcdef0",
mountPath: "/mnt/tools",
},
],
});
const publicSpec: HarnessSpec = { ...vpcSpec, networkMode: "PUBLIC", networkConfig: undefined };

const result = plan({ spec: publicSpec });

expect(result.runtime.networkMode).toBe("PUBLIC");
expect(result.runtime.platformVersion).toBe("V2");
expect(result.runtime.networkConfig).toBeUndefined();

// The exported runtime must validate inside a project spec rather than be rejected later.
const spec = projectSpec();
spec.runtimes.push(result.runtime);
expect(() => ProjectSpecSchema.parse(spec)).not.toThrow(z.ZodError);
});

test("the produced entry validates inside a project spec", () => {
const result = plan({});
const spec = projectSpec();
Expand Down
6 changes: 6 additions & 0 deletions src/core/project/templates/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export function mapHarnessToExportPlan(input: HarnessExportInput): HarnessExport
spec.timeoutSeconds !== undefined;

const filesystemConfigurations = buildFilesystemConfigurations(spec);
const hasAccessPointMount = filesystemConfigurations.some(
(mount) => "efsAccessPoint" in mount || "s3FilesAccessPoint" in mount,
);
const envVars = Object.entries(spec.environmentVariables ?? {}).map(([name, value]) => ({
name,
value,
Expand Down Expand Up @@ -272,6 +275,9 @@ export function mapHarnessToExportPlan(input: HarnessExportInput): HarnessExport
runtimeVersion: "PYTHON_3_14",
...(envVars.length > 0 && { envVars }),
...(spec.networkMode && { networkMode: spec.networkMode }),
// A PUBLIC access-point mount requires platformVersion V2 (projectSchemas/runtime.ts). The
// harness spec carries no platformVersion, so set it here or the exported runtime is rejected.
...(spec.networkMode === "PUBLIC" && hasAccessPointMount && { platformVersion: "V2" as const }),
...(networkConfig && { networkConfig }),
...(spec.authorizerType && { authorizerType: spec.authorizerType }),
...(spec.authorizerConfiguration && {
Expand Down
43 changes: 43 additions & 0 deletions src/handlers/project/add/runtime/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,49 @@ describe("project add runtime", () => {
expect(await runtimeOf(projectRoot, "s3_agent")).toMatchSnapshot();
});

test("public EFS and S3 Files mounts are written to the spec entry", async () => {
const { projectRoot, cleanup } = await initProject();
cleanups.push(cleanup);
await run([
"add",
"runtime",
"--name",
"public_mounts",
"--language",
"python",
"--network-mode",
"PUBLIC",
"--platform-version",
"V2",
"--filesystem-configurations",
JSON.stringify([
{
efsAccessPoint: {
accessPointArn:
"arn:aws:elasticfilesystem:us-east-1:123456789012:access-point/fsap-0123456789abcdef0",
mountPath: "/mnt/efs",
},
},
{
s3FilesAccessPoint: {
accessPointArn:
"arn:aws:s3files:us-east-1:123456789012:file-system/fs-0123456789abcdef01/access-point/fsap-0123456789abcdef1",
mountPath: "/mnt/s3",
},
},
]),
]);

expect(await runtimeOf(projectRoot, "public_mounts")).toMatchObject({
networkMode: "PUBLIC",
platformVersion: "V2",
filesystemConfigurations: [
{ efsAccessPoint: { mountPath: "/mnt/efs" } },
{ s3FilesAccessPoint: { mountPath: "/mnt/s3" } },
],
});
});

test("an existing folder keeps the user's files; only missing docs are added", async () => {
const { projectRoot, cleanup } = await initProject();
cleanups.push(cleanup);
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/project/add/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const createAddRuntimeHandler = (config: AddProjectResourceConfig) =>
),
flag(
"filesystem-configurations",
"filesystem mount configurations (JSON); an s3BucketMount needs --platform-version V2",
"filesystem mount configurations (JSON); EFS and S3 Files access-point mounts use VPC, or --network-mode PUBLIC with --platform-version V2 (Preview, commercial Regions only)",
z.string().optional(),
{ group: ENVIRONMENT },
),
Expand Down
Loading
Loading