-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudformation-template.yaml
More file actions
265 lines (239 loc) · 7.93 KB
/
cloudformation-template.yaml
File metadata and controls
265 lines (239 loc) · 7.93 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Enhanced Security Hub to Excel Pipeline - AI-Powered Analysis & Workflow Automation'
Parameters:
S3BucketName:
Type: String
Description: S3 bucket name for storing Excel reports
Default: security-hub-reports-enhanced
MinLength: 3
MaxLength: 63
AllowedPattern: '^[a-z0-9][a-z0-9-]*[a-z0-9-]*[a-z0-9-]*$'
SourceS3Key:
Type: String
Description: S3 key for Lambda source code
Default: source/lambda-enhanced.zip
FunctionName:
Type: String
Description: Lambda function name
Default: security-hub-excel-generator-enhanced
MinLength: 1
MaxLength: 64
AllowedPattern: '^[a-zA-Z][a-zA-Z0-9-]*[a-zA-Z0-9-]*$'
MemorySize:
Type: Number
Description: Lambda function memory size in MB
Default: 512
MinValue: 128
MaxValue: 3008
Timeout:
Type: Number
Description: Lambda function timeout in seconds
Default: 300
MinValue: 1
MaxValue: 900
EnableAIAnalysis:
Type: String
Description: Enable AWS Bedrock AI analysis
Default: 'true'
AllowedValues: ['true', 'false']
EnableSlack:
Type: String
Description: Enable Slack notifications
Default: 'false'
AllowedValues: ['true', 'false']
EnableServiceNow:
Type: String
Description: Enable ServiceNow integration
Default: 'false'
AllowedValues: ['true', 'false']
EnableJira:
Type: String
Description: Enable Jira integration
Default: 'false'
AllowedValues: ['true', 'false']
Resources:
# Enhanced IAM Role for Lambda Function
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub '${FunctionName}-execution-role'
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: SecurityHubExcelEnhancedPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
# Security Hub Access
- Effect: Allow
Action:
- securityhub:GetFindings
- securityhub:GetEnabledStandards
- securityhub:DescribeHub
Resource: '*'
# AWS Bedrock Access
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: '*'
# S3 Access
- Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
- s3:GetObject
- s3:ListBucket
Resource:
- !Sub 'arn:aws:s3:::${S3BucketName}/*'
- !Sub 'arn:aws:s3:::${S3BucketName}'
# Secrets Manager Access
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource: '*'
# CloudWatch Logs Access
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:*'
# Enhanced Lambda Function
SecurityHubExcelFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Ref FunctionName
Runtime: python3.9
Handler: lambda_function.lambda_handler
Role: !GetAtt LambdaExecutionRole.Arn
Code:
S3Bucket: !Ref S3BucketName
S3Key: !Ref SourceS3Key
MemorySize: !Ref MemorySize
Timeout: !Ref Timeout
Environment:
Variables:
S3_BUCKET_NAME: !Ref S3BucketName
BEDROCK_MODEL_ID: anthropic.claude-3-haiku-20240307-v1:0
ENABLE_AI_ANALYSIS: !Ref EnableAIAnalysis
ENABLE_SLACK: !Ref EnableSlack
ENABLE_SERVICENOW: !Ref EnableServiceNow
ENABLE_JIRA: !Ref EnableJira
SLACK_WEBHOOK_URL: ''
SERVICENOW_SECRET_NAME: ''
JIRA_SECRET_NAME: ''
Description: 'Enhanced Security Hub to Excel report generator with AI analysis and workflow automation'
Tags:
- Key: Project
Value: SecurityHubExcelEnhanced
- Key: Environment
Value: Production
- Key: DeploymentMethod
Value: CloudFormation
- Key: Features
Value: AI-Powered,Multi-Framework,Workflow-Integration
# S3 Bucket for Reports
ReportsBucket:
Type: AWS::S3::Bucket
Condition: CreateBucket
Properties:
BucketName: !Ref S3BucketName
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
ServerSideEncryptionConfiguration:
ServerSideEncryptionRule:
ApplyServerSideEncryptionByDefault: true
SSEAlgorithm: AES256
LifecycleConfiguration:
Rules:
- Id: DeleteOldReports
Status: Enabled
ExpirationInDays: 90
Filter:
Prefix: reports/
NotificationConfiguration:
LambdaConfigurations:
- Event: s3:ObjectCreated:*
Function: !GetAtt SecurityHubExcelFunction.Arn
Filter:
S3Key:
Rules:
- Name: prefix
Value: reports/
Tags:
- Key: Project
Value: SecurityHubExcelEnhanced
- Key: Environment
Value: Production
- Key: Purpose
Value: Compliance-Reports
# CloudWatch Log Group
FunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub '/aws/lambda/${FunctionName}'
RetentionInDays: 30
# EventBridge Rule for Scheduled Execution (Optional - disabled by default)
ScheduledExecutionRule:
Type: AWS::Events::Rule
Properties:
Name: !Sub '${FunctionName}-weekly-schedule'
Description: 'Weekly execution of Enhanced Security Hub Excel generator'
ScheduleExpression: 'rate(7 days)'
State: DISABLED
Targets:
- Arn: !GetAtt SecurityHubExcelFunction.Arn
Id: SecurityHubExcelTarget
# Permission for EventBridge to invoke Lambda
LambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref FunctionName
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt ScheduledExecutionRule.Arn
Conditions:
CreateBucket: !Equals [!Ref S3BucketName, 'security-hub-reports-enhanced']
Outputs:
FunctionName:
Description: 'Enhanced Lambda function name'
Value: !Ref SecurityHubExcelFunction
Export:
Name: !Sub '${AWS::StackName}-FunctionName'
FunctionArn:
Description: 'Enhanced Lambda function ARN'
Value: !GetAtt SecurityHubExcelFunction.Arn
Export:
Name: !Sub '${AWS::StackName}-FunctionArn'
S3BucketName:
Description: 'S3 bucket for enhanced reports'
Value: !Ref S3BucketName
Export:
Name: !Sub '${AWS::StackName}-S3Bucket'
ScheduleRuleArn:
Description: 'EventBridge rule ARN for scheduling'
Value: !GetAtt ScheduledExecutionRule.Arn
Export:
Name: !Sub '${AWS::StackName}-ScheduleRule'
LogGroupName:
Description: 'CloudWatch log group name'
Value: !Ref FunctionLogGroup
Export:
Name: !Sub '${AWS::StackName}-LogGroup'
StackStatus:
Description: 'Deployment status and features enabled'
Value: !Sub 'Enhanced Security Hub Excel Pipeline deployed with AI Analysis: ${EnableAIAnalysis}, Slack: ${EnableSlack}, ServiceNow: ${EnableServiceNow}, Jira: ${EnableJira}'