Skip to content

Commit 2a02aa7

Browse files
authored
Merge pull request #159 from NetApp/add_secret_rotate
Changed the rotate function to set the secret value to a structure.
2 parents 473d430 + fdbd9df commit 2a02aa7

File tree

7 files changed

+98
-40
lines changed

7 files changed

+98
-40
lines changed

EKS/FSxN-as-PVC-for-EKS/README.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Variables that can be changed include:
8383
- aws_region - The AWS region where you want to deploy the resources.
8484
- aws_secrets_region - The region where the fsx password secret will be created.
8585
- fsx_name - The name you want applied to the FSx for NetApp ONTAP File System. Must not already exist.
86-
- fsx_password_secret_name - A base name of the AWS SecretsManager secret that will hold the FSxN password.
86+
- secret_name_prefix - The base name of the AWS SecretsManager secrets that will be created that will hold the FSxN adminstrator, and SVM, passwords.
8787
A random string will be appended to this name to ensure uniqueness.
8888
- fsx_storage_capacity - The storage capacity of the FSx for NetApp ONTAP File System.
8989
Read the "description" of the variable to see the valid range.
@@ -109,32 +109,23 @@ the following is an example of last part of the output of a successful deploymen
109109
```bash
110110
Outputs:
111111

112-
eks-cluster-name = "fsx-eks-DB0H69vL"
113-
eks-jump-server = "Instance ID: i-0e99a61431a39d327, Public IP: 54.244.16.198"
114-
fsx-id = "fs-0887a493cXXXXXXXX"
115-
fsx-management-ip = "198.19.255.174"
116-
fsx-password-secret-arn = "arn:aws:secretsmanager:us-west-2:759995400000:secret:fsx-eks-secret-3b8bde97-Fst5rj"
117-
fsx-password-secret-name = "fsx-eks-secret-3b8bde97"
112+
Outputs:
113+
114+
eks-cluster-name = "eksfs-eks-lutuycvJ"
115+
eks-jump-server = "Instance ID: i-00de97f46e3c9a617, Public IP: 54.213.93.236"
116+
fsx-id = "fs-04f1b48f8da639a7f"
117+
fsx-management-ip = "198.19.255.245"
118+
fsx-password-secret-arn = "arn:aws:secretsmanager:us-west-2:759995470648:secret:keith-eksfs-fsxn-55fd4eb7-4Oy2ab"
119+
fsx-password-secret-name = "eksfs-fsxn-55fd4eb7"
118120
fsx-svm-name = "ekssvm"
119121
region = "us-west-2"
120-
vpc-id = "vpc-03ed6b1867d76e1a9"
122+
svm-password-secret-arn = "arn:aws:secretsmanager:us-west-2:759995470648:secret:keith-eksfs-svm-6ad11609-nApoUp"
123+
svm-password-secret-name = "eksfs-svm-6ad11609"
124+
vpc-id = "vpc-0791cc0566462082b"
121125
```
122126
:bulb: **Tip:** You will use the values in the commands below, so probably a good idea to copy the output somewhere
123127
so you can easily reference it later.
124128

125-
> [!IMPORTANT]
126-
> Note that an FSxN File System was created, with a vserver (a.k.a. SVM). The default username
127-
> for the FSxN File System is 'fsxadmin'. And the default username for the vserver is 'vsadmin'. The
128-
> password for both of these users is the same and is what is stored in the AWS SecretsManager secret
129-
> shown above. Since Terraform was used to create the secret, the password is stored in
130-
> plain text in its "state" database and therefore it is **HIGHLY** recommended that you change
131-
> the password to something else by first changing the passwords via the AWS Management Console and
132-
> then updating the password in the AWS SecretsManager secret. You can update the 'username' key in
133-
> the secret if you want, but it must be a vserver admin user, not a system level user. This secret
134-
> is used by Astra Trident and it will always login via the vserver management LIF and therefore it
135-
> must be a vserver admin user. If you want to create a separate secret for the 'fsxadmin' user,
136-
> feel free to do so.
137-
138129
### SSH to the jump server to complete the setup
139130
Use the following command to 'ssh' to the jump server:
140131
```bash
@@ -164,7 +155,7 @@ Note that if you are using an SSO to authenticate with AWS, then the actual user
164155
you need to add is slightly different than what is output from the above command.
165156
The following command will take the output from the above command and format it correctly:
166157

167-
:warning: **Warning:** Only run this command if you are using an SSO to authenticate with aws.
158+
:warning: **Caution:** Only run this command if you are using an SSO to authenticate with aws.
168159
```bash
169160
user_ARN=$(aws sts get-caller-identity | jq -r '.Arn' | awk -F: '{split($6, parts, "/"); printf "arn:aws:iam::%s:role/aws-reserved/sso.amazonaws.com/%s\n", $5, parts[2]}')
170161
echo $user_ARN
@@ -246,7 +237,7 @@ other files you'll need to complete the setup.
246237
After making the following substitutions in the commands below:
247238
- \<fsx-id> with the FSxN ID.
248239
- \<fsx-svm-name> with the name of the SVM that was created.
249-
- \<secret-arn> with the ARN of the AWS SecretsManager secret that holds the FSxN password.
240+
- \<secret-arn> with the ARN of the AWS SecretsManager secret that holds the SVM password (not the FSxN password).
250241

251242
Run them to configure Trident to use the FSxN file system that was
252243
created earlier using the `terraform --apply` command:
@@ -281,7 +272,7 @@ kubectl get tridentbackendconfig -n trident --output=json | jq '.items[] | .stat
281272
```
282273
Once you have resolved any issues, you can remove the failed backend by running:
283274

284-
:warning: **Warning:** Only run this command if the backend is in a failed state and you are ready to get rid of it.
275+
:warning: **Caution:** Only run this command if the backend is in a failed state and you are ready to get rid of it.
285276
```bash
286277
kubectl delete -n trident -f temp/backend-tbc-ontap-nas.yaml
287278
```

Management-Utilities/fsxn-rotate-secret/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Note that the Lambda function can only manage one password, so either set the va
7171

7272
:warning: **Warning:** If both the `fsx_id` and `svm_id` tags are set, the `svm_id` tag will be used and the fsx_id will be silently ignored.
7373

74+
Also note that the secret value will be a JSON object with the following fields:
75+
- `username` - The username will either be set to 'fsxadmin' or 'vsadmin' depending on whether the `fsx_id` or `svm_id` tag is set.
76+
- `password` - The password associated with the username.
77+
7478
##### Step 3.2 - Enable rotation feature
7579
Click on the Rotation tab and then click on the "Edit rotation" button. That should bring up a
7680
pop-up window. Click on the "Automatic rotation" slider to enable the feature and then configure
@@ -185,6 +189,10 @@ The following are the outputs for the module:
185189
| role_arn | The ARN of the IAM role created. |
186190
| role_name | The name of the IAM role created. |
187191

192+
Note that the secret value will be a JSON object with the following fields:
193+
- `username` - The username will either be set to 'fsxadmin' or 'vsadmin' depending on whether the `fsx_id` or `svm_id` tag is set.
194+
- `password` - The password associated with the username.
195+
188196
## Author Information
189197

190198
This repository is maintained by the contributors listed on [GitHub](https://github.com/NetApp/FSx-ONTAP-samples-scripts/graphs/contributors).

Management-Utilities/fsxn-rotate-secret/fsxn_rotate_secret.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import boto3
1111
import logging
1212
import os
13+
import json
1314

1415
charactersToExcludeInPassword = '/"\'\\'
1516

@@ -46,8 +47,27 @@ def create_secret(secretsClient, arn, token):
4647
# Generate a random password.
4748
passwd = secretsClient.get_random_password(ExcludeCharacters=charactersToExcludeInPassword, PasswordLength=8, IncludeSpace=False)
4849
#
50+
# Get the FSx file system ID, SVM ID and region from the secret's tags so we can figure out if this password
51+
# is for the FSx file system or the SVM.
52+
secretMetadata = secretsClient.describe_secret(SecretId=arn)
53+
tags = secretMetadata['Tags']
54+
fsxId = getTagValue(tags, 'fsx_id')
55+
fsxRegion = getTagValue(tags, 'region')
56+
svmId = getTagValue(tags, 'svm_id')
57+
logging.info(f"fsxId={fsxId}, svmId={svmId}, fsxRegion={fsxRegion}")
58+
59+
if (fsxId is None and svmId is None) or fsxRegion is None:
60+
message=f"Error, tags 'fsxId' or 'svmId' and the 'region' have to be set on the secret's ({arn}) resource."
61+
logger.error(message)
62+
raise Exception(message) # Signal to the Secrets Manager that the rotation failed.
63+
64+
if svmId is None or svmId == "":
65+
username="fsxadmin"
66+
else:
67+
username="vsadmin"
68+
#
4969
# Put the secret.
50-
secretsClient.put_secret_value(SecretId=arn, ClientRequestToken=token, SecretString=passwd['RandomPassword'], VersionStages=['AWSPENDING'])
70+
secretsClient.put_secret_value(SecretId=arn, ClientRequestToken=token, SecretString='{"username": "' + username + '", "password": "' + passwd["RandomPassword"] + '"}', VersionStages=['AWSPENDING'])
5171
logger.info(f"create_secret: Successfully put secret for ARN {arn} with ClientRequestToken {token} and VersionStage = 'AWSPENDING'.")
5272

5373
################################################################################
@@ -66,7 +86,7 @@ def set_secret(secretsClient, arn, token):
6686
# Pass the exception on so the Secret Manager will know that the rotate failed.
6787
raise e
6888

69-
password = secretValueResponse['SecretString']
89+
password = json.loads(secretValueResponse['SecretString'])['password']
7090
#
7191
# Get the FSx file system ID, SVM ID and region from the secret's tags.
7292
secretMetadata = secretsClient.describe_secret(SecretId=arn)

Terraform/deploy-fsx-ontap/module/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ Calling this terraform module will result the following:
3434
- **Ingress** allow ssh port 22
3535
- **Ingress** allow https port 443
3636
- **Egress** allow all traffic
37+
38+
* Two new AWS secrets. One that contains the fsxadmin password and another that contains the SVM admin password.
39+
3740
* Create a new FSx for Netapp ONTAP file-system in your AWS account named "_terraform-fsxn_". The file-system will be created with the following configuration parameters:
3841
* 1024Gb of storage capacity
3942
* Multi AZ deployment type
4043
* 128Mbps of throughput capacity
4144

4245
* Create a Storage Virtual Maching (SVM) in this new file-system named "_first_svm_"
46+
4347
* Create a new FlexVol volume in this SVM named "_vol1_" with the following configuration parameters:
4448
* Size of 1024Mb
4549
* Storage efficiencies mechanism enabled
@@ -283,14 +287,16 @@ terraform apply
283287
284288
| Name | Description |
285289
|------|-------------|
290+
| filesystem_id | The ID of the FSxN Filesystem |
291+
| filesystem_management_ip | The management IP of the FSxN Filesystem. |
286292
| fsxn_secret_arn | The ARN of the secret |
287293
| fsxn_secret_name | The Name of the secret |
288-
| my_filesystem_id | The ID of the FSxN Filesystem |
289-
| my_fsx_ontap_security_group_id | The ID of the FSxN Security Group |
290-
| my_svm_id | The ID of the FSxN Storage Virtual Machine |
291-
| my_vol_id | The ID of the ONTAP volume in the File System |
294+
| security_group_id | The ID of the FSxN Security Group |
295+
| svm_id | The ID of the FSxN Storage Virtual Machine |
296+
| svm_management_ip | The management IP of the Storage Virtual Machine. |
292297
| svm_secret_arn | The Name of the secret |
293298
| svm_secret_name | The Name of the secret |
299+
| vol_id | The ID of the ONTAP volume in the File System |
294300
295301
## Author Information
296302

Terraform/deploy-fsx-ontap/module/output.tf

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
output "my_fsx_ontap_security_group_id" {
1+
output "security_group_id" {
22
description = "The ID of the FSxN Security Group"
33
value = var.create_sg ? [element(aws_security_group.fsx_sg[*].id, 0)] : []
44
}
55

6-
output "my_filesystem_id" {
6+
output "filesystem_id" {
77
description = "The ID of the FSxN Filesystem"
88
value = aws_fsx_ontap_file_system.terraform-fsxn.id
99
}
1010

11-
output "my_svm_id" {
11+
output "svm_id" {
1212
description = "The ID of the FSxN Storage Virtual Machine"
1313
value = aws_fsx_ontap_storage_virtual_machine.mysvm.id
1414
}
1515

16-
output "my_vol_id" {
16+
output "vol_id" {
1717
description = "The ID of the ONTAP volume in the File System"
1818
value = aws_fsx_ontap_volume.myvol.id
1919
}
@@ -37,3 +37,13 @@ output "svm_secret_name" {
3737
description = "The Name of the secret"
3838
value = module.svm_rotate_secret.secret_name
3939
}
40+
41+
output "filesystem_management_ip" {
42+
description = "The management IP of the FSxN Filesystem."
43+
value = format(join("", aws_fsx_ontap_file_system.terraform-fsxn.endpoints[0].management[0].ip_addresses))
44+
}
45+
46+
output "svm_management_ip" {
47+
description = "The management IP of the Storage Virtual Machine."
48+
value = format(join("", aws_fsx_ontap_storage_virtual_machine.mysvm.endpoints[0].management[0].ip_addresses))
49+
}

Terraform/deploy-fsx-ontap/standalone-module/README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,22 @@ Running this terraform sample will result the following:
3737
- **Ingress** allow ssh port 22
3838
- **Ingress** allow https port 443
3939
- **Egress** allow all traffic
40+
41+
* Two new AWS secrets. One that contains the fsxadmin password and another that contains the SVM admin password.
42+
4043
* Create a new FSx for Netapp ONTAP file-system in your AWS account named "_terraform-fsxn_". The file-system will be created with the following configuration parameters:
4144
* 1024Gb of storage capacity
4245
* Multi AZ deployment type
4346
* 128Mbps of throughput capacity
4447

4548
* Create a Storage Virtual Maching (SVM) in this new file-system named "_first_svm_"
49+
4650
* Create a new FlexVol volume in this SVM named "_vol1_" with the following configuration parameters:
4751
* Size of 1024Mb
4852
* Storage efficiencies mechanism enabled
4953
* Auto tiering policy with 31 cooling days
5054
* post-delete backup disabled
5155

52-
> [!NOTE]
53-
> Even though this Terraform code is set up to use AWS SecretsManager to retrieve the FSxN password, it will store the password in its `state database`. Therefore, it is assumed you have properly secured that database so that unauthorized personal can't access the password.
54-
5556
## Prerequisites
5657

5758
1. [Terraform prerequisites](#terraform)
@@ -122,12 +123,28 @@ terraform init
122123

123124
A succesfull initialization should display the following output:
124125
```shell
125-
126126
Initializing the backend...
127+
Initializing modules...
128+
Downloading git::https://github.com/Netapp/FSx-ONTAP-samples-scripts.git for fsxn_rotate_secret...
129+
- fsxn_rotate_secret in .terraform/modules/fsxn_rotate_secret/Management-Utilities/fsxn-rotate-secret/terraform
130+
Downloading git::https://github.com/Netapp/FSx-ONTAP-samples-scripts.git for svm_rotate_secret...
131+
- svm_rotate_secret in .terraform/modules/svm_rotate_secret/Management-Utilities/fsxn-rotate-secret/terraform
127132

128133
Initializing provider plugins...
129-
- Reusing previous version of hashicorp/aws from the dependency lock file
130-
- Using previously-installed hashicorp/aws v5.25.0
134+
- Finding hashicorp/aws versions matching ">= 5.25.0"...
135+
- Finding latest version of hashicorp/random...
136+
- Finding latest version of hashicorp/archive...
137+
- Installing hashicorp/aws v5.59.0...
138+
- Installed hashicorp/aws v5.59.0 (signed by HashiCorp)
139+
- Installing hashicorp/random v3.6.2...
140+
- Installed hashicorp/random v3.6.2 (signed by HashiCorp)
141+
- Installing hashicorp/archive v2.4.2...
142+
- Installed hashicorp/archive v2.4.2 (signed by HashiCorp)
143+
144+
Terraform has created a lock file .terraform.lock.hcl to record the provider
145+
selections it made above. Include this file in your version control repository
146+
so that Terraform can guarantee to make the same selections by default when
147+
you run "terraform init" in the future.
131148

132149
Terraform has been successfully initialized!
133150

@@ -210,6 +227,7 @@ terraform apply
210227
| my_fsx_ontap_security_group_id | The ID of the FSxN Security Group |
211228
| my_fsxn_secret_name | The name of the secret containing the ONTAP admin password |
212229
| my_svm_id | The ID of the FSxN Storage Virtual Machine |
230+
| my_svm_management_ip | The management IP of the Storage Virtual Machine. |
213231
| my_svm_secret_name | The name of the secret containing the SVM admin password |
214232
| my_vol_id | The ID of the ONTAP volume in the File System |
215233

Terraform/deploy-fsx-ontap/standalone-module/output.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ output "my_svm_id" {
1818
value = aws_fsx_ontap_storage_virtual_machine.mysvm.id
1919
}
2020

21+
output "my_svm_management_ip" {
22+
description = "The management IP of the Storage Virtual Machine."
23+
value = format(join("", aws_fsx_ontap_storage_virtual_machine.mysvm.endpoints[0].management[0].ip_addresses))
24+
}
25+
2126
output "my_vol_id" {
2227
description = "The ID of the ONTAP volume in the File System"
2328
value = aws_fsx_ontap_volume.myvol.id

0 commit comments

Comments
 (0)