fix: handle additional Microsoft Graph authorization errors for signInActivity retry#181
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Hey @ferreirasc, thank you for the contribution! I have this on my radar and plan to review soon 🙂 |
AzureHound collects
signInActivityfor users by including it in the$selectparameterwhen calling the Microsoft Graph
/usersendpoint. When the principal lacks the requiredAuditLog.Read.Allpermission, AzureHound is designed to detect the authorization error,log a warning, and retry the request without
signInActivity.However, this retry logic only covered one specific error code
(
Authentication_MSGraphPermissionMissing), leaving other scenariosunhandled, causing the retry to not trigger and the collection to fail.
When authenticating using a FOCI token (e.g. MSOffice), the Graph API responds to the
signInActivityrequest withHTTP 403 and error code
UnknownErroralong with a message like:This is semantically the same authorization denial, but the error code differs from the standard
Authentication_MSGraphPermissionMissing, so the original check never matched and the retry never happened, resulting in aERR unable to continue processing userserror — even though user enumeration without signInActivity would have succeeded, as the principal has the required User.Read.All permission.Same happens when the authenticated principal has a role that does not support reading
signInActivity(e.g. a non-privileged role lacking
AuditLog.Read.All), the Graph API returns:This error was also not covered, so the retry was never triggered. And this is probably the root cause for the following issue btw: #173.
Changes
The
isGraphAuthorizationDeniedfunction incmd/list-users.gowas extended to recognizeall three authorization denial scenarios:
Authentication_MSGraphPermissionMissing+auditlog.read.allin the message(existing behavior — app registration without the required application permission)
UnknownError+does not have authorizationin the message(new — FOCI/delegated token scenarios; broadened from the Office-specific message to
cover any client that produces this pattern)
Authentication_RequestFromUnsupportedUserRole(new — principal role does not support reading signInActivity)
The existing single-case test in
TestIsGraphAuthorizationDeniedwas also refactored intoa table-driven test covering all three positive cases plus an unrelated error and a nil
error, to prevent regressions.
Files changed
Summary by CodeRabbit
Bug Fixes
Tests