SELinux: Unterschied zwischen den Versionen

Aus SchnallIchNet
Wechseln zu: Navigation, Suche
(audit2why)
(audit2allow)
Zeile 104: Zeile 104:
  
 
<pre>
 
<pre>
# echo "type=AVC msg=audit(1347538264.046:1782214): avc:  denied  { getattr } for  pid=12639 comm="snmpwalk" path="/var/lib/net-snmp" dev=sdb5 ino=201334640 scontext=unconfined_u:system_r:nagios_t:s0 tcontext=system_u:object_r:snmpd_var_lib_t:s0 tclass=dir
+
# echo "type=AVC msg=audit(1347538264.046:1782214): avc:  denied  { getattr } for  pid=12639 comm="snmpwalk"  
type=SYSCALL msg=audit(1347538264.046:1782214): arch=c000003e syscall=4 success=yes exit=0 a0=1569860 a1=7fff30da71d0 a2=7fff30da71d0 a3=12 items=0 ppid=12628 pid=12639 auid=0 uid=498 gid=498 euid=498 suid=498 fsuid=498 egid=498 sgid=498 fsgid=498 tty=(none) ses=30 comm="snmpwalk" exe="/usr/bin/snmpwalk" subj=unconfined_u:system_r:nagios_t:s0 key=(null)" | audit2allow
+
path="/var/lib/net-snmp" dev=sdb5 ino=201334640 scontext=unconfined_u:system_r:nagios_t:s0  
 +
tcontext=system_u:object_r:snmpd_var_lib_t:s0 tclass=dir
 +
type=SYSCALL msg=audit(1347538264.046:1782214): arch=c000003e syscall=4 success=yes exit=0 a0=1569860  
 +
a1=7fff30da71d0 a2=7fff30da71d0 a3=12 items=0 ppid=12628 pid=12639 auid=0 uid=498 gid=498 euid=498 suid=498  
 +
fsuid=498 egid=498 sgid=498 fsgid=498 tty=(none) ses=30 comm="snmpwalk" exe="/usr/bin/snmpwalk"  
 +
subj=unconfined_u:system_r:nagios_t:s0 key=(null)" | audit2allow
  
  
Zeile 117: Zeile 122:
  
 
<pre>
 
<pre>
# echo "type=AVC msg=audit(1347538264.046:1782214): avc:  denied  { getattr } for  pid=12639 comm="snmpwalk" path="/var/lib/net-snmp" dev=sdb5 ino=201334640 scontext=unconfined_u:system_r:nagios_t:s0 tcontext=system_u:object_r:snmpd_var_lib_t:s0 tclass=dir
+
# echo "type=AVC msg=audit(1347538264.046:1782214): avc:  denied  { getattr } for  pid=12639 comm="snmpwalk"  
type=SYSCALL msg=audit(1347538264.046:1782214): arch=c000003e syscall=4 success=yes exit=0 a0=1569860 a1=7fff30da71d0 a2=7fff30da71d0 a3=12 items=0 ppid=12628 pid=12639 auid=0 uid=498 gid=498 euid=498 suid=498 fsuid=498 egid=498 sgid=498 fsgid=498 tty=(none) ses=30 comm="snmpwalk" exe="/usr/bin/snmpwalk" subj=unconfined_u:system_r:nagios_t:s0 key=(null)" | audit2allow -M local
+
path="/var/lib/net-snmp" dev=sdb5 ino=201334640 scontext=unconfined_u:system_r:nagios_t:s0  
 +
tcontext=system_u:object_r:snmpd_var_lib_t:s0 tclass=dir
 +
type=SYSCALL msg=audit(1347538264.046:1782214): arch=c000003e syscall=4 success=yes exit=0 a0=1569860  
 +
a1=7fff30da71d0 a2=7fff30da71d0 a3=12 items=0 ppid=12628 pid=12639 auid=0 uid=498 gid=498 euid=498  
 +
suid=498 fsuid=498 egid=498 sgid=498 fsgid=498 tty=(none) ses=30 comm="snmpwalk" exe="/usr/bin/snmpwalk"  
 +
subj=unconfined_u:system_r:nagios_t:s0 key=(null)" | audit2allow -M local
 
******************** IMPORTANT ***********************
 
******************** IMPORTANT ***********************
 
To make this policy package active, execute:
 
To make this policy package active, execute:
Zeile 131: Zeile 141:
  
 
have fun!
 
have fun!
 
  
 
== Deaktivieren ==
 
== Deaktivieren ==

Version vom 13. September 2012, 13:38 Uhr

Userland-Tools

sestatus -v

zeigt den aktuellen selinux status an

# getenforce
Enforcing

Befindet sich SELinux im permissive oder enforcing mode?

setenforce 0
setenforce 1

Den enforcing mode aus- und wieder anschalten.

getsebool -a

zeigt alle bool-werte an

system-config-securitylevel

graphisches config-tool

newrole -r sysadm_t

Die SELinux-Rolle wechseln (gibt es nur in der strict policy).

# ls -Z ./xyz.txt
-rw-r--r--  root root unconfined_u:object_r:admin_home_t:s0 xyz.txt

# chcon 'system_u:object_r:admin_home_t:s0' ./xyz.txt

# ls -Z ./xyz.txt
-rw-r--r--  root root system_u:object_r:admin_home_t:s0 ./xyz.txt

Den security context einzelner Dateien oder Dateisysteme ändern. Als Beispiel ändern wir hier den SELinux-Benutzer der Datei xyz.txt von unconfined_u nach system_u.

# ls -lZ /etc/zshrc
-rw-r--r--  root root unconfined_u:object_r:admin_home_t:s0 zshrc

# restorecon -vn /etc/zshrc
restorecon reset /etc/zshrc context unconfined_u:object_r:admin_home_t:s0->system_u:object_r:etc_t:s0
# restorecon /etc/zshrc

# ls -lZ /etc/zshrc
-rw-r--r--  root root system_u:object_r:etc_t:s0       /etc/zshrc

Dateien mit dem Standardkontext der Policy relablen. Mit -vn kann man sich erstmal anschauen, was geändert würde.

# setenforce 0
# vim&
[1] 5686 
# runcon 'system_u:object_r:admin_home_t:s0' vim&
[2] 5701 
# ps Z
...
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 5686 pts/1 T   0:00 vim
system_u:object_r:admin_home_t:s0 5701 pts/1   T      0:00 vim
...

Einen Prozess in einem bestimmten Kontext starten (geht nur im permissive mode)

# run_init /etc/init.d/apache2 start

Initskripte und somit einen Dämon im richtigen security context starten:

Es folgen noch einige Befehle ohne Beispiele. Hilfsmittel, um aus Regelverletzungen, die in den SELinux logs erscheinen, entsprechende Änderungen an der Policy durchzuführen. Es bewahrt einen davor, selbst manuell ins Regelwerk einzugreifen zu müssen. audit2allow

Hilfsmittel, um den Grund von denied-Meldungen zu verstehen. audit2why

Dateisysteme mit security context labeln bzw. korrigieren. setfiles fixfiles

Das folgende Kommando zeigt Zahlen des access vector caches an (Statistik). avcstat


generell fehler beheben

audit2why

get error/denied message from audit.log and pipe it

# echo "type=AVC msg=audit(1347538264.046:1782214): avc:  denied  { getattr } for  pid=12639 
comm="snmpwalk" path="/var/lib/net-snmp" dev=sdb5 ino=201334640 scontext=unconfined_u:system_r:nagios_t:s0 
tcontext=system_u:object_r:snmpd_var_lib_t:s0 tclass=dir
type=SYSCALL msg=audit(1347538264.046:1782214): arch=c000003e syscall=4 success=yes exit=0 
a0=1569860 a1=7fff30da71d0 a2=7fff30da71d0 a3=12 items=0 ppid=12628 pid=12639 auid=0 uid=498 
gid=498 euid=498 suid=498 fsuid=498 egid=498 sgid=498 fsgid=498 tty=(none) ses=30 
comm="snmpwalk" exe="/usr/bin/snmpwalk" subj=unconfined_u:system_r:nagios_t:s0 key=(null)" | audit2why

        Was caused by:
                Missing type enforcement (TE) allow rule.

                You can use audit2allow to generate a loadable module to allow this access.

audit2allow

ok like mentioned above we try audit2allow...

# echo "type=AVC msg=audit(1347538264.046:1782214): avc:  denied  { getattr } for  pid=12639 comm="snmpwalk" 
path="/var/lib/net-snmp" dev=sdb5 ino=201334640 scontext=unconfined_u:system_r:nagios_t:s0 
tcontext=system_u:object_r:snmpd_var_lib_t:s0 tclass=dir
type=SYSCALL msg=audit(1347538264.046:1782214): arch=c000003e syscall=4 success=yes exit=0 a0=1569860 
a1=7fff30da71d0 a2=7fff30da71d0 a3=12 items=0 ppid=12628 pid=12639 auid=0 uid=498 gid=498 euid=498 suid=498 
fsuid=498 egid=498 sgid=498 fsgid=498 tty=(none) ses=30 comm="snmpwalk" exe="/usr/bin/snmpwalk" 
subj=unconfined_u:system_r:nagios_t:s0 key=(null)" | audit2allow


#============= nagios_t ==============
allow nagios_t snmpd_var_lib_t:dir getattr;

as we can see, the rule is printed to stdout...
not what i exactly wanted... push it to selinux directly!
consult man-page of audit2allow you will find how, or se next command... ;-)

# echo "type=AVC msg=audit(1347538264.046:1782214): avc:  denied  { getattr } for  pid=12639 comm="snmpwalk" 
path="/var/lib/net-snmp" dev=sdb5 ino=201334640 scontext=unconfined_u:system_r:nagios_t:s0 
tcontext=system_u:object_r:snmpd_var_lib_t:s0 tclass=dir
type=SYSCALL msg=audit(1347538264.046:1782214): arch=c000003e syscall=4 success=yes exit=0 a0=1569860 
a1=7fff30da71d0 a2=7fff30da71d0 a3=12 items=0 ppid=12628 pid=12639 auid=0 uid=498 gid=498 euid=498 
suid=498 fsuid=498 egid=498 sgid=498 fsgid=498 tty=(none) ses=30 comm="snmpwalk" exe="/usr/bin/snmpwalk" 
subj=unconfined_u:system_r:nagios_t:s0 key=(null)" | audit2allow -M local
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i local.pp

you can see it creates the right rule in right place and tells us the command to activate ... nice!
so do it!

# semodule -i local.pp

have fun!

Deaktivieren

setsebool -P nagios_disable_trans=1

deaktiviert SELinux fuer den nagios-daemon
oder

setsebool -P named_disable_trans=1

deaktiviert SELinux fuer den nameserver-daemon (bind)


Firefox

ich habe firefox im home-verzeichnis installiert, benutze also nicht den distro-firefox...
manchmal hat man dann allerdings probleme mit selinux nach firefox-update.
firfox will nicht mehr starten... ;-)

chcon -t texrel_shlib_t /home/ME/firefox/libxul.so

behebt das wieder!
selbiges gilt neuerdings f. den flash-player

chcon -t textrel_shlib_t '/usr/lib/flash-plugin/libflashplayer.so'

Siehe auch

http://wiki.centos.org/HowTos/SELinux
http://www.os-t.de/HTML-SELinux/node97.html