Giter Club home page Giter Club logo

azure-tenant-activity-logs's Introduction

Collect Tenant Activity Logs

I've opened up a feedback item for adding documentation and integration with diagnostic settings. Feel free to use that request as a means to drive Microsoft to better document these logs and provide a simple means to export them.

Microsoft Azure records platform-level events to the Activity Log. The Activity Log will contain events related to the creation, modification, and deletion of Azure resources. Examples include the creation of a role assignment or modification of a Virtual Machine's network interface. It is critical for organizations to preserve and analyze these logs to maintain the security of the Azure platform.

Microsoft public documentation focuses on Activity Logs at the subcription scope. However, there are also Activity Logs at the Management Group and Tenant scope. Management Group Activity Logs include important events such as modification of Azure Policy or Azure RBAC. Tenant Activity Logs include modifications of Azure RBAC of the root scope (/).

Azure Monitor maintains 90 days worth of these logs by default. Customers must export the logs to retain longer than 90 days.Activity Logs at the subscription scope can be exported using Azure Diagnostic Settings using the Portal, CLI, or REST API. At this time, Management Group Activity logs can be exported using diagnostic settings only via the REST API. Tenant Activity Logs do not support diagnostic settings at this time and must be manually pulled from the REST API.

What problem does this solve?

This Python solution demonstrates how a service principal could be used to export Tenant Activity Logs. The logs are exported into a single JSON file which can be imported into a SIEM solution or stored in long term storage such as Azure Blob Storage.

Requirements

Azure Identity and Access Management Requirements

Setup

  1. Create a new service principal and assign the Monitoring Reader RBAC role at the root (/).
mysp=$(az ad sp create-for-rbac --name test-sp1 \
--role "Monitoring Reader" \
--scopes "/")
  1. Create environment variables for the service principal client id, client secret, and tenant name.
export CLIENT_ID=$(echo $mysp | jq -r .appId)
export CLIENT_SECRET=$(echo $mysp | jq -r .password)
export TENANT_NAME="mytenant.com"
  1. Create an environment variable for how many days back you want to query the logs for. The script accepts up to a maximum value of 89. A value of 89 will query the past 90 days.
export DAYS=7
  1. Install the appropriate supporting libraries listed in the requirements.txt file. You can optionally create a virtual environment if you want to keep the libraries isolated to the script. Remember to switch to this virtual environment before running the solution.
pip install -r requirements.txt
  1. Run the script and the output file will be produced in working directory.
python3 app.py

azure-tenant-activity-logs's People

Contributors

mattfeltonma avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.