Skip to content

Commit 1b023a8

Browse files
committed
Changed the way secrets are retrieved
1 parent bbbd905 commit 1b023a8

File tree

2 files changed

+84
-26
lines changed

2 files changed

+84
-26
lines changed

Monitoring/ingest_nas_audit_logs_into_cloudwatch/README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ systems that you want to ingest the audit logs from.
3939

4040
**You can either create the following items before running the CloudFormation script, or allow it to create the items for you.**
4141

42-
- AWS Endpoints. Since the Lambda function runs within your VPC it will not have access to the Internet, even if you can access the Internet
43-
from the Subnet it runs from. Although, if you are using an AWS Transit Gateway, you can configure it to allow the Lambda function to access the Internet.
44-
If you don't have a Transit Gateway then there needs to be an VPC endpoint for all the AWS services that the Lambda function uses.
42+
- AWS Endpoints. Since the Lambda function runs within your VPC it will have restrictions as to how it can access the Internet.
43+
It will not be able to access the Internet from a "Public" subnet (i.e. one that has a Internet gateway attached it it.) It will, however,
44+
be able to access the Internet through a Transit or a NAT gateway. So, if the subnets you plan to run this Lambda function from
45+
don't have a Transit or NAT gateway then there needs to be an VPC AWS service endpoint for all the AWS services that this Lambda function uses.
4546
Specifically, the Lambda function needs to be able to access the following AWS services:
4647
- FSx.
4748
- Secrets Manager.
4849
- CloudWatch Logs.
4950
- S3 - Note that typically there is a Gateway type VPC endpoint for S3, therefore you typically you don't need to create a VPC endpoint for S3.
5051

52+
**NOTE**: That if you specify to have the CloudFormation template create an endpoint and one already exist, it will cause the CloudFormation script to fail.
53+
5154
- Role for the Lambda function. Create a role with the necessary permissions to allow the Lambda function to do the following:
5255

5356
<!--- Using HTML to create a table that has rowspan attributes since the markdown table syntax does not support that. --->
@@ -69,7 +72,9 @@ Where:
6972

7073
- &lt;accountID&gt; - is your AWS account ID.
7174
- &lt;region&gt; - is the region where the FSx for ONTAP file systems are located.
72-
- &lt;secretName&gt; - is the name of the secret that contains the credentials for the fsxadmin accounts.
75+
- &lt;secretName&gt; - is the name of the secret that contains the credentials for the fsxadmin accounts. Note that this
76+
resource string, through wild card characters, must include all the secrets that the Lambda function will access. Or
77+
must list each secret ARN individually.
7378

7479
Notes:
7580
- Since the Lambda function runs within your VPC it needs to be able to create and delete network interfaces.
@@ -96,6 +101,8 @@ and `DeleteNetworkInterface` actions. The correct resource line is `arn:aws:ec2:
96101
|s3BucketName|Yes|The name of the S3 bucket where the stats file is stored. This bucket must already exist.|
97102
|s3BucketRegion|Yes|The region of the S3 bucket resides.|
98103
|copyToS3|No|If set to `true` it will copy the audit logs to the S3 bucket specified in `s3BucketName`.|
104+
|createWatchdogAlarm|No|If set to `true` it will create a CloudWatch alarm that will alert you if the Lambda function throws in error.|
105+
|snsTopicArn|No|The ARN of the SNS topic to send the alarm to. This is required if `createWatchdogAlarm` is set to `true`.|
99106
|fsxnSecretARNsFile|No|The name of a file within the S3 bucket that contains the Secret ARNs for each for the FSxN file systems. The format of the file should be just `<fsID>=<secretARN>`. For example: `fs-0e8d9172fa5411111=arn:aws:secretsmanager:us-east-1:123456789012:secret:fsxadmin-abc123`|
100107
|fileSystem1ID|No|The ID of the first FSxN file system to ingest the audit logs from.|
101108
|fileSystem1SecretARN|No|The ARN of the secret that contains the credentials for the first FSx for Data ONTAP file system.|
@@ -107,8 +114,6 @@ and `DeleteNetworkInterface` actions. The correct resource line is `arn:aws:ec2:
107114
|fileSystem4SecretARN|No|The ARN of the secret that contains the credentials for the forth FSx for Data ONTAP file system.|
108115
|fileSystem5ID|No|The ID of the fifth FSx for Data ONTAP file system to ingest the audit logs from.|
109116
|fileSystem5SecretARN|No|The ARN of the secret that contains the credentials for the fifth FSx for Data ONTAP file system.|
110-
|createWatchdogAlarm|No|If set to `true` it will create a CloudWatch alarm that will alert you if the Lambda function throws in error.|
111-
|snsTopicArn|No|The ARN of the SNS topic to send the alarm to. This is required if `createWatchdogAlarm` is set to `true`.|
112117
|lambdaRoleArn|No|The ARN of the role that the Lambda function will use. If not provided, the CloudFormation script will create a role for you.|
113118
|schedulerRoleArn|No|The ARN of the role that the EventBridge scheduler will run as. If not provided, the CloudFormation script will create a role for you.|
114119
|createFsxEndpoint|No|If set to `true` it will create the VPC endpoints for the FSx service|

