@aws-cdk/aws-bedrock-agentcore-alpha 2.250.0-alpha.0 → 2.252.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +11883 -7285
- package/.jsii.tabl.json.gz +0 -0
- package/.warnings.jsii.js +4 -0
- package/README.md +405 -0
- package/lib/gateway/gateway-base.js +1 -1
- package/lib/gateway/gateway.d.ts +58 -0
- package/lib/gateway/gateway.js +46 -3
- package/lib/gateway/inbound-auth/authorizer.d.ts +27 -1
- package/lib/gateway/inbound-auth/authorizer.js +37 -5
- package/lib/gateway/inbound-auth/custom-claim.js +1 -1
- package/lib/gateway/interceptor.js +1 -1
- package/lib/gateway/outbound-auth/api-key.js +1 -1
- package/lib/gateway/outbound-auth/credential-provider.js +1 -1
- package/lib/gateway/protocol.js +2 -2
- package/lib/gateway/targets/schema/api-schema.js +4 -4
- package/lib/gateway/targets/schema/tool-schema.js +4 -4
- package/lib/gateway/targets/target-base.js +1 -1
- package/lib/gateway/targets/target-configuration.js +6 -6
- package/lib/gateway/targets/target.js +1 -1
- package/lib/index.d.ts +8 -0
- package/lib/index.js +13 -1
- package/lib/memory/memory-strategy.js +1 -1
- package/lib/memory/memory.js +2 -2
- package/lib/memory/strategies/managed-strategy.js +1 -1
- package/lib/memory/strategies/self-managed-strategy.js +1 -1
- package/lib/network/network-configuration.js +4 -4
- package/lib/policy/perms.d.ts +50 -0
- package/lib/policy/perms.js +62 -0
- package/lib/policy/policy-base.d.ts +194 -0
- package/lib/policy/policy-base.js +120 -0
- package/lib/policy/policy-engine-base.d.ts +260 -0
- package/lib/policy/policy-engine-base.js +193 -0
- package/lib/policy/policy-engine.d.ts +150 -0
- package/lib/policy/policy-engine.js +290 -0
- package/lib/policy/policy-statement.d.ts +518 -0
- package/lib/policy/policy-statement.js +927 -0
- package/lib/policy/policy-types.d.ts +66 -0
- package/lib/policy/policy-types.js +30 -0
- package/lib/policy/policy.d.ts +127 -0
- package/lib/policy/policy.js +225 -0
- package/lib/policy/validation-helpers.d.ts +139 -0
- package/lib/policy/validation-helpers.js +276 -0
- package/lib/runtime/inbound-auth/custom-claim.js +1 -1
- package/lib/runtime/inbound-auth/runtime-authorizer-configuration.js +1 -1
- package/lib/runtime/observability.d.ts +105 -0
- package/lib/runtime/observability.js +317 -0
- package/lib/runtime/runtime-artifact.js +1 -1
- package/lib/runtime/runtime-base.js +1 -1
- package/lib/runtime/runtime-endpoint-base.js +1 -1
- package/lib/runtime/runtime-endpoint.js +1 -1
- package/lib/runtime/runtime.d.ts +17 -0
- package/lib/runtime/runtime.js +10 -2
- package/lib/tools/browser.js +2 -2
- package/lib/tools/code-interpreter.js +2 -2
- package/package.json +9 -9
- package/rosetta/default.ts-fixture +2 -0
package/.jsii.tabl.json.gz
CHANGED
|
Binary file
|
package/.warnings.jsii.js
CHANGED
|
@@ -83,6 +83,10 @@ const VALIDATORS = { _aws_cdk_aws_bedrock_agentcore_alpha_MemoryProps: function
|
|
|
83
83
|
try {
|
|
84
84
|
if (!visitedObjects.has(p.lifecycleConfiguration))
|
|
85
85
|
module.exports._aws_cdk_aws_bedrock_agentcore_alpha_LifecycleConfiguration(p.lifecycleConfiguration);
|
|
86
|
+
if (p.loggingConfigs != null)
|
|
87
|
+
for (const o of p.loggingConfigs)
|
|
88
|
+
if (!visitedObjects.has(o))
|
|
89
|
+
module.exports._aws_cdk_aws_bedrock_agentcore_alpha_LoggingConfig(o);
|
|
86
90
|
}
|
|
87
91
|
finally {
|
|
88
92
|
visitedObjects.delete(p);
|
package/README.md
CHANGED
|
@@ -114,6 +114,14 @@ This construct library facilitates the deployment of Bedrock AgentCore primitive
|
|
|
114
114
|
- [Memory with Custom Execution Role](#memory-with-custom-execution-role)
|
|
115
115
|
- [Memory with self-managed Strategies](#memory-with-self-managed-strategies)
|
|
116
116
|
- [Memory Strategy Methods](#memory-strategy-methods)
|
|
117
|
+
- [Policy](#policy)
|
|
118
|
+
- [PolicyEngine Properties](#policyengine-properties)
|
|
119
|
+
- [Policy Properties](#policy-properties)
|
|
120
|
+
- [Basic PolicyEngine and Policy Creation](#basic-policyengine-and-policy-creation)
|
|
121
|
+
- [Associating a Policy Engine with a Gateway](#associating-a-policy-engine-with-a-gateway)
|
|
122
|
+
- [Type-Safe Policy Builder](#type-safe-policy-builder)
|
|
123
|
+
- [PolicyEngine with KMS Encryption](#policyengine-with-kms-encryption)
|
|
124
|
+
- [Policy Validation Modes](#policy-validation-modes)
|
|
117
125
|
|
|
118
126
|
## AgentCore Runtime
|
|
119
127
|
|
|
@@ -800,6 +808,52 @@ new agentcore.Runtime(this, 'test-runtime', {
|
|
|
800
808
|
});
|
|
801
809
|
```
|
|
802
810
|
|
|
811
|
+
#### Observability configuration
|
|
812
|
+
|
|
813
|
+
The Runtime construct supports observability features including X-Ray tracing and logging to CloudWatch Logs, S3, or Kinesis Data Firehose. This allows you to monitor and debug your agent runtime invocations.
|
|
814
|
+
|
|
815
|
+
You can configure:
|
|
816
|
+
|
|
817
|
+
- tracingEnabled: Enable X-Ray tracing for the runtime
|
|
818
|
+
- loggingConfigs: Send APPLICATION_LOGS (agent runtime invocations) and USAGE_LOGS (session-level resource consumption) to CloudWatch Logs, S3, or Kinesis Data Firehose
|
|
819
|
+
|
|
820
|
+
For additional information, please refer to the [Set up logging and tracing for AgentCore](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/observability.html).
|
|
821
|
+
|
|
822
|
+
```typescript fixture=default
|
|
823
|
+
const repository = new ecr.Repository(this, 'TestRepository', {
|
|
824
|
+
repositoryName: 'test-agent-runtime',
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
const agentRuntimeArtifact = agentcore.AgentRuntimeArtifact.fromEcrRepository(repository, 'v1.0.0');
|
|
828
|
+
|
|
829
|
+
// Create logging destinations
|
|
830
|
+
const logGroup = new logs.LogGroup(this, 'RuntimeLogGroup');
|
|
831
|
+
const logBucket = new s3.Bucket(this, 'RuntimeLogBucket');
|
|
832
|
+
const firehoseStream = new firehose.DeliveryStream(this, 'RuntimeLogStream', {
|
|
833
|
+
destination: new firehose.S3Bucket(logBucket),
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
new agentcore.Runtime(this, 'test-runtime', {
|
|
837
|
+
runtimeName: 'test_runtime',
|
|
838
|
+
agentRuntimeArtifact: agentRuntimeArtifact,
|
|
839
|
+
tracingEnabled: true,
|
|
840
|
+
loggingConfigs: [
|
|
841
|
+
{
|
|
842
|
+
logType: agentcore.LogType.APPLICATION_LOGS,
|
|
843
|
+
destination: agentcore.LoggingDestination.cloudWatchLogs(logGroup),
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
logType: agentcore.LogType.APPLICATION_LOGS,
|
|
847
|
+
destination: agentcore.LoggingDestination.s3(logBucket),
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
logType: agentcore.LogType.APPLICATION_LOGS,
|
|
851
|
+
destination: agentcore.LoggingDestination.firehose(firehoseStream),
|
|
852
|
+
},
|
|
853
|
+
],
|
|
854
|
+
});
|
|
855
|
+
```
|
|
856
|
+
|
|
803
857
|
## Browser
|
|
804
858
|
|
|
805
859
|
The Amazon Bedrock AgentCore Browser provides a secure, cloud-based browser that enables AI agents to interact with websites. It includes security features such as session isolation, built-in observability through live viewing, CloudTrail logging, and session replay capabilities.
|
|
@@ -1177,6 +1231,7 @@ The Gateway construct provides a way to create Amazon Bedrock Agent Core Gateway
|
|
|
1177
1231
|
| `kmsKey` | `kms.IKey` | No | The AWS KMS key used to encrypt data associated with the gateway |
|
|
1178
1232
|
| `role` | `iam.IRole` | No | The IAM role that provides permissions for the gateway to access AWS services. A new role will be created if not provided |
|
|
1179
1233
|
| `tags` | `{ [key: string]: string }` | No | Tags for the gateway. A list of key:value pairs of tags to apply to this Gateway resource |
|
|
1234
|
+
| `policyEngineConfiguration` | `GatewayPolicyEngineConfig` | No | Associates a policy engine with this gateway. All agent requests are evaluated against the Cedar policies in the engine. The gateway role is automatically granted evaluate permissions. Default: no policy engine |
|
|
1180
1235
|
|
|
1181
1236
|
### Basic Gateway Creation
|
|
1182
1237
|
|
|
@@ -1265,6 +1320,20 @@ const lambdaRole = new iam.Role(this, "LambdaRole", {
|
|
|
1265
1320
|
gateway.grantInvoke(lambdaRole);
|
|
1266
1321
|
```
|
|
1267
1322
|
|
|
1323
|
+
**No Authorization** – Creates a gateway with no inbound authorization. This is useful for building public MCP servers,
|
|
1324
|
+
or when you want to skip gateway-level authentication and enforce tool execution-level authentication using Gateway Interceptors.
|
|
1325
|
+
|
|
1326
|
+
```typescript fixture=default
|
|
1327
|
+
const gateway = new agentcore.Gateway(this, "MyGateway", {
|
|
1328
|
+
gatewayName: "my-gateway",
|
|
1329
|
+
authorizerConfiguration: agentcore.GatewayAuthorizer.withNoAuth(),
|
|
1330
|
+
});
|
|
1331
|
+
```
|
|
1332
|
+
|
|
1333
|
+
> **⚠️ Important:** Do not use No Authorization gateways for production workloads unless you have implemented all the security best practices. No Authorization gateways are most appropriate for testing and development purposes. See [Security Best Practices](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-inbound-auth.html#gateway-inbound-auth-none) for required compensating controls.
|
|
1334
|
+
|
|
1335
|
+
For more information, see [No Authorization](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-inbound-auth.html#gateway-inbound-auth-none).
|
|
1336
|
+
|
|
1268
1337
|
**Cognito with M2M (Machine-to-Machine) Authentication (Default)** – When no authorizer is specified, the construct automatically creates a Cognito User Pool configured for OAuth 2.0 client credentials flow. This enables machine-to-machine authentication suitable for AI agents and service-to-service communication.
|
|
1269
1338
|
|
|
1270
1339
|
For more information, see [Setting up Amazon Cognito for Gateway inbound authorization](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/identity-idp-cognito.html).
|
|
@@ -2520,3 +2589,339 @@ const memory = new agentcore.Memory(this, "test-memory", {
|
|
|
2520
2589
|
memory.addMemoryStrategy(agentcore.MemoryStrategy.usingBuiltInSummarization());
|
|
2521
2590
|
memory.addMemoryStrategy(agentcore.MemoryStrategy.usingBuiltInSemantic());
|
|
2522
2591
|
```
|
|
2592
|
+
|
|
2593
|
+
## Policy Engine
|
|
2594
|
+
|
|
2595
|
+
A policy engine is a collection of policies that evaluates and authorizes agent tool calls. When associated with a gateway, the policy engine intercepts all agent requests and determines whether to allow or deny each action based on the defined policies.
|
|
2596
|
+
|
|
2597
|
+
### PolicyEngine Properties
|
|
2598
|
+
|
|
2599
|
+
| Name | Type | Required | Description |
|
|
2600
|
+
|------|------|----------|-------------|
|
|
2601
|
+
| `policyEngineName` | `string` | No | The name of the policy engine. Valid characters: a-z, A-Z, 0-9, _ (underscore). Must start with a letter, 1-48 characters. If not provided, a unique name will be auto-generated |
|
|
2602
|
+
| `description` | `string` | No | Optional description for the policy engine (max 4,096 characters). Default: no description |
|
|
2603
|
+
| `kmsKey` | `IKey` | No | Custom KMS key for encryption. **IMPORTANT**: Once set, cannot be changed (requires replacement). Must be symmetric ENCRYPT_DECRYPT key. If key becomes inaccessible, all authorization decisions will be DENIED. Default: AWS owned key |
|
|
2604
|
+
| `tags` | `{ [key: string]: string }` | No | Tags for the policy engine (max 50 tags). Default: no tags |
|
|
2605
|
+
|
|
2606
|
+
### Understanding Cedar Policies in AgentCore
|
|
2607
|
+
|
|
2608
|
+
Policies are constructed using [Cedar language](https://www.cedarpolicy.com/en/tutorial), an open source language for writing and enforcing authorization policies.
|
|
2609
|
+
Cedar policies in AgentCore follow a specific structure with three main components: **Principal**, **Action**, and **Resource**. Understanding how these components work together is critical for writing effective policies.
|
|
2610
|
+
|
|
2611
|
+
#### Policy Structure
|
|
2612
|
+
|
|
2613
|
+
Every Cedar policy has this basic structure:
|
|
2614
|
+
|
|
2615
|
+
```cedar
|
|
2616
|
+
permit( // or forbid
|
|
2617
|
+
principal, // Who is making the request
|
|
2618
|
+
action, // What operation they want to perform
|
|
2619
|
+
resource // What Gateway/tool they want to access
|
|
2620
|
+
)
|
|
2621
|
+
when { // Optional conditions
|
|
2622
|
+
// Additional constraints
|
|
2623
|
+
};
|
|
2624
|
+
```
|
|
2625
|
+
|
|
2626
|
+
Example Policy
|
|
2627
|
+
|
|
2628
|
+
```cedar
|
|
2629
|
+
permit(
|
|
2630
|
+
principal,
|
|
2631
|
+
action == AgentCore::Action::"ApplicationToolTarget___create_application",
|
|
2632
|
+
resource == AgentCore::Gateway::"<gateway-arn>"
|
|
2633
|
+
) when {
|
|
2634
|
+
context.input.coverage_amount <= 1000000
|
|
2635
|
+
};
|
|
2636
|
+
```
|
|
2637
|
+
|
|
2638
|
+
### Basic PolicyEngine and Policy Creation
|
|
2639
|
+
|
|
2640
|
+
Create a policy engine and add policies to it.
|
|
2641
|
+
|
|
2642
|
+
```typescript fixture=default
|
|
2643
|
+
|
|
2644
|
+
// Create a Policy engine
|
|
2645
|
+
const policyEngine = new agentcore.PolicyEngine(this, "MyPolicyEngine", {
|
|
2646
|
+
policyEngineName: "my_policy_engine",
|
|
2647
|
+
description: "Policy engine for access control",
|
|
2648
|
+
});
|
|
2649
|
+
|
|
2650
|
+
const gateway = new agentcore.Gateway(this, "MyGateway", {
|
|
2651
|
+
gatewayName: "my-gateway",
|
|
2652
|
+
policyEngineConfiguration: {
|
|
2653
|
+
policyEngine: policyEngine,
|
|
2654
|
+
},
|
|
2655
|
+
});
|
|
2656
|
+
|
|
2657
|
+
// Add policy to policy engine
|
|
2658
|
+
policyEngine.addPolicy("AllowAllActions", {
|
|
2659
|
+
definition: `
|
|
2660
|
+
permit(
|
|
2661
|
+
principal,
|
|
2662
|
+
action,
|
|
2663
|
+
resource == AgentCore::Gateway::"${gateway.gatewayArn}"
|
|
2664
|
+
);
|
|
2665
|
+
`,
|
|
2666
|
+
description: "Allow all actions on specific gateway (development)",
|
|
2667
|
+
validationMode: agentcore.PolicyValidationMode.IGNORE_ALL_FINDINGS, // This will ignore all cedar warnings
|
|
2668
|
+
});
|
|
2669
|
+
|
|
2670
|
+
// you can add multiple policies to the policy engine
|
|
2671
|
+
policyEngine.addPolicy("SpecificToolPolicy", {
|
|
2672
|
+
definition: `
|
|
2673
|
+
permit(
|
|
2674
|
+
principal is AgentCore::OAuthUser,
|
|
2675
|
+
action == AgentCore::Action::"WeatherTool__get_forecast",
|
|
2676
|
+
resource == AgentCore::Gateway::"${gateway.gatewayArn}"
|
|
2677
|
+
);
|
|
2678
|
+
`,
|
|
2679
|
+
description: "Allow specific weather tool access",
|
|
2680
|
+
validationMode: agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS, // This will fail policy creation for any cedar warning
|
|
2681
|
+
});
|
|
2682
|
+
```
|
|
2683
|
+
|
|
2684
|
+
### Type-Safe Policy Builder
|
|
2685
|
+
|
|
2686
|
+
For a more type-safe approach, use the `PolicyStatement` builder instead of writing raw Cedar syntax.
|
|
2687
|
+
|
|
2688
|
+
```typescript fixture=default
|
|
2689
|
+
const gateway = new agentcore.Gateway(this, "MyGateway", {
|
|
2690
|
+
gatewayName: "my-gateway",
|
|
2691
|
+
});
|
|
2692
|
+
|
|
2693
|
+
const policyEngine = new agentcore.PolicyEngine(this, "MyPolicyEngine", {
|
|
2694
|
+
policyEngineName: "my_policy_engine",
|
|
2695
|
+
});
|
|
2696
|
+
|
|
2697
|
+
const allowAllPolicy = new agentcore.Policy(this, "AllowAllPolicy", {
|
|
2698
|
+
policyEngine: policyEngine,
|
|
2699
|
+
policyName: "allow_all",
|
|
2700
|
+
statement: agentcore.PolicyStatement.permit()
|
|
2701
|
+
.forAllPrincipals() // ** This will give overly permission to all principals
|
|
2702
|
+
.onAllActions()
|
|
2703
|
+
.onResource('AgentCore::Gateway', gateway.gatewayArn),
|
|
2704
|
+
description: "Allow all actions on specific gateway (development only)",
|
|
2705
|
+
validationMode: agentcore.PolicyValidationMode.IGNORE_ALL_FINDINGS,
|
|
2706
|
+
});
|
|
2707
|
+
|
|
2708
|
+
// Generated Cedar:
|
|
2709
|
+
// permit(
|
|
2710
|
+
// principal,
|
|
2711
|
+
// action,
|
|
2712
|
+
// resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:region:account:gateway/gateway-id"
|
|
2713
|
+
// );
|
|
2714
|
+
```
|
|
2715
|
+
|
|
2716
|
+
#### Policy with Specific Actions
|
|
2717
|
+
|
|
2718
|
+
```typescript fixture=default
|
|
2719
|
+
declare const policyEngine: agentcore.PolicyEngine;
|
|
2720
|
+
declare const gateway: agentcore.Gateway;
|
|
2721
|
+
|
|
2722
|
+
// Allow specific tool actions on specific gateway
|
|
2723
|
+
// Action names follow pattern: "ToolName__operation"
|
|
2724
|
+
policyEngine.addPolicy("SpecificToolPolicy", {
|
|
2725
|
+
statement: agentcore.PolicyStatement.permit()
|
|
2726
|
+
.forPrincipal('AgentCore::OAuthUser::your-client-id')
|
|
2727
|
+
.onActions([
|
|
2728
|
+
'AgentCore::Action::WeatherTool__get_forecast',
|
|
2729
|
+
'AgentCore::Action::WeatherTool__get_current',
|
|
2730
|
+
])
|
|
2731
|
+
.onResource('AgentCore::Gateway', gateway.gatewayArn),
|
|
2732
|
+
description: "Allow specific weather tool operations",
|
|
2733
|
+
validationMode: agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS,
|
|
2734
|
+
});
|
|
2735
|
+
|
|
2736
|
+
// Generated Cedar:
|
|
2737
|
+
// permit(
|
|
2738
|
+
// principal is AgentCore::OAuthUser,
|
|
2739
|
+
// action in [
|
|
2740
|
+
// AgentCore::Action::"WeatherTool__get_forecast",
|
|
2741
|
+
// AgentCore::Action::"WeatherTool__get_current"
|
|
2742
|
+
// ],
|
|
2743
|
+
// resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-east-1:123:gateway/gw-123"
|
|
2744
|
+
// );
|
|
2745
|
+
```
|
|
2746
|
+
|
|
2747
|
+
#### Policy with Conditions
|
|
2748
|
+
|
|
2749
|
+
Use `when` clauses to add advanced conditions based on principal tags (from OAuth token) or context:
|
|
2750
|
+
|
|
2751
|
+
```typescript fixture=default
|
|
2752
|
+
declare const policyEngine: agentcore.PolicyEngine;
|
|
2753
|
+
declare const gateway: agentcore.Gateway;
|
|
2754
|
+
|
|
2755
|
+
// Policy with when conditions using principal tags
|
|
2756
|
+
const conditionalPolicy = new agentcore.Policy(this, "ConditionalPolicy", {
|
|
2757
|
+
policyEngine: policyEngine,
|
|
2758
|
+
policyName: "conditional_access",
|
|
2759
|
+
statement: agentcore.PolicyStatement.permit()
|
|
2760
|
+
.forPrincipal('AgentCore::OAuthUser') // Type constraint
|
|
2761
|
+
.onAllActions()
|
|
2762
|
+
.onResource('AgentCore::Gateway', gateway.gatewayArn) // Specific ARN
|
|
2763
|
+
.when()
|
|
2764
|
+
.principalAttribute('department').equalTo('Engineering')
|
|
2765
|
+
.and()
|
|
2766
|
+
.contextAttribute('input.priority').equalTo('high')
|
|
2767
|
+
.done(),
|
|
2768
|
+
description: "Allow engineers for high-priority requests",
|
|
2769
|
+
validationMode: agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS,
|
|
2770
|
+
});
|
|
2771
|
+
|
|
2772
|
+
// Generated Cedar:
|
|
2773
|
+
// permit(
|
|
2774
|
+
// principal is AgentCore::OAuthUser,
|
|
2775
|
+
// action,
|
|
2776
|
+
// resource == AgentCore::Gateway::"arn:..."
|
|
2777
|
+
// )
|
|
2778
|
+
// when {
|
|
2779
|
+
// principal.department == "Engineering" && context.input.priority == "high"
|
|
2780
|
+
// };
|
|
2781
|
+
```
|
|
2782
|
+
|
|
2783
|
+
#### Forbid (Deny) Policy
|
|
2784
|
+
|
|
2785
|
+
Use `forbid` to explicitly deny access. Forbid policies override permit policies.
|
|
2786
|
+
|
|
2787
|
+
```typescript fixture=default
|
|
2788
|
+
declare const policyEngine: agentcore.PolicyEngine;
|
|
2789
|
+
declare const gateway: agentcore.Gateway;
|
|
2790
|
+
|
|
2791
|
+
// Explicitly deny dangerous tool operations
|
|
2792
|
+
policyEngine.addPolicy("DenyDangerous", {
|
|
2793
|
+
statement: agentcore.PolicyStatement.forbid()
|
|
2794
|
+
.forAllPrincipals()
|
|
2795
|
+
.onAction('AgentCore::Action::DeleteTool__delete_all')
|
|
2796
|
+
.onResource('AgentCore::Gateway', gateway.gatewayArn),
|
|
2797
|
+
description: "Forbid delete_all operation for all users",
|
|
2798
|
+
validationMode: agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS,
|
|
2799
|
+
});
|
|
2800
|
+
|
|
2801
|
+
// Generated Cedar:
|
|
2802
|
+
// forbid(
|
|
2803
|
+
// principal,
|
|
2804
|
+
// action == AgentCore::Action::"DeleteTool__delete_all",
|
|
2805
|
+
// resource == AgentCore::Gateway::"arn:..."
|
|
2806
|
+
// );
|
|
2807
|
+
```
|
|
2808
|
+
|
|
2809
|
+
#### Raw Cedar for Advanced Cases
|
|
2810
|
+
|
|
2811
|
+
For advanced Cedar features not supported by the builder, use raw Cedar strings:
|
|
2812
|
+
|
|
2813
|
+
```typescript fixture=default
|
|
2814
|
+
declare const policyEngine: agentcore.PolicyEngine;
|
|
2815
|
+
|
|
2816
|
+
// Option 1: Using definition property
|
|
2817
|
+
const advancedPolicy = new agentcore.Policy(this, "AdvancedPolicy", {
|
|
2818
|
+
policyEngine: policyEngine,
|
|
2819
|
+
definition: 'permit(principal, action, resource) when { context.custom > 10 };',
|
|
2820
|
+
description: "Advanced policy with custom Cedar logic",
|
|
2821
|
+
});
|
|
2822
|
+
|
|
2823
|
+
// Option 2: Using fromCedar() with statement property
|
|
2824
|
+
policyEngine.addPolicy("CustomPolicy", {
|
|
2825
|
+
statement: agentcore.PolicyStatement.fromCedar(
|
|
2826
|
+
'forbid(principal, action, resource) when { resource.confidential == true };'
|
|
2827
|
+
),
|
|
2828
|
+
description: "Custom policy from Cedar string",
|
|
2829
|
+
});
|
|
2830
|
+
```
|
|
2831
|
+
|
|
2832
|
+
**Note**: You must specify **either** `definition` (raw Cedar string) **or** `statement` (PolicyStatement builder), but not both.
|
|
2833
|
+
|
|
2834
|
+
#### Accessing Policies on PolicyEngine
|
|
2835
|
+
|
|
2836
|
+
You can access the list of policies added to a PolicyEngine using policyEngine.policies.
|
|
2837
|
+
|
|
2838
|
+
### PolicyEngine with KMS Encryption
|
|
2839
|
+
|
|
2840
|
+
Encrypt policy data with a custom KMS key.
|
|
2841
|
+
|
|
2842
|
+
```typescript fixture=default
|
|
2843
|
+
// Create a custom KMS key
|
|
2844
|
+
const policyKey = new kms.Key(this, "PolicyEngineKey", {
|
|
2845
|
+
enableKeyRotation: true,
|
|
2846
|
+
description: "KMS key for policy engine encryption",
|
|
2847
|
+
});
|
|
2848
|
+
|
|
2849
|
+
// Create policy engine with encryption
|
|
2850
|
+
const policyEngine = new agentcore.PolicyEngine(this, "EncryptedEngine", {
|
|
2851
|
+
policyEngineName: "encrypted_engine",
|
|
2852
|
+
description: "Policy engine with KMS encryption",
|
|
2853
|
+
kmsKey: policyKey,
|
|
2854
|
+
});
|
|
2855
|
+
```
|
|
2856
|
+
|
|
2857
|
+
### Importing Existing PolicyEngine
|
|
2858
|
+
|
|
2859
|
+
Import an existing policy engine from its ARN:
|
|
2860
|
+
|
|
2861
|
+
```typescript fixture=default
|
|
2862
|
+
const importedEngine = agentcore.PolicyEngine.fromPolicyEngineAttributes(
|
|
2863
|
+
this,
|
|
2864
|
+
"ImportedEngine",
|
|
2865
|
+
{
|
|
2866
|
+
policyEngineArn: "policy-engine-arn",
|
|
2867
|
+
kmsKeyArn: "kms-arn",
|
|
2868
|
+
}
|
|
2869
|
+
);
|
|
2870
|
+
|
|
2871
|
+
// Use the imported engine
|
|
2872
|
+
const policy = new agentcore.Policy(this, "PolicyForImportedEngine", {
|
|
2873
|
+
policyEngine: importedEngine,
|
|
2874
|
+
definition: "permit(principal, action, resource);",
|
|
2875
|
+
});
|
|
2876
|
+
```
|
|
2877
|
+
|
|
2878
|
+
### Importing Existing Policy
|
|
2879
|
+
|
|
2880
|
+
Import an existing policy from its ARN:
|
|
2881
|
+
|
|
2882
|
+
```typescript fixture=default
|
|
2883
|
+
const importedEngine = agentcore.PolicyEngine.fromPolicyEngineAttributes(
|
|
2884
|
+
this,
|
|
2885
|
+
"ImportedEngine",
|
|
2886
|
+
{
|
|
2887
|
+
policyEngineArn: "policy-engine/my-engine-id",
|
|
2888
|
+
}
|
|
2889
|
+
);
|
|
2890
|
+
|
|
2891
|
+
const importedPolicy = agentcore.Policy.fromPolicyAttributes(
|
|
2892
|
+
this,
|
|
2893
|
+
"ImportedPolicy",
|
|
2894
|
+
{
|
|
2895
|
+
policyArn: "my-policy-arn",
|
|
2896
|
+
policyEngine: importedEngine,
|
|
2897
|
+
}
|
|
2898
|
+
);
|
|
2899
|
+
|
|
2900
|
+
// Grant permissions to the imported policy
|
|
2901
|
+
const role = new iam.Role(this, "PolicyRole", {
|
|
2902
|
+
assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
|
|
2903
|
+
});
|
|
2904
|
+
|
|
2905
|
+
importedPolicy.grantRead(role);
|
|
2906
|
+
```
|
|
2907
|
+
|
|
2908
|
+
### PolicyEngine IAM Permissions
|
|
2909
|
+
|
|
2910
|
+
Grant various levels of access to policy engines:
|
|
2911
|
+
|
|
2912
|
+
```typescript fixture=default
|
|
2913
|
+
const policyEngine = new agentcore.PolicyEngine(this, "MyEngine", {
|
|
2914
|
+
policyEngineName: "my_engine",
|
|
2915
|
+
});
|
|
2916
|
+
|
|
2917
|
+
const lambdaRole = new iam.Role(this, "LambdaRole", {
|
|
2918
|
+
assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
|
|
2919
|
+
});
|
|
2920
|
+
|
|
2921
|
+
// Grant read permissions
|
|
2922
|
+
policyEngine.grantRead(lambdaRole);
|
|
2923
|
+
|
|
2924
|
+
// Grant evaluation permissions
|
|
2925
|
+
policyEngine.grantEvaluate(lambdaRole);
|
|
2926
|
+
|
|
2927
|
+
```
|
|
@@ -25,7 +25,7 @@ var GatewayExceptionLevel;
|
|
|
25
25
|
* Base Class
|
|
26
26
|
*****************************************************************************/
|
|
27
27
|
class GatewayBase extends aws_cdk_lib_1.Resource {
|
|
28
|
-
static [JSII_RTTI_SYMBOL_1] = { fqn: "@aws-cdk/aws-bedrock-agentcore-alpha.GatewayBase", version: "2.
|
|
28
|
+
static [JSII_RTTI_SYMBOL_1] = { fqn: "@aws-cdk/aws-bedrock-agentcore-alpha.GatewayBase", version: "2.252.0-alpha.0" };
|
|
29
29
|
/**
|
|
30
30
|
* A reference to a Gateway resource.
|
|
31
31
|
*/
|
package/lib/gateway/gateway.d.ts
CHANGED
|
@@ -10,10 +10,54 @@ import type { IGatewayAuthorizerConfig } from './inbound-auth/authorizer';
|
|
|
10
10
|
import type { IInterceptor } from './interceptor';
|
|
11
11
|
import type { ICredentialProviderConfig } from './outbound-auth/credential-provider';
|
|
12
12
|
import type { IGatewayProtocolConfig } from './protocol';
|
|
13
|
+
import type { IPolicyEngine } from '../policy/policy-engine-base';
|
|
13
14
|
import type { ApiSchema } from './targets/schema/api-schema';
|
|
14
15
|
import type { ToolSchema } from './targets/schema/tool-schema';
|
|
15
16
|
import { GatewayTarget } from './targets/target';
|
|
16
17
|
import type { ApiGatewayToolConfiguration, MetadataConfiguration } from './targets/target-configuration';
|
|
18
|
+
/**
|
|
19
|
+
* The enforcement mode for a policy engine associated with a gateway.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare class PolicyEngineMode {
|
|
23
|
+
/**
|
|
24
|
+
* Evaluates actions and adds traces but does not enforce decisions.
|
|
25
|
+
* Use this mode for testing and validation before enabling enforcement.
|
|
26
|
+
*/
|
|
27
|
+
static readonly LOG_ONLY: PolicyEngineMode;
|
|
28
|
+
/**
|
|
29
|
+
* Enforces decisions by allowing or denying agent operations based on Cedar policies.
|
|
30
|
+
*/
|
|
31
|
+
static readonly ENFORCE: PolicyEngineMode;
|
|
32
|
+
/**
|
|
33
|
+
* The string value of the policy engine mode.
|
|
34
|
+
*/
|
|
35
|
+
readonly value: string;
|
|
36
|
+
constructor(value: string);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for associating a policy engine with a gateway.
|
|
40
|
+
*
|
|
41
|
+
* When configured, the policy engine intercepts all agent requests through this
|
|
42
|
+
* gateway and evaluates them against the defined Cedar policies.
|
|
43
|
+
* [disable-awslint:prefer-ref-interface]
|
|
44
|
+
*/
|
|
45
|
+
export interface GatewayPolicyEngineConfig {
|
|
46
|
+
/**
|
|
47
|
+
* The policy engine to associate with this gateway.
|
|
48
|
+
* [disable-awslint:prefer-ref-interface]
|
|
49
|
+
*/
|
|
50
|
+
readonly policyEngine: IPolicyEngine;
|
|
51
|
+
/**
|
|
52
|
+
* The enforcement mode for the policy engine.
|
|
53
|
+
*
|
|
54
|
+
* - `LOG_ONLY`: Evaluates and logs decisions without enforcing them. Use for testing.
|
|
55
|
+
* - `ENFORCE`: Actively allows or denies requests based on Cedar policy evaluation.
|
|
56
|
+
*
|
|
57
|
+
* @default PolicyEngineMode.LOG_ONLY
|
|
58
|
+
*/
|
|
59
|
+
readonly mode?: PolicyEngineMode;
|
|
60
|
+
}
|
|
17
61
|
/******************************************************************************
|
|
18
62
|
* Props
|
|
19
63
|
*****************************************************************************/
|
|
@@ -246,6 +290,16 @@ export interface GatewayProps {
|
|
|
246
290
|
* @see https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-interceptors.html
|
|
247
291
|
*/
|
|
248
292
|
readonly interceptorConfigurations?: IInterceptor[];
|
|
293
|
+
/**
|
|
294
|
+
* The policy engine configuration for this gateway.
|
|
295
|
+
*
|
|
296
|
+
* When provided, the specified policy engine will be associated with this gateway.
|
|
297
|
+
* All agent requests through this gateway will be evaluated against the Cedar policies
|
|
298
|
+
* defined in the policy engine.
|
|
299
|
+
*
|
|
300
|
+
* @default - No policy engine (requests are not subject to Cedar policy authorization)
|
|
301
|
+
*/
|
|
302
|
+
readonly policyEngineConfiguration?: GatewayPolicyEngineConfig;
|
|
249
303
|
}
|
|
250
304
|
/**
|
|
251
305
|
* Attributes for importing an existing Gateway
|
|
@@ -377,6 +431,10 @@ export declare class Gateway extends GatewayBase {
|
|
|
377
431
|
* @internal
|
|
378
432
|
*/
|
|
379
433
|
private responseInterceptorConfig?;
|
|
434
|
+
/**
|
|
435
|
+
* The policy engine configuration associated with this gateway.
|
|
436
|
+
*/
|
|
437
|
+
readonly policyEngineConfiguration?: GatewayPolicyEngineConfig;
|
|
380
438
|
/**
|
|
381
439
|
* The Cognito User Pool Domain created for the gateway (if using default Cognito authorizer)
|
|
382
440
|
*/
|