فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
feat(holoo): summarize inherited public mutation grants in LAB inventory
Davood Mehraban committed
Nov 22, 2026 at 23:43 UTC
dff654f1cd285c66b01b3b18815c8215618fd1f7
2 files changed
+10
-1
scripts/holoo-lab-principal-inventory.ps1
+6
-1
@@ -20,6 +20,11 @@ try {
20
$grants=Get-Rows $c "SELECT USER_NAME(p.grantee_principal_id) AS principal_name,p.state_desc,p.permission_name,p.class_desc,CASE WHEN p.class=1 THEN OBJECT_SCHEMA_NAME(p.major_id)+'.'+OBJECT_NAME(p.major_id) ELSE NULL END AS object_name FROM sys.database_permissions p ORDER BY principal_name,p.permission_name"
21
$principals=Get-Rows $c "SELECT name,type_desc FROM sys.database_principals WHERE type IN ('S','U','G','R') ORDER BY name"
22
$serverRoles=Get-Rows $c "SELECT SUSER_SNAME(srm.member_principal_id) AS member_name,SUSER_SNAME(srm.role_principal_id) AS role_name FROM sys.server_role_members srm ORDER BY member_name,role_name"
23
- $result=[pscustomobject]@{schemaVersion=1;readOnlyInventory=$true;identity=$identity[0];databasePrincipals=@($principals);databaseRoleMemberships=@($memberships);databasePermissions=@($grants);serverRoleMemberships=@($serverRoles);productionWriteGate='NO-GO';note='Metadata inventory only; inherited Windows group rights and effective privilege closure require separate review'}
23
+ # Explain inherited public privilege risk without changing any principal.
24
+ $publicGrants=@($grants|Where-Object {$_.principal_name -eq 'public' -and $_.state_desc -in @('GRANT','GRANT_WITH_GRANT_OPTION')})
25
+ $publicExecute=@($publicGrants|Where-Object {$_.permission_name -eq 'EXECUTE'})
26
+ $publicDml=@($publicGrants|Where-Object {$_.permission_name -in @('INSERT','UPDATE','DELETE')})
27
+ $risk=[pscustomobject]@{publicExecuteGrantCount=$publicExecute.Count;publicDmlGrantCount=$publicDml.Count;publicDmlTargets=@($publicDml|ForEach-Object {$_.object_name}|Sort-Object -Unique);databaseWideReadOnlyProven=$false;reason='Public grants are inherited; inventory cannot prove a future Windows principal has no effective mutation paths'}
28
+ $result=[pscustomobject]@{schemaVersion=1;readOnlyInventory=$true;identity=$identity[0];databasePrincipals=@($principals);databaseRoleMemberships=@($memberships);databasePermissions=@($grants);serverRoleMemberships=@($serverRoles);publicPrivilegeRisk=$risk;productionWriteGate='NO-GO';note='Metadata inventory only; inherited Windows group rights and effective privilege closure require separate review'}
29
if($Json){$result|ConvertTo-Json -Depth 7 -Compress}else{$result|Format-List}
30
} finally {$c.Dispose()}
tests/holoo-lab-principal-inventory.test.mjs
+4
@@ -17,5 +17,9 @@ test('live LAB principal inventory is read-only and scoped', {skip:process.platf
17
assert.equal(inventory.identity.database_name,'HolooBackup_050808_LAB_20261110');
18
assert.equal(inventory.readOnlyInventory,true);
19
assert.equal(inventory.productionWriteGate,'NO-GO');
20
+ assert.equal(inventory.publicPrivilegeRisk.publicExecuteGrantCount,31);
21
+ assert.equal(inventory.publicPrivilegeRisk.publicDmlGrantCount,3);
22
+ assert.deepEqual(inventory.publicPrivilegeRisk.publicDmlTargets,['dbo.dtproperties']);
23
+ assert.equal(inventory.publicPrivilegeRisk.databaseWideReadOnlyProven,false);
24
for(const key of ['databasePrincipals','databaseRoleMemberships','databasePermissions','serverRoleMemberships']) assert.ok(Array.isArray(inventory[key]),key);
25
});