25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

Need help?

Our experts have had an average response time of 11.43 minutes in March 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Ansible CIS Hardening Debian | Setup Tutorial

by | Oct 4, 2022

Let’s explore more about CIS and system hardening with Ansible on Debian in this article. Bobcares, as a part of our Server Management Services, offers solutions to every query that comes our way.

Ansible CIS Hardening On Debian

We can defend systems, software, and networks against modern, growing cyber threats with the aid of CIS (Center for Internet Security) Benchmarks. In order to protect IT systems and data from cyberattacks, CIS benchmarks are widely recognized as security standards. They provide prescriptive advice for creating a secure baseline configuration, and thousands of businesses use them.

ansible cis hardening debian

For industries like banking, telecommunications, and healthcare that must comply with PCI-DSS and HIPPA, auditors frequently suggest using CIS benchmarks as a system hardening option.

In this article, we’ll look at how to use Ansible to leverage CIS Benchmark compliance while running a straightforward playbook on Debian. We have to configure Debian 10 machine to be CIS compliant.

How to set up Ansible CIS Hardening on Debian?

The Debian CIS benchmarks divide into two distinct profiles called “Level 1” and “Level 2,” which are designed for server and workstation environments, respectively. The goal of a Level 1 profile is to secure a system in an efficient and responsible manner with a minimal performance impact. For systems where security is a high priority and can affect negatively the system performance, we use a Level 2 profile.

We can automate system hardening in a variety of ways by using the CIS Benchmarks as a guide. Here, we are going to use the Ansible playbook. They may outline a set of steps in a general IT process or a policy users want the remote systems to follow. They can assign tasks to other hosts, delegate multi-tier rollouts with rolling updates, and interact with load balancers and monitoring servers as they go.

The main steps includes:

  • Firstly, install Ansible.
  • Then create an Ansible playbook.
  • Lastly, run the Ansible playbook.

Let’s see each step in detail.

Ansible Installation
  1. Firstly, log into the Ubuntu instance.
  2. Then type the below command on the command line.
    sudo apt install software-properties-common
  3. Now install Ansible by typing the command:
    sudo apt install ansible
  4. After the installation completes, upgrade the Ansible using the command:
    sudo apt upgrade ansible
  5. Now go to the installation directory of Ansible using the following command:
    cd /etc/ansible
  6. Create a directory in which we can keep our playbooks using the command:
    sudo mkdir playbooks
  7. Here use the 2.3.4 CIS Benchmark configuration. Also, make sure the telnet client is not installed. We should design the playbook as such so that we can add multiple plays for a particular section in a single playbook because this particular configuration item is a part of a larger section, 2.3 Service Clients.

    In order to do this, confirm we are on the Ansible directory and type the below command. This will create a .yaml file called 2.3_service_clients.yaml:

    sudo touch 2.3_service_clients.yaml
Playbook Creation
  1. Every playbook starts with 3 dashes to indicate the beginning of a .yaml file. So put a “—” at the beginning of the playbook.
  2. Now configure the host. Here, we are running it locally. So set the port to 127.0.0.1 and the connection to local in the playbook.
  3. Then define a task or list of tasks that we want to run in the playbook. “– name: 2.3.4 Ubuntu and Debian Ensure telnet client is not installed (Scored)” is a logical name of a task that is going to run.
  4. Now define the Ansible module that we will be using. Using the parameter “state,” we’ll specify that the desired package state is “absent.” In order for the playbook to know whether to run apt or yum depending on the OS, we also have an Ansible conditional statement. This will guarantee that the telnet client is not present or has been removed from our local machine:
    apt:

    name: telnet

    state: absent

    yum:

    name: telnet

    state: absent

     

  5. And add a conditional statement so we can run the playbook across multiple OSs.
    when: ansible_distribution == ‘Debian’ or ansible_distribution == ‘Ubuntu’

    when: ansible_distribution == ‘CentOS’ or ansible_distribution == ‘Red Hat Enterprise Linux’

     

Playbook Execution
  1. Firstly, use the below command to ensure the telnet client is installed so that we can see the changes all the way through and make sure the playbook is working.
    dpkg -s telnet
  2. Then confirm we are on the directory: /etc/ansible/playbooks. Now run the Ansible Playbook.
    sudo ansible-playbook 2.3_service_clients.yaml
  3. We will see in the output above that the first task ran successfully and a change in the “2.3.4 Ubuntu & Debian Ensure telnet client is not installed (Scored)” play and that the “2.3.4 CentOS & Rhel Ensure telnet client is not installed (Scored)” play was skipped. To verify the change was successful, we can run the below command:
    dpkg -s telnet
  4. We can also run the Ansible playbook again to confirm that no changes were made. This is because Ansible will skip over a defined task if no modifications are necessary. We can do this by including the second play in the playbook to remove the talk client.
  5. The task of uninstalling the talk client for the “2.3.3 Ubuntu & Debian Ensure talk client is not installed (Scored)” play was changed, as we can see from the result. The playbook ran successfully, as we can see.

[Looking for a solution to another query? We’re available 24/7.]

Conclusion

Many playbooks get very complex depending on their purpose like implementing all Level 1 CIS Benchmarks. The one we explained in the article is a simple Ansible playbook for CIS – hardening on Debian.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

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

Categories

Tags

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF