Skip to content

fix(import): strip reserved aws: tags from imported resources - #2289

Open
jariy17 wants to merge 1 commit into
mainfrom
fix/import-strip-reserved-aws-tags
Open

fix(import): strip reserved aws: tags from imported resources#2289
jariy17 wants to merge 1 commit into
mainfrom
fix/import-strip-reserved-aws-tags

Conversation

@jariy17

@jariy17 jariy17 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Problem

agentcore import <resource> copies every tag from the source resource into agentcore.json. CloudFormation stamps aws:cloudformation:{stack-id,stack-name,logical-id} on every resource it provisions, and a resource retained after its stack is deleted keeps these as orphans. Because aws:-prefixed keys are reserved and not customer-writable, they fail TagKeySchema during config validation — blocking the import before any AWS call:

runtimes[0].tags.aws:cloudformation:stack-name: Invalid key in record
runtimes[0].tags.aws:cloudformation:logical-id: Invalid key in record
runtimes[0].tags.aws:cloudformation:stack-id: Invalid key in record

Fix

Add a shared stripReservedTags() helper in import-utils.ts and apply it at all four import read-paths (runtime, memory, gateway, evaluator). User tags are preserved; aws:-prefixed tags are dropped from the local config and stay untouched on the resource in AWS.

The aws: refine in TagKeySchema is intentionally left in place — it is correct for user-authored tags. Filtering happens at the import read-path instead.

Testing

  • New strip-reserved-tags.test.ts: reserved keys dropped, user tags kept, undefined when only reserved remain, and output passes TagsSchema.parse.
  • Full import suite green (373 tests); typecheck, lint, build clean.
  • Verified end-to-end against a real CloudFormation-provisioned runtime carrying aws:cloudformation:* tags: pre-fix reproduces the validation failure above; post-fix the import writes agentcore.json successfully.
  • Also updates the vi.mock('../import-utils') factory in import-runtime-handler.test.ts to spread the real module, so new utils are no longer silently undefined in that test.

CloudFormation stamps aws:cloudformation:{stack-id,stack-name,logical-id}
on every resource it provisions. A resource retained after its stack is
deleted keeps these as orphans, and they are not customer-writable.

The import commands copied all tags from the source resource verbatim into
agentcore.json. Any aws:-prefixed key then fails TagKeySchema ("aws:" is
reserved) during config validation, blocking the import before any AWS call:

  runtimes[0].tags.aws:cloudformation:stack-name: Invalid key in record

Add a shared stripReservedTags() helper and apply it at all four import
read-paths (runtime, memory, gateway, evaluator). User tags are preserved;
reserved tags are dropped and stay untouched on the resource in AWS.
@jariy17
jariy17 requested a review from a team September 11, 2026 19:53
@github-actions github-actions Bot added the size/s PR size: S label Sep 11, 2026
@jariy17
jariy17 deployed to e2e-testing September 11, 2026 19:53 — with GitHub Actions Active
@agentcore-devx-automation agentcore-devx-automation Bot added agentcore-harness-reviewing AgentCore Harness review in progress claude-security-reviewing Claude Code /security-review in progress labels Sep 11, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.28.1.tgz

How to install

gh release download pr-2289-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.28.1.tgz

@agentcore-devx-automation agentcore-devx-automation Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Sep 11, 2026

@agentcore-devx-automation agentcore-devx-automation Bot left a comment

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.

AgentCore Harness Review

Verdict: Looks good

Nice tight fix. The stripReservedTags helper is applied consistently to every import path that carries tags (import-runtime, import-evaluator, import-memory, import-gateway), and I confirmed the two remaining import modules (import-online-eval, import-pipeline) don't propagate tags into the spec, so nothing is missed. The aws: prefix check matches exactly what TagKeySchema rejects in src/schema/schemas/primitives/tags.ts, and the "returns undefined when nothing remains" contract keeps the callsites clean (...(tags && { tags })).

The test file is a good regression net — it exercises the real TagsSchema rather than mocking it, which is exactly the right level. The runtime-handler test tweak to use importOriginal for ../import-utils is the correct way to keep the mock working now that stripReservedTags is called from inside import-runtime.ts.

No telemetry gap here since this rides on the existing withCommandRunTelemetry wrappers in each import command.

Good to merge.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 41.09% 15749 / 38326
🔵 Statements 40.35% 16799 / 41627
🔵 Functions 35.21% 2714 / 7707
🔵 Branches 34.24% 10527 / 30737
Generated in workflow #4470 for commit 69517bf by the Vitest Coverage Report Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant