Starting with syslog-ng PE version 7.0.17, you can fetch logs from your Office 365 account using the Office 365 Management Activity API.
The syslog-ng PE application supports every content type of the Management Activity API using a corresponding source driver:
-
Audit.AzureActiveDirectory: office365-azure-active-directory()
-
Audit.Exchange: office365-exchange()
-
Audit.General: office365-general()
-
Audit.SharePoint: office365-sharepoint()
-
DLP.All: office365-dlp()
Limitations
-
In some cases, the logs will appear only 24-48 hours after successfully configuring syslog-ng PE and Office 365.
-
Due to the distributed nature of the Office 365 log management architecture, there is a synchronization interval in the Office 365 Management Activity API. During this interval, the messages returned to queries can be inconsistent. To avoid this synchronization window, syslog-ng PE does not fetch the logs in real-time, only 15 minutes after the message becomes available in the management API. This means that there is a 15-minute latency between the logs available in the Office 365 Management Activity API and syslog-ng PE.
Declaration
source s_office365 {
office365-<content-type>(
tenant_id('tenant-id')
client_id('client-id')
client_secret('client-secret')
);
};
Example: Fetching Azure Active Directory logs from Office 365
The following example configuration fetches logs from and Audit.AzureActiveDirectory subscription using the office365-azure-active-directory() source driver.
@version: 7.0
@include "scl.conf"
source s_o365_ad {
office365-azure-active-directory(
tenant_id('tenant-id')
client_id('client-id')
client_secret('client-secret')
);
};
destination d_file { file("/tmp/o365_ad_out.log"); };
log {
source(s_o365_ad);
destination(d_file);
flags(flow-control);
};
This procedure summarizes how to configure Office 365 to permit syslog-ng Premium Edition (syslog-ng PE) to fetch log messages using the Office 365 Management Activity API.
Prerequisites
-
A valid Office 365 account (for example: Azure Active Directory Premium P2).
-
Administrator permissions to the Office 365 account.
-
Content subscription must be enabled for the content types you want to fetch logs from.
-
syslog-ng Premium Edition version 7.0.15 or later.
-
The syslog-ng PE application communicates with the Management Activity API through a service app registered in Azure. Complete the following steps to register a service app. For details on registering an app, see the Office 365 documentation.
-
Login to https://portal.azure.com.
-
Register a new web application (for example, syslog-service-app).
-
Grant all application permissions and delegated permissions to the created app.
-
Create secret (password) for the app. Record the password somewhere, as you will need it later to configure syslog-ng PE. If you set an expiration to the password, make sure to renew the password and update it in your syslog-ng PE configuration file before it expires.
-
Alternatively: Add your client's certificate to the app's Certificates. Make sure to renew the certificate and update your syslog-ng PE configuration before the certificate expires.
NOTE: Key and certificate pairs generated with client_server_auth extension do not work in certificate based authentication.
-
In the authentication settings of the new app, enable Access Tokens.
-
Enabling audit logging in Office 365. Note that your user must have an administrator permissions to enable audit logging. For details on enabling audit logging, see the Office 365 documentation. If you have problems enabling audit logging, see Troubleshooting audit logging in Office 365
-
Start content subscriptions for the content types you want to fetch logs from using the following command. The office365subscriptiontool utility is automatically installed with syslog-ng PE version 7.0.15 and newer.
%syslog-ng-installation-directory%/bin/office365subscriptiontool start --tenant-id=[your tenant-id] --client-id=[your client-id] --client-secret=[your client-secret in escaped format] --content-type=[content-type-to-fetch-logs-from]
Note that special characters (for example, ?/*+!$) in the client secret must be escaped (according to the rules of escaping in bash/shell) when starting the content subscription.
Here's an example for office365subscriptiontool utility in case of using certificate and key pair to authenticate instead of client secret:
%syslog-ng-installation-directory%/bin/office365subscriptiontool start --tenant-id=[your tenant-id] --client-id=[your client-id] --client-key=[path to the client's private key] --client-cert=[path to the cert added to the service app] --content-type=[content-type-to-fetch-logs-from]
In your syslog-ng PE configuration, you will have to use the source driver matching the content type of the content subscription. For example, use the office365-azure-active-directory() driver for the Audit.AzureActiveDirectory content type.
Repeat this step for every content type you want to fetch logs from.
NOTE: When a subscription is created, it can take up to 12 hours for the first content blobs to become available for that subscription.
The office365() drivers have the following options. The tenant-id(), client-id(), and client-secret() option is required, the others are optional.
client-secret()
Description: The password of the service app. For details, see Configuring Office 365 to permit fetching logs.
If you set an expiration to the password, make sure to renew the password and update it in your syslog-ng PE configuration file before it expires.
NOTE: client-secret() and client-cert(), client-key() options are mutually exclusive, only one is accepted in the same source configuration.
client-cert()
Description: The path to the certificate added to the service app. For details, see Configuring Office 365 to permit fetching logs.
Make sure to renew the certificate and update your syslog-ng PE configuration before the certificate expires.
NOTE: client-cert() and client-key() are both mandatory in case of certificate based authentication.
client-key()
Description: The path to the private key belonging to the certificate which was added to the service app. For details, see Configuring Office 365 to permit fetching logs.
NOTE: client-cert() and client-key() are both mandatory in case of certificate based authentication.
fetch-no-data-delay()
Description: When there are no messages available in a poll event, the Office 365 Management Activity API waits fetch-no-data-delay() seconds before the next poll.
NOTE: You can set the fetch-no-data-delay() value to fractions, for example:
fetch-no-data-delay(0.5)
persist-name()
Type: |
string |
Default: |
None |
Description:If you receive the following error message during syslog-ng PE startup, set the persist-name() option of the duplicate drivers:
Error checking the uniqueness of the persist names, please override it with persist-name option. Shutting down.
This error occurs if you use identical drivers in multiple sources, for example, if you configure two file sources to read from the same file. In this case, set the persist-name() of the drivers to a custom string, for example, persist-name("example-persist-name1").
tenant-id()
Description: The ID of the Tenant that the Office 365 account belongs to.
time-reopen()
Accepted values: |
number [seconds] |
Default: |
60 |
Description: The time to wait in seconds before a dead connection is reestablished.
By default, this option uses the value set in the time-reopen() global option.
If you have trouble with enabling audit logging in Office 365, complete the following steps.
-
Login to https://protection.office.com/.
-
Verify that the Search > Audit log search context is active. If it is not, execute the following commands from PowerShell:
$ $UserCredential = Get-Credential
# use your Azure account
$ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
$ Import-PSSession $Session -DisableNameChecking
$ Enable-OrganizationCustomization
# Wait 4 hours
$ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true
# Wait 1 hour
$ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $false
# Wait 1 hour
$ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true
# Wait 1 hour
-
Login to https://protection.office.com/ and check if there are audit logs under Search > Audit log search. Note that in some cases, the logs will appear only after 24-48 hours.