chroot and selinux

23
chroot and SELinux mailto:[email protected]

Upload: shay-cohen

Post on 13-Jul-2015

266 views

Category:

Software


2 download

TRANSCRIPT

Page 1: chroot and SELinux

chroot and SELinux

● mailto:[email protected]

Page 2: chroot and SELinux

Chroot

A secure way of running untrusted or security-flawed software.Limit program access to system resources outside jail.Confinement of programs to their own ‘/’ filesystem.Safely testing software in confined environment.

Page 3: chroot and SELinux

Chroot

chroot is a command and a system call.Changes the ‘/’ of current process.chroot should be executed only by root.New ‘/’ should contain all programs and files needed by programs running in chroot.

Page 4: chroot and SELinux

Chroot

A widely-spread example of chroot usage is anonymous ftp.Upon anonymous ftp login, the ftp client has access to chrooted ‘/’ which actually is a part of the bigger filesystem.The ftp user cannot access files outside the chrooted environment.

Page 5: chroot and SELinux

Chroot

Chroot ‘/’ should contain all files used by programs running inside it.Among others, FTP requires the following files:

/bin/ls/bin/false/usr/lib/libc.*/etc/passwd/etc/group/lib/ld.so.1Etc…

Chroot syntax: chroot <NEW ROOT PATH>

Page 6: chroot and SELinux

SELinux Overview

SELinux - Security Enhanced Linux.Developed by NSA.Linux kernel extensions.Implements Mandatory Access Control.Extends UNIX traditional access control mechanism.

Page 7: chroot and SELinux

SELinux Compatibility

A number of user-space utilities replaced with SELinux aware ones.

login,ls,ps,etc..Kernel modules compiled with regular kernel need to be recompiled.SELinux provides application compatibility. System calls interfaces and application visible data structures remain unchanged.

Page 8: chroot and SELinux

Current Linux security model

Root has complete control:

Uid = 0 Complete control.Setuid Binaries

Passwd, su, mount.Privilaged daemons

Cron, cups, apache master,etc..Any mis-configuration can lead to complete compromise of the system.

Page 9: chroot and SELinux

Discretionary VS Mandatory

Discretionary access control – the owner of the object defines access to it

This is the current Linux behaviourMandatory access control – central security policy

Policy cannot be overridden by malware or by accidentGranular access control to specific users and objects

Page 10: chroot and SELinux

More on MAC

Prevents privileges escalationRole-basedAllows protection from untrusted software codeCentralized security policy allows easy analysis and management

Page 11: chroot and SELinux

MAC in SELinux

Implements MAC using a combination of methods:

Type enforcement.

Role-based access control.

User identity.

Type enforcement is the most commonly used.

SELinux access control is evaluated after standard UNIX access control.

Page 12: chroot and SELinux

Type Enforcement

Everything on the system has a type.

Includes: files,TCP ports,etc…

Type Examples: system_u, user_home_tFine-grained access control for each object class.

ioctl, read, write, getattr, etc..

Page 13: chroot and SELinux

Domain

Domains resemble types in characteristic.Unlike types, domain are defined on processes.Domain examples:

Init_t – init domainsysadm_t – privileged domainuser_t – unprivileged domain

Fine-grained access control for each object class.fork signal getattr

Page 14: chroot and SELinux

Security Policy

Specifies which access methods are allowed.Allow type1 type2:clas {perm1 perm2 …};

Examples:allow user_t proc_t:file {getattr read};allow sysadm_t user_t:proccess {ptrace};allow named_t dns_port_t:udp_socket {name_bind}

Anything not explicitly allowed is denied.

Page 15: chroot and SELinux

Roles

Role is authorized for a set of domains.A single UNIX user may be authorized for multiple roles.

sysadm_r, developer_rCurrent role can be switched using ‘newrole’ command:

newrole –r sysadm_r

Page 16: chroot and SELinux

Identity

Not the same as uid.Determines which roles and domains can be used.Remains constant for a user. – su command doesn’t change identity, it

changes a domain.

Page 17: chroot and SELinux

Security Context

Combined security information – combined from:

Identity.

Role.

Domain/type.

Security context can be checked using:

id command – will show user’s security context.

ls –context – will show object’s context.

Page 18: chroot and SELinux

Examining Security Context

Security context is displayed as following:identity:role:domain/typeExample:

$ ls –dZ /home/testuser drwx--x--x testuser testuser system_u:object_r:user_home_dir_t /home/testuser*SELinux version of ls is used.

Page 19: chroot and SELinux

Strict VS Targeted policy

SELinux general configuration file is /etc/sysconfig/selinux.

Strict Policy

All processes including user logins and root, run in restricted mode. Anything not allowed explicitly is denied.

Targeted Policy

Only specific applications and objects are confined by SELinux.

Everything else runs in unconfined_t domain, which eliminates all SELinux restrictions.

Page 20: chroot and SELinux

Bundled targeted policy

Targeted Policies:

dhcpd, named, httpd, squid, portmap, nscd,etc..*More can be added.

Policy booleans allow easy policy configurations, such as:

Deny httpd access to home directories.

Allow dhcp failover mode.

Page 21: chroot and SELinux

Permissive vs Enforced

Permissive mode

Logs all SELinux related messages.

Does not enforce policies.

Good for analysis and auditing.

Safe.

Enforced mode

Kicks in all SELinux policies.

Should be used after configuration tests in permissive mode.

Page 22: chroot and SELinux

Logging

SELinux logs messages via syslog.

SELinux log record examples:

User tried to edit /etc/shadow and failed.avc: denied { getattr } for pid=6011 exe=/usr/bin/vim \ path=/etc/shadow dev=03:03 ino=123456 \ scontext=testuser:user_r:user_t \ tcontext=system_u:object_r:shadow_t tclass=file

User executed /bin/bash and succeeded. avc: granted for pid=1050 exe=/bin/bash path=/bin/bash\

dev 03:03 ino=1122 scontext=testuser:user_r:user_t \ tcontext=system_u:object_r:file_t tclass=file

Page 23: chroot and SELinux

Policy Editing

Policy source files reside under/etc/security/selinux/src/policy.

Policy is edited using text editor and later compiled using ‘checkpolicy’.

Audit2allow tool converts SELinux syslog messages into possible policy rules.

For custom made policies, use separate files to avoid upgrade collisions.