Home / Community / Blog

There is "small" difference between

chcon -t some_file_type_t /some/file

and

semanage fcontext -a -t some_file_type_t /some/file
restorecon -v /some/file

The first one only set contex for specified file, but when file id deleted and created again or restored from backup (ie. tar without --selinux attribute) the changed context is not restored.

To permanently change context to file or some files, even created you have to use semanage:

semanage fcontext -a -t fome_file_type_t "/some/dir(/.*)?"

to change context to directory /some/dir and all files in this directory.

If you want to use Submin, or any other web application that resides outside default Apache directory (/var/www/html) you have to set proper SELinux context for all files. In this case all files are located in /var/lib/submin directory. Without this you will get some error messages in /var/log/audit/audit.log:

avc:  denied  { write } for  pid=1813 comm="python2" name="submin.db" dev=dm-0 ino=664032 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_lib_t:s0 tclass=file

and in /var/log/messages:

setroubleshoot: SELinux is preventing /usr/bin/python from read access on the file /var/lib/submin/conf/settings.py
setroubleshoot: SELinux is preventing /usr/bin/python from read access on the file /var/lib/submin/conf/settings.pyc
setroubleshoot: SELinux is preventing /usr/bin/python from write access on the directory /var/lib/submin/conf
setroubleshoot: SELinux is preventing /usr/bin/python from getattr access on the file /var/lib/submin/conf/submin.db

You should change context of /var/lib/submin/cgi-bin/submin.cgi to httpd_sys_script_exec_t and whole /var/lib/submin/conf/ directory to httpd_sys_script_rw_t:

cd /var/lib/submin
chcon -t httpd_sys_script_exec_t cgi-bin/submin.cgi
chcon -R -t httpd_sys_script_rw_t conf

additionally if You want Submin to work with Apache on different port (ie. 88), you have to change http_vhost options:

submin2-admin /var/lib/submin config set http_vhost "http://your.host.com:88"

note there is no tailing slash (/) in address.

Czasem jest potrzeba monitorowania kto i kiedy (czy aby nie za często) zagląda do określonych plików. O ile dostęp dla zwykłych użytkowników możemy ograniczyć, chociażby przez ACL'e lub mechanizmy SE Linux, to z administratorami (słynny root) jest większy problem. Jest to szczególnie ważne w środowiskach gdzie jest kilku administratorów z uprawnieniami do korzystania z polecenia su lub/i sudo.

Linuks ma gotowe rozwiązanie każdego problemu (w końcu wykonuje pętlę nieskończona w 5 sekund) - w tym przypadku jest to auditd.

Aby monitorować kto zagląda do katalogu /shares/dokumety trzeba dopisać w pliku /etc/audit/audit.rules (na końcu):

-a exit,always -S all -F dir=/shares/dokumenty

i uruchomić ponownie auditd. Teraz każde odczytanie katalogu (polecenie ls to właśnie odczytanie katalogu) czy pliku w ścieżce /shares/dokumenty (łącznie z podkatalogami) będzie monitorowane.

Oczywiście tego może być dużo, a po drugie dla kogoś te dokumenty są, dlatego można dodać ogranicznik (na końcu lini)

-F gid!=555

jeżeli użytkownicy należący do grupy o numerze 555 mają mieć dostęp. Ponadto jeżeli interesuje nas tylko otwarcie pliku to można zamiast -S all dać -S open -S truncate. W całości taka reguła będzie wyglądała tak:

-a exit,always -S open -S truncate -F dir=/shares/dokumenty -F gid!=555

o innych opcjach można sobie jeszcze poczytać:

man audit.rules
man auditctl

Jak już wspomniałem taki logów może być dużo, a przeglądanie surowego pliku /var/log/audit.log nie nalezy do najprzyjemniejszych. Na szczeście do przeglądania logów można użyć polecenia ausearch z przełącznikiem -i które ładniej wyświetli daty zamiast timestamp'u i użytkowników zamiast ich uid'ów.

Just my blog...

Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31