Skip to content

Commit

Permalink
Merge pull request #975 from jpomfret/guestuserconnect
Browse files Browse the repository at this point in the history
New check - GuestUserConnect
  • Loading branch information
jpomfret authored May 31, 2023
2 parents d962e41 + 438a2a8 commit 7929a16
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions source/checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,13 @@ Describe "Compatibility Level" -Tag CompatibilityLevel, High, Database -ForEach
}
}
}

Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -ForEach $InstancesToTest {
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.security.guestuserconnect').Value

Context "Testing Guest user has CONNECT permission" {
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 } } {
$psitem.GuestUserConnect | Should -BeFalse -Because "we don't want the guest user to have connect access to our database."
}
}
}
1 change: 1 addition & 0 deletions source/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Set-PSFConfig -Module dbachecks -Name policy.database.status.excluderestoring -V
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"
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"
Set-PSFConfig -Module dbachecks -Name database.compatibilitylevel.excludedb -Value @() -Initialize -Description "A list of databases that we do not want to check compatibility level"
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"

Set-PSFConfig -Module dbachecks -Name policy.database.filegrowthdaystocheck -Value $null -Initialize -Description "The number of days to go back to check for growth events"
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"
Expand Down
5 changes: 5 additions & 0 deletions source/internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ function Get-AllDatabaseInfo {
$compatibilityLevel = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'compatexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'database.compatibilitylevel.excludedb').Value
}
'GuestUserConnect' {
$guestUserConnect = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'guestuserexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'database.guestuser.excludedb').Value
}
Default { }
}

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

0 comments on commit 7929a16

Please sign in to comment.