@prism-d1/cli 1.0.26 → 1.0.28
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/dist/assets/eval-harness/README.md +114 -0
- package/dist/assets/eval-harness/eval-config.json +10 -0
- package/dist/assets/eval-harness/rubrics/agent-quality.json +79 -0
- package/dist/assets/eval-harness/rubrics/api-response-quality.json +45 -0
- package/dist/assets/eval-harness/rubrics/code-quality.json +98 -0
- package/dist/assets/eval-harness/rubrics/security-compliance.json +145 -0
- package/dist/assets/eval-harness/rubrics/spec-compliance.json +67 -0
- package/dist/assets/eval-harness/run-eval.sh +122 -0
- package/dist/assets/github-workflows/README.md +110 -0
- package/dist/assets/github-workflows/prism-agent-eval.yml +313 -0
- package/dist/assets/github-workflows/prism-ai-metrics.yml +261 -0
- package/dist/assets/github-workflows/prism-dora-weekly.yml +334 -0
- package/dist/assets/github-workflows/prism-eval-gate.yml +310 -0
- package/dist/assets/infra/bin/app.ts +56 -0
- package/dist/assets/infra/cdk.json +12 -0
- package/dist/assets/infra/lib/api-stack.ts +347 -0
- package/dist/assets/infra/lib/constructs/bedrock-guardrail-construct.ts +201 -0
- package/dist/assets/infra/lib/constructs/guardrail-enforcer-construct.ts +59 -0
- package/dist/assets/infra/lib/constructs/prism-vpc-construct.ts +75 -0
- package/dist/assets/infra/lib/constructs/security-agent-construct.ts +266 -0
- package/dist/assets/infra/lib/dashboard-stack.ts +1392 -0
- package/dist/assets/infra/lib/lambda/api-handler.ts +477 -0
- package/dist/assets/infra/lib/lambda/defect-correlator.ts +142 -0
- package/dist/assets/infra/lib/lambda/exfiltration-detector.ts +100 -0
- package/dist/assets/infra/lib/lambda/layers/guardrail-enforcer/nodejs/guardrail-enforcer.js +53 -0
- package/dist/assets/infra/lib/lambda/metrics-processor.ts +748 -0
- package/dist/assets/infra/lib/lambda/security-agent-processor.ts +231 -0
- package/dist/assets/infra/lib/lambda/security-remediation-tracker.ts +120 -0
- package/dist/assets/infra/lib/lambda/security-response-automator.ts +130 -0
- package/dist/assets/infra/lib/lambda/spec-to-code-calculator.ts +123 -0
- package/dist/assets/infra/lib/metrics-pipeline-stack.ts +701 -0
- package/dist/assets/infra/package.json +23 -0
- package/dist/assets/infra/tsconfig.json +24 -0
- package/dist/src/commands/bootstrapper/install-eval-harness.d.ts.map +1 -1
- package/dist/src/commands/bootstrapper/install-eval-harness.js +3 -4
- package/dist/src/commands/bootstrapper/install-eval-harness.js.map +1 -1
- package/dist/src/commands/bootstrapper/install-git-hooks.d.ts.map +1 -1
- package/dist/src/commands/bootstrapper/install-git-hooks.js +2 -5
- package/dist/src/commands/bootstrapper/install-git-hooks.js.map +1 -1
- package/dist/src/commands/securityagent/setup.d.ts.map +1 -1
- package/dist/src/commands/securityagent/setup.js +2 -3
- package/dist/src/commands/securityagent/setup.js.map +1 -1
- package/dist/src/commands/workshop/deploy-infra.d.ts.map +1 -1
- package/dist/src/commands/workshop/deploy-infra.js +2 -3
- package/dist/src/commands/workshop/deploy-infra.js.map +1 -1
- package/dist/src/commands/workshop/generate-demo-data.d.ts.map +1 -1
- package/dist/src/commands/workshop/generate-demo-data.js +3 -8
- package/dist/src/commands/workshop/generate-demo-data.js.map +1 -1
- package/dist/src/commands/workshop/perform-pen-test.d.ts.map +1 -1
- package/dist/src/commands/workshop/perform-pen-test.js +5 -14
- package/dist/src/commands/workshop/perform-pen-test.js.map +1 -1
- package/dist/src/utils/root.d.ts +6 -0
- package/dist/src/utils/root.d.ts.map +1 -1
- package/dist/src/utils/root.js +29 -0
- package/dist/src/utils/root.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import * as cdk from 'aws-cdk-lib';
|
|
2
|
+
import * as securityagent from 'aws-cdk-lib/aws-securityagent';
|
|
3
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
4
|
+
import * as kms from 'aws-cdk-lib/aws-kms';
|
|
5
|
+
import * as logs from 'aws-cdk-lib/aws-logs';
|
|
6
|
+
import { Construct } from 'constructs';
|
|
7
|
+
import { NagSuppressions } from 'cdk-nag';
|
|
8
|
+
|
|
9
|
+
export interface SecurityAgentProps {
|
|
10
|
+
/**
|
|
11
|
+
* Name for the agent space.
|
|
12
|
+
*/
|
|
13
|
+
agentSpaceName: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Description of the agent space.
|
|
17
|
+
*/
|
|
18
|
+
description?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* KMS key for encrypting Security Agent data.
|
|
22
|
+
* If not provided, the PRISM KMS key should be passed in.
|
|
23
|
+
*/
|
|
24
|
+
kmsKey?: kms.IKey;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Target domains to register for pen testing.
|
|
28
|
+
* Each domain requires ownership verification.
|
|
29
|
+
*/
|
|
30
|
+
targetDomains?: Array<{
|
|
31
|
+
domainName: string;
|
|
32
|
+
verificationMethod: 'DNS_TXT' | 'HTTP_ROUTE';
|
|
33
|
+
}>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* VPC configuration for pen tests that need network access.
|
|
37
|
+
*/
|
|
38
|
+
vpcConfig?: {
|
|
39
|
+
securityGroupIds: string[];
|
|
40
|
+
subnetIds: string[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Risk types to exclude from pen testing.
|
|
45
|
+
* Example: ['DENIAL_OF_SERVICE']
|
|
46
|
+
*/
|
|
47
|
+
excludeRiskTypes?: string[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether to enable automatic code remediation.
|
|
51
|
+
* @default 'DISABLED'
|
|
52
|
+
*/
|
|
53
|
+
codeRemediationStrategy?: 'AUTOMATIC' | 'DISABLED';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Tags applied to all Security Agent resources.
|
|
57
|
+
*/
|
|
58
|
+
tags?: Record<string, string>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* CDK construct that provisions AWS Security Agent resources:
|
|
63
|
+
* - AgentSpace: defines scope, integrations, and settings
|
|
64
|
+
* - TargetDomains: registers domains for pen testing
|
|
65
|
+
* - Service role with least-privilege permissions
|
|
66
|
+
*
|
|
67
|
+
* Pentests are triggered on-demand via API or the GitHub Actions workflow,
|
|
68
|
+
* not provisioned statically via CloudFormation.
|
|
69
|
+
*/
|
|
70
|
+
export class SecurityAgentConstruct extends Construct {
|
|
71
|
+
public readonly agentSpaceId: string;
|
|
72
|
+
public readonly serviceRole: iam.Role;
|
|
73
|
+
public readonly targetDomainIds: string[];
|
|
74
|
+
|
|
75
|
+
constructor(scope: Construct, id: string, props: SecurityAgentProps) {
|
|
76
|
+
super(scope, id);
|
|
77
|
+
|
|
78
|
+
// Service role for Security Agent pen tests
|
|
79
|
+
this.serviceRole = new iam.Role(this, 'SecurityAgentRole', {
|
|
80
|
+
roleName: `prism-d1-security-agent-${props.agentSpaceName}`,
|
|
81
|
+
assumedBy: new iam.ServicePrincipal('securityagent.amazonaws.com'),
|
|
82
|
+
description: 'Service role for AWS Security Agent pen tests in PRISM D1',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Grant Security Agent permissions scoped to this agent space
|
|
86
|
+
this.serviceRole.addToPolicy(
|
|
87
|
+
new iam.PolicyStatement({
|
|
88
|
+
effect: iam.Effect.ALLOW,
|
|
89
|
+
actions: ['securityagent:*'],
|
|
90
|
+
resources: [
|
|
91
|
+
`arn:aws:securityagent:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:agent-space/*`,
|
|
92
|
+
],
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Grant KMS permissions for encrypted agent spaces
|
|
97
|
+
if (props.kmsKey) {
|
|
98
|
+
props.kmsKey.grantEncryptDecrypt(this.serviceRole);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Grant CloudWatch Logs access for pen test logging
|
|
102
|
+
this.serviceRole.addToPolicy(
|
|
103
|
+
new iam.PolicyStatement({
|
|
104
|
+
effect: iam.Effect.ALLOW,
|
|
105
|
+
actions: [
|
|
106
|
+
'logs:CreateLogGroup',
|
|
107
|
+
'logs:CreateLogStream',
|
|
108
|
+
'logs:PutLogEvents',
|
|
109
|
+
],
|
|
110
|
+
resources: ['arn:aws:logs:*:*:log-group:/aws/securityagent/*'],
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// cdk-nag suppressions for Security Agent role
|
|
115
|
+
NagSuppressions.addResourceSuppressions(
|
|
116
|
+
this.serviceRole,
|
|
117
|
+
[
|
|
118
|
+
{
|
|
119
|
+
id: 'AwsSolutions-IAM5',
|
|
120
|
+
reason: 'Security Agent service requires securityagent:* as individual actions are not yet documented in IAM service authorization reference',
|
|
121
|
+
appliesTo: ['Action::securityagent:*'],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'AwsSolutions-IAM5',
|
|
125
|
+
reason: 'Agent space ID is generated at deploy time; wildcard required for the service role to operate on its own space',
|
|
126
|
+
appliesTo: [`Resource::arn:aws:securityagent:<AWS::Region>:<AWS::AccountId>:agent-space/*`],
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: 'AwsSolutions-IAM5',
|
|
130
|
+
reason: 'Security Agent creates log groups dynamically at /aws/securityagent/<space>/pt-<id>; wildcard required',
|
|
131
|
+
appliesTo: ['Resource::arn:aws:logs:*:*:log-group:/aws/securityagent/*'],
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
true,
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// If VPC config provided, grant network interface permissions
|
|
138
|
+
if (props.vpcConfig) {
|
|
139
|
+
this.serviceRole.addToPolicy(
|
|
140
|
+
new iam.PolicyStatement({
|
|
141
|
+
effect: iam.Effect.ALLOW,
|
|
142
|
+
actions: ['ec2:DescribeNetworkInterfaces'],
|
|
143
|
+
resources: ['*'],
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
this.serviceRole.addToPolicy(
|
|
147
|
+
new iam.PolicyStatement({
|
|
148
|
+
effect: iam.Effect.ALLOW,
|
|
149
|
+
actions: ['ec2:CreateNetworkInterface', 'ec2:DeleteNetworkInterface'],
|
|
150
|
+
resources: [
|
|
151
|
+
`arn:aws:ec2:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:network-interface/*`,
|
|
152
|
+
...props.vpcConfig.subnetIds.map(s => `arn:aws:ec2:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:subnet/${s}`),
|
|
153
|
+
...props.vpcConfig.securityGroupIds.map(sg => `arn:aws:ec2:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:security-group/${sg}`),
|
|
154
|
+
],
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Agent Space
|
|
160
|
+
const agentSpace = new securityagent.CfnAgentSpace(this, 'AgentSpace', {
|
|
161
|
+
name: props.agentSpaceName,
|
|
162
|
+
description: props.description ?? `PRISM D1 Security Agent space: ${props.agentSpaceName}`,
|
|
163
|
+
...(props.kmsKey && {
|
|
164
|
+
kmsKeyId: props.kmsKey.keyArn,
|
|
165
|
+
}),
|
|
166
|
+
awsResources: {
|
|
167
|
+
iamRoles: [this.serviceRole.roleArn],
|
|
168
|
+
},
|
|
169
|
+
tags: [
|
|
170
|
+
{ key: 'prism:component', value: 'security-agent' },
|
|
171
|
+
{ key: 'prism:agent-space', value: props.agentSpaceName },
|
|
172
|
+
...Object.entries(props.tags ?? {}).map(([key, value]) => ({ key, value })),
|
|
173
|
+
],
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
this.agentSpaceId = agentSpace.attrAgentSpaceId;
|
|
177
|
+
|
|
178
|
+
// Target Domains
|
|
179
|
+
this.targetDomainIds = [];
|
|
180
|
+
for (const domain of props.targetDomains ?? []) {
|
|
181
|
+
const targetDomain = new securityagent.CfnTargetDomain(this, `Domain-${domain.domainName.replace(/\./g, '-')}`, {
|
|
182
|
+
targetDomainName: domain.domainName,
|
|
183
|
+
verificationMethod: domain.verificationMethod,
|
|
184
|
+
tags: [
|
|
185
|
+
{ key: 'prism:component', value: 'security-agent' },
|
|
186
|
+
{ key: 'prism:domain', value: domain.domainName },
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
this.targetDomainIds.push(targetDomain.attrTargetDomainId);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Associate target domains with agent space if any were created
|
|
193
|
+
if (this.targetDomainIds.length > 0) {
|
|
194
|
+
// Update the agent space with target domain IDs
|
|
195
|
+
// Note: This requires the domains to be verified first
|
|
196
|
+
(agentSpace as any).targetDomainIds = this.targetDomainIds;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Log group for pen test results (Security Agent writes to /aws/securityagent/<space>/pt-<id>)
|
|
200
|
+
new logs.LogGroup(this, 'PentestLogGroup', {
|
|
201
|
+
logGroupName: `/aws/securityagent/${props.agentSpaceName}`,
|
|
202
|
+
retention: logs.RetentionDays.SIX_MONTHS,
|
|
203
|
+
removalPolicy: cdk.RemovalPolicy.RETAIN,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Outputs
|
|
207
|
+
new cdk.CfnOutput(this, 'AgentSpaceIdOutput', {
|
|
208
|
+
value: this.agentSpaceId,
|
|
209
|
+
description: `Security Agent space ID for ${props.agentSpaceName}`,
|
|
210
|
+
exportName: `PrismD1SecurityAgentSpaceId`,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
new cdk.CfnOutput(this, 'ServiceRoleArnOutput', {
|
|
214
|
+
value: this.serviceRole.roleArn,
|
|
215
|
+
description: 'Security Agent service role ARN',
|
|
216
|
+
exportName: `PrismD1SecurityAgentRoleArn`,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (this.targetDomainIds.length > 0) {
|
|
220
|
+
new cdk.CfnOutput(this, 'TargetDomainIdsOutput', {
|
|
221
|
+
value: this.targetDomainIds.join(','),
|
|
222
|
+
description: 'Registered target domain IDs',
|
|
223
|
+
exportName: `PrismD1SecurityAgentDomainIds`,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Creates a CfnPentest resource for on-demand pen testing.
|
|
230
|
+
* Call this method to define a pen test configuration that can be
|
|
231
|
+
* triggered via the AWS CLI or API.
|
|
232
|
+
*/
|
|
233
|
+
createPentestConfig(
|
|
234
|
+
id: string,
|
|
235
|
+
props: {
|
|
236
|
+
title: string;
|
|
237
|
+
endpoints: Array<{ uri: string }>;
|
|
238
|
+
serviceRole?: iam.IRole;
|
|
239
|
+
vpcConfig?: { securityGroupArns: string[]; subnetArns: string[] };
|
|
240
|
+
excludeRiskTypes?: string[];
|
|
241
|
+
codeRemediationStrategy?: 'AUTOMATIC' | 'DISABLED';
|
|
242
|
+
},
|
|
243
|
+
): securityagent.CfnPentest {
|
|
244
|
+
return new securityagent.CfnPentest(this, id, {
|
|
245
|
+
agentSpaceId: this.agentSpaceId,
|
|
246
|
+
serviceRole: (props.serviceRole ?? this.serviceRole).roleArn,
|
|
247
|
+
title: props.title,
|
|
248
|
+
assets: {
|
|
249
|
+
endpoints: props.endpoints.map((ep) => ({
|
|
250
|
+
uri: ep.uri,
|
|
251
|
+
})),
|
|
252
|
+
},
|
|
253
|
+
...(props.excludeRiskTypes && { excludeRiskTypes: props.excludeRiskTypes }),
|
|
254
|
+
...(props.codeRemediationStrategy && { codeRemediationStrategy: props.codeRemediationStrategy }),
|
|
255
|
+
...(props.vpcConfig && {
|
|
256
|
+
vpcConfig: {
|
|
257
|
+
securityGroupArns: props.vpcConfig.securityGroupArns,
|
|
258
|
+
subnetArns: props.vpcConfig.subnetArns,
|
|
259
|
+
},
|
|
260
|
+
}),
|
|
261
|
+
logConfig: {
|
|
262
|
+
logGroup: `/prism/security-agent/${this.node.id}`,
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|