With the arrival of the Sprint 154 updates, auditing has been introduced in the Azure DevOps. This has been a long standing demand from various enterprises (including Ours !). We wanted to observe activities and monitor changes that have occurred in the Azure DevOps across the Organization. It is in the preview phase as of this writing of this blog post, but it is very useful in the preview phase as well. In this blog post, we are going to see what is recorded in the Azure DevOps as part of the auditing, how we can access it and what we can do with the same.
Enable Auditing for Azure DevOps
First things first, how do we enable auditing for Azure DevOps? In the cloud version of Azure DevOps, auditing is enabled by default at the organization level. So you do not need to do any actions on your end to enable the same. As a security measure, you are not allowed to disable auditing. Also, if someone has viewed the audit logs, that also gets recorded. This ensures that no one escapes auditing process.
Audit events are currently stored for 90 days (not an adjustable limit). After this, they are deleted. However, you can download audit logs explained later in the post), fed to log monitoring systems and then choose to keep the audit data for longer than 90-day period.
View and Export Audit Logs
Audit logs can be viewed by going to Organization Settings -> Auditing:
You can adjust the date and time range for which you want to view the audit logs. You can also export audit logs as CSV and JSON files using the Download button in the top-right-hand side of the auditing page. Events are downloaded based on the time range you’ve selected in the filter.
Once the logs are exported, we can analyze the same using tool of our choice or we can feed it to external log monitoring system by various means. We can also use REST APIs to export this information at defined frequency to automate the whole process from end to end.
Manage Access for the Audit Logs
By default, Project Collection Administrators are the only group that can access the auditing feature.
If you are not able to view audit logs for your organization, you need to ask for the same your from your admins. This can be done by going to Security -> Permissions -> find the group or users to provide auditing access to -> Set ‘View Audit log’ to allow:
What is captured as part of Auditing
Audit events may occur in any portion of Azure DevOps; some examples of auditable events include: Git repository creations, permission changes, resource deletions, code downloads, accessing the auditing feature, and much more.
The audit events include information such as who caused the event to be logged and their IP, what happened, and other useful details that can help you answer the who, what, when, and where questions.
Below details covers what is available on the auditing page:
|Actor||Display name of the individual that triggered the audit event to be recorded|
|IP||IP address of the individual that triggered the audit event to be recorded|
|Timestamp||Time that the triggered event happened. Time is localized to your time zone|
|Area||Location in Azure DevOps where the event took place|
|Category||Description of the type of action that occurred For example, Modify, Rename, Create, Delete, Remove, Access|
|Details||Brief description of what happened during the event|
Besides what you can see on the auditing page, each audit event records additional pieces of information to what is viewable on the auditing page. This information includes the authentication mechanism, a correlation ID to link similar events together, user agent, and additional information that’s dependent on the type of audit event. This information can only be viewed by downloading auditing events.
Parse Audit logs using PowerShell
Since logs files are available in CSV and JSON, it can be easily parsed using native cmdlets such as Import-CSV and/or ConvertFrom-JSON and output can be tuned to one’s choice. Below is the quick and dirty example for same:
You can choose to use any programming language you want to.
Import Azure DevOps logs using REST API
Although you can go fed Azure DevOps logs to a variety of logs monitoring tools, the part that you need to go to Azure DevOps portal to download the logs is a manual process. Thankfully, there are REST APIs to automate this as well.
We can use below PowerShell code to download logs:
You can tune it further to your needs and run this code at defined frequencies.
Summary and Notes
Audit logs functionality is a very useful feature and we can use the same to track all the activities that have occurred in Azure DevOps. We can also download the logs using REST APIs and then fed the logs to external log monitoring systems. We can also set alerts by parsing the logs downloaded and be notified of critical events.
The source code used in this blog post might not be shown due to feature restrictions set by AMP. If you are unable to view the same, open this blog post in a full browser.
The source code used in this blog post can be found here at GitHub and is available under blog/8480 and master branches.