<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ajay K. Dhyani</title>
    <description>The latest articles on DEV Community by Ajay K. Dhyani (@ajaykdl).</description>
    <link>https://dev.to/ajaykdl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F697771%2F50885e6d-4c06-40dd-906b-d7a5377ad968.png</url>
      <title>DEV Community: Ajay K. Dhyani</title>
      <link>https://dev.to/ajaykdl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ajaykdl"/>
    <language>en</language>
    <item>
      <title>How to setup and Install Auditd on Ubuntu</title>
      <dc:creator>Ajay K. Dhyani</dc:creator>
      <pubDate>Tue, 28 Sep 2021 16:40:13 +0000</pubDate>
      <link>https://dev.to/ajaykdl/how-to-setup-auditd-on-ubuntu-jfk</link>
      <guid>https://dev.to/ajaykdl/how-to-setup-auditd-on-ubuntu-jfk</guid>
      <description>&lt;p&gt;Securing our microservice's backend infrastructure is very crucial nowadays,  managing lots of endpoints, clusters(Database, workers) is not an easy task.  In this post, I am sharing how we can use Auditd for auditing our cloud-native infrastructure. We will take a look on &lt;a href="https://kubefront.com/linux/how-to-enable-configure-auditd-on-ubuntu"&gt;&lt;strong&gt;how to install and configure Auditd on Ubuntu&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://man7.org/linux/man-pages/man8/auditd.8.html"&gt;&lt;strong&gt;Auditd&lt;/strong&gt;&lt;/a&gt; is a very light but powerful tool for managing or we can say auditing Linux-based systems using its native kernel feature called The &lt;a href="https://kubefront.com/linux/how-to-enable-configure-auditd-on-ubuntu"&gt;Linux Auditing System(LAS)&lt;/a&gt;.  LAS effectively collects some useful system activities and saves them in its own logs which helps security guys to better investigate any occurred incident.&lt;/p&gt;

&lt;p&gt;I will cover Auditd use case in another part because for better narration, for now, we will understand how we can &lt;a href="https://kubefront.com/linux/how-to-enable-configure-auditd-on-ubuntu"&gt;&lt;strong&gt;install Auditd&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Linux Ubuntu machine: Any version&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Internet for downloading stuff&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And finally, some basic Linux understanding&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install Auditd on Ubuntu Linux
&lt;/h2&gt;

&lt;p&gt;Install Bash if not present, on your Ubuntu system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;bash-completion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After these initial steps, now &lt;strong&gt;Install Auditd&lt;/strong&gt;. The following command will install Auditd's latest version on your ubuntu system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;auditd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can start and enable your auditd service so it will run up after system restart or reboot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
service status auditd

auditd start

auditd restart

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Auditd is very light, so it will not take much effort. Now time to configure Auditd on Ubuntu system.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="http://kubefront.com/linux/how-to-enable-configure-auditd-on-ubuntu"&gt;&lt;strong&gt;Configure Auditd on Ubuntu&lt;/strong&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;By default, you can find &lt;strong&gt;auditd's config&lt;/strong&gt; file here &lt;code&gt;/etc/audit/auditd.conf&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;auditd_buffer_size: 32768
auditd_fail_mode: 1
aauditd_maximum_rate: 60
auditd_enable_flag: 1
auditd_local_events: "yes"
auditd_write_logs: "yes"
auditd_log_file: /var/log/audit/audit.log
auditd_log_group: root
auditd_log_format: RAW
auditd_flush: incremental_async
auditd_freq: 50
auditd_max_log_file: 8
auditd_num_logs: 5
auditd_priority_boost: 4
auditd_disp_qos: lossy
auditd_dispatcher: /sbin/audispd
auditd_name_format: none
auditd_max_log_file_action: rotate
auditd_space_left: 75
auditd_space_left_action: syslog
auditd_verify_email: "yes"
auditd_action_mail_acct: root
auditd_admin_space_left: 50
auditd_admin_space_left_action: suspend
auditd_disk_full_action: suspend
auditd_disk_error_action: suspend
auditd_use_libwrap: "yes"
auditd_tcp_listen_queue: 5
auditd_tcp_max_per_addr: 1
auditd_tcp_client_max_idle: 0
auditd_enable_krb5: "no"
auditd_krb5_principal: auditd
auditd_distribute_network: "no"
auditd_manage_rules: yes
auditd_default_arch: b64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this above auditd.conf config file &lt;code&gt;auditd_local_events: "yes"&lt;/code&gt; entry is important, because it will define would auditd audit local system or not. So, change to &lt;code&gt;no&lt;/code&gt; or remove this part.&lt;/p&gt;

&lt;h2&gt;
  
  
  How To Write Custom System Audit Rules on Ubuntu
&lt;/h2&gt;

&lt;p&gt;After all the configuration now time to write some rules for Auditd&lt;/p&gt;

&lt;p&gt;For viewing a current set of audit rules using &lt;code&gt;auditctl -l&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo auditctl -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the first time, it will show &lt;code&gt;no rules&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;no rules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, auditd's rules are written here &lt;code&gt;/etc/audit/rules.d/audit.rules&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#This file contains the auditctl rules that are loaded&lt;/span&gt;

&lt;span class="c"&gt;# whenever the audit daemon is started via the init scripts.&lt;/span&gt;

&lt;span class="c"&gt;# The rules are simply the parameters that would be passed&lt;/span&gt;

&lt;span class="c"&gt;# to auditctl.&lt;/span&gt;

&lt;span class="c"&gt;# First rule - delete all&lt;/span&gt;

&lt;span class="nt"&gt;-D&lt;/span&gt;

&lt;span class="c"&gt;# Increase the buffers to survive stress events.&lt;/span&gt;

&lt;span class="c"&gt;# Make this bigger for busy systems&lt;/span&gt;

&lt;span class="nt"&gt;-b&lt;/span&gt; 320

&lt;span class="c"&gt;# Feel free to add below this line. See auditctl man page&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;a href="http://kubefront.com/linux/how-to-enable-configure-auditd-on-ubuntu"&gt;Adding Audit Rules&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;For adding auditd rules, we can use CLI util for that but for simplicity, I am using the direct method, but update our &lt;code&gt;/etc/audit/rules.d/audit.rules&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="http://kubefront.com/linux/how-to-enable-configure-auditd-on-ubuntu"&gt;Syntax for Auditd rules&lt;/a&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;auditctl &lt;span class="nt"&gt;-w&lt;/span&gt; path_to_file &lt;span class="nt"&gt;-p&lt;/span&gt; permissions &lt;span class="nt"&gt;-k&lt;/span&gt; key_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
