fix(unit-only): Add a secretless link path in pre-deploy-identity.ts: in ... (#1032)#64
Draft
aidandaly24 wants to merge 1 commit into
Draft
fix(unit-only): Add a secretless link path in pre-deploy-identity.ts: in ... (#1032)#64aidandaly24 wants to merge 1 commit into
aidandaly24 wants to merge 1 commit into
Conversation
… without a local secret (aws#1032)
Coverage Report
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs aws#1032
Issues
agentcore deploycannot wire that provider's ARN. If a gateway target's outbound auth references such a credential, deploy fails at CDK synth withCredential "X" not found in deployed state. This is an enhancement gap, not a regression: the normal create/update-from-local-secret path works, and putting the secret in .env.local is a workaround.Root cause
CLI-side, confirmed by reading v0.20.2. setupApiKeyCredentialProvider returns status:'skipped' with no credentialProviderArn when the local secret is absent (src/cli/operations/deploy/pre-deploy-identity.ts:175-181); same for OAuth at lines 405-411 (missing client id/secret) and 415-423 (no discoveryUrl). The ARN-collection loops only persist a credential when result.credentialProviderArn is truthy: src/cli/commands/deploy/actions.ts:287-293 (API key) and 323-331 (OAuth), and src/cli/tui/hooks/useCdkPreflight.ts:819-825 and 864-872. So a 'skipped' credential never reaches deployed-state. The throw the user actually sees is in the CDK construct (consumer): agentcore-l3-cdk-constructs src/cdk/constructs/components/mcp/Gateway.ts:282-284 looks up this.credentials?.[credentialName] and throws
Credential "X" not found in deployed statewhen the ARN is missing. The CDK is correctly rejecting incomplete state; the missing-ARN root cause is purely CLI. Note: getOAuth2Provider already exists and is already exported (src/cli/operations/identity/oauth2-credential-provider.ts:122 and index.ts:9); only an analogous getApiKeyProvider must be added.The fix
Add a secretless link path in pre-deploy-identity.ts: in the three skip branches, before skipping, attempt to resolve an existing provider's ARN by name (new getApiKeyProvider helper wrapping the existing GetApiKeyCredentialProviderCommand at api-key-credential-provider.ts:54; reuse the already-present getOAuth2Provider for OAuth). On success, return a new status 'linked' carrying credentialProviderArn (and clientSecretArn/callbackUrl for OAuth) so the existing ARN-collection loops persist it to deployed-state.json for CDK wiring. Keep create/update behavior unchanged when a local secret is present. Surface a clear error only when neither a local secret nor a remote provider exists. This is exactly PR aws#973 (OPEN, +204/-19). Recommendation: review and merge aws#973; the design decision to settle is the not-found failure mode (error vs continue) — PR makes it fail clearly. Minor: the brief overstates the change set (getOAuth2Provider already exists/exported; OAuth needs wiring, not a new function).
Files touched: src/cli/operations/deploy/pre-deploy-identity.ts (setupApiKeyCredentialProvider skip branch 175-181; setupSingleOAuth2Provider skip branches 405-411 and 415-423); src/cli/operations/identity/api-key-credential-provider.ts (add getApiKeyProvider using GetApiKeyCredentialProviderCommand at line 54); src/cli/operations/identity/index.ts (export getApiKeyProvider; getOAuth2Provider already exported at line 9); src/cli/tui/hooks/useCdkPreflight.ts (handle new 'linked' status ~802/845, ARN collection 819-825/864-872); src/cli/commands/deploy/actions.ts (287-293/323-331). Consumers requiring no change: src/assets/cdk/lib/cdk-stack.ts:100-114 forwards credentials map; agentcore-l3-cdk-constructs src/cdk/constructs/components/mcp/Gateway.ts:282-284 is the throw site (pinned ^0.1.0-alpha.19; the brief's cited Gateway.ts:227-229 is the IAM grant block, not the throw).
Validation evidence
The fix was verified by reproducing the original symptom and re-running after the change:
Test suite: green.
Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.