Jenkins Audit log

Jenkins is an open-source automation server that is widely used for Continuous Integration and Continuous Deployment (CI/CD) processes. It provides a wide range of features, including pipeline support, build triggers, build agents, and plugins. With such a complex setup and multiple users involved in the development process, it becomes crucial to have a mechanism to track and audit all the activities happening within Jenkins. This is where the Jenkins audit log comes into play.

Overview of Jenkins Audit Log

The Jenkins audit log is a feature that allows you to track and monitor all the activities happening within your Jenkins server. It helps in identifying potential security issues, tracking down user actions, and maintaining an audit trail for compliance purposes. The audit log records events such as user login/logout, job creation/update/deletion, configuration changes, build triggers, plugin installation/removal, etc.

Enabling Audit Logging in Jenkins

To enable audit logging in Jenkins, you need to install the Audit Log plugin. Follow these steps to enable audit logging:

1. Navigate to the Jenkins dashboard and click on “Manage Jenkins” in the left-hand sidebar.

2. Click on “Manage Plugins” to open the plugin manager.

3. In the “Available” tab, search for “Audit Log” using the search box.

4. Check the checkbox next to the “Audit Log” plugin and click on “Download now and install after restart”.

5. Once the plugin is installed, restart Jenkins http request to apply the changes.

Configuring Audit Log Settings  

After enabling the Audit Log plugin, you can configure the audit log settings as per your requirements. Follow these steps to configure the audit log settings:

1. Navigate to the Jenkins dashboard and click on “Manage Jenkins” in the left-hand sidebar.

2. Click on “Configure System” to open the system configuration page.

3. Scroll down to the “Audit Log” section.

4. Enable the “Enable Audit Logging” checkbox to start recording audit events.

5. Specify the path where you want to store the audit log file. By default, the log file is stored in the `.jenkins/audit.log` file within the Jenkins home directory.

6. Choose the log rotation strategy. You can select “None” to keep the log file unlimited in size, or you can choose “Size” or “Time” to rotate the log file based on size or time intervals.

7. Set the maximum log file size or time interval, depending on the log rotation strategy chosen.

8. Click on “Save” to apply the changes.

Accessing the Audit Log

To access the audit log, you can either navigate to the log file location specified in the configuration or use the Jenkins UI. Follow these steps to access the audit log via the Jenkins UI:

1. Navigate to the Jenkins dashboard and click on “Manage Jenkins” in the left-hand sidebar.

2. Click on “System Log” to open the log viewer.

3. In the log viewer, you can filter the logs by selecting “Audit Log” from the “Loggers” dropdown.

4. You can also specify additional filters based on log level, message text, or time range.

5. Click on “Search” to retrieve the audit log events based on the specified filters.

Interpreting and Analyzing the Audit Log

The audit log provides a detailed record of all the activities happening within your Jenkins server. It includes information such as the username, timestamp, event type, event description, and IP address of the user performing the action. By analyzing the audit log, you can gain insights into the usage patterns, identify any suspicious activities, and ensure compliance with organizational policies.

Here’s an example of how an audit log entry looks like:

2022-01-01 12:34:56 INFO jenkins.model.Jenkins audit [username]: [event-type] [event-description]

In this log entry, `[username]` represents the username of the user performing the action. `[event-type]` represents the type of event, such as “LOGIN”, “JOB_CREATED”, “JOB_UPDATED”, “PLUGIN_INSTALLED”, etc. `[event-description]` provides additional details about the event, such as the job name, plugin name, or configuration changes.

By parsing and analyzing the audit log, you can generate reports, detect anomalies, and flag any suspicious activities. For example, you can track user access patterns, identify any unauthorized configuration changes, or monitor the installation/removal of plugins.

Sample Audit Log Analysis with Python

To demonstrate how to analyze the Jenkins audit log, let’s consider a scenario where we want to monitor the installation and removal of plugins. We can use Python and regular expressions to parse the audit log and extract the relevant information.

Here’s a sample Python script that reads the Jenkins logs file and prints the details of plugin installation and removal events:

import re

audit_log_file = "/path/to/audit.log"

plugin_installation_regex = re.compile(r'\[username\]: PLUGIN_INSTALLED \[(.*)\]')

plugin_removal_regex = re.compile(r'\[username\]: PLUGIN_REMOVED \[(.*)\]')

with open(audit_log_file, 'r') as file:

for line in file:

match = plugin_installation_regex.search(line)

if match:

print(f"Plugin installed: {match.group(1)}")

match = plugin_removal_regex.search(line)

if match:

print(f"Plugin removed: {match.group(1)}")

In this script, we define two regular expressions (`plugin_installation_regex` and `plugin_removal_regex`) to match the plugin installation and removal events based on the log entry format.

By iterating through each line of the audit log file, we search for matches using the regular expressions. If a match is found, we extract the plugin name and print the corresponding event.

The Jenkins audit log is a powerful tool for tracking and monitoring all the activities happening within your Jenkins server. It helps in maintaining a record of user actions, identifying potential security issues, and ensuring compliance with organizational policies. By enabling and configuring the audit log, you can gain insights into the usage patterns, detect anomalies, and generate reports for analysis. By leveraging scripting languages like Python, you can parse and analyze the audit log to extract specific information and perform custom analysis based on your requirements.

Do you like to read more educational content? Read our blogs at Cloudastra Technologies or contact us for business enquiry at Cloudastra Contact Us .

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top