-
Notifications
You must be signed in to change notification settings - Fork 52
feat: add policy engine and policy support #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
33c4b00
feat: add policy engine and policy support with full deploy pipeline
jesseturner21 a80a005
feat: use composite key for policy removal to handle cross-engine nam…
jesseturner21 0bc9914
fix: sync package-lock.json for npm@10 compatibility
jesseturner21 b0197e0
fix: resolve lint and formatting issues for CI
jesseturner21 e118d1e
fix: make --statement, --source, --generate mutually exclusive in add…
jesseturner21 c61bfce
feat: add policy engine and policy support to TUI remove flow
jesseturner21 f5c37ea
fix: write both CLIENT_ID and CLIENT_SECRET env vars for managed OAut…
jesseturner21 d642bd7
feat: add PolicyEngineConfiguration support for gateways
Hweinstock 0486995
feat: add policy engine selection to gateway TUI wizard
Hweinstock c9c86ca
fix: shorten disabled policy generate description to prevent truncation
jesseturner21 7bfc445
fix: prevent infinite loop when pressing Escape on policy generation …
jesseturner21 17997d6
chore: remove legacy McpGateway output pattern from gateway parser
jesseturner21 2f90d2b
test: add integ tests for --statement/--source/--generate mutual excl…
jesseturner21 d03d32c
fix: remove unnecessary sourceFile existence check from validate
jesseturner21 62a73a1
fix: respect --json flag in policy remove command
jesseturner21 900810a
chore: co-locate hasPolicyEngines with other has* checks in preflight
jesseturner21 d0a4df2
fix: address PR review comments for policy support
jesseturner21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import { getCredentialProvider } from './account'; | ||
| import { | ||
| BedrockAgentCoreControlClient, | ||
| GetPolicyGenerationCommand, | ||
| ListPolicyGenerationAssetsCommand, | ||
| StartPolicyGenerationCommand, | ||
| waitUntilPolicyGenerationCompleted, | ||
| } from '@aws-sdk/client-bedrock-agentcore-control'; | ||
| import { WaiterState } from '@smithy/util-waiter'; | ||
|
|
||
| export interface StartPolicyGenerationOptions { | ||
| policyEngineId: string; | ||
| description: string; | ||
| region: string; | ||
| resourceArn: string; | ||
| } | ||
|
|
||
| export interface StartPolicyGenerationResult { | ||
| generationId: string; | ||
| } | ||
|
|
||
| export interface GetPolicyGenerationOptions { | ||
| generationId: string; | ||
| policyEngineId: string; | ||
| region: string; | ||
| } | ||
|
|
||
| export interface GetPolicyGenerationResult { | ||
| status: string; | ||
| statement: string; | ||
| } | ||
|
|
||
| export async function startPolicyGeneration( | ||
| options: StartPolicyGenerationOptions | ||
| ): Promise<StartPolicyGenerationResult> { | ||
| const client = new BedrockAgentCoreControlClient({ | ||
| region: options.region, | ||
| credentials: getCredentialProvider(), | ||
| }); | ||
|
|
||
| const command = new StartPolicyGenerationCommand({ | ||
| policyEngineId: options.policyEngineId, | ||
| resource: { arn: options.resourceArn }, | ||
| content: { | ||
| rawText: options.description, | ||
| }, | ||
| name: `cli_generation_${Date.now()}`, | ||
| }); | ||
|
|
||
| const response = await client.send(command); | ||
|
|
||
| if (!response.policyGenerationId) { | ||
| throw new Error('No generation ID returned from StartPolicyGeneration'); | ||
| } | ||
|
|
||
| return { generationId: response.policyGenerationId }; | ||
| } | ||
|
|
||
| export async function getPolicyGeneration(options: GetPolicyGenerationOptions): Promise<GetPolicyGenerationResult> { | ||
| const client = new BedrockAgentCoreControlClient({ | ||
| region: options.region, | ||
| credentials: getCredentialProvider(), | ||
| }); | ||
|
|
||
| // Use the SDK waiter to poll until generation completes | ||
| const waiterResult = await waitUntilPolicyGenerationCompleted( | ||
| { client, maxWaitTime: 120, minDelay: 2, maxDelay: 5 }, | ||
| { policyGenerationId: options.generationId, policyEngineId: options.policyEngineId } | ||
| ); | ||
|
|
||
| if (waiterResult.state !== WaiterState.SUCCESS) { | ||
| throw new Error( | ||
| `Policy generation did not complete within the timeout period (state: ${waiterResult.state}). ` + | ||
| `Generation ID: ${options.generationId}` | ||
| ); | ||
| } | ||
|
|
||
| // Check the final status | ||
| const getCommand = new GetPolicyGenerationCommand({ | ||
| policyGenerationId: options.generationId, | ||
| policyEngineId: options.policyEngineId, | ||
| }); | ||
|
|
||
| const statusResponse = await client.send(getCommand); | ||
|
|
||
| if (statusResponse.status === 'GENERATE_FAILED') { | ||
| const reasons = statusResponse.statusReasons?.join(', ') ?? 'Unknown reason'; | ||
| throw new Error(`Policy generation failed: ${reasons}`); | ||
| } | ||
|
|
||
| // Fetch the generated assets | ||
| const assetsCommand = new ListPolicyGenerationAssetsCommand({ | ||
| policyGenerationId: options.generationId, | ||
| policyEngineId: options.policyEngineId, | ||
| }); | ||
|
|
||
| const assetsResponse = await client.send(assetsCommand); | ||
| const assets = assetsResponse.policyGenerationAssets ?? []; | ||
|
|
||
| if (assets.length === 0) { | ||
| throw new Error('Policy generation completed but no assets were returned'); | ||
| } | ||
|
|
||
| // Get the Cedar statement from the first asset | ||
| const firstAsset = assets[0]!; | ||
|
jesseturner21 marked this conversation as resolved.
|
||
| const cedarStatement = firstAsset.definition?.cedar?.statement; | ||
|
|
||
| if (!cedarStatement) { | ||
| throw new Error('Policy generation completed but no Cedar policy statement was found in the assets'); | ||
| } | ||
|
|
||
| return { | ||
| status: statusResponse.status ?? 'GENERATED', | ||
| statement: cedarStatement, | ||
| }; | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.