Skip to content

Commit 3c0ad47

Browse files
so that we cna check for public role perms #882
1 parent 1573d64 commit 3c0ad47

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

source/checks/Instancev5.Tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,16 @@ Describe "Login SA cannot exist" -Tag SaExist, CIS, Medium, Instance -ForEach $I
367367
}
368368
}
369369

370+
Describe "Public Role Permissions" -Tag PublicPermission, PublicRolePermission, Security, CIS, Instance -ForEach $InstancesToTest {
371+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.PublicPermission' }).Value
372+
373+
Context "Testing if the public role permissions don't have permissions on <_.Name>" {
374+
It "All permissions should be set to CIS standards on the public role on <_.Name>" -Skip:$skip {
375+
$PsItem.PublicRolePermissions | Should -Be 0 -Because "We expected the public role to have no permissions for CIS compliance."
376+
}
377+
}
378+
}
379+
370380
Describe "SA Login Renamed" -Tag SaRenamed, DISA, CIS, Medium, Instance -ForEach $InstancesToTest {
371381
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.SaRenamed' }).Value
372382
Context "Checking that sa login has been renamed on <_.Name>" {

source/internal/functions/NewGet-AllInstanceInfo.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,21 @@ function NewGet-AllInstanceInfo {
416416
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings], $LoginInitFields)
417417
}
418418

419+
{ 'PublicRolePermissions' -or 'PublicPermission' } {
420+
#This needs to be done in query just in case the account had already been renamed
421+
$query = "
422+
SELECT Count(*) AS [RowCount]
423+
FROM master.sys.server_permissions
424+
WHERE (grantee_principal_id = SUSER_SID(N'public') and state_desc LIKE 'GRANT%')
425+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'VIEW ANY DATABASE' and class_desc = 'SERVER')
426+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 2)
427+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 3)
428+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 4)
429+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 5);
430+
"
431+
$PublicRolePermsCount = $srv.Query($query).RowCount
432+
}
433+
419434
'SuspectPageLimit' {
420435
$sql = "Select
421436
COUNT(file_id) as 'SuspectPageCount'
@@ -620,6 +635,7 @@ function NewGet-AllInstanceInfo {
620635
LoginPasswordExpirationCount = $LoginPasswordExpirationCount
621636
AgentServiceAdminExist = $AgentServiceAdminExist
622637
SqlEngineServiceAccount = $SqlEngineServiceAccount
638+
PublicRolePermissions = $PublicRolePermsCount
623639
# TempDbConfig = [PSCustomObject]@{
624640
# TF118EnabledCurrent = $tempDBTest[0].CurrentSetting
625641
# TF118EnabledRecommended = $tempDBTest[0].Recommended

0 commit comments

Comments
 (0)