Skip to content

Commit 7929a16

Browse files
authored
Merge pull request #975 from jpomfret/guestuserconnect
New check - GuestUserConnect
2 parents d962e41 + 438a2a8 commit 7929a16

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

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/internal/configurations/configuration.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Set-PSFConfig -Module dbachecks -Name policy.database.status.excluderestoring -V
164164
Set-PSFConfig -Module dbachecks -Name database.querystoreenabled.excludedb -Value @('model', 'tempdb', 'master') -Initialize -Description "A List of databases that we do not want to check for Query Store enabled"
165165
Set-PSFConfig -Module dbachecks -Name database.querystoredisabled.excludedb -Value @('model', 'tempdb', 'master') -Initialize -Description "A List of databases that we do not want to check for Query Store disabled"
166166
Set-PSFConfig -Module dbachecks -Name database.compatibilitylevel.excludedb -Value @() -Initialize -Description "A list of databases that we do not want to check compatibility level"
167+
Set-PSFConfig -Module dbachecks -Name database.guestuser.excludedb -Value @('master', 'tempdb', 'msdb') -Initialize -Description "A list of databases that we do not want to check guest user connect permissions for"
167168

168169
Set-PSFConfig -Module dbachecks -Name policy.database.filegrowthdaystocheck -Value $null -Initialize -Description "The number of days to go back to check for growth events"
169170
Set-PSFConfig -Module dbachecks -Name policy.database.trustworthyexcludedb -Value @('msdb') -Initialize -Description "A List of databases that we do not want to check for Trustworthy being on"

source/internal/functions/Get-AllDatabaseInfo.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ function Get-AllDatabaseInfo {
135135
$compatibilityLevel = $true
136136
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'compatexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'database.compatibilitylevel.excludedb').Value
137137
}
138+
'GuestUserConnect' {
139+
$guestUserConnect = $true
140+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'guestuserexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'database.guestuser.excludedb').Value
141+
}
138142
Default { }
139143
}
140144

@@ -169,6 +173,7 @@ function Get-AllDatabaseInfo {
169173
QueryStore = @(if ($qs) { $psitem.QueryStoreOptions.ActualState })
170174
CompatibilityLevel = @(if ($compatibilitylevel) { $psitem.CompatibilityLevel })
171175
ServerLevel = @(if ($compatibilitylevel) { [Enum]::GetNames('Microsoft.SqlServer.Management.Smo.CompatibilityLevel').Where{ $psitem -match $Instance.VersionMajor } })
176+
GuestUserConnect = @(if ($guestUserConnect) { if ($psitem.EnumDatabasePermissions('guest') | Where-Object { $_.PermissionState -eq 'Grant' -and $_.PermissionType.Connect }) { $true } } )
172177
}
173178
}
174179
}

0 commit comments

Comments
 (0)