Skip to content

Optimize 21814 - Privileged accounts are cloud native identities - #1572

Merged
Anton Staykov (astaykov) merged 10 commits into
devfrom
optimize-21814
Oct 16, 2026
Merged

Anton Staykov (astaykov) merged 10 commits into
devfrom
optimize-21814

Conversation

@sandeepjha000

Copy link
Copy Markdown
Collaborator

Copilot AI balanced review requested due to automatic review settings October 9, 2026 04:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

User counts can be overstated, deprecated metadata remains, and the new database behavior lacks focused tests.

1 open finding
What changed in this PR

Optimizes assessment 21814 by replacing per-user Graph calls with exported database queries.

Changes:

  • Queries privileged role users from vwRole and User.
  • Evaluates synchronization status from cached data.
  • Simplifies result generation and metadata.
File Description
src/​powershell/​tests/​Test-Assessment.21814.ps1 Migrates assessment logic and reporting to database-backed role data.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/powershell/tests/Test-Assessment.21814.ps1
Copilot AI balanced review requested due to automatic review settings October 9, 2026 04:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The reported user count can overcount identities, deprecated metadata remains, and the migration lacks regression tests.

1 open finding
Previously missed (2)

In code that hasn't changed since last review

Medium severity Add Pester coverage for assessment 21814 migration cases

src/​powershell/​tests/​Test-Assessment.21814.ps1:52

This migration replaces live Graph requests with SQL over direct, eligible, and expanded group assignments, but assessment 21814 has no Pester coverage. Add database-backed cases for synced/cloud-only users, duplicate roles, group-expanded assignments, and an empty result, following the assessment-test pattern in code-tests/test-assessments/Test-Assessment.21868.Tests.ps1.

Medium severity Count distinct privileged users instead of role assignments

src/​powershell/​tests/​Test-Assessment.21814.ps1:66

SELECT DISTINCT still returns one row per role because roleDisplayName is selected, so a synced account assigned to multiple privileged roles is counted multiple times here. The message therefore reports role assignments as “privileged users”; count distinct user IDs while retaining the per-role rows for the table.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 9, 2026 05:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The database-backed implementation preserves assessment behavior while eliminating repeated Graph calls.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sandeep Jha (@sandeepjha000) Please, address my feeedback.

Comment thread src/powershell/tests/Test-Assessment.21814.ps1

$passed = $privilegedRoles.ZtUsers.onPremisesSyncEnabled -notcontains $true
#region Assessment Logic
$syncedPrivilegedRoleUsers = @($privilegedRoleUsers | Where-Object { $_.onPremisesSyncEnabled -eq $true })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Count Distinct Users Separately From Role Rows

The filtered collection at line 58 still contains one row per role/user combination:

    $syncedPrivilegedRoleUsers = @($privilegedRoleUsers | Where-Object { $_.onPremisesSyncEnabled -eq $true })

The computed count at line 65 therefore counts role rows, not distinct people. One synchronized user assigned two privileged roles was reported as two privileged users. This is a data-count issue, not a wording review.

The base implementation also counted users separately within each role, so this is an inherited limitation, not a new blocker. Keep the role rows for the table and use unique user IDs for a future user count correction.

@sandeepjha000 Sandeep Jha (sandeepjha000) removed the ready for review PR is ready for review and merging label Oct 12, 2026
Copilot AI balanced review requested due to automatic review settings October 13, 2026 04:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Export statistics are not shared with parallel test workers, making the new completeness checks unreliable.

1 open finding

🧠 Review effort: Balanced

Comment thread src/powershell/tests/Test-Assessment.21814.ps1 Outdated
Copilot AI balanced review requested due to automatic review settings October 14, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The database-backed implementation is consistent with existing export structures and has no unresolved correctness issues.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 14, 2026 03:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Confirmed policy failures are incorrectly overridden with an Investigate status when unresolved records also exist.

1 open finding

🧠 Review effort: Balanced

Comment thread src/powershell/tests/Test-Assessment.21814.ps1 Outdated
Copilot AI balanced review requested due to automatic review settings October 14, 2026 05:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Missing role-definition records can be silently excluded, allowing an incomplete export to pass.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

Comment thread src/powershell/tests/Test-Assessment.21814.ps1 Outdated
Copilot AI balanced review requested due to automatic review settings October 16, 2026 05:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No blocking issues were identified in the assessment logic or its database and reporting integration.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@astaykov
Anton Staykov (astaykov) merged commit 8bcbf35 into dev Oct 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review PR is ready for review and merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants