Bugfix/ServicePrincipal sql error when running Invoke-ZtAssessment#1189
Open
DickTracyII wants to merge 2 commits into
Open
Bugfix/ServicePrincipal sql error when running Invoke-ZtAssessment#1189DickTracyII wants to merge 2 commits into
DickTracyII wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes DuckDB view creation during Invoke-ZtAssessment by making vwRole resilient to Microsoft Graph schema changes where principal.userPrincipalName may now be returned as principal.uniqueName.
Changes:
- Updated
Get-RoleSelectSqlto resolveuserPrincipalNamevia JSON extraction with a fallback touniqueNamewhenuserPrincipalNameis absent.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
this works and tested Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Author
|
@copilot apply changes based on the comments in this thread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Handle
uniqueNamefield in role principal struct for DuckDB view creationResolves #1152
Resolves #1151
Problem
Binder Error: Could not find key "userprincipalname" in struct
Candidate Entries: "uniqueName"
Invoke-ZtAssessmentfails during the "Creating database" step with:The SQL in
Get-RoleSelectSql(Export-Database.ps1) accessedr.principal.userPrincipalNamedirectly on the DuckDB struct. A recent Microsoft Graph API change renamed this field to
uniqueNamein theprincipalobject on role assignment tables(
RoleAssignmentScheduleInstance,RoleAssignment,RoleEligibilityScheduleInstance).When the exported JSON contains
uniqueNameinstead ofuserPrincipalName, DuckDB throwsa binder error and the entire database creation fails.
Replaced the direct struct field access:
With a coalesce over json_extract_string, falling back between both field names:
coalesce( json_extract_string(r.principal::JSON, '$.userPrincipalName'), json_extract_string(r.principal::JSON, '$.uniqueName') ) as userPrincipalName,This makes the query resilient to both the old and new Graph API schema — userPrincipalName
is tried first (returns NULL if absent rather than throwing), and uniqueName is used
as the fallback.