Monitoring/ingest_nas_audit_logs_into_cloudwatch/cloudformation-template.yaml

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Metadata:
1616
- s3BucketRegion
1717
- copyToS3
1818
- createWatchdogAlarm
19+
- snsTopicArn
1920

2021
- Label:
2122
default: "Secrets Manager specifications"
@@ -33,10 +34,14 @@ Metadata:
3334
- fileSystem5SecretARN
3435

3536
- Label:
36-
default: "Network Configuration"
37-
- snsTopicArn
37+
default: "Security Configuration"
38+
Parameters:
3839
- lambdaRoleArn
3940
- schedulerRoleArn
41+
42+
- Label:
43+
default: "VPC Endpoint Configuration"
44+
Parameters:
4045
- createFSxEndpoint
4146
- createCloudWatchEndpoint
4247
- createSecretManagerEndpoint
@@ -45,9 +50,29 @@ Metadata:
4550
- vpcId
4651
- endpointSecurityGroupIds
4752

48-
ParameterLabels
49-
ParamterFileWithListOfFileSystemIDsWithSecretARNs:
50-
default: "File with list of FSxN file systems and their secret ARNs"
53+
ParameterLabels:
54+
volumeName:
55+
default: "Volume Name"
56+
checkInterval:
57+
default: "Check Interval (minutes)"
58+
logGroupName:
59+
default: "CloudWatch Log Group Name"
60+
subNetIds:
61+
default: "Subnets for Lambda Function"
62+
lambdaSecurityGroupIds:
63+
default: "Security Groups for Lambda Function"
64+
s3BucketName:
65+
default: "S3 Bucket Name"
66+
s3BucketRegion:
67+
default: "S3 Bucket Region"
68+
copyToS3:
69+
default: "Copy to S3"
70+
createWatchdogAlarm:
71+
default: "Create Watchdog Alarm"
72+
snsTopicArn:
73+
default: "SNS Topic ARN"
74+
fsxnSecretARNsFile:
75+
default: "File with the list of FSxN file systems and their secret ARNs"
5176
fileSystem1ID:
5277
default: "File System 1 ID"
5378
fileSystem1SecretARN:
@@ -68,6 +93,24 @@ Metadata:
6893
default: "File System 5 ID"
6994
fileSystem5SecretARN:
7095
default: "File System 5 Secret ARN"
96+
lambdaRoleArn:
97+
default: "Lambda Role ARN"
98+
schedulerRoleArn:
99+
default: "Scheduler Role ARN"
100+
createFSxEndpoint:
101+
default: "Create FSx Endpoint"
102+
createCloudWatchEndpoint:
103+
default: "Create CloudWatch Endpoint"
104+
createSecretManagerEndpoint:
105+
default: "Create Secrets Manager Endpoint"
106+
createS3Endpoint:
107+
default: "Create S3 Endpoint"
108+
routeTableIds:
109+
default: "Route Table IDs"
110+
vpcId:
111+
default: "VPC ID"
112+
endpointSecurityGroupIds:
113+
default: "Security Groups for VPC Endpoints"
71114

72115
Parameters:
73116
volumeName:
@@ -78,35 +121,36 @@ Parameters:
78121
Description: "The interval, in minutes, to check for new audit logs to process."
79122
Type: Number
80123
Default: 5
124+
MinValue: 1
81125

82126
logGroupName:
83-
Description: "The name of the CloudWatch log group to use to store the audit logs. This Log Group must already exist."
127+
Description: "The name of the CloudWatch log group to store the audit logs to. This Log Group must already exist. It must be in the same region as this CloudFormation stack."
84128
Type: String
85129

86130
subNetIds:
87-
Description: "The subnet IDs where you want the Lambda function to run. There must be connectivity to all the FSxN management endpoints from these subnets. If creating VPC endpoints, the endpionts will be created in these subnets."
131+
Description: "The subnet IDs where you want the Lambda function to run. There must be connectivity to all the FSxN management endpoints from these subnets. If creating VPC endpoints, the endpoints will be created in these subnets."
88132
Type: List<AWS::EC2::Subnet::Id>
89133

90134
lambdaSecurityGroupIds:
91135
Description: "The security group IDs, comma separated list, to associate with the Lambda function. Must allow traffic outbound from the Lambda function over TCP port 443.to the FSxN management endpoints and AWS endpoints."
92136
Type: List<AWS::EC2::SecurityGroup::Id>
93137

94138
s3BucketName:
95-
Description: "The name of the s3 bucket to use to store the last message processed stats file."
139+
Description: "The name of the S3 bucket where the last audit file processed stats file will be stored. Also, where the Lambda layer file should already be stored."
96140
Type: String
97141

98142
s3BucketRegion:
99-
Description: "The AWS region where the s3 bucket resides."
143+
Description: "The AWS region where the S3 bucket resides."
100144
Type: String
101145

102146
copyToS3:
103-
Description: "Set to 'true' if you to copy the audit log files to the S3 bucket as well as sending the individual events to the CloudWatch log stream."
147+
Description: "Set to 'true' if you want to copy the audit log files to the S3 bucket as well as sending the individual events to the CloudWatch log stream."
104148
Type: String
105149
Default: "false"
106150
AllowedValues: ["true", "false"]
107151

108152
fsxnSecretARNsFile:
109-
Description: "The name of the file that contains the list of FSxN file systems and their secret ARNs. Either provide this file or the individual file system IDs and secret ARNs below."
153+
Description: "The name of the file that contains the list of FSxN file systems and their secret ARNs. It should already be stored in the S3 bucket. Either provide this file or the individual file system IDs and secret ARNs below."
110154
Type: String
111155
Default: ""
112156

@@ -116,7 +160,7 @@ Parameters:
116160
Default: ""
117161

118162
fileSystem1SecretARN:
119-
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system."
163+
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system specified above."
120164
Type: String
121165
Default: ""
122166

@@ -126,7 +170,7 @@ Parameters:
126170
Default: ""
127171

128172
fileSystem2SecretARN:
129-
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system."
173+
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system specified above."
130174
Type: String
131175
Default: ""
132176

@@ -136,7 +180,7 @@ Parameters:
136180
Default: ""
137181

138182
fileSystem3SecretARN:
139-
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system."
183+
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system specified above."
140184
Type: String
141185
Default: ""
142186

@@ -146,7 +190,7 @@ Parameters:
146190
Default: ""
147191

148192
fileSystem4SecretARN:
149-
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system."
193+
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system specified above."
150194
Type: String
151195
Default: ""
152196

@@ -155,14 +199,19 @@ Parameters:
155199
Type: String
156200
Default: ""
157201

202+
fileSystem5SecretARN:
203+
Description: "The ARN of the secret in Secrets Manager that holds the credentials for the FSxN file system specified above."
204+
Type: String
205+
Default: ""
206+
158207
createWatchdogAlarm:
159-
Description: "Create a CloudWatch alarm to monitor the Lambda function. It will send an alert to the SNS topic set below if the function throws an error."
208+
Description: "Create a CloudWatch alarm to monitor the Lambda function. It will send an alert to the SNS topic set below if the Lambda function throws an error."
160209
Type: String
161-
Default: "false"
210+
Default: "true"
162211
AllowedValues: ["true", "false"]
163212

164213
snsTopicArn:
165-
Description: "The ARN of the SNS topic to use to send Watchdog alerts to. Only needed if you are creating a Watchdog alarm."
214+
Description: "The ARN of the SNS topic where the Watchdog should send alerts to. Only needed if you are creating a Watchdog alarm. The topic must be in the same region as this CloudFormation stack."
166215
Type: String
167216
Default: ""
168217

@@ -311,11 +360,15 @@ Resources:
311360
- Effect: "Allow"
312361
Action:
313362
- "secretsManager:GetSecretValue"
363+
Resource:
364+
- !Sub "arn:aws:secretsmanager:*:${AWS::AccountId}:secret:*"
365+
366+
- Effect: "Allow"
367+
Action:
314368
- "s3:GetObject"
315369
- "s3:PutObject"
316370
- "s3:ListBucket"
317-
Resource:
318-
- !Ref secretArn
371+
Resource:
319372
- !Sub "arn:aws:s3:::${s3BucketName}"
320373
- !Sub "arn:aws:s3:::${s3BucketName}/*"
321374

0 commit comments

Comments
 (0)