Skip to content

Commit 74f6266

Browse files
Merge branch 'containers' of github.com:dataplat/dbachecks into containers
2 parents f7346a2 + 688b07a commit 74f6266

File tree

13 files changed

+325
-179
lines changed

13 files changed

+325
-179
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"extensions": [
1717
"ms-vscode.powershell",
1818
"github.vscode-pull-request-github",
19-
"2gua.rainbow-brackets",
2019
"oderwat.indent-rainbow",
2120
"mhutchie.git-graph",
2221
"usernamehw.errorlens",
@@ -25,7 +24,8 @@
2524
"TylerLeonhardt.vscode-inline-values-powershell",
2625
"cschleiden.vscode-github-actions",
2726
"ms-mssql.mssql",
28-
"Gruntfuggly.todo-tree"
27+
"Gruntfuggly.todo-tree",
28+
"streetsidesoftware.code-spell-checker"
2929
],
3030
"settings": {
3131
"editor.renderWhitespace": "all",

.devcontainer/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3"
22
services:
33
dbachecks1:
4-
image: dbachecks/sqlinstance1:v2.36.0
4+
image: dbachecks/sqlinstance1:v2.37.0
55
volumes:
66
- mydata:/var/opt/backups
77
- shared:/shared
@@ -13,7 +13,7 @@ services:
1313
hostname: dbachecks1
1414

1515
dbachecks2:
16-
image: dbachecks/sqlinstance2:v2.36.0
16+
image: dbachecks/sqlinstance2:v2.37.0
1717
volumes:
1818
- mydata:/var/opt/backups
1919
- shared:/shared
@@ -27,7 +27,7 @@ services:
2727

2828
# This is our SQL2022 container
2929
dbachecks3:
30-
image: dbachecks/sqlinstance3:v2.36.0
30+
image: dbachecks/sqlinstance3:v2.37.0
3131
volumes:
3232
- mydata:/var/opt/backups
3333
- shared:/shared

RequiredModules.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
}
88
}
99

10+
'dbatools.library' = 'latest'
1011
InvokeBuild = 'latest'
1112
PSScriptAnalyzer = 'latest'
1213
Pester = 'latest'

containers/JessAndBeard.psm1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,13 +2343,27 @@ The Tags are the same"
23432343
PassedChange = 0 # + or - the number of tests passed for v5
23442344
FailedChange = -12 # + or - the number of tests failed for v5
23452345
SkippedChange = 0 # + or - the number of tests skipped for v5
2346-
}
2346+
},
23472347
@{
23482348
Name = 'LinkedServerConnection'
23492349
RunChange = -3 # + or - the number of tests for v5
23502350
PassedChange = -3 # + or - the number of tests passed for v5
23512351
FailedChange = 0 # + or - the number of tests failed for v5
23522352
SkippedChange = 0 # + or - the number of tests skipped for v5
2353+
},
2354+
@{
2355+
Name = 'SupportedBuild'
2356+
RunChange = -3 # + or - the number of tests run for v5
2357+
PassedChange = -3 # + or - the number of tests passed for v5
2358+
FailedChange = 0 # + or - the number of tests failed for v5
2359+
SkippedChange = 0 # + or - the number of tests skipped for v5
2360+
},
2361+
@{
2362+
Name = 'GuestUserConnect'
2363+
RunChange = 0 # + or - the number of tests run for v5
2364+
PassedChange = +2 # + or - the number of tests passed for v5
2365+
FailedChange = -2 # + or - the number of tests failed for v5
2366+
SkippedChange = 0 # + or - the number of tests skipped for v5
23532367
}
23542368
)
23552369
$runchange = 0

developing/Robs-Instance.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ $Checks = 'NetworkLatency'
99
$Checks = 'LinkedServerConnection'
1010
$Checks = 'MaxMemory'
1111
$Checks = 'OrphanedFile'
12+
$Checks = 'MemoryDump'
13+
$Checks = 'HideInstance'
14+
$Checks = 'LoginAuditFailed'
15+
$Checks = 'LoginAuditSuccessful'
16+
$Checks = 'LoginCheckPolicy'
17+
$Checks = 'SuspectPageLimit'
18+
$Checks = 'SupportedBuild'
19+
$Checks = 'LoginMustChange'
20+
$Checks = 'LoginAuditSuccessful', 'LoginAuditFailed'
1221

1322
Invoke-PerfAndValidateCheck -Checks $Checks
1423
Invoke-PerfAndValidateCheck -Checks $Checks -PerfDetail
@@ -17,7 +26,7 @@ $password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
1726
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
1827
$show = 'All'
1928

20-
$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru
29+
$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru -verbose
2130
# Run v5 checks
2231
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose
2332

@@ -44,4 +53,4 @@ $traci = Trace-Script -ScriptBlock {
4453
$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru
4554
}
4655

47-
Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check failsafeoperator -legacy $false -Show $show -verbose
56+
Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check failsafeoperator -legacy $false -Show $show -verbose

source/checks/Databasev5.Tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,13 @@ Describe "Compatibility Level" -Tag CompatibilityLevel, High, Database -ForEach
222222
}
223223
}
224224
}
225+
226+
Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -ForEach $InstancesToTest {
227+
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.security.guestuserconnect').Value
228+
229+
Context "Testing Guest user has CONNECT permission" {
230+
It "Database Guest user should return no CONNECT permissions in <_.Name> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.guestuserexclude -notcontains $psitem.Name } } {
231+
$psitem.GuestUserConnect | Should -BeFalse -Because "we don't want the guest user to have connect access to our database."
232+
}
233+
}
234+
}

source/checks/Instancev5.Tests.ps1

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ Describe "Error Log Count" -Tag ErrorLogCount, CIS, Low, Instance -ForEach $Inst
140140
}
141141
}
142142

143+
Describe "Hide Instance" -Tag HideInstance, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
144+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.hideinstance' }).Value
145+
Context "Checking the Hide an Instance of SQL Server Database Engine property on <_.Name>" {
146+
It "The Hide an Instance of SQL Server Database Engine property on SQL Server instance <_.Name>" -Skip:$skip {
147+
# We don't make this -BeTrue because the possible results are $true/$false/'Could not connect'
148+
$psitem.HideInstance.Result | Should -Be $true -Because "We expected the hide instance property to be set to $true"
149+
}
150+
}
151+
}
152+
143153
Describe "Instance Connection" -Tag InstanceConnection, Connectivity, High, Instance -ForEach $InstancesToTest {
144154
BeforeAll {
145155
$skipall = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection' }).Value
@@ -190,6 +200,51 @@ Describe "Linked Servers" -Tag LinkedServerConnection, Connectivity, Medium, Ins
190200
}
191201
}
192202

203+
Describe "Failed Login Auditing" -Tag LoginAuditFailed, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
204+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.loginauditlevelfailed' }).Value
205+
Context "Testing if failed login auditing is in place on <_.Name>" {
206+
It "The failed login auditing should be set on <_.Name>" -Skip:$skip {
207+
$psitem.Settings.AuditLevel | Should -BeIn @("Failure", "All") -Because "We expected the audit level to be set to capture failed logins"
208+
}
209+
}
210+
}
211+
212+
Describe "Successful Login Auditing" -Tag LoginAuditSuccessful, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
213+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.loginauditlevelsuccessful' }).Value
214+
Context "Testing if successful and failed login auditing is in place on <_.Name>" {
215+
It "The successful and failed auditing should be set on <_.Name>" -Skip:$skip {
216+
$psitem.Settings.AuditLevel | Should -Be "All" -Because "We expected the audit level to be set to capture all logins (successful and failed)"
217+
}
218+
}
219+
}
220+
221+
Describe "Login Check Policy" -Tag LoginCheckPolicy, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
222+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.LoginCheckPolicy' }).Value
223+
Context "Testing if the CHECK_POLICY is enabled on all logins on <_.Name>" {
224+
It "All logins should have the CHECK_POLICY option set to ON on <_.Name>" -Skip:$skip {
225+
($psitem.logins | Where-Object { $_.LoginType -eq 'SqlLogin' -and $_.PasswordPolicyEnforced -eq $false -and $_.IsDisabled -eq $false }).Count | Should -Be 0 -Because "We expected the CHECK_POLICY for the all logins to be enabled"
226+
}
227+
}
228+
}
229+
230+
Describe "Login Must Change" -Tag LoginMustChange, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
231+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.LoginMustChange' }).Value
232+
Context "Testing if the new SQL logins that have not logged have to change their password when they log in on <_.Name>" {
233+
It "All new sql logins should have the have to change their password when they log in for the first time on <_.Name>" -Skip:$skip {
234+
$PsItem.LoginMustChangeCount | Should -Be 0 -Because "We expected the all the new sql logins to have to change the password on first login"
235+
}
236+
}
237+
}
238+
239+
Describe "Login Password Expiration" -Tag LoginPasswordExpiration, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
240+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.LoginPasswordExpiration' }).Value
241+
Context "Testing if the login password expiration is enabled for sql logins in the sysadmin role on <_.Name>" {
242+
It "All sql logins should have the password expiration option set to ON in the sysadmin role on <_.Name>" -Skip:$skip {
243+
$PsItem.LoginPasswordExpirationCount | Should -Be 0 -Because "We expected the password expiration policy to set on all sql logins in the sysadmin role"
244+
}
245+
}
246+
}
247+
193248
Describe "Instance MaxDop" -Tag MaxDopInstance, MaxDop, Medium, Instance -ForEach ($InstancesToTest | Where-Object { $psitem.Name -notin $psitem.ConfigValues.ExcludeInstanceMaxDop }) {
194249
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.MaxDopInstance' }).Value
195250
Context "Testing Instance MaxDop Value on <_.Name>" {
@@ -213,11 +268,11 @@ Describe "Max Memory" -Tag MaxMemory, High, Instance -ForEach $InstancesToTest {
213268
}
214269
}
215270

216-
Describe "SQL Memory Dumps" -Tags MemoryDump, Medium, Instance -ForEach $InstancesToTest {
271+
Describe "SQL Memory Dumps" -Tag MemoryDump, Medium, Instance -ForEach $InstancesToTest {
217272
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.memorydump' }).Value
218273
Context "Testing SQL Memory Dumps on <_.Name>" {
219274
It "There should be less than <_.MemoryDump.MaxDumps> since <_.MemoryDump.DumpDateCheckFrom> on <_.Name>" -Skip:$skip {
220-
$Psitem.MemoryDump.Result | Should -BeTrue -Because "We expected less than $($Psitem.MemoryDump.MaxDumps) dumps since $(PsItem.MemoryDump.DumpDateCheckFrom)but found $($Psitem.MemoryDump.DumpCount) . Memory dumps often suggest issues with the SQL Server instance"
275+
$Psitem.MemoryDump.Result | Should -BeTrue -Because "We expected less than $($Psitem.MemoryDump.MaxDumps) dumps since $($PsItem.MemoryDump.DumpDateCheckFrom)but found $($Psitem.MemoryDump.DumpCount) . Memory dumps often suggest issues with the SQL Server instance"
221276
}
222277
}
223278
}
@@ -338,6 +393,29 @@ Describe "SQL Mail XPs Disabled" -Tag SQLMailXPsDisabled, Security, CIS, Low, In
338393
}
339394
}
340395

396+
Describe "Supported Build" -Tag SupportedBuild, DISA, High, Instance -ForEach $InstancesToTest {
397+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.SupportedBuild' }).Value
398+
Context "Checking that build is still supported by Microsoft for <_.Name>" -Skip:$skip {
399+
It "The build is not behind the latest build by more than <_.SupportedBuild.BuildBehind> for <_.Name>" {
400+
$psItem.SupportedBuild.Compliant | Should -BeTrue -Because "this build $($psItem.SupportedBuild.Build) should not be behind the required build"
401+
}
402+
It "The build is supported by Microsoft for <_.Name>" {
403+
$psItem.SupportedBuild.InsideMicrosoftSupport | Should -BeTrue -Because "this build $($psItem.SupportedBuild.Build) is now unsupported by Microsoft"
404+
}
405+
It "The build is supported by Microsoft within the warning window of <_.SupportedBuild.BuildWarning> months for <_.Name>" {
406+
$psItem.SupportedBuild.InsideBuildWarning | Should -BeTrue -Because "this build $($psItem.SupportedBuild.Build) will be unsupported by Microsoft on $($psItem.SupportedBuild.SupportedUntil) which is less than $($psItem.SupportedBuild.BuildWarning) months away"
407+
}
408+
}
409+
}
410+
411+
Describe "Suspect Page Limit Nearing" -Tag SuspectPageLimit, Medium, Instance -ForEach $InstancesToTest {
412+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.suspectpagelimit' }).Value
413+
Context "Testing if the suspect_pages table is nearing the limit of 1000 rows on on <_.Name>" {
414+
It "The suspect_pages table in msdb shouldn't be nearing the limit of 1000 rows on on <_.Name>" -Skip:$skip {
415+
$PSItem.SuspectPageCountResult | Should -BeTrue -Because "The suspect_pages table in msdb shouldn't be nearing the limit of 1000 rows"
416+
}
417+
}
418+
}
341419
Describe "Trace Flags Expected" -Tag TraceFlagsExpected, TraceFlag, High, Instance -ForEach $InstancesToTest {
342420
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.TraceFlagsExpected' }).Value
343421
Context "Testing Expected Trace Flags on <_.Name>" {

source/dbachecks.psd1

402 Bytes
Binary file not shown.

source/functions/Invoke-DbcCheck.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,13 @@ function Invoke-DbcCheck {
288288
process {
289289
if ($legacy) {
290290
try {
291+
Write-PSFMessage 'Running in legacy mode, we need Version 4'
291292
if (Get-Module Pester | Where-Object { $_.Version -gt '5.0.0' }) {
293+
Write-PSFMessage 'Remove Version 5' -Level Verbose
292294
Remove-Module Pester -ErrorAction SilentlyContinue
293-
Write-PSFMessage 'Running in legacy mode, we need to import Version 4' -Level Verbose
294-
Import-Module Pester -RequiredVersion 4.10.1 -Global
295295
}
296+
Write-PSFMessage 'import Version 4' -Level Verbose
297+
Import-Module Pester -RequiredVersion 4.10.1 -Global
296298
} catch {
297299
Write-PSFMessage -Message 'Something Went wrong' -Level Warning -ErrorRecord $_
298300
Return

0 commit comments

Comments
 (0)