A New Microsoft 365 Audit Platform Service Plan, App Governance, and Fetching Service Principal Sign-in Information
Service principals are one of the fundamental underpinnings of application interaction with Azure AD. One way of thinking about service principals is that they’re a convenient container for holding the permissions granted to applications. This applies both to the set of applications registered by a tenant and enterprise applications created by a publisher like Microsoft or Apple and intended for use in many Microsoft 365 tenants.
Which brings me to MC549532 (Last updated Jun 9, 2023), announcing that Microsoft is adding a new Microsoft 365 Audit Platform service plan and adding the new service plan to accounts licensed to use the app governance add-on for Microsoft Defender for Cloud Apps (like accounts with Office 365 E5 licenses). The idea behind app governance is that it gives administrators better insight into the set of apps within the tenant. The original implementation in 2021 wasn’t great, but app governance is more comprehensive and useful now.
App Governance
Knowing what apps are present and the permissions held by the apps is important. Attackers like to plant OAuth apps in compromised tenant and use the apps to access data (here’s an example of an attack on Exchange Online). Reviewing the information available in app governance is helpful, but only if administrators take the time to look through the data and have sufficient knowledge about the apps in the tenant to know when something isn’t quite right.
App governance (Figure 1) includes app policies with “machine learning-based detection algorithms” to search for odd conditions within the tenant that can indicate the existence of an app that isn’t quite right. A set of predefined policies deliver immediate insight into the state of the tenant. If that coverage isn’t sufficient, administrators can tailor custom policies to address specific requirements.
Figure 1: Policies available in App Governance in the Microsoft 365 Defender portal
Of course, not every tenant has Office 365 E5 or above licenses. If you’re in this situation, you can create your own automated checks (like this one using PowerShell running in Azure Automation) to look for anomalous conditions and report back to administrators.
Understanding Service Principal Sign-In Activity
The point is that tools exist to help organizations understand what’s happening within their Microsoft 365 tenant. The data is there if you go looking for it. For example, the Graph API (beta) includes a servicePrincipalSignInActivity resource. This is interesting because it allows tenants to know the last time apps use service principals to sign in. If an app isn’t being used, it becomes a candidate for removal unless a good case exists for its retention.
It’s easy to use the List servicePrincipalSignInActivities API to fetch sign-in activity information for service principals. The information returned is in a series of hash tables (one per service principal), so a little effort is necessary to parse the content of the hash tables and make them human-friendly.
Here’s a PowerShell script to:
Connect to the Microsoft Graph PowerShell SDK with the AuditLog.Read.All scope (permission) needed to access audit data.
Select the beta endpoint.
Use the Invoke-MgGraphRequest cmdlet to fetch the sign in information for service principals.
For each record, fetch some information about the service principal (display name, publisher, and creation date) and extract the last sign in date and time for both application and delegate access.
Capture the information in a PowerShell list.
Connect-MgGraph -Scopes AuditLog.Read.All
Select-MgProfile Beta
[array]$AuditData = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/beta/reports/servicePrincipalSignInActivities"
If (!($AuditData)) { Write-Host "Error fetching service principal sign in activity data..." ; break }
$AuditData = $AuditData.Value
$Report = [System.Collections.Generic.List[Object]]::new()
ForEach ($SP in $AuditData) {
$SpAppId = $SP['appId']
$ServicePrincipal = Get-MgServicePrincipal -Filter "Appid eq '$SpAppId'"
$SPName = $ServicePrincipal.DisplayName
If ($SPName) {
$SPCreatedDate = Get-Date($ServicePrincipal.additionalProperties.createdDateTime) -format g
} Else {
$SPCreatedDate = $Null }
$ReportLine = [PSCustomObject]@{
AppId = $SP['appId']
'Display name' = $ServicePrincipal.DisplayName
Publisher = $ServicePrincipal.PublisherName
'Sign in audience' = $ServicePrincipal.SignInAudience
'Last sign in' = $SP['lastSignInActivity'].lastSignInDateTime
'Last app sign in' = $SP['applicationAuthenticationClientSignInActivity'].lastSignInDateTime
'Last delegate sign in' = $SP['delegatedClientSignInActivity'].lastSignInDateTime
}
$Report.Add($ReportLine)
}
# Filter out the records that can't be resolved against service principals in the tenant
$ReportSPs = $Report | Where-Object {$Null -ne $_.'Display name'}
$ReportSPs | Out-GridView
When I ran the script in my tenant, Azure AD responded with sign-in information for 347 application identifiers. However, many of these application identifiers could not be resolved in the tenant. I suspect that some belong to deleted apps and some are owned by Microsoft internal processes. I’m following up on this point. To clean things up, I create an array of service principals with complete information, shown using the Out-GridView cmdlet in Figure 2.
Figure 2: Azure AD Service Principals and sign-in information
The list includes many Microsoft apps (not all stamped with a publisher name), some tenant apps, and some apps from other sources like idPowerToys.
The Persistence of the iOS Accounts App
We also see the iOS Accounts app from Apple used to reset iOS devices with modern authentication during the deprecation of basic authentication for Exchange Online last year. On the surface, that app is a candidate for removal because none of the iOS devices in the tenant need reconfiguration to work with Exchange Online, but I see a last sign-in date of 11 June 2023 at 20:46. That’s a delegate access, implying that a user invoked the app in some way. Maybe iOS is still checking to be sure that basic authentication is dead and gone. That’s yet another thing to follow up.
Learn how to exploit the data available to Microsoft 365 tenant administrators through the Office 365 for IT Pros eBook. We love figuring out how things work.
{"id":null,"mode":"button","open_style":"in_modal","currency_code":"EUR","currency_symbol":"\u20ac","currency_type":"decimal","blank_flag_url":"https:\/\/office365itpros.com\/wp-content\/plugins\/tip-jar-wp\/\/assets\/images\/flags\/blank.gif","flag_sprite_url":"https:\/\/office365itpros.com\/wp-content\/plugins\/tip-jar-wp\/\/assets\/images\/flags\/flags.png","default_amount":100,"top_media_type":"featured_image","featured_image_url":"https:\/\/office365itpros.com\/wp-content\/uploads\/2022\/11\/cover-141x200.jpg","featured_embed":"","header_media":null,"file_download_attachment_data":null,"recurring_options_enabled":true,"recurring_options":{"never":{"selected":true,"after_output":"One time only"},"weekly":{"selected":false,"after_output":"Every week"},"monthly":{"selected":false,"after_output":"Every month"},"yearly":{"selected":false,"after_output":"Every year"}},"strings":{"current_user_email":"","current_user_name":"","link_text":"Virtual Tip Jar","complete_payment_button_error_text":"Check info and try again","payment_verb":"Pay","payment_request_label":"Office 365 for IT Pros","form_has_an_error":"Please check and fix the errors above","general_server_error":"Something isn't working right at the moment. Please try again.","form_title":"Office 365 for IT Pros","form_subtitle":null,"currency_search_text":"Country or Currency here","other_payment_option":"Other payment option","manage_payments_button_text":"Manage your payments","thank_you_message":"Thank you for supporting the work of Office 365 for IT Pros!","payment_confirmation_title":"Office 365 for IT Pros","receipt_title":"Your Receipt","print_receipt":"Print Receipt","email_receipt":"Email Receipt","email_receipt_sending":"Sending receipt...","email_receipt_success":"Email receipt successfully sent","email_receipt_failed":"Email receipt failed to send. Please try again.","receipt_payee":"Paid to","receipt_statement_descriptor":"This will show up on your statement as","receipt_date":"Date","receipt_transaction_id":"Transaction ID","receipt_transaction_amount":"Amount","refund_payer":"Refund from","login":"Log in to manage your payments","manage_payments":"Manage Payments","transactions_title":"Your Transactions","transaction_title":"Transaction Receipt","transaction_period":"Plan Period","arrangements_title":"Your Plans","arrangement_title":"Manage Plan","arrangement_details":"Plan Details","arrangement_id_title":"Plan ID","arrangement_payment_method_title":"Payment Method","arrangement_amount_title":"Plan Amount","arrangement_renewal_title":"Next renewal date","arrangement_action_cancel":"Cancel Plan","arrangement_action_cant_cancel":"Cancelling is currently not available.","arrangement_action_cancel_double":"Are you sure you'd like to cancel?","arrangement_cancelling":"Cancelling Plan...","arrangement_cancelled":"Plan Cancelled","arrangement_failed_to_cancel":"Failed to cancel plan","back_to_plans":"\u2190 Back to Plans","update_payment_method_verb":"Update","sca_auth_description":"Your have a pending renewal payment which requires authorization.","sca_auth_verb":"Authorize renewal payment","sca_authing_verb":"Authorizing payment","sca_authed_verb":"Payment successfully authorized!","sca_auth_failed":"Unable to authorize! Please try again.","login_button_text":"Log in","login_form_has_an_error":"Please check and fix the errors above","uppercase_search":"Search","lowercase_search":"search","uppercase_page":"Page","lowercase_page":"page","uppercase_items":"Items","lowercase_items":"items","uppercase_per":"Per","lowercase_per":"per","uppercase_of":"Of","lowercase_of":"of","back":"Back to plans","zip_code_placeholder":"Zip\/Postal Code","download_file_button_text":"Download File","input_field_instructions":{"tip_amount":{"placeholder_text":"How much would you like to tip?","initial":{"instruction_type":"normal","instruction_message":"How much would you like to tip? Choose any currency."},"empty":{"instruction_type":"error","instruction_message":"How much would you like to tip? Choose any currency."},"invalid_curency":{"instruction_type":"error","instruction_message":"Please choose a valid currency."}},"recurring":{"placeholder_text":"Recurring","initial":{"instruction_type":"normal","instruction_message":"How often would you like to give this?"},"success":{"instruction_type":"success","instruction_message":"How often would you like to give this?"},"empty":{"instruction_type":"error","instruction_message":"How often would you like to give this?"}},"name":{"placeholder_text":"Name on Credit Card","initial":{"instruction_type":"normal","instruction_message":"Enter the name on your card."},"success":{"instruction_type":"success","instruction_message":"Enter the name on your card."},"empty":{"instruction_type":"error","instruction_message":"Please enter the name on your card."}},"privacy_policy":{"terms_title":"Terms and conditions","terms_body":null,"terms_show_text":"View Terms","terms_hide_text":"Hide Terms","initial":{"instruction_type":"normal","instruction_message":"I agree to the terms."},"unchecked":{"instruction_type":"error","instruction_message":"Please agree to the terms."},"checked":{"instruction_type":"success","instruction_message":"I agree to the terms."}},"email":{"placeholder_text":"Your email address","initial":{"instruction_type":"normal","instruction_message":"Enter your email address"},"success":{"instruction_type":"success","instruction_message":"Enter your email address"},"blank":{"instruction_type":"error","instruction_message":"Enter your email address"},"not_an_email_address":{"instruction_type":"error","instruction_message":"Make sure you have entered a valid email address"}},"note_with_tip":{"placeholder_text":"Your note here...","initial":{"instruction_type":"normal","instruction_message":"Attach a note to your tip (optional)"},"empty":{"instruction_type":"normal","instruction_message":"Attach a note to your tip (optional)"},"not_empty_initial":{"instruction_type":"normal","instruction_message":"Attach a note to your tip (optional)"},"saving":{"instruction_type":"normal","instruction_message":"Saving note..."},"success":{"instruction_type":"success","instruction_message":"Note successfully saved!"},"error":{"instruction_type":"error","instruction_message":"Unable to save note note at this time. Please try again."}},"email_for_login_code":{"placeholder_text":"Your email address","initial":{"instruction_type":"normal","instruction_message":"Enter your email to log in."},"success":{"instruction_type":"success","instruction_message":"Enter your email to log in."},"blank":{"instruction_type":"error","instruction_message":"Enter your email to log in."},"empty":{"instruction_type":"error","instruction_message":"Enter your email to log in."}},"login_code":{"initial":{"instruction_type":"normal","instruction_message":"Check your email and enter the login code."},"success":{"instruction_type":"success","instruction_message":"Check your email and enter the login code."},"blank":{"instruction_type":"error","instruction_message":"Check your email and enter the login code."},"empty":{"instruction_type":"error","instruction_message":"Check your email and enter the login code."}},"stripe_all_in_one":{"initial":{"instruction_type":"normal","instruction_message":"Enter your credit card details here."},"empty":{"instruction_type":"error","instruction_message":"Enter your credit card details here."},"success":{"instruction_type":"normal","instruction_message":"Enter your credit card details here."},"invalid_number":{"instruction_type":"error","instruction_message":"The card number is not a valid credit card number."},"invalid_expiry_month":{"instruction_type":"error","instruction_message":"The card's expiration month is invalid."},"invalid_expiry_year":{"instruction_type":"error","instruction_message":"The card's expiration year is invalid."},"invalid_cvc":{"instruction_type":"error","instruction_message":"The card's security code is invalid."},"incorrect_number":{"instruction_type":"error","instruction_message":"The card number is incorrect."},"incomplete_number":{"instruction_type":"error","instruction_message":"The card number is incomplete."},"incomplete_cvc":{"instruction_type":"error","instruction_message":"The card's security code is incomplete."},"incomplete_expiry":{"instruction_type":"error","instruction_message":"The card's expiration date is incomplete."},"incomplete_zip":{"instruction_type":"error","instruction_message":"The card's zip code is incomplete."},"expired_card":{"instruction_type":"error","instruction_message":"The card has expired."},"incorrect_cvc":{"instruction_type":"error","instruction_message":"The card's security code is incorrect."},"incorrect_zip":{"instruction_type":"error","instruction_message":"The card's zip code failed validation."},"invalid_expiry_year_past":{"instruction_type":"error","instruction_message":"The card's expiration year is in the past"},"card_declined":{"instruction_type":"error","instruction_message":"The card was declined."},"missing":{"instruction_type":"error","instruction_message":"There is no card on a customer that is being charged."},"processing_error":{"instruction_type":"error","instruction_message":"An error occurred while processing the card."},"invalid_request_error":{"instruction_type":"error","instruction_message":"Unable to process this payment, please try again or use alternative method."},"invalid_sofort_country":{"instruction_type":"error","instruction_message":"The billing country is not accepted by SOFORT. Please try another country."}}}},"fetched_oembed_html":false}
I believe that iOS Accounts / Apple Internet Accounts is always required for multi-factor authentication via the iOS (and macOS) Mail app.
If you disable the app, the native MacOS Mail and iOS Mail apps will stop working.
https://support.apple.com/en-gb/guide/deployment/dep158966b23/web
Good point! The only thing is that I use Outlook mobile, but I do know one tenant user who insists on using the iOS mail app…