Custom reporting for Office 365 Audit logs is possible using data fetched from the Security and Compliance center. In the previous blogs here, we have seen how to use PowerShell and Office 365 Management API to fetch the data. In this blog, we will look at planning, prerequisites and rationale to help decide between the approaches.
The Office 365 Audit logs are available from the Security and Compliance center when enabled. At present, audit logging is not enabled by default and needs to be enabled from the Security and Compliance center. This could be turned on (if not done already) via the Start recording user and admin activity on the Audit log search page in the Security & Compliance Center. In future, supposedly Microsoft will be turning it On by default. The Audit information across all Office 365 services are tracked after enabling.
The Audit log search in Security and Compliance center allows to search the audit logs but is limited in what is provided. Also it takes a long time to obtain the results. All the below cases need custom hosting to provide more efficiency and performance
Planning and prerequisites:
Few considerations for custom processes are as follows:
- Need additional compute to process the data – Create a periodic job to fetch the data from the Office 365 audit log using a custom process since the audit log data is huge and queries take a longer time. The options are using a PowerShell job or Azure Function App as detailed below.
- Need additional hosting for storing Office 365 Audit log data – The records could range from 5000 to 20000 per hour depending on the data sources and relevant data size. Hence to make it easier to retrieve the data later, store the data in a custom database. Since the data cost could be significant for this, use either dedicated hosting or NOSQL hosting such as Azure Tables/CosmosDB (Azure) or SimpleDB / DynamoDB (AWS)
- Might need additional Service Account or Azure AD App – The data will be retrieved using an elevated account at runtime so use an Azure AD app or service account to gather the data. For more information about this, please refer to this blog here.
Scenarios:
Some of the scenarios when the Office 365 Audit log data could be useful.
- Create custom reports for user activities and actions
- Store audit log data for greater than 90 days
- Custom data reporting and alerts which are not supported in Security and Compliance center
Approaches:
Below are few approaches to pull the data from the Office 365 Audit Logs. Also there is benefits and limitations of the approaches in order to help decide on implementation.
Using PowerShell
Search-UnifiedAuditLog of Exchange Online PowerShell could be used to retrieve data from Office 365 Audit log. More implementation details could be found at the blog here.
Benefits:
- Doesn’t need additional compute hosting. The PowerShell job could be run on a local system with a service account or on a server.
- One off data-pull is possible and can be retrieved later
- Able to retrieve data more than 90 days from Office 365 Audit log
- No session time out constraints as long the PowerShell console can stay active
- Local Date filtering is applicable while searching. No need to convert to GMT Formats
Limitations:
- It Need Tenant Admin rights when connecting to Exchange PowerShell to download cmdlets from Exchange Online
- Needs active connection to Exchange online PowerShell every time it runs
- It is not possible to run it on Azure or AWS at present as connection with Exchange Online PowerShell cmdlet is not possible in serverless environment
- Needs longer active window time as the job could run for hours depending on the data
Using Office 365 Management API :
The Office Management API provides another way to retrieve data from Azure Logs using a subscription service and Azure AD App. For more detailed information, please check the blog here.
Benefits:
- Support of any language such as C#, Javascript, Python etc.
- Parallel processing allows greater speed and flexibility of data management
- Controlled data pull depending on data size to increase efficiency and performance
Limitations:
- Need Additional compute hosting for serverless workloads or web jobs to process the data
- Needs an Azure AD app or OAuth layer to connect to the subscription service
- Needs additional Time zone processing since all dates are in GMT for retrieving data
- Session timeout might occur in data pull involving large datasets. So advisable to use smaller time slot windows for data pull
- Multilevel data pull required to fetch the audit log. Please check the blog here to get more information
Final Thoughts
Both PowerShell and Office 365 Management Activity APIs are a great way to fetch Office 365 Audit log data in order to create custom reports. The above points could be used to decide on an approach to fetch the data efficiently and process it. For more details on the steps of the process, please check the blog here (PowerShell) and here (Office 365 Management API).