SlideShare a Scribd company logo
SELinux by Example
Miroslav Spousta <qiq@ucw.cz>
Example
Running untrusted code on the backend server
Example
Running untrusted code on the backend server
- WTF?
Example
Running untrusted code on the backend server
- export web page as PDF to send it by e-mail
- use headless browser (e.g. PhantomJS)
- based on (obsolete?) WebKit browser
- possibly running customer’s code (JavaScript)
- must restrict access to filesystem and network
How to Restrict Access?
Separate virtual machine for every export task?
- too heavy weight (setup, resources)
UNIX permissions and ACLs?
- coarse-grained, hard to manage, inflexible
SELinux seems to be a perfect fit here
- may be used to restrict all programs
SELinux?!
Available since ~2004 (Fedora 3), kernel 2.6
- everybody knows how to switch it off
MAC (Mandatory Access Control)
Too complicated? Not really!
Not explicitly allowed? => denied
- targeted policy - only restrict some programs
SELinux Labels
Label for files, processes, ports
- process is given access to files, ports
SELinux Labels
Label for files, processes, ports
- process is given access to files, ports
UNIX: almost everything is file
SELinux Labels
Label for files, processes, ports
- process is given access to files, ports
UNIX: almost everything is file
subject objects
SELinux Labels
Label for files, processes, ports
- process is given access to files, ports
Every process is running in some domain
- confined or unconfined
- transition from domain to another on exec(2)
How to Create Policy
1. create domain transition
2. run program in permissive mode, inspect log
3. add rules (use policy macros, if possible)
- audit2allow helps
- setenforce 1; setenforce 0 clears AVC cache
4. run program in enforcing mode
Example
… example policy for HTTP server running
image to PDF conversion service
Example
… example policy for HTTP server running
image to PDF conversion service
- policy consists of .fc, .if and .te files
- compile and load using Makefile provided
Example
- type definitions
# myserver.te
policy_module(myserver, 1.0.0)
# required types
gen_require(`
type unconfined_t;
type proc_t;
type sysfs_t;
type tmp_t;
')
# new types
type myserver_exec_t;
type myserver_t;
type convert_exec_t;
role unconfined_r types myserver_t;
Example
- type definitions
- domain transition
# force domain transition executing myserver_exec_t
domain_type(myserver_t)
domain_entry_file(myserver_t,myserver_exec_t)
domtrans_pattern(unconfined_t,myserver_exec_t,myserv
er_t)
Example
- type definitions
- domain transition
- macros
# allow read of /usr/bin/* files
corecmd_read_bin_files(myserver_t)
# allow read of e.g. /usr/share/* files
files_read_usr_files(myserver_t)
# localization
miscfiles_read_localization(myserver_t)
Example
- type definitions
- domain transition
- macros
- allow rules
# allow to listen on port 8080
allow myserver_t http_cache_port_t:tcp_socket
name_bind;
# allow to run convert
allow myserver_t convert_exec_t:file { read execute open
getattr execute_no_trans };
allow myserver_t node_t:tcp_socket node_bind;
allow myserver_t self:fifo_file { read write ioctl getattr };
allow myserver_t self:process getsched;
allow myserver_t self:tcp_socket { setopt read bind create
ioctl accept write getattr listen };
Example
- type definitions
- domain transition
- macros
- allow rules
- dontaudit rules
dontaudit myserver_t etc_t:file { read getattr open };
dontaudit myserver_t proc_t:file { read getattr open };
dontaudit myserver_t sysfs_t:dir search;
dontaudit myserver_t sysfs_t:file { read open };
dontaudit myserver_t user_devpts_t:chr_file { read write
ioctl };
dontaudit myserver_t user_home_dir_t:dir search;
Example
- type definitions
- domain transition
- macros
- allow rules
- dontaudit rules
- file contexts
# myserver.fc
/usr/bin/myserver.pl --
gen_context(system_u:object_r:myserver_exec_t,s0)
/usr/bin/convert --
gen_context(system_u:object_r:convert_exec_t,s0)
- make -f /usr/share/selinux/default/include/Makefile load
- semanage; sestatus; setenforce [0|1]
- ps -Z; ls -Z; id -Z
- chcon; restorecon; fixfiles
- audit2allow </var/log/audit/audit.log
- strace
Tooling

More Related Content

What's hot

ops300 Week5 storage (1)
ops300 Week5 storage (1)ops300 Week5 storage (1)
ops300 Week5 storage (1)
trayyoo
 

What's hot (19)

Jenkins, Bhyve, and Webdriver: Continuous Integration testing on FreeNAS by C...
Jenkins, Bhyve, and Webdriver: Continuous Integration testing on FreeNAS by C...Jenkins, Bhyve, and Webdriver: Continuous Integration testing on FreeNAS by C...
Jenkins, Bhyve, and Webdriver: Continuous Integration testing on FreeNAS by C...
 
Samba
SambaSamba
Samba
 
Ltsp talk
Ltsp talkLtsp talk
Ltsp talk
 
SELF 2014: PBI v10: Application Management Made Easy
SELF 2014: PBI v10: Application Management Made EasySELF 2014: PBI v10: Application Management Made Easy
SELF 2014: PBI v10: Application Management Made Easy
 
Websocket technology for XPages
Websocket technology for XPagesWebsocket technology for XPages
Websocket technology for XPages
 
Presentation on samba server & apache server
Presentation on samba server & apache serverPresentation on samba server & apache server
Presentation on samba server & apache server
 
Introduction to FreeNAS development by John Hixson
Introduction to FreeNAS development by John HixsonIntroduction to FreeNAS development by John Hixson
Introduction to FreeNAS development by John Hixson
 
Linux system administration
Linux system administrationLinux system administration
Linux system administration
 
ops300 Week5 storage (1)
ops300 Week5 storage (1)ops300 Week5 storage (1)
ops300 Week5 storage (1)
 
بسم الله الرحمن الرحیم
بسم الله الرحمن الرحیمبسم الله الرحمن الرحیم
بسم الله الرحمن الرحیم
 
Sweden11
Sweden11Sweden11
Sweden11
 
Стажировка 2015. Разработка. Занятие 5. Использование nginx
Стажировка 2015. Разработка. Занятие 5. Использование nginxСтажировка 2015. Разработка. Занятие 5. Использование nginx
Стажировка 2015. Разработка. Занятие 5. Использование nginx
 
Ltsp Slide
Ltsp SlideLtsp Slide
Ltsp Slide
 
Ltsp
LtspLtsp
Ltsp
 
Cloud Compt
Cloud ComptCloud Compt
Cloud Compt
 
BSD for Linux Users
BSD for Linux UsersBSD for Linux Users
BSD for Linux Users
 
Restricting unix users
Restricting unix usersRestricting unix users
Restricting unix users
 
SMB3 Offload Data Transfer (ODX)
SMB3 Offload Data Transfer (ODX)SMB3 Offload Data Transfer (ODX)
SMB3 Offload Data Transfer (ODX)
 
Python on FreeBSD
Python on FreeBSDPython on FreeBSD
Python on FreeBSD
 

Similar to SELinux by Example

Black hat 2010-bannedit-advanced-command-injection-exploitation-1-wp
Black hat 2010-bannedit-advanced-command-injection-exploitation-1-wpBlack hat 2010-bannedit-advanced-command-injection-exploitation-1-wp
Black hat 2010-bannedit-advanced-command-injection-exploitation-1-wp
rgster
 
Feb. 9, 2010 ICACT 2010@Phoenix Park, Korea
Feb. 9, 2010 ICACT 2010@Phoenix Park, Korea Feb. 9, 2010 ICACT 2010@Phoenix Park, Korea
Feb. 9, 2010 ICACT 2010@Phoenix Park, Korea
webhostingguy
 
Deploying nginx with minimal system resources
Deploying nginx with minimal system resourcesDeploying nginx with minimal system resources
Deploying nginx with minimal system resources
Max Ukhanov
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
grim_radical
 
Ch 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet ServersCh 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet Servers
webhostingguy
 

Similar to SELinux by Example (20)

Black hat 2010-bannedit-advanced-command-injection-exploitation-1-wp
Black hat 2010-bannedit-advanced-command-injection-exploitation-1-wpBlack hat 2010-bannedit-advanced-command-injection-exploitation-1-wp
Black hat 2010-bannedit-advanced-command-injection-exploitation-1-wp
 
Php myadmin
Php myadminPhp myadmin
Php myadmin
 
Feb. 9, 2010 ICACT 2010@Phoenix Park, Korea
Feb. 9, 2010 ICACT 2010@Phoenix Park, Korea Feb. 9, 2010 ICACT 2010@Phoenix Park, Korea
Feb. 9, 2010 ICACT 2010@Phoenix Park, Korea
 
FreeBSD and Hardening Web Server
FreeBSD and Hardening Web ServerFreeBSD and Hardening Web Server
FreeBSD and Hardening Web Server
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)
 
LCJ2010-KaiGai-Memcached
LCJ2010-KaiGai-MemcachedLCJ2010-KaiGai-Memcached
LCJ2010-KaiGai-Memcached
 
Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment Docker - Demo on PHP Application deployment
Docker - Demo on PHP Application deployment
 
Deploying nginx with minimal system resources
Deploying nginx with minimal system resourcesDeploying nginx with minimal system resources
Deploying nginx with minimal system resources
 
RHCE (RED HAT CERTIFIED ENGINEERING)
RHCE (RED HAT CERTIFIED ENGINEERING)RHCE (RED HAT CERTIFIED ENGINEERING)
RHCE (RED HAT CERTIFIED ENGINEERING)
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
IT Operations for Web Developers
IT Operations for Web DevelopersIT Operations for Web Developers
IT Operations for Web Developers
 
Docker interview Questions-3.pdf
Docker interview Questions-3.pdfDocker interview Questions-3.pdf
Docker interview Questions-3.pdf
 
Open shift and docker - october,2014
Open shift and docker - october,2014Open shift and docker - october,2014
Open shift and docker - october,2014
 
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
 
Ch 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet ServersCh 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet Servers
 
Cloud init and cloud provisioning [openstack summit vancouver]
Cloud init and cloud provisioning [openstack summit vancouver]Cloud init and cloud provisioning [openstack summit vancouver]
Cloud init and cloud provisioning [openstack summit vancouver]
 
Lotus Domino 8.5
Lotus Domino 8.5Lotus Domino 8.5
Lotus Domino 8.5
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 

SELinux by Example

  • 1. SELinux by Example Miroslav Spousta <qiq@ucw.cz>
  • 2. Example Running untrusted code on the backend server
  • 3. Example Running untrusted code on the backend server - WTF?
  • 4. Example Running untrusted code on the backend server - export web page as PDF to send it by e-mail - use headless browser (e.g. PhantomJS) - based on (obsolete?) WebKit browser - possibly running customer’s code (JavaScript) - must restrict access to filesystem and network
  • 5. How to Restrict Access? Separate virtual machine for every export task? - too heavy weight (setup, resources) UNIX permissions and ACLs? - coarse-grained, hard to manage, inflexible SELinux seems to be a perfect fit here - may be used to restrict all programs
  • 6. SELinux?! Available since ~2004 (Fedora 3), kernel 2.6 - everybody knows how to switch it off MAC (Mandatory Access Control) Too complicated? Not really! Not explicitly allowed? => denied - targeted policy - only restrict some programs
  • 7. SELinux Labels Label for files, processes, ports - process is given access to files, ports
  • 8. SELinux Labels Label for files, processes, ports - process is given access to files, ports UNIX: almost everything is file
  • 9. SELinux Labels Label for files, processes, ports - process is given access to files, ports UNIX: almost everything is file subject objects
  • 10. SELinux Labels Label for files, processes, ports - process is given access to files, ports Every process is running in some domain - confined or unconfined - transition from domain to another on exec(2)
  • 11. How to Create Policy 1. create domain transition 2. run program in permissive mode, inspect log 3. add rules (use policy macros, if possible) - audit2allow helps - setenforce 1; setenforce 0 clears AVC cache 4. run program in enforcing mode
  • 12. Example … example policy for HTTP server running image to PDF conversion service
  • 13. Example … example policy for HTTP server running image to PDF conversion service - policy consists of .fc, .if and .te files - compile and load using Makefile provided
  • 14. Example - type definitions # myserver.te policy_module(myserver, 1.0.0) # required types gen_require(` type unconfined_t; type proc_t; type sysfs_t; type tmp_t; ') # new types type myserver_exec_t; type myserver_t; type convert_exec_t; role unconfined_r types myserver_t;
  • 15. Example - type definitions - domain transition # force domain transition executing myserver_exec_t domain_type(myserver_t) domain_entry_file(myserver_t,myserver_exec_t) domtrans_pattern(unconfined_t,myserver_exec_t,myserv er_t)
  • 16. Example - type definitions - domain transition - macros # allow read of /usr/bin/* files corecmd_read_bin_files(myserver_t) # allow read of e.g. /usr/share/* files files_read_usr_files(myserver_t) # localization miscfiles_read_localization(myserver_t)
  • 17. Example - type definitions - domain transition - macros - allow rules # allow to listen on port 8080 allow myserver_t http_cache_port_t:tcp_socket name_bind; # allow to run convert allow myserver_t convert_exec_t:file { read execute open getattr execute_no_trans }; allow myserver_t node_t:tcp_socket node_bind; allow myserver_t self:fifo_file { read write ioctl getattr }; allow myserver_t self:process getsched; allow myserver_t self:tcp_socket { setopt read bind create ioctl accept write getattr listen };
  • 18. Example - type definitions - domain transition - macros - allow rules - dontaudit rules dontaudit myserver_t etc_t:file { read getattr open }; dontaudit myserver_t proc_t:file { read getattr open }; dontaudit myserver_t sysfs_t:dir search; dontaudit myserver_t sysfs_t:file { read open }; dontaudit myserver_t user_devpts_t:chr_file { read write ioctl }; dontaudit myserver_t user_home_dir_t:dir search;
  • 19. Example - type definitions - domain transition - macros - allow rules - dontaudit rules - file contexts # myserver.fc /usr/bin/myserver.pl -- gen_context(system_u:object_r:myserver_exec_t,s0) /usr/bin/convert -- gen_context(system_u:object_r:convert_exec_t,s0)
  • 20. - make -f /usr/share/selinux/default/include/Makefile load - semanage; sestatus; setenforce [0|1] - ps -Z; ls -Z; id -Z - chcon; restorecon; fixfiles - audit2allow </var/log/audit/audit.log - strace Tooling