In this lesson,
we will learn about operating system security.
Operating system security
refers to the measures and mechanisms
implemented within an operating system or OS
to protect it from unauthorized access, malware,
and other security threats.
In this section, we will focus on Security-Enhanced Linux,
also known as SELinux.
SELinux is a security module
integrated into the Linux kernel that provides a framework
for supporting access control security policies.
Let's learn more about Security-Enhanced Linux,
or SELinux.
SELinux is a security module
directly integrated into the Linux kernel.
It is designed to enforce strict security policies
that control access to files,
processes, and other resources.
It operates at the kernel level,
intercepting every access attempt
and checking it against predefined policies
before allowing or denying the action.
For example, when a web server process
tries to read a configuration file,
SELinux checks the security context
of both the process and the file.
A security context in SELinux
is a set of security attributes
assigned to files, processes,
and other system resources
that define how they can interact with each other,
based on the enforced security policies.
Security contexts are assigned to every file,
process, and resource.
For example, if a policy does not explicitly
allow a web server to access a specific file,
SELinux will deny the attempt,
blocking the process and logging the denial.
This mechanism ensures that only authorized actions
as defined by security policies are permitted,
greatly reducing the risk of unauthorized access
or malicious activities on the system.
Additionally, SELinux uses Mandatory Access Control or MAC,
a security model
that enforces strict rules on access rights
by applying policies that dictate what actions
users, applications, and processes can perform,
regardless of their traditional permissions.
This is achieved through the use of labels and tags,
which are assigned as part of the security context
to every file, process, and system resource.
Each security context includes tags,
such as user, role, type, and level,
which define how these labeled objects
can interact with one another
according to the enforced security policies.
For example, a file might have a type label
that only allows specific processes to access it,
while a process has its own labels
specifying what types of files it can read or modify.
This relationship between labels and tags
ensures that SELinux makes access decisions
based on predefined policies,
rather than standard user permissions,
providing an extra layer of control
to prevent unauthorized actions and enhance system security.
In an enterprise, SELinux is often used
to secure critical servers and applications.
For instance, administrators can set policies
that prevent a database server from accessing any files
outside of its own data directory.
So, even if a hacker finds a vulnerability
into the database software,
SELinux will stop them from accessing
or altering other parts of the system.
Implementing SELinux involves setting up security rules
using command-line tools.
For example, the S-E-T-S-E-B-O-O-L
or setsebool command,
is used to enable or disable settings
by toggling Boolean options.
The semanage command helps manage policies
like adding rules to allow new applications access
to specific directories,
and the audit2allow tool creates custom rules
by analyzing logged denials.
These security rules allow administrators
to quickly generate policies
to permit previously blocked actions when needed.
Now, let's conduct a demonstration of SELinux.
For this demonstration, SELinux is installed,
configured, and running in enforcing mode
on this Kali Linux system.
First, let's ensure everything is set up correctly.
We'll do this with the sestatus command.
We can see that SELinux status is enabled
and the current mode is enforcing.
Second, let's set up a test environment
by creating a test directory and file.
We'll do this by creating a directory
called tmp and then selinux-test.
Then, we'll create a file in that directory
called secure-file.txt.
Let's now take a look at the security context
of our newly created secure-file.text file.
We'll do this with the following command:
ls -z/tmp/selinux-test
and then the secure-file.txt.
This is our context.
Our context is comprised of user, role, type,
and the level information.
First is the user information.
Ours is unconfined_u.
Unconfined_u typically represents a user
who is not restricted by SELinux policies
and has fewer security constraints.
Next, we have the role defined,
in this case object_r.
Object_r is the common role
for files and other objects,
such as a directories and devices,
meaning it's a regular object
without any specific elevated or restricted roles.
Next, we have the type:
user_tmp_t.
User_tmp_t is used for files that are temporary
and can be accessed by standard users.
Finally, we have the sensitivity level.
In this case, s0 is the default sensitivity level
representing the lowest level of clearance.
Now that we understand the context,
let's change this file security context
to a type meant for web server content.
For example, httpd_sys_content_t.
This context is used for web server files
restricting access to HTTP daemons only.
We'll do this with the following command:
sudo chcon -t httpd_sys_content_t
/tmp/selinux-test/secure-file.txt.
Now, let's take another look at that security context.
You can see that the context type has changed
to httpd_sys_content_t.
So, if a command such as cat or concatenate
were used to access this file from a standard user terminal,
we wouldn't expect it to work
because a web server should not be accessing this file
with the cat command.
So, in enforcing mode,
SELinux would block this request.
So, remember, operating system security
involves implementing measures
to protect an operating system from unauthorized access,
malware, or other security threats.
One powerful tool for enhancing security on Linux systems
is Security-Enhanced Linux or SELinux.
SELinux enforces strict access control policies
using security contexts,
which are sets of labels
assigned to files, processes, and resources
that define how they can interact with each other.
By controlling access through security contexts,
SELinux keeps systems secure
from unauthorized actions and potential threats.