d557cd6c07 | ||
---|---|---|
.. | ||
O365APItoAS-Template | ||
O365APItoAS-Template.zip | ||
azuredeploy.json | ||
azuredeploy.parameters.json | ||
azuredeploy2.json | ||
readme.md |
readme.md
Deploy Function App for getting Office 365 Management API data into Azure Sentinel
This function app will poll O365 Activity Managment API every 5 mins for logs. It is designed to get Audit.General and DLP.All events.
Deployment and Configuration
Add AAD App Permissions
- Go to Azure Active Directory / App Registrations
- Create +New Registration
- Call it "O365APItoAzureSentinel". Click Register.
- Click API Permissions Blade.
- Click Add a Permission.
- Click Office 365 Management APIs.
- Click Appplication Permissions
- Check all permissions for each category. Click Add permissions.
- Click grant admin consent for domain.com
- Click Certificates and Secrets
- Click New Client Secret
- Enter a description, select never. Click Add.
- IMPORTANT. Click copy next to the new secret and paste it somewhere temporaily. You can not come back to get the secret once you leave the blade.
- Copy the client Id from the application properties and paste it somewhere.
- Also copy the tenant Id from the AAD directory properties blade.
Create O365 API Subscription
- Open Powershell
- Run the following commands
$ClientID = "<GUID> from AAD App Registration"
$ClientSecret = "<clientSecret> from AAD App Registrtion"
$loginURL = "https://login.microsoftonline.com/"
$tenantdomain = "<domain>.onmicrosoft.com"
$TenantGUID = "<tenantguid> from AAD"
$resource = "https://manage.office.com"
$body = @{grant_type="client_credentials";resource=$resource;client_id=$ClientID;client_secret=$ClientSecret}
$oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$tenantdomain/oauth2/token?api-version=1.0 -Body $body
$headerParams = @{'Authorization'="$($oauth.token_type) $($oauth.access_token)"}
$publisher = "<randomGuid>" Get a guid from https://guidgenerator.com/
- Run this command to enable Audit.General Subscription.
Invoke-WebRequest -Method Post -Headers $headerParams -Uri "https://manage.office.com/api/v1.0/$tenantGuid/activity/feed/subscriptions/start?contentType=Audit.General&PublisherIdentifier=$Publisher"
- Run this command to enable DLP.ALL subscription
Invoke-WebRequest -Method Post -Headers $headerParams -Uri "https://manage.office.com/api/v1.0/$tenantGuid/activity/feed/subscriptions/start?contentType=DLP.ALL&PublisherIdentifier=$Publisher"
Deploy the Function App
There are 2 deployment Options.
1: Deploy via Azure ARM Template
- Deploy the template.
- Deploy permissions for the function to the Key Vault.
1: Deploy via VS Code
Note: You will need to prepare VS code for Azure function development. See https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-powershell#prerequisites
- Download the Zip file of the Azure Funciton app from Github.
- Extract to location on your machine.
- Open VS Code
- Click File -> Open Folder
- Select the Top folder from extracted files.
- Type Crtl+Shift+P.
- Click Azure Functions: Deploy to function app. You maybe asked to sign in to azure.
- Click Create New function app in Azure (advanced)
- Provide a unique name like "O365APItoAS". Press Enter
- Click Windows
- Click Consumption
- Click PowerShell
- Click Create new Resource Group
- Press enter to accept the name
- Click Create a new storage Account
- Press enter to accept the name
- Click Create new Application Insights resource
- Press enter to accept the name
- Pick a location
- Deployment will begin.
- Wait for the deployment to complete, then click upload settings in the bottom right
- Click yes to all to upload.
- Go to the Azure Portal.
- Go to the resource group that was created. Click the Function.
- Click Stop.
- Click Platform Features Tab.
- Click Identity
- Click On under system assigned. Click Save. Click Yes.
Create a Key Vault
- Go to the Azure Portal.
- Go to the resource group that was created. Click Add.
- Type Key Vault.
- Create a Key vault.
- Go to the resource created.
- Click Access Policies.
- Click Add Access Policy
- Select Secret Management from Configure from template
- Click Select Principal
- Search for the name of the function app. Click Select.
- Click Add.
- Click Save
- Click Secrets
- Click Generate
- Enter O365Tenant1_clientsecret. Paste the AAD app secret. Click Create.
- Click Generate
- Enter O365workspaceKey. Paste the Azure Sentinel Workspace Key. Click Create.
- Click O365clientsecret and copy the current version string to a temp location.
- Click O365workspaceKey and copy the current version stringto a temp location.
- Go to the Overiew blade. Copy the DNS Name to a temp location. Note: you will need to create additional keys if you have multiple tenants.
Confiugure Settings for the Function
- Go to the Azure Portal.
- Go to the resource group that was created. Click the Function.
- Click Platform Features Tab.
- Click Configuration under General.
- click edit next to clientSecret.
- Update the value using your copied properties.
- @Microsoft.KeyVault(SecretUri=https:///secrets/O365Tenant1_clientSecret/)
- Click Ok.
- click edit next to workspaceKey.
- Update the value using your copied properties
- @Microsoft.KeyVault(SecretUri=https:///secrets/O365workspacekey/)
- Click Ok.
- Update each setting
- clientID = AAD app registration id
- contentTypes = Audit.General or Audit.General,DLP.All or DLP.All
- domain = from .onmicrosoft.com
- publisher is a random guid for throttling that we used in steps to create subscription.
- recordTypes This can be 0 or a list of record types comma seperated like 28,40,41 (see https://docs.microsoft.com/en-us/office/office-365-management-api/office-365-management-activity-api-schema#auditlogrecordtype)
- tenantGuid is your AAD tenant guid.
- workspaceId is your Azure Sentinel workspace id
- Click Save
- Go back to the function and click start under the overview blade.