Press "Enter" to skip to content

SELinux Nedir ne iş yapar ?

SELinux Nedir ne iş yapar ?

SELinux (Security-Enhanced Linux) Linux’ da zorunlu erişim denetimi (MAC) mekanizmasına gerçekleşmesini sağlayan bir projedir.

DAC ve MAC

İsteğe bağlı erişim denetimi (DAC) altında, bir kullanıcı veya sürecin dosyalara, socketlere ve diğer kaynaklara erişip erişemeyeceği  kullanıcı sahipliğine veya izinlere bakarak belirlenir.

Zorunlu erişim denetimi ise  (MAC) kullanıcıların (subjects) oluşturdukları nesnelern (objects) üzerindeki denetim düzeyini kısıtlayan bir güvenlik mekanizmasıdır. İsteğe bağlı erişim denetimi kontrolünde kullanıcılar kendi dosya, dizin, vb üzerinde tam denetime sahipken, zorunlu erişim denetimi tüm dosya sistemi nesneleri için, ek etiket ya da kategori ekler. Kullanıcılar ve süreçlerin bu nesnelerle erişebilmesi için bu kategorilere uygun erişim hakları olmalıdır.

İsteğe bağlı erişim kontrolünde tüm erişim kararları kullancının kimliği ve sahipliğine göre verilir. Bu da güvenlik açığından faydalanılıp kötü amaçlı kullanılan bir uygulamanın kullanıcısının sahibi olduğu ve erişebildiği tüm SELinux Nedir ne iş yapar ?kaynakları dilediği gibi kullanacağı anlamına gelmektedir. SELinux ile kullanıcı ve o kullanıcının sahip olduğu haklar farklılaştırılabilir. Örneğin; bir bir shell veya GUI aracılığı ile sistemde oturum açmış kullanıcı kendi ev dizininde istediğini yapmasına izin verilebilirken, o kullanıcının çalıştırdığı bir uygulamanın bu ev dizininde bazı dosya veya dizinlere erişimi kısıtlanabilir.

SELinux Nasıl Çalışır ?
SELinux Nedir ne iş yapar ?

Bir subject (örneğin bir uygulama) bir objecte (örneğin bir dosya) erişmeye çalıştığında çekirdekteki politika uygulama sunucusu subject ve object izinleri için öncelikle erişim vektörü önbelleğini (Access Vector Cache) kontrol eder. Eğer önbelleğe bakılarak karar verilemezse sunucu güvenlik politikalarına göre erişimin gerçekleşip gerçekleşmeyeceğini belirler. Ayrıca söylemekte fayda var SELinux DAC’ta belirlenen erişim kurallarını ezmez.

SELinux Modları

SELinux’un 3 modu vardır. Bunlar:

  • enforcing: Kaynaklara erişimin SELinux politikasına göre belirlendiği moddur.

  • permissive: Bu modda erişimler SELinux politikası zorlanmaz. Ancak erişim politikasına uymayan durumlar bir günlük dosyasına yazılır. (Redhat’te /var/log/audit/audit.log dosyasına varsayılan olarak yazılır)

  • disabled: SELinux tamamen devre dışıdır. Sadece DAC kuralları geçerlidir.

SELinux’u /etc/selinux/config dosyasını kullanarak yapılandırabilirsiniz.

# This file controls the state of SELinux on the system.
SELINUX=enforcing
SELINUXTYPE=targeted

SELINUX seçeneği ile SELinux’ un hangi modda çalışağını söylüyoruz. SELINUXTYPE ile de hangi SELinux politikasının uygulanacağını belirtmiş oluyoruz. Bunlar:

  • stricted: Erişim politikası sistemdeki tüm süreçler için işler.

  • targeted: Erişim politikası sadece hedeflenen süreçler için işler. (dhcpd, httpd, named, nscd, ntpd gibi)

  • mls: Çok seviyeli güvenlik koruması

getenforce ve sestatus komutları SELinux’un hangi modda olduğunu öğrenmek için kullanılabilir.

$getenforce
Enforcing
$sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          disabled
Policy version:                 24
Policy from config file:        targeted

Aslında bu yazıyı yazmamdaki en büyük neden SELinux’ un Redhat’te varsayılan olarak enforced modda gelmesi ve benim bundan bihaber olmamdı. Sunucu üzerinde bir daemon için SELinux politikasında tanımlı olmayan port kullandığımda veya web sunucusunun mail sunucusunu kullanarak mail atmaya çalıştığında permission denied şeklinde uyarılar alıyordum. Böyle bir durumda /var/log/audit/audit.log günlük dosyasına bakarak politikaya uymayan erişim isteklerini görebiliriz.

audit.log dosyasından örnek bir satır:

type=AVC msg=audit(1375367543.933:109729): avc:  denied  { name_connect } for  pid=2591 comm=”httpd” dest=25 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:smtp_port_t:s0 tclass=tcp_socket

Bu satır bize pid:2591 olan httpd isimli süreç 25 numaralı porta porta bağlanmaya çalıştığını ancak erişimin reddedildiğini söylüyor. Çıktıyı daha okunabilir hale audit2allow komutuna -w(why) parametresini ekleyerek getirebiliriz:

#audit2allow -a -w
Was caused by:
Unknown - would be allowed by active policy
Possible mismatch between this policy and the one under which the audit message was generated.
Possible mismatch between current in-memory boolean settings vs. permanent ones.

#audit2allow -a
#============= httpd_t ==============
allow httpd_t home_root_t:file getattr;
#!!!! This avc can be allowed using one of the these booleans:
#     httpd_can_sendmail, allow_ypbind, httpd_can_network_connect
allow httpd_t smtp_port_t:tcp_socket name_connect;

Bu komutun çalışması sonucunda audit.log dosyasında ki reddedilen erişimlere izin verecek kuralları görebiliyoruz.

#audit2allow -a -M httpd_module

Komutu ile de httpd_module.pp isminde type enforcement kurallarının derlendiği bir politika paketi ve type enforcement kurallarının yazdığı httpd_module.te isimli iki dosya oluşuyor.

Modulü yüklemek içinde aşağıdaki komutu kullanıyoruz:

#semodule -i httpd_module.pp


SELinux English desc.

Security-Enhanced Linux (SELinux) is a Linux kernel security module that provides a mechanism for supporting access control security policies, including United States Department of Defense–style mandatory access controls (MAC).

SELinux is a set of kernel modifications and user-space tools that have been added to various Linux distributions. Its architecture strives to separate enforcement of security decisions from the security policy itself and streamlines the volume of software charged with security policy enforcement.[2][3] The key concepts underlying SELinux can be traced to several earlier projects by the United States National Security Agency.

Overview

From NSA Security-enhanced Linux Team:[4]

NSA Security-enhanced Linux is a set of patches to the Linux kernel and some utilities to incorporate a strong, flexible mandatory access control (MAC) architecture into the major subsystems of the kernel. It provides an enhanced mechanism to enforce the separation of information based on confidentiality and integrity requirements, which allows threats of tampering and bypassing of application security mechanisms to be addressed and enables the confinement of damage that can be caused by malicious or flawed applications. It includes a set of sample security policy configuration files designed to meet common, general-purpose security goals.

A Linux kernel integrating SELinux enforces mandatory access-control policies that confine user programs’ and system servers’ access to files and network resources. Limiting privilege to the minimum required to work reduces or eliminates the ability of these programs and daemons to cause harm if faulty or compromised (via buffer overflows or misconfigurations, for example). This confinement mechanism operates independently of the traditional Linux (discretionary) access control mechanisms. It has no concept of a “root” super-user, and does not share the well-known shortcomings of the traditional Linux security mechanisms (such as a dependence on setuid/setgid binaries).

The security of an “unmodified” Linux system (a system without SELinux) depends on the correctness of the kernel, of all the privileged applications, and of each of their configurations. A problem in any one of these areas may allow the compromise of the entire system. In contrast, the security of a “modified” system (based on an SELinux kernel) depends primarily on the correctness of the kernel and its security-policy configuration. While problems with the correctness or configuration of applications may allow the limited compromise of individual user programs and system daemons, they do not necessarily pose a threat to the security of other user programs and system daemons or to the security of the system as a whole.

From a purist perspective, SELinux provides a hybrid of concepts and capabilities drawn from mandatory access controls, mandatory integrity controls, role-based access control (RBAC), and type enforcement architecture. Third-party tools enable one to build a variety of security policies.

History

The earliest work directed toward standardizing an approach toward provision of mandatory and discretionary access controls (MAC and DAC) within a UNIX (more precisely, POSIX) computing environment can be attributed to the National Security Agency’s Trusted UNIX (TRUSIX) Working Group, which met from 1987 to 1991 and published one Rainbow Book (#020A), and produced a formal model and associated evaluation evidence prototype (#020B) that was ultimately unpublished.

SELinux was designed to demonstrate the value of mandatory access controls to the Linux community and how such controls could be added to Linux. Originally, the patches that make up SELinux had to be explicitly applied to the Linux kernel source; SELinux has been merged into the Linux kernel mainline in the 2.6 series of the Linux kernel.

The United States National Security Agency (NSA), the original primary developer of SELinux, released the first version to the open source development community under the GNU GPL on December 22, 2000.[5] The software merged into the mainline Linux kernel 2.6.0-test3, released on 8 August 2003. Other significant contributors include Red Hat, Network Associates, Secure Computing Corporation, Tresys Technology, and Trusted Computer Solutions. Experimental ports of the FLASK/TE implementation have been made available via the TrustedBSD Project for the FreeBSD and Darwin operating systems.

Security-Enhanced Linux implements the Flux Advanced Security Kernel (FLASK). Such a kernel contains architectural components prototyped in the Fluke operating system. These provide general support for enforcing many kinds of mandatory access control policies, including those based on the concepts of type enforcement, role-based access control, and multilevel security. FLASK, in turn, was based on DTOS, a Mach-derived Distributed Trusted Operating System, as well as Trusted Mach, a research project from Trusted Information Systems that had an influence on the design and implementation of DTOS.

Users, policies and security contexts

SELinux users and roles do not have to be related to the actual system users and roles. For every current user or process, SELinux assigns a three string context consisting of a username, role, and domain (or type). This system is more flexible than normally required: as a rule, most of the real users share the same SELinux username, and all access control is managed through the third tag, the domain. The circumstances under which a process is allowed into a certain domain must be configured in the policies. The command runcon allows for the launching of a process into an explicitly specified context (user, role and domain), but SELinux may deny the transition if it is not approved by the policy.

Files, network ports, and other hardware also have an SELinux context, consisting of a name, role (seldom used), and type. In case of file systems, mapping between files and the security contexts is called labeling. The labeling is defined in policy files but can also be manually adjusted without changing the policies. Hardware types are quite detailed, for instance, bin_t (all files in the folder /bin) or postgresql_port_t (PostgreSQL port, 5432). The SELinux context for a remote file system can be specified explicitly at mount time.

SELinux adds the -Z switch to the shell commands ls, ps, and some others, allowing the security context of the files or process to be seen.

Typical policy rules consist of explicit permissions; which domains the user must possess to perform certain actions with the given target (read, execute, or, in case of network port, bind or connect), and so on. More complex mappings are also possible, involving roles and security levels.

A typical policy consists of a mapping (labeling) file, a rule file, and an interface file, that define the domain transition. These three files must be compiled together with the SELinux tools to produce a single policy file. The resulting policy file can be loaded into the kernel, making it active. Loading and unloading policies does not require a reboot. The policy files are either hand written or can be generated from the more user friendly SELinux management tool. They are normally tested in permissive mode first, where violations are logged but allowed. The audit2allow tool can be used later to produce additional rules that extend the policy to allow all legitimate activities of the application being confined.

Features

SELinux features include:

  • clean separation of policy from enforcement
  • well-defined policy interfaces
  • support for applications querying the policy and enforcing access control (for example, crond running jobs in the correct context)
  • independence of specific policies and policy languages
  • independence of specific security-label formats and contents
  • individual labels and controls for kernel objects and services
  • support for policy changes
  • separate measures for protecting system integrity (domain-type) and data confidentiality (multilevel security)
  • flexible policy
  • controls over process initialization and inheritance and program execution
  • controls over file systems, directories, files, and open file descriptors
  • controls over sockets, messages, and network interfaces
  • controls over the use of “capabilities”
  • cached information on access-decisions via the Access Vector Cache (AVC)[6]

Implementations

SELinux is available with commercial support as part of Red Hat Enterprise Linux (RHEL) version 4 and all future releases. This presence is also reflected in corresponding versions of CentOS and Scientific Linux. The supported policy in RHEL4 is the targeted policy which aims for maximum ease of use and thus is not as restrictive as it might be. Future versions of RHEL are planned to have more targets in the targeted policy which will mean more restrictive policies. SELinux has been implemented in Android since version 4.3[7]

In free community supported GNU/Linux distributions, Fedora was one of the earliest adopters, including support for it by default since Fedora Core 2. Other distributions include support for it such as Debian as of the etch release[8] and Ubuntu as of 8.04 Hardy Heron.[9] As of version 11.1, openSUSE contains SELinux “basic enablement”.[10] SUSE Linux Enterprise 11 features SELinux as a “technology preview”.[11]

Use scenarios

SELinux can potentially control which activities a system allows each user, process and daemon, with very precise specifications. However, it is mostly used to confine daemons[citation needed] like database engines or web servers that have more clearly defined data access and activity rights. This limits potential harm from a confined daemon that becomes compromised. Ordinary user-processes often run in the unconfined domain, not restricted by SELinux but still restricted by the classic Linux access rights.

Command-line utilities include:[12] chcon,[13] restorecon,[14] restorecond,[15] runcon,[16] secon,[17] fixfiles,[18] setfiles,[19] load_policy,[20] booleans,[21] getsebool,[22] setsebool,[23] togglesebool[24] setenforce, semodule, postfix-nochroot, check-selinux-installation, semodule_package, checkmodule, selinux-config-enforcing,[25] selinuxenabled,[26] and selinux-policy-upgrade[27]

Examples

To put SELinux into enforcing mode:

$ sudo setenforce 1

To query the SELinux status:

$ getenforce

Comparison with AppArmor

SELinux represents one of several possible approaches to the problem of restricting the actions that installed software can take. Another popular alternative is called AppArmor and is available on SUSE Linux Enterprise Server (SLES), openSUSE and Ubuntu platforms. AppArmor was developed as a component to the now-defunct Immunix Linux platform. Because AppArmor and SELinux differ radically from one another, they form distinct alternatives for software control. Whereas SELinux re-invents certain concepts in order to provide access to a more expressive set of policy choices, AppArmor was designed to be simple by extending the same administrative semantics used for DAC up to the mandatory access control level.

There are several key differences:

  • One important difference is that AppArmor identifies file system objects by path name instead of inode. This means that, for example, a file that is inaccessible may become accessible under AppArmor when a hard link is created to it, while SELinux would deny access through the newly created hard link.
    • As a result, AppArmor can be said not to be a type enforcement system, as files are not assigned a type; instead, they are merely referenced in a configuration file.
  • SELinux and AppArmor also differ significantly in how they are administered and how they integrate into the system.[28]
  • Since it endeavors to recreate traditional DAC controls with MAC-level enforcement, AppArmor’s set of operations is also considerably smaller than those available under most SELinux implementations. For example, AppArmor’s set of operations consist of: read, write, append, execute, lock, and link.[29] Most SELinux implentations will support numbers of operations orders of magnitude more than that. For example, SELinux will usually support those same permissions, but also includes controls for mknod, binding to network sockets, implicit use of POSIX capabilities, loading and unloading kernel modules, various means of accessing shared memory, etc.
  • There are no controls in AppArmor for categorically bounding POSIX capabilities. Since the current implementation of capabilities contains no notion of a subject for the operation (only the actor and the operation itself) it is usually the job of the MAC layer to prevent privileged operations on files outside the actor’s enforced realm of control (i.e. “Sandbox”). AppArmor can prevent its own policy from being altered, and prevent filesystems from being mounted/unmounted, but does nothing to prevent users from stepping outside their approved realms of control.
    • For example, it may be deemed beneficial for help desk employees to change ownership or permissions on certain files even if they don’t own them (for example, on a departmental file share). You obviously don’t want to give the user(s) root on the box so you give them CAP_FOWNER or CAP_DAC_OVERRIDE. Under SELinux you (or your platform vendor) can configure SELinux to deny all capabilities to otherwise unconfined users, then create confined domains for the employee to be able to transition into after logging in, one that can exercise those capabilities, but only upon files of the appropriate type.
  • There is no notion of multi-level security with AppArmor, thus there is no hard BLP or Biba enforcement available.
  • AppArmor configuration is done using solely regular flat files. SELinux (by default in most implementations) uses a combination of flat files (used by administrators and developers to write human readable policy before it’s compiled) and extended attributes.
  • SELinux supports the concept of a “remote policy server” (configurable via /etc/selinux/semanage.conf) as an alternative source for policy configuration. Central management of AppArmor is usually complicated considerably since administrators must decide between configuration deployment tools being run as root (to allow policy updates) or configured manually on each server.

Similar systems

See also: Samsung Knox

Isolation of processes can also be accomplished by mechanisms like virtualization; the OLPC project, for example, in its first implementation[30] sandboxed individual applications in lightweight Vservers. Also, the NSA has adopted some of the SELinux concepts in Security-Enhanced Android.[31]

Kaynaklar.

https://selinuxproject.org/page/Main_Page

https://blog.kartaca.com/2013/08/selinux-nedir-varsayilan-guvenlik-politikasina-uymayan-durumlara-nasil-izin-verilir/

https://en.wikipedia.org/wiki/Security-Enhanced_Linux

Buna benzer diğer yazılarım

Maldet kurulum ve kullanımı Merhaba arkadaşlar bu yazıda Maldet nedir Maldet nasıl kurulur ve Maldet nasıl kullanılır anlatacağım. Maldet Nedir ? Maldet linux sunucularda shel...
Cloudflare mi Sucuri mi ? Merhaba arkadaşlar Güvenlik piyasasının iki büyük devi CloudFlare ve Sucuri karşılaştırmasının yapıldığı bir makale ile karşınızdayım 🙂 Günümüz di...
WordPress Malware tarayıcı Merhaba beyler bu yazıda WordPress Malware tarayıcı, şimdiye kadar geliştirilen en iyi antivirüs )MAlware scanner( i size tanıtmak istiyorum. 2012 yıl...
LXC vs Docker LXC vs Docker Docker vs LXC tartışmasıyla dev ve test ortamları da dahil olmak üzere BT operasyonlarını göz önüne almalıyız.  BSD, BT O...
İmunify360 nedir ve İmunify360 Nedir diyecek olursak CloudLinux tarafından geliştirilen Linux sunucularda güvenliği artırmak bir üst seviyeye çıkartmak için yapılan bir m...
CentOS Rsync Kurulum ve kullanım Rsync, Linux tabanlı işletim sistemlerinde sıklıkla kullanılan dosya transfer uygulamasıdır. Sunucu içerisinde yada sunucular arası yedekleme ve d...

Bu yazı 6570 Defa okundu. Diğer yazılarımı da oku süper yazarım :)

||||

Ali Çömez
Ali Çömez

Kaldırımda yürürken beyaz çizgilere basmamaya çalışan, Sabah yüzünü yıkarken dirseklerinden su sızmasından nefret eden, Dönerle ayranı aynı anda bitirebilen, son dakikada otobüsü kaçırsada grur yapıp arkasından koşmayan... bir insanım :)

View all posts

4 Comments

  1. Benim için bu bilgiler çok yararli oldu. Paylasiminiz için tesekkürler.. Kolay gelsin!.

  2. çok detaylı bilgileri senin web sitende bulduğumuzu belirtmek isterim. Elinize sağlık.

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir