Skip to content

fix(project): deploy credentials through CloudFormation, and stop deleting stacks - #2089

Draft
notgitika wants to merge 3 commits into
refactorfrom
feat/project-deploy-credentials
Draft

fix(project): deploy credentials through CloudFormation, and stop deleting stacks#2089
notgitika wants to merge 3 commits into
refactorfrom
feat/project-deploy-credentials

Conversation

@notgitika

@notgitika notgitika commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Warning

This depends on changes on the refactor branch of the L3 CDK package.

Summary

Hardens agentcore project deploy and moves credential-provider ownership into CloudFormation:

  • Rejects synthesized stacks with no resources before bootstrap or deploy, preventing CDK from deleting an existing stack and reporting success.
  • Verifies that the selected stack artifact matches the target account and region. Environment-agnostic stacks remain supported.
  • Creates API key and OAuth credential providers in the stack so their lifecycle and rollback are managed by CloudFormation.
  • Keeps real secrets out of synthesized templates. Secrets Manager references are passed directly to CloudFormation; secrets from .env.local use a placeholder that the CLI replaces through the Identity API after a successful deploy.
  • Validates credentials before synth so missing local secrets fail without creating resources.
  • Rejects payment credentials up front because CloudFormation has no payment credential-provider resource. This limitation is tracked in project deploy cannot create payment credential providers; support Quick Create connectors first #2095.
  • Resolves payment connector credentials by name inside the stack, removing the vended app's dependency on deployed-state.json.

Testing

Added unit coverage for stack safety and environment validation, credential preflight and deploy ordering, inline and external secrets, API key and OAuth synchronization, and unsupported payment credentials.

Also verified against a real AWS account that secrets do not appear in cdk.out, inline secrets are synchronized after deploy, external secrets remain untouched, and redeploying does not reset synchronized values.

@github-actions github-actions Bot added the size/xl PR size: XL label Aug 24, 2026
@github-actions github-actions Bot added agentcore-harness-reviewing AgentCore Harness review in progress size/xl PR size: XL and removed agentcore-harness-reviewing AgentCore Harness review in progress size/xl PR size: XL labels Aug 24, 2026
Base automatically changed from feat/project-deploy-implementation to refactor August 24, 2026 19:39
@notgitika
notgitika force-pushed the feat/project-deploy-credentials branch from a1b6cbf to c255cdd Compare August 24, 2026 19:50
@notgitika
notgitika marked this pull request as draft August 24, 2026 19:50
@notgitika notgitika changed the title feat(project): create credential providers before synthesizing a deploy fix(project): stop deploy silently dropping credentials, deleting stacks, and trusting a tag Aug 24, 2026
@notgitika notgitika changed the title fix(project): stop deploy silently dropping credentials, deleting stacks, and trusting a tag fix(project): tighten agentcore project deploy command Aug 24, 2026
@codecov-commenter

codecov-commenter commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.17886% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.25%. Comparing base (768ef10) to head (378208a).
⚠️ Report is 1 commits behind head on refactor.

Files with missing lines Patch % Lines
src/core/project/backends/cdk/credentials.ts 78.06% 34 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           refactor    #2089      +/-   ##
============================================
- Coverage     97.36%   97.25%   -0.12%     
============================================
  Files           410      411       +1     
  Lines         24796    25026     +230     
============================================
+ Hits          24142    24338     +196     
- Misses          654      688      +34     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Two review findings from #2058, both cases of deploy trusting something it
had not checked.

A synthesized template with no resources makes the CDK Toolkit *delete* an
existing stack of that name and return as though it deployed. #2058 caught
that after the fact, by which point the stack was already gone. Check the
resource count before handing the assembly to the Toolkit instead.

Stack selection matched on the target-name tag alone, never on the account
and region the artifact was synthesized for. Those derive from the same
target today and so cannot disagree, but nothing enforced it, and the
Toolkit deploys where the artifact's environment points rather than where
the tag says. Both fields were also being stripped on read, since the
manifest schema declared neither.

stackArtifactIdForTarget becomes stackArtifactForTarget, returning the
template path alongside the id so the resource check needs no second read
of the manifest.
Credentials declared in agentcore.json are not provisioned by `project deploy`
on this branch: the synthesized app reads their provider ARNs out of
.cli/deployed-state.json and tolerates the file's absence, and nothing writes it.

Points at #2093 rather than working around it here. Credential providers are
supported by CloudFormation, so the fix belongs in the synthesized stack, not in
an imperative pre-synth step in the CLI.
@notgitika
notgitika force-pushed the feat/project-deploy-credentials branch from 1a13ff1 to dfb7780 Compare August 24, 2026 20:38
@notgitika notgitika changed the title fix(project): tighten agentcore project deploy command fix(project): stop deploy deleting stacks and trusting a tag Aug 24, 2026
`agentcore project deploy` created credential providers imperatively over the
Identity API before synth, so the CLI owned resources CloudFormation did not
know about and a rolled-back stack left them orphaned.

The stack now declares them. Real secret material still never reaches the
template: a credential carrying an external Secrets Manager reference deploys
pointing at that secret, and one whose secret lives in `.env.local` is created
with the L3's placeholder, which the CLI replaces over the Identity API once the
deploy succeeds.

- `assertCredentialsDeployable` runs before synth. A missing `.env.local`
  variable fails there, naming the variable and the file, rather than after a
  provider is already live holding a placeholder no later run would replace.
- `createCredentialSynchronizer` runs after the deploy, because the providers do
  not exist until CloudFormation makes them. It updates every provider whose
  secret is inline on every deploy: the placeholder cannot be told apart from a
  real key by reading the provider back, since `ApiKey` is a write-only
  CloudFormation property and `GetApiKeyCredentialProvider` returns only the
  secret's ARN.
- A `PaymentCredentialProvider` is refused up front. CloudFormation has no
  payment credential provider resource, and a payment provider needs vendor
  configuration `agentcore.json` has no fields for.
- Payment connectors now carry the credential's *name*; the stack resolves it to
  the ARN of the provider it created. That drops the last reader of
  `deployed-state.json` from the vended CDK app.

Both passes share one `resolveSecret`, so the preflight cannot disagree with the
sync about which credentials need a secret pushed.
@notgitika notgitika changed the title fix(project): stop deploy deleting stacks and trusting a tag fix(project): deploy credentials through CloudFormation, and stop deleting stacks Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xl PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants