Skip to content

Commit 9b20b3e

Browse files
authored
Merge pull request #237 from NetApp/update_ingest_nas
Changed the way it obtains credentials for the FSxN file systems. Instead of one secret with all the credentials, it will assume one secret per file system. This required also having a way to pass an unknown number of credentials.
2 parents 4d74885 + 7eca55d commit 9b20b3e

File tree

4 files changed

+577
-151
lines changed

4 files changed

+577
-151
lines changed

Monitoring/ingest_nas_audit_logs_into_cloudwatch/README-MANUAL.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ or by following the manual instructions found in the this file.
1414

1515
## Prerequisites
1616
- An FSx for Data ONTAP file system.
17-
- An S3 bucket to store the "stats" file and a Lambda layer zip file.
18-
- You will need to download the [Lambda layer zip file](https://raw.githubusercontent.com/NetApp/FSx-ONTAP-samples-scripts/main/Monitoring/ingest_nas_audit_logs_into_cloudwatch/lambda_layer.zip) from this repo and upload it to the S3 bucket. Be sure to perserve the name `lambda_layer.zip`.
19-
- The "stats" file is maintained by the program. It is used to keep track of the last time the Lambda function successfully ingested audit logs from each SVM. Its size will be small (i.e. less than a few megabytes).
17+
- An S3 bucket to store the "stats" file and optionally a copy of all the raw NAS audit log files. It will also
18+
hold a Lambda layer file needed to be able to an add Lambda Layer from a CloudFormation script.
19+
- You will need to download the [Lambda layer zip file](https://raw.githubusercontent.com/NetApp/FSx-ONTAP-samples-scripts/main/Monitoring/ingest_nas_audit_logs_into_cloudwatch/lambda_layer.zip)
20+
from this repo and upload it to the S3 bucket. Be sure to preserve the name `lambda_layer.zip`.
21+
- The "stats" file is maintained by the program. It is used to keep track of the last time the Lambda function
22+
successfully ingested audit logs from each SVM. Its size will be small (i.e. less than a few megabytes).
2023
- A CloudWatch log group to ingest the audit logs into. Each audit log file with get its own log stream within the log group.
2124
- Have NAS auditing configured and enabled on the SVM within a FSx for Data ONTAP file system. **Ensure you have selected the XML format for the audit logs.** Also,
2225
ensure you have set up a rotation schedule. The program will only act on audit log files that have been finalized, and not the "active" one. You can read this
@@ -79,7 +82,7 @@ and `DeleteNetworkInterface` actions. The correct resource line is `arn:aws:ec2:
7982
`zip -r ingest_nas_audit_logs.zip .`<br>
8083

8184
2. Within the AWS console, or using the AWS API, create a Lambda function with:
82-
1. Python 3.10, or higher, as the runtime.
85+
1. Python 3.11, or higher, as the runtime.
8386
1. Set the permissions to the role created above.
8487
1. Under `Additional Configurations` select `Enable VPC` and select a VPC and Subnet that will have access to all the FSx for ONTAP
8588
file system management endpoints that you want to gather audit logs from. Also, select a Security Group that allows TCP port 443 outbound.
@@ -90,15 +93,29 @@ process a lot of audit entries and/or process a lot of SVMs.
9093

9194
3. Configure the Lambda function by setting the following environment variables. For a Lambda function you do this by clicking on the `Configuration` tab and then the `Environment variables` sub tab.
9295

93-
| Variable | Description |
94-
| --- | --- |
95-
| fsxRegion | The region where the FSx for ONTAP file systems are located. |
96-
| secretArn | The ARN of the secret that contains the credentials for all the FSx for ONTAP file systems you want to gather audit logs from. |
97-
| s3BucketRegion | The region of the S3 bucket where the stats file is stored. |
98-
| s3BucketName | The name of the S3 bucket where the stats file is stored. |
99-
| statsName | The name you want to use as the stats file. |
100-
| logGroupName | The name of the CloudWatch log group to ingest the audit logs into. |
101-
| volumeName | The name of the volume, on all the FSx for ONTAP file systems, where the audit logs are stored. |
96+
| Variable | Required| Description |
97+
| --- | --- | --- |
98+
| fsxRegion | Yes |The region where the FSx for ONTAP file systems are located. |
99+
| s3BucketRegion |Yes | The region of the S3 bucket where the stats file is stored. |
100+
| s3BucketName | Yes |The name of the S3 bucket where the stats file is stored. |
101+
| copyToS3 | No| Set to `true` if you want to copy the raw audit log files to the S3 bucket.|
102+
|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`|
103+
|fileSystem1ID|No|The ID of the first FSxN file system to ingest the audit logs from.|
104+
|fileSystem1SecretARN|No|The ARN of the secret that contains the credentials for the first FSx for Data ONTAP file system.|
105+
|fileSystem2ID|No|The ID of the second FSx for Data ONTAP file system to ingest the audit logs from.|
106+
|fileSystem2SecretARN|No|The ARN of the secret that contains the credentials for the second FSx for Data ONTAP file system.|
107+
|fileSystem3ID|No|The ID of the third FSx for Data ONTAP file system to ingest the audit logs from.|
108+
|fileSystem3SecretARN|No|The ARN of the secret that contains the credentials for the third FSx for Data ONTAP file system.|
109+
|fileSystem4ID|No|The ID of the forth FSx for Data ONTAP file system to ingest the audit logs from.|
110+
|fileSystem4SecretARN|No|The ARN of the secret that contains the credentials for the forth FSx for Data ONTAP file system.|
111+
|fileSystem5ID|No|The ID of the fifth FSx for Data ONTAP file system to ingest the audit logs from.|
112+
|fileSystem5SecretARN|No|The ARN of the secret that contains the credentials for the fifth FSx for Data ONTAP file system.|
113+
| statsName | Yes| The name you want to use as the stats file. |
114+
| logGroupName | Yes| The name of the CloudWatch log group to ingest the audit logs into. |
115+
| volumeName | Yes| The name of the volume, on all the FSx for ONTAP file systems, where the audit logs are stored. |
116+
117+
**NOTE:** You only need to set the `fsxnSecretARNsFile` or the `fileSystemXID` and `fileSystemXSecretARN` variables.
118+
If both are provide, then the `fsxnSecretARNsFile` will be used and the `fileSystemXID` and `fileSystemXSecretARN` variables will be ignored.
102119

103120
4. Test the Lambda function by clicking on the `Test` tab and then clicking on the `Test` button. You should see "Executing function: succeeded".
104121
If not, click on the "Details" button to see what errors there are.
@@ -122,4 +139,4 @@ Unless required by applicable law or agreed to in writing, software distributed
122139

123140
See the License for the specific language governing permissions and limitations under the License.
124141

125-
© 2024 NetApp, Inc. All Rights Reserved.
142+
© 2025 NetApp, Inc. All Rights Reserved.

Monitoring/ingest_nas_audit_logs_into_cloudwatch/README.md

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,47 @@ It will maintain a "stats" file in an S3 bucket that will keep track of the last
1010
SVM to try to ensure it doesn't process an audit file more than once.
1111
You can run this script as a standalone program or as a Lambda function. These directions assume you are going to run it as a Lambda function.
1212

13-
**NOTE**: There are two ways to install this program. Either with the [CloudFormaiton script](cloudformation-template.yaml) found this this repo,
13+
**NOTE**: There are two ways to install this program. Either with the [CloudFormation script](cloudformation-template.yaml) found this this repo,
1414
or by following the manual instructions found in the [README-MANUEL.md](README-MANUAL.md) file.
1515

1616
## Prerequisites
1717
- An FSx for Data ONTAP file system.
18-
- An S3 bucket to store the "stats" file and a Lambda layer zip file.
19-
- You will need to download the [Lambda layer zip file](https://raw.githubusercontent.com/NetApp/FSx-ONTAP-samples-scripts/main/Monitoring/ingest_nas_audit_logs_into_cloudwatch/lambda_layer.zip) from this repo and upload it to the S3 bucket. Be sure to preserve the name `lambda_layer.zip`.
20-
- The "stats" file is maintained by the program. It is used to keep track of the last time the Lambda function successfully ingested audit logs from each SVM. Its size will be small (i.e. less than a few megabytes).
18+
- An S3 bucket to store the "stats" file and optionally a copy of all the raw NAS audit log files. It will also
19+
hold a Lambda layer file needed to be able to an add Lambda Layer from a CloudFormation script.
20+
- You will need to download the [Lambda layer zip file](https://raw.githubusercontent.com/NetApp/FSx-ONTAP-samples-scripts/main/Monitoring/ingest_nas_audit_logs_into_cloudwatch/lambda_layer.zip)
21+
from this repo and upload it to the S3 bucket. Be sure to preserve the name `lambda_layer.zip`.
22+
- The "stats" file is maintained by the program. It is used to keep track of the last time the Lambda function successfully
23+
ingested audit logs from each SVM. Its size will be small (i.e. less than a few megabytes).
2124
- A CloudWatch log group to ingest the audit logs into. Each audit log file will get its own log stream within the log group.
2225
- Have NAS auditing configured and enabled on the SVM within a FSx for Data ONTAP file system. **Ensure you have selected the XML format for the audit logs.** Also,
2326
ensure you have set up a rotation schedule. The program will only act on audit log files that have been finalized, and not the "active" one. You can read this
2427
[knowledge based article](https://kb.netapp.com/on-prem/ontap/da/NAS/NAS-KBs/How_to_set_up_NAS_auditing_in_ONTAP_9) for instructions on how to setup NAS auditing.
2528
- Have the NAS auditing configured to store the audit logs in a volume with the same name in all SVMs on all the FSx for Data ONTAP file
2629
systems that you want to ingest the audit logs from.
27-
- An AWS Secrets Manager secret that contains the credentials for all the FSxNs you want to use to obtain the NAS Audit logs from.
28-
- The secret should be in the form of key/value pairs where the key is the file system ID and value is a dictionary with the keys `username` and `password`. For example:
29-
```json
30+
- An AWS Secrets Manager secret for each of the FSxN file systems you wish to ingest the audit logs from. The secret should have two keys `username` and `password`. For example:
31+
```json
3032
{
31-
"fs-0e8d9172fa5411111": {"username": "fsxadmin", "password": "superSecretPassword"},
32-
"fs-0e8d9172fa5422222": {"username": "service_account", "password": "superSecretPassword"}
33+
"username": "fsxadmin",
34+
"password": "superSecretPassword"
3335
}
34-
```
36+
```
37+
You can use the same secret for multiple file systems if the credentials are the same.
3538
- You have applied the necessary SACLs to the files you want to audit. The knowledge base article linked above provides guidance on how to do this.
3639

37-
**You can either create the following items before running the CloudFormaiton script, or allow it to create the items for you.**
40+
**You can either create the following items before running the CloudFormation script, or allow it to create the items for you.**
3841

39-
- 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
40-
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.
41-
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.
4246
Specifically, the Lambda function needs to be able to access the following AWS services:
4347
- FSx.
4448
- Secrets Manager.
4549
- CloudWatch Logs.
4650
- 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.
4751

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+
4854
- Role for the Lambda function. Create a role with the necessary permissions to allow the Lambda function to do the following:
4955

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

6773
- &lt;accountID&gt; - is your AWS account ID.
6874
- &lt;region&gt; - is the region where the FSx for ONTAP file systems are located.
69-
- &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 the use of wild card characters, must include all the secrets that the Lambda function will access.
77+
Or you must list each secret ARN individually.
7078

7179
Notes:
7280
- Since the Lambda function runs within your VPC it needs to be able to create and delete network interfaces.
@@ -92,11 +100,22 @@ and `DeleteNetworkInterface` actions. The correct resource line is `arn:aws:ec2:
92100
|lambdaSecruityGroupsIds|Yes|Select the security groups that you want the Lambda function associated with. The security group must allow outbound traffic on TCP port 443. Inbound rules don't matter since the Lambda function is not accessible from a network.|
93101
|s3BucketName|Yes|The name of the S3 bucket where the stats file is stored. This bucket must already exist.|
94102
|s3BucketRegion|Yes|The region of the S3 bucket resides.|
95-
|secretArn|Yes|The ARN to the secret that contains the credentials for the FSxN file systems that you want to ingest audit logs from.|
103+
|copyToS3|No|If set to `true` it will copy the audit logs to the S3 bucket specified in `s3BucketName`.|
96104
|createWatchdogAlarm|No|If set to `true` it will create a CloudWatch alarm that will alert you if the Lambda function throws in error.|
97105
|snsTopicArn|No|The ARN of the SNS topic to send the alarm to. This is required if `createWatchdogAlarm` is set to `true`.|
106+
|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 have one line for each file system where it specifies the file system id, an equal sign, and then the Secret ARN to use. For example: `fs-0e8d9172fa5411111=arn:aws:secretsmanager:us-east-1:123456789012:secret:fsxadmin-abc123`|
107+
|fileSystem1ID|No|The ID of the first FSxN file system to ingest the audit logs from.|
108+
|fileSystem1SecretARN|No|The ARN of the secret that contains the credentials for the first FSx for Data ONTAP file system.|
109+
|fileSystem2ID|No|The ID of the second FSx for Data ONTAP file system to ingest the audit logs from.|
110+
|fileSystem2SecretARN|No|The ARN of the secret that contains the credentials for the second FSx for Data ONTAP file system.|
111+
|fileSystem3ID|No|The ID of the third FSx for Data ONTAP file system to ingest the audit logs from.|
112+
|fileSystem3SecretARN|No|The ARN of the secret that contains the credentials for the third FSx for Data ONTAP file system.|
113+
|fileSystem4ID|No|The ID of the forth FSx for Data ONTAP file system to ingest the audit logs from.|
114+
|fileSystem4SecretARN|No|The ARN of the secret that contains the credentials for the forth FSx for Data ONTAP file system.|
115+
|fileSystem5ID|No|The ID of the fifth FSx for Data ONTAP file system to ingest the audit logs from.|
116+
|fileSystem5SecretARN|No|The ARN of the secret that contains the credentials for the fifth FSx for Data ONTAP file system.|
98117
|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.|
99-
|schedulreRoleArn|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.|
118+
|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.|
100119
|createFsxEndpoint|No|If set to `true` it will create the VPC endpoints for the FSx service|
101120
|createCloudWatchLogsEndpoint|No|If set to `true` it will create the VPC endpoints for the CloudWatch Logs service|
102121
|createSecretsManagerEndpoint|No|If set to `true` it will create the VPC endpoints for the Secrets Manager service|
@@ -105,6 +124,8 @@ and `DeleteNetworkInterface` actions. The correct resource line is `arn:aws:ec2:
105124
|vpcId|No|This is the VPC that the endpoint(s) will be created in. Only needed if you are creating an endpoint.|
106125
|endpointSecurityGroupIds|No|The security group that the endpoint(s) will be associated with. Must allow incoming TCP traffic over port 443. Only needed if you are creating an endpoint.|
107126

127+
**Note**: You must either provide the fsxnSecretARNsFile or the fileSystem1ID, fileSystem1SecretARN, fileSystem2ID, fileSystem2SecretARN, etc. parameters.
128+
108129
6. Click on the `Next` button.
109130
7. The next page will provide for some additional configuration options. You can leave these as the default values.
110131
At the bottom of the page, there is a checkbox that you must check to allow the CloudFormation script to create the
@@ -124,6 +145,26 @@ see a log stream, check the Lambda function's configuration to ensure it is corr
124145
output from the Lambda function. You should see log messages indicating that it is ingesting audit logs. If you see any "Errors" then you will
125146
need to investigate and correct the issue. If you can't figure it out, please open an [issue](https://github.com/NetApp/FSx-ONTAP-samples-scripts/issues) in this repository.
126147

148+
### Add more FSx for ONTAP file systems.
149+
The way the program is written, it will automatically discover all FSxN file systems within a region,
150+
and then all the vservers under that FSxN. So, if you add another FSxN it will automatically attempt
151+
to ingest the audit files from all the vservers under it. Unfortunately, it won't be able to, until
152+
you provide a Secret ARN for that file system.
153+
154+
The best way to add a secret ARN, is to either update the secretARNs file you
155+
initially passed to the CloudFormation script, that should be in the S3 bucket you specified in
156+
the `s3BucketName` parameter, or create that file with the information for all the FSxN file systems
157+
you want to ingest the audit logs from and then store it in the S3 bucket. See the description
158+
of the `fsxnSecretARNsFile` parameter above for the format of the file.
159+
160+
If you are creating the file for the first time, you'll also need to set the `fsxSecretARNsFile` environment variable
161+
to point to the file. You can leave all the other parameters as they are, including the `fileSystem1ID`, `fileSystem1SecretARN`, etc. ones.
162+
The program will ignore those parameters if the `fsxnSecretARNsFile` environment variable is set. To set
163+
the environment variable, go to the Lambda function's configuration page and click on the "Configuration" tab. Then
164+
click on the "Environment variables" sub tab. Click on the "Edit" button. The `fsxnSecretARNsFile`
165+
environment variable should already be there, but the value should be blank. If the variable isn't there click on the
166+
'add' button and add it. Once the line is there with the `fsxnSecretARNsFile` variable, set the value
167+
to the name of the file you created.
127168

128169
## Author Information
129170

0 commit comments

Comments
 (0)