-
Notifications
You must be signed in to change notification settings - Fork 0
/
secure.ps1
1897 lines (1211 loc) · 51.4 KB
/
secure.ps1
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#requires -version 7
<#
.SYNOPSIS
Applies security-related settings based on an input file {secure}.ini. Security settings are based on DISA ONTAP STIG v1r3.
.DESCRIPTION
Applies security-related settings based on an input file {secure}.ini. Security settings are based on DISA ONTAP STIG v1r3.
See 'secure_template.ini' for details on the parameters
Workflow:
1. Test for configuration file
2. Process configuration file
3. Verify Settings
4. Ping cluster IP (verify reachable)
5. Check REST API connection to cluster - Get cluster name and ONTAP version
6. Set Concurrent Sessions [Session Limit ]
7. Set Session Timeout [Session Timeout ]
8. Configure Audit Account-enabling actions [Cluster Logging ]
9. Set Consecutive Failed Logon Attempts [Login Attempts ]
10. Set Banner & Message of the Day for Cluster and SVMs [Banner & MOTD ]
11. ONTAP Audit Protocols [ONTAP Audit ]
12. SVM Audit Configuration (NAS SVMs) [SVM Audit - SMB/NFS ]
13. Add NTP Servers [NTP Servers ]
14. Set Time Stamp for Audit Records (UTC/GMT) [Time Zone ]
15. Configure MultiFactor Authentication [MultiFactor Auth ]
16. On-Demand Cluster Configuration Backup [Config Backup ]
17. Service Policies (Packet Filtering) [Service Policies ]
18. Add Domain Accounts with Admin Role [Domain Accounts ]
19. Enable/Disable FIPS 140-2 [FIPS 140-2 ]
20. Enable & Configure SNMP [Configure SNMP ]
21. Set Password Complexity Minimums [Password Complexity ]
22. Create Account of Last Resort (1 Local Admin Account) [Local Admin ]
23. Check if Reboot Required
24. Lock / Unlock Default admin Account [Default Admin Account]
.PARAMETER SecureFile
The {configuration}.ini file that contains settings for each specific STIG and Hardening Guide item.
.EXAMPLE
PS> .\secure.ps1 -SecureFile secure_cluster1.ini -ClusterIP 10.0.10.10 -Login admin
Processes secure_cluster1.ini for settings and checks each security item for compliance
.LINK
ONTAP 9 Documentation: https://docs.netapp.com/ontap-9/index.jsp
.LINK
ONTAP 9 REST API: https://{ClusterIP}/docs/api
#>
[cmdletbinding()]
param (
[Parameter(Mandatory = $True)]
[string]$SecureFile,
[Parameter(Mandatory = $True)]
[ipaddress]$ClusterIP,
[Parameter(Mandatory = $True)]
[string]$Login
)
# -------------------- TODO LIST --------------------
# Check if only 1 local admin account before locking
# -------------------- Functions --------------------
function Get-ConfigSettings ($file) {
# Processes a standard .ini file into hash key/values and returns the object
$ini = @{ }
$section = "NO_SECTION"
$ini[$section] = @{ }
switch -regex -file $file {
"^\[(.+)\]$" {
$section = $matches[1].Trim()
$ini[$section] = @{ }
}
"^\s*([^#].+?)\s*=\s*(.*)" {
$name, $value = $matches[1 .. 2]
if (!($name.StartsWith(";")))
{
$ini[$section][$name] = $value.Trim()
}
}
}
return $ini
}
function Invoke-ONTAP {
[cmdletbinding()]
param (
[Parameter(Mandatory = $True)]
[ValidateSet('Get', 'Post', 'Patch', 'Delete')]$Method,
[Parameter(Mandatory = $True)]
[string]$URL,
[string]$Body = '{}',
[switch]$ReturnNullOnError
)
# Inputs:
# - Method [Get|Post|Patch|Delete]
# - URL
# - Body
#
# Outputs:
# - Result of REST API call
#
# Body is only required for Post|Patch - a default of an empty JSON body {} can be used depending on the DELETE API requirements
#
# Errors:
# - Exception Messages are displayed and script is terminated
#
try {
if ($Method -eq 'Get') {
$_result = Invoke-RestMethod -Method $Method -Uri $URL -Credential $script:Credential -Headers $script:header -SkipCertificateCheck -ErrorAction Stop
} else {
$_result = Invoke-RestMethod -Method $Method -Uri $URL -Credential $script:Credential -Headers $script:header -Body $Body -SkipCertificateCheck -ErrorAction Stop
}
} catch {
if ($ReturnNullOnError) {
$_result = $null
} else {
Write-Host -ForegroundColor Red "`n $_.Exception.Message `n"
Write-Host -ForegroundColor Yellow " $($error[0].ErrorDetails.Message) `n"
Exit
}
}
return $_result
}
function Get-TrueFalse {
[cmdletbinding()]
param (
[Parameter(Mandatory = $True)]
[string]$YesNo
)
# Returns True if value equals 'yes|true' - not case sensitive
# Any other value will return False
if (($YesNo -eq 'yes') -or ($YesNo -eq 'true')) {
return $true
} else {
return $false
}
}
function Convert-UnitsToBytes {
[cmdletbinding()]
param (
[Parameter(Mandatory = $True)]
[uint64]$Size,
[Parameter(Mandatory = $True)]
[ValidateSet('MB', 'GB', 'TB')]$Unit
)
# Converts BYTES to a specified UNIT (MB|GB|TB)
# - Any other Unit will return the original value passed in
$Unit = $Unit.ToUpper()
switch ($Unit) {
'MB' {
$bytes = $size * 1MB
}
'GB' {
$bytes = $size * 1GB
}
'TB' {
$bytes = $size * 1TB
}
Default {
$bytes = $size
}
}
return $bytes
}
# -------------------- Test for configuration file --------------------
if (!(Test-Path $SecureFile)){
Write-Host -ForegroundColor Red "Configuration File ($SecureFile) Not Found"
Write-Host
Exit
}
# -------------------- Process configuration file --------------------
# Process configuration file
$config = Get-ConfigSettings "$SecureFile"
# SECURITY
$concurrent_sessions = ($config["SECURITY"]).concurrent_sessions
$session_timeout = ($config["SECURITY"]).session_timeout
$max_login_attempts = ($config["SECURITY"]).max_login_attempts
$banner = ($config["SECURITY"]).banner
$motd = ($config["SECURITY"]).motd
$set_timezone = ($config["SECURITY"]).set_timezone
if ($set_timezone.Length -eq 0) { $set_timezone = 'Etc/UTC'}
$fips = (($config["SECURITY"]).fips).ToLower()
$service_policies = (($config["SECURITY"]).service_policies).ToLower()
# NTP
$ntp_servers = (($config["NTP"]).ntp_servers).Split(',')
$ntp_keys = (($config["NTP"]).ntp_keys).Split(',')
# SNMP
$snmp_enable = Get-TrueFalse -YesNo (($config["SNMP"]).snmp_enable)
$traps_enable = Get-TrueFalse -YesNo (($config["SNMP"]).traps_enable)
$trap_host = ($config["SNMP"]).trap_host
$snmp_community = ($config["SNMP"]).community
# SNMP v3
$snmpv3_host = ($config["SNMPV3"]).snmpv3_host
$usm_user_name = ($config["SNMPV3"]).usm_user_name
$usm_auth_password = ($config["SNMPV3"]).usm_auth_password
$usm_privacy_password = ($config["SNMPV3"]).usm_privacy_password
# PASSWORDCOMPLEXITY
$minlength = ($config["PASSWORDCOMPLEXITY"]).minlength
$minuppercase = ($config["PASSWORDCOMPLEXITY"]).minuppercase
$minlowercase = ($config["PASSWORDCOMPLEXITY"]).minlowercase
$minspecial = ($config["PASSWORDCOMPLEXITY"]).minspecial
$alphanum = (($config["PASSWORDCOMPLEXITY"]).alphanum).ToLower()
# LOCALADMIN
$local_account = ($config["LOCALADMIN"]).account
$local_password = ($config["LOCALADMIN"]).password
$lock_default_admin = Get-TrueFalse -YesNo (($config["LOCALADMIN"]).lock_default_admin)
# DOMAINAUTH
$auth_svm_name = ($config["DOMAINAUTH"]).svm_name
$auth_ad_name = ($config["DOMAINAUTH"]).ad_name
$auth_ad_fqdn = ($config["DOMAINAUTH"]).ad_fqdn
$auth_ad_join_account = ($config["DOMAINAUTH"]).ad_join_account
$auth_ad_join_password = ($config["DOMAINAUTH"]).ad_join_password
$auth_lif_name = ($config["DOMAINAUTH"]).lif_name
$auth_lif_ip = ($config["DOMAINAUTH"]).lif_ip
$auth_lif_netmask = ($config["DOMAINAUTH"]).lif_netmask
$auth_lif_gateway = ($config["DOMAINAUTH"]).lif_gateway
$auth_lif_ipspace = ($config["DOMAINAUTH"]).lif_ipspace
$auth_lif_broadcastdomain = ($config["DOMAINAUTH"]).lif_broadcastdomain
$auth_lif_homenode = ($config["DOMAINAUTH"]).lif_homenode
$auth_dns_domains = (($config["DOMAINAUTH"]).dns_domains).Split(',')
$auth_dns_servers = (($config["DOMAINAUTH"]).dns_servers).Split(',')
# DOMAINACCOUNTS
$auth_domain_accounts = (($config["DOMAINACCOUNTS"]).accounts).Split(',')
# AUDIT
$audit_cli = Get-TrueFalse -YesNo (($config["AUDIT"]).cli)
$audit_http = Get-TrueFalse -YesNo (($config["AUDIT"]).http)
$audit_ontapi = Get-TrueFalse -YesNo (($config["AUDIT"]).ontapi)
# AUDITSVM
$audit_volume_name = ($config["AUDITSVM"]).volume_name
$audit_volume_sizeGB = ($config["AUDITSVM"]).volume_sizeGB
$audit_volsize = Convert-UnitsToBytes -Size $audit_volume_sizeGB -Unit GB
$audit_path = ($config["AUDITSVM"]).path
$audit_rotate_sizeMB = ($config["AUDITSVM"]).rotate_sizeMB
$audit_rotate_size = Convert-UnitsToBytes -Size $audit_rotate_sizeMB -Unit MB
$audit_rotate_limit = ($config["AUDITSVM"]).rotate_limit
$audit_log_format = (($config["AUDITSVM"]).log_format).ToLower()
# LOGGING
$log_ipaddress = ($config["LOGGING"]).ipaddress
$log_facility = ($config["LOGGING"]).facility
$log_ipspace = ($config["LOGGING"]).ipspace
$log_dest_port = ($config["LOGGING"]).dest_port
$log_protocol = ($config["LOGGING"]).protocol
$log_verify = Get-TrueFalse -YesNo (($config["LOGGING"]).verify)
# -------------------- Validation Lists --------------------
$valid_timezones = @('Etc/UTC','UTC','GMT','GMT+0','GMT-0','GMT0','Greenwich')
$valid_Enabled = @('enabled','disabled')
$valid_Enable = @('enable','disable')
$valid_Filter = @('filter','unfilter')
$valid_Format = @('evtx','xml')
$valid_log_facility = @('kern','user','local0','local1','local2','local3','local4','local5','local6','local7')
$valid_log_protocol = @('udp_unencrypted','tcp_unencrypted','tcp_encrypted')
# -------------------- Validate Settings --------------------
$err_msgs = @()
if (!($concurrent_sessions -match "\d+")) { $err_msgs += " Invalid Concurrent Sessions Setting ($concurrnet_sessions)"}
if (!($session_timeout -match "\d+")) { $err_msgs += " Invalid Session Timeout Setting ($session_timeout)"}
if (!($max_login_attempts -match "\d+")) { $err_msgs += " Invalid Max Login Attempts Setting ($max_login_attempts)"}
if (!($valid_timezones.Contains($set_timezone))) { $err_msgs += " Time Zone $set_timezone Not Valid ($set_timezone)" }
if (!($valid_Enable.Contains($fips))) { $err_msgs += " FIPS 140-2 Setting Not Valid ($fips) - Must Be 'Enable' or 'Disable'" }
if (!($valid_Filter).Contains($service_policies)) { $err_msgs += " Invalid Service Policy Filter Settting - Must Be 'filter' or 'unfilter'" }
if (!($minlength -match "\d+")) { $err_msgs += " Invalid Password Minimum Length Setting ($minlength)"}
if (!($minuppercase -match "\d+")) { $err_msgs += " Invalid Password Minimum Uppercase Characters Setting ($minuppercase)"}
if (!($minlowercase -match "\d+")) { $err_msgs += " Invalid Password Minimum Lowercase Characters Setting ($minlowercase)"}
if (!($minspecial -match "\d+")) { $err_msgs += " Invalid Password Minimum Special Characters Setting ($minspecial)"}
if (!($valid_Enabled).Contains($alphanum)) { $err_msgs += " Password Complexity AlphaNum Invalid - Must Be 'Enabled' or 'Disabled'" }
if ((!($trap_host -as [IPAddress] -as [Bool])) -and $trap_host.Length -gt 0 ) { $err_msgs += " INvalid Trap Host IP Address ($trap_host)"}
foreach($ntp IN $ntp_servers) {
if ((!($ntp -as [IPAddress] -as [Bool])) -and $ntp -ne '') {
$err_msgs += " Invalid NTP Server IP Address ($ntp)"
}
}
# Configure Logging
if (($log_ipaddress.Length -gt 0) -and ($log_facility.Length -gt 0) -and ($log_ipspace.Length -gt 0) -and `
($log_dest_port.Length -gt 0) -and ($log_protocol.Length -gt 0) -and ($log_verify.Length -gt 0))
{
$config_logging = $true
if (!($log_ipaddress -as [IPAddress] -as [Bool])) { $err_msgs += " Invalid Cluster Log IP Address ($log_ipaddress)"}
if (!($valid_log_facility.Contains($log_facility))) { $err_msgs += " Invalid Cluster Log Facility ($log_facility)"}
if (!($valid_log_protocol.Contains($log_protocol))) { $err_msgs += " Invalid Cluster Log Protocol ($log_protocol)"}
} else {
$config_logging = $false
}
# Configure Domain Tunnel (Domain Authentication)
if (($auth_svm_name.Length -gt 0) -and ($auth_ad_name.Length -gt 0) -and `
($auth_ad_fqdn.Length -gt 0) -and ($auth_ad_join_account.Length -gt 0) -and `
($auth_lif_name.Length -gt 0) -and ($auth_lif_ip.Length -gt 0) -and `
($auth_lif_netmask.Length -gt 0) -and ($auth_lif_gateway.Length -gt 0) -and `
($auth_lif_ipspace.Length -gt 0) -and ($auth_lif_broadcastdomain.Length -gt 0) -and`
($auth_lif_homenode.Length -gt 0) -and ($auth_dns_domains.Length -gt 0) -and `
($auth_dns_servers.Length -gt 0))
{
$auth_tunnel = $true
if (!($auth_lif_ip -as [IPAddress] -as [Bool])) { $err_msgs += " Invalid Domain Auth IP Address ($auth_lif_ip)"}
if (!($auth_lif_gateway -as [IPAddress] -as [Bool])) { $err_msgs += " Invalid Domain Auth Gateway ($auth_lif_gateway)"}
} else {
$auth_tunnel = $false
}
# Configure Auditing
if (($audit_volume_name.Length -gt 0) -and ($audit_volume_sizeGB.Length -gt 0) -and `
($audit_volsize.Length -gt 0) -and ($audit_path.Length -gt 0) -and `
($audit_rotate_sizeMB.Length -gt 0) -and ($audit_rotate_limit.Length -gt 0) -and `
($audit_log_format.Length -gt 0))
{
$config_audit = $true
if (!($audit_volume_sizeGB -match "\d+")) { $err_msgs += " Invalid Audit Volume Size Setting ($audit_volume_sizeGB)"}
if (!($audit_rotate_sizeMB -match "\d+")) { $err_msgs += " Invalid Audit Rotate Size Setting ($audit_rotate_sizeMB)"}
if (!($audit_rotate_limit -match "\d+")) { $err_msgs += " Invalid Audit Rotate Limit Setting ($audit_rotate_limit)"}
if (!($valid_Format.Contains($audit_log_format))) { $err_mesgs += " Invalid Audit Log Format ($audit_log_format)"}
} else {
$config_audit = $false
}
# -------------------- Display Error Messages - Exit if Errors --------------------
if ($err_msgs.Count -gt 0) {
Clear-Host
Write-Host
foreach ($msg IN $err_msgs) {
Write-Host -ForegroundColor Yellow " *** $msg "
}
Write-Host
exit
}
# -------------------- Start --------------------
$inc = 1
Clear-Host
# -------------------- Ping Cluster IP --------------------
if (!(Test-Connection -Ping $clusterip -Count 2 -Quiet )) {
Write-Host -ForegroundColor Yellow "Cluster $ClusterIP Did Not Respond to PING test"
Exit
}
# -------------------- Build Header --------------------
# Create a standard HEADER object
# - $script: makes the variable available to the functions in the script so they do not need to passed in
$script:header = @{
'Accept' = "application/json"
'Content-Type' = 'application/json'
}
# -------------------- Build Credential --------------------
# Prompt for Password
Write-Host
$pass = Read-Host " Enter [$Login] Password " -AsSecureString
# If Domain Tunnel Settings validated and AD Join Account Password is missing...
if ($auth_tunnel -and ($auth_ad_join_password.Length -eq 0)) {
Write-Host
$ad_pass = Read-Host " Enter [$auth_ad_name\$auth_ad_join_account] Password " -AsSecureString
$auth_ad_join_password = = ConvertFrom-SecureString -SecureString $ad_pass -AsPlainText
}
Clear-Host
Write-Host
Write-Host -ForegroundColor Gray " ---------------------------------------------------------------------------------"
Write-Host -ForegroundColor Magenta " Secure ONTAP Cluster v1.0"
Write-Host -ForegroundColor Gray " ---------------------------------------------------------------------------------"
# Generate the authorization credential
# - $script: makes the variable available to the functions in the script so they do not need to be passed in
$script:Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$Login", $pass
# -------------------- Check Cluster --------------------
# Build REST API URL
$apiUri = "https://$clusterip/api"
# Query the 'cluster' category
$uri = $apiUri + '/cluster'
# Get cluster details
$result = Invoke-ONTAP -Method Get -URL $uri
# Save cluster name
$ClusterName = $result.name
# -------------------- Save Cluster Version --------------------
$ClusterVersion = $result.version.full
Write-Host -ForegroundColor White " $ClusterVersion"
Write-Host -ForegroundColor Gray " ---------------------------------------------------------------------------------"
# -------------------- STIG V-246922: Concurrent Sessions --------------------
Write-Host -ForegroundColor Gray " $(($inc++))`." -NoNewline
Write-Host -ForegroundColor Cyan " Session Limit `t`t" -NoNewline
# Set session limit
$vUrl = $apiUri + "/private/cli/security/session/limit?interface=cli&category=application"
$vBody = @{
max_active_limit = $concurrent_sessions
}
$body = $vBody | ConvertTo-Json -Depth 5
$vResult = Invoke-ONTAP -Method Patch -URL $vUrl -Body $body
Write-Host -ForegroundColor White $concurrent_sessions
# -------------------- STIG V-246923/V-246959 : Session Timeout (Lock) --------------------
Write-Host -ForegroundColor Gray " $(($inc++))`." -NoNewline
Write-Host -ForegroundColor Cyan " Session Timeout `t`t" -NoNewline
# Set Session Timeout
$vUrl = $apiUri + "/private/cli/system/timeout"
$vBody = @{
timeout = $session_timeout
}
$body = $vBody | ConvertTo-Json -Depth 5
$vResult = Invoke-ONTAP -Method Patch -URL $vUrl -Body $body
Write-Host -ForegroundColor White "$session_timeout minutes"
# -------------------- STIG V-246925/V-246964 : Audit Account-enabling actions --------------------
Write-Host -ForegroundColor Gray " $(($inc++))`." -NoNewline
Write-Host -ForegroundColor Cyan " Cluster Logging `t`t" -NoNewline
# If .INI settings are sufficient...
if ($config_logging) {
# Check if already configured
$vUrl = $apiUri + "/security/audit/destinations/$log_ipaddress/$log_port"
$vResult = Invoke-ONTAP -Method Get -URL $vUrl
if ($vResult.num_records -ne 0) {
Write-Host -ForegroundColor Yellow "EXISTS"
} else {
# Configure cluster logging
$vUrl = $apiUri + "/security/audit/destinations?force=true"
$vBody = @{
address = $log_ipaddress
facility = $log_facility
ipspace = @{
name = $log_ipspace
}
port = $log_dest_port
protocol = $log_protocol
verify_server = $log_verify
}
$body = $vBody | ConvertTo-Json -Depth 5
$vResult = Invoke-ONTAP -Method Post -URL $vUrl -Body $body
Write-Host -ForegroundColor Green 'CONFIGURED'
}
} else {
Write-Host -ForegroundColor Yellow 'NOT CONFIGURED - Insufficient Settings'
}
# -------------------- STIG V-246931 : Consecutive Failed Logon Attempts --------------------
Write-Host -ForegroundColor Gray " $(($inc++))`." -NoNewline
Write-Host -ForegroundColor Cyan " Login Attempts `t`t" -NoNewline
# Get each role with Maximum Failed Login Attempts
$vUrl = $apiUri + "/private/cli/security/login/role/config?fields=max-failed-login-attempts"
$vResult = Invoke-ONTAP -Method Get -URL $vUrl
$roles = @()
foreach ($rec IN $vResult.records) {
if ($rec.max_failed_login_attempts -ne 3) {
$roles += $rec.role
}
}
# Set each role to 3 attempts if current setting is less than 3
foreach ($rec IN $vResult.records) {
if ($rec.max_failed_login_attempts -ne 3) {
$vBody = @{
max_failed_login_attempts = $max_login_attempts
}
$body = $vBody | ConvertTo-Json -Depth 5
$vUrl = $apiUri + '/private/cli/security/login/role/config?role=' + $rec.role + '&vserver=' + $rec.vserver
$vResult = Invoke-ONTAP -Method Patch -URL $vUrl -Body $body
}
}
Write-Host -ForegroundColor White $max_login_attempts
# -------------------- STIG V-246932 : Banner & Message of the Day --------------------
Write-Host -ForegroundColor Gray " $(($inc++))`." -NoNewline
Write-Host -ForegroundColor Cyan " Banner & MOTD `t`t" -NoNewline
# Set Banner and MOTD for Cluster
$vUrl = $apiUri + "/security/login/messages?scope=cluster"
$vBody = @{
banner = $banner
message = $motd
}
$body = $vBody | ConvertTo-Json -Depth 5
$vResult = Invoke-ONTAP -Method Patch -URL $vUrl -Body $body
# Set Banner and MOTD for Existing SVMs
$vUrl = $apiUri + "/svm/svms"
$vResultSvms = Invoke-ONTAP -Method Get -URL $vUrl
foreach ($sn IN $vResultSvms.records) {
$svm_name = $sn.name
$vUrl = $apiUri + "/security/login/messages?svm.name=$svm_name"
$vResult = Invoke-ONTAP -Method Patch -URL $vUrl -Body $body
}
Write-Host -ForegroundColor Green "SET"
# -------------------- STIG: V-246935 : Audit Guarantee --------------------
Write-Host -ForegroundColor Gray " $(($inc++))`." -NoNewline
Write-Host -ForegroundColor Cyan " ONTAP Audit `t`t" -NoNewline
# Enable/Disable Auditing for CLI, HTTP, and ONTAPI
$vUrl = $apiUri + "/security/audit"
$vBody = @{
cli = $audit_cli
http = $audit_http
ontapi = $audit_ontapi
}
$body = $vBody | ConvertTo-Json -Depth 5
$vResult = Invoke-ONTAP -Method Patch -URL $vUrl -Body $body
Write-Host -ForegroundColor White "CLI: $audit_cli HTTP: $audit_http ONTAPI: $audit_ontapi"
# -------------------- Configure Auditing on NAS SVMs --------------------
Write-Host -ForegroundColor Gray " $(($inc++))`." -NoNewline
Write-Host -ForegroundColor Cyan " SVM Audit - NAS`t`t" -NoNewline
if ($config_audit) {
Write-Host
$eligible = 0
# Get SVMs
$vUrl = $apiUri + "/svm/svms?fields=name,cifs.enabled,nfs.enabled,aggregates&subtype=default"
$svms = Invoke-ONTAP -Method Get -URL $vUrl
foreach ($rec IN $svms.records){
$svmname = $rec.name
$cifs = $rec.cifs.enabled
$nfs = $rec.nfs.enabled
$aggr = $rec.aggregates[0].name
# Get Audit Settings for SVM
$vUrl = $apiUri + "/protocols/audit?fields=*&svm.name=$svmname"
$audit = Invoke-ONTAP -Method Get -URL $vUrl
# No audit settings found and SVM is cifs or nfs enabled
if ( ($audit.num_records -eq 0) -and (($cifs -or $nfs)) ) {
# Get '{svmname}_audit' Export Policy with Rule
$audit_policy = $svmname + '_audit'
$vUrl = $apiUri + "/protocols/nfs/export-policies?svm.name=$svmname&name=$audit_policy&return_records=false"
$vResult = Invoke-ONTAP -Method Get -URL $vUrl
# Policy Does Not Exist - Create Policy
if ($VResult.num_records -eq 0) {
$vUrl = $apiUri + "/protocols/nfs/export-policies"
$vBody = @{
name = $audit_policy
svm = @{
name = "$svmname"
}
}
$body = $vBody | ConvertTo-Json -Depth 5
$vUrl = $apiUri + "/protocols/nfs/export-policies"
$vResult = Invoke-ONTAP -Method Post -URL $vUrl -Body $body
# Get ID for export policy
$vUrl = $apiUri + "/protocols/nfs/export-policies?svm.name=$svmname&name=$audit_policy&fields=*&return_records=true"
$vResult = Invoke-ONTAP -Method Get -URL $vUrl
$exp_ID = $vResult.records[0].id
# Add Export Policy Rule
$vRule = @{
clients = @(
@{
match = "0.0.0.0/0"
}
)
protocols = @(
"any"
)
ro_rule = @(
"sys"
)
rw_rule = @(
"never"
)
superuser = @(
"sys"
)
}
$body = $vRule | ConvertTo-Json -Depth 5
$vUrl = $apiUri + "/protocols/nfs/export-policies/" + $exp_ID + '/rules'
$vResult = Invoke-ONTAP -Method Post -URL $vUrl -Body $body
}
# Get Volume
$svmvolume = $svmname + '_' + $audit_volume_name
$vUrl = $apiUri + "/storage/volumes?fields=name,nas.path&name=$svmvolume"
$vResult = Invoke-ONTAP -Method Get -URL $vUrl
# Volume Does Not Exist - Create Volume with Export Policy
if ($vResult.num_records -eq 0) {
$vBody = @{
name = $svmvolume
aggregates = @(
@{
name = $aggr
}
)
svm = @{
name = $svmname
}
size = $audit_volsize
nas = @{
export_policy = @{
name = $audit_policy
}
path = $audit_path
security_style = 'mixed'
}
guarantee = @{
type = "volume"
}
}
$body = $vBody | ConvertTo-Json -Depth 5
$vUrl = $apiUri + "/storage/volumes"
$vResult = Invoke-ONTAP -Method Post -URL $vUrl -Body $body
# Monitor Job
$vUrl = $apiUri + "/cluster/jobs/$($vResult.job.uuid)"
$more = $true
$pause = 10
while ($more) {
$jobResult = Invoke-ONTAP -Method Get -URL $vUrl
if ($jobResult.state -eq 'failure') {
Write-Host -ForegroundColor Red "`n`n $($jobResult.Message) `n`n"
Exit
} elseif ($jobResult.state -eq 'success') {
$pause = 1
$more = $false
} else {
$more = $true
}
Start-Sleep -Seconds $pause
}
}
# Create Audit Configuration
$vBody = @{
svm = @{
name = $svmname
}
log_path = $audit_path
log = @{
format = $audit_log_format
rotation = @{
size = $audit_rotate_size
}
retention = @{
count = $audit_rotate_limit
}
}
guarantee = $true
enabled = $true
}
$body = $vBody | ConvertTo-Json -Depth 5
# Create/Enable Auditing
$vUrl = $apiUri + "/protocols/audit"
$vResult = Invoke-ONTAP -Method Post -URL $vUrl -Body $body
Write-Host -ForegroundColor White " - $svmname`t`t`t" -NoNewline
Write-Host -ForegroundColor Green "CONFIGURED"
$eligible++
}
# Audit settings found and SVM is cifs or nfs enabled
if ( ($audit.num_records -eq 1) -and (($cifs -or $nfs)) ) {
$svm_uuid = $audit.records[0].svm.uuid
$audit_enabled = $audit.records[0].enabled
$audit_path = $audit.records[0].log_path
$audit_guarantee = $audit.records[0].guarantee
if (!($audit_guarantee)) {
# Guarantee - vserver audit modify -vserver $svmname -audit-guarantee true
$vUrlAudit = $apiUri + "/protocols/audit/$svm_uuid"
$vBody = @{
guarantee = $true
}
$body = $vBody | ConvertTo-Json -Depth 5
$aResult = Invoke-ONTAP -Method Patch -URL $vUrlAudit -Body $body
$audit_guarantee = $true
}
if (!($audit_enabled)) {
# Enable Auditing
$vUrlAudit = $apiUri + "/protocols/audit/$svm_uuid"
$vBody = @{
enabled = $true
}
$body = $vBody | ConvertTo-Json -Depth 5
$aResult = Invoke-ONTAP -Method Patch -URL $vUrlAudit -Body $body
$audit_enabled = $true
}
Write-Host -ForegroundColor White " - $svmname`t`t`t" -NoNewline
Write-Host -ForegroundColor White "CONFIGURED - Guarantee: $audit_guarantee Enabled: $audit_enabled"
$eligible++
}
}
if ($eligible -eq 0) {
Write-Host -ForegroundColor White " - No Eligible SVMs Found"
}
} else {
Write-Host -ForegroundColor Yellow "NOT CONFIGURED - Insufficient Settings"
}
# -------------------- STIG V-246936 : NTP Servers --------------------
Write-Host -ForegroundColor Gray " $(($inc++))`." -NoNewline
Write-Host -ForegroundColor Cyan " NTP Servers `t`t" -NoNewline
# Get NTP Servers
$vUrl = $apiUri + "/cluster/ntp/servers?"
$vResult = Invoke-ONTAP -Method Get -URL $vUrl
$current_ntp_servers = @()
if ( $vResult.num_records -lt 3 ) {
$current_ntp_servers = @()
foreach ($rec IN $vResult.records) {
$current_ntp_servers += $rec.server
}
}
$i = 0
$ntp_added = $false
# Add NTP servers from .INI (if any)
foreach ($ntp IN $ntp_servers) {
if ((!($current_ntp_servers.contains($ntp))) -and ($ntp -ne '')) {
$vBody = @{
server = $ntp
}
# Include KEY if in .INI
if ($ntp_keys[$i] -ne '') {
$vKey = @{
key_id = $ntp_keys[$i]
}
$vBody += $vKey
}
$body = $vBody | ConvertTo-Json -Depth 5
$vUrl = $apiUri + '/private/cli/cluster/time-service/ntp/server'
$vResult = Invoke-ONTAP -Method Post -URL $vUrl -Body $body