Commit 4da709b
feat: add policy engine and policy support (#579)
* feat: add policy engine and policy support with full deploy pipeline
Add Cedar authorization policy support to AgentCore CLI:
- Schema: PolicyEngine and Policy schemas with Zod validation
- TUI: Full add/remove wizards for policy engines and policies
- Source methods: Cedar file, inline statement, or AI generation
- Gateway selection for generation flow
- Expandable text input for generation prompts
- CLI: Non-interactive add/remove commands with all flags
- agentcore add policy-engine --name <name>
- agentcore add policy --name <name> --engine <engine> --source/--statement/--generate
- agentcore remove policy-engine/policy --name <name>
- Deploy: CDK construct integration, CloudFormation output parsing,
deployed state tracking with composite engine/policy keys
- Status: Policy engines and policies shown in status command and
ResourceGraph TUI with correct deployment state diffing
- Generation: StartPolicyGeneration + waiter integration with
deployed engine ID and gateway ARN resolution
- Validation: Schema validation for names, statements, validation modes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: use composite key for policy removal to handle cross-engine name collisions
Policies are nested under engines, so the same policy name can exist in
multiple engines. Switch getRemovable/remove/previewRemove to use an
"engineName/policyName" composite key so the generic TUI remove flow can
uniquely identify policies with a single string.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: sync package-lock.json for npm@10 compatibility
Regenerate lock file with npm@10 to resolve missing yaml@2.8.2
dependency entry that caused `npm ci` failures on Node 20.x and 22.x.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: resolve lint and formatting issues for CI
- Merge duplicate imports in policy-generation.ts
- Use dot notation instead of bracket notation in outputs test
- Replace Array<T> with T[] in outputs.ts and useDeployFlow.ts
- Add void operator for floating promises in AddPolicyFlow
- Wrap async handlers with void for no-misused-promises
- Escape quotes in JSX text in AddPolicyScreen
- Fix prettier formatting across all changed files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: make --statement, --source, --generate mutually exclusive in add policy
Previously, passing multiple source flags (e.g. --statement + --source) was
silently accepted with an implicit precedence order. Now the command returns
a clear error if more than one is provided.
Also fix pre-existing type errors in dev config tests by adding the required
policyEngines field to test fixtures.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add policy engine and policy support to TUI remove flow
Add interactive TUI support for removing policy engines and policies,
including menu entries, selection screens, confirmation, and success states.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: write both CLIENT_ID and CLIENT_SECRET env vars for managed OAuth credentials
The createManagedOAuthCredential method was only writing the client secret
with an incorrect env var name. Now correctly writes both _CLIENT_ID and
_CLIENT_SECRET suffixed env vars, matching the pattern used by CredentialPrimitive.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add PolicyEngineConfiguration support for gateways
* feat: add policy engine selection to gateway TUI wizard
* fix: shorten disabled policy generate description to prevent truncation
The "Generate a Cedar policy" option's disabled description was too long
("Requires deployed engine — run `deploy` first") and got cut off in
narrow terminals. Shortened to "Deploy engine first".
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: prevent infinite loop when pressing Escape on policy generation error
When the policy generation API returned an error, pressing Escape on the
review step would loop back to the loading step and re-trigger the API
call, creating an infinite loop. The root cause was the double goBack()
pattern (one immediate, one via setTimeout) suffering from stale closures
— both calls saw the same step, so the second never reached the
description step, while the first landed on loading and re-fired the
useEffect.
The fix uses a skipGeneration ref: when navigating back from review, the
ref is set to true and a single goBack() moves to the loading step. The
useEffect detects the ref, resets it, and calls goBack() again (now with
the correct step in scope) to reach the description step — without ever
starting generation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: remove legacy McpGateway output pattern from gateway parser
The CDK constructs renamed McpGateway to Gateway in PR #65. No deployed
stacks use the old prefix since this is pre-GA.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add integ tests for --statement/--source/--generate mutual exclusivity
Cover all pairwise combinations and the triple-flag case to ensure
the CLI rejects conflicting policy source flags.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: remove unnecessary sourceFile existence check from validate
The sourceFile field is metadata tracking where a policy statement
originated. The statement itself is persisted in agentcore.json, so
the original .cedar file is not needed after add. Failing validation
when the source file is cleaned up is incorrect.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: respect --json flag in policy remove command
The remove action always output JSON regardless of whether --json was
passed. Now matches the add command behavior: plain text by default,
JSON only when --json is specified.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: co-locate hasPolicyEngines with other has* checks in preflight
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address PR review comments for policy support
- Validate --validation-mode CLI flag with ValidationModeSchema.parse()
instead of unsafe cast (PolicyPrimitive)
- Add ambiguity check in remove/previewRemove when policy exists in
multiple engines without --engine specified (PolicyPrimitive)
- Gate JSON output behind --json flag in policy engine remove
(PolicyEnginePrimitive)
- Add uniqueBy validation on policies array to prevent duplicate names
(policy schema)
- Narrow validationModeItems type to remove unnecessary cast
(AddPolicyScreen)
- Disable reviewNav when generation error is shown (AddPolicyScreen)
- Add expandable to inline Cedar statement TextInput (AddPolicyScreen)
- Check waiter result state before proceeding (policy-generation)
- Revert SelectList wrap from truncate back to wrap
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Harrison Weinstock <hkobew@amazon.com>1 parent 0023284 commit 4da709b
58 files changed
Lines changed: 4165 additions & 1832 deletions
File tree
- integ-tests
- src
- assets
- __tests__/__snapshots__
- cdk/test
- cli
- aws
- cloudformation
- __tests__
- commands
- add
- create
- deploy
- logs/__tests__
- remove
- status
- external-requirements/__tests__
- logging
- operations
- agent/generate
- deploy
- dev/__tests__
- primitives
- tui
- components
- hooks
- __tests__
- screens
- add
- create
- deploy
- mcp
- policy
- remove
- __tests__
- schema/schemas
- primitives
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| 377 | + | |
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
2 | 8 | | |
3 | 9 | | |
4 | 10 | | |
| |||
285 | 291 | | |
286 | 292 | | |
287 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
0 commit comments