Инструменты пользователя

Инструменты сайта


linux:samba:audit

Samba – лог файл аудита используя full_audit

Начало

File server auditing is a must have process for all companies that rely on file servers to store their critical data and applications. Malicious and accidental modifications to files, permissions, file sharing settings can severely impact your organization. (C) Где то в интернет..

Я не могу согласиться с этим, у меня не было такой цели, этот файл аудита просто одна из линий защиты от пользователей, которые любят орать «ГДЕ МОЙ МАЛЕНЬКИЙ И ОЧЕНЬ НУЖНЫЙ ДЛЯ МЕНЯ ФАЙЛ?!». В этой статье я расскажу как настроить аудит файлов Samba демона на Linux файл-сервере.

Аудит файлов на фейл-сервере это очень простая вещь: Оно записывает каждое действие пользователя с файлом на файл-сервере.

Так что мы легко можем сказать, что же случилось с тем или иным файлом:

Oct 23 16:06:44 server smbd_audit: user01|192.168.0.23|project|opendir|ok|.
Oct 23 16:06:44 server smbd_audit: user01|192.168.0.23|project|closedir|ok|
Oct 23 16:06:44 server smbd_audit: user01|192.168.0.23|project|open|ok|r|file.txt
Oct 23 16:06:44 server smbd_audit: user01|192.168.0.23|project|pread|ok|file.txt
Oct 23 16:06:44 server smbd_audit: user01|192.168.0.23|project|close|ok|file.txt

Приступим.

Настройка Samba

У нас есть samba-3.0.33 на Gentoo сервере. Айдит файлов включается использованием модуля full_audit.

Открываем smb.conf, обычно в /etc/samba/smb.conf

И добавляем эти строки в секцию global.

# Audit settings
full_audit:prefix = %u|%I|%S
full_audit:failure = connect
full_audit:success = connect disconnect opendir mkdir rmdir closedir open close read pread write pwrite sendfile rename unlink chmod
fchmod chown fchown chdir ftruncate lock symlink readlink link mknod realpath
full_audit:facility = local5
full_audit:priority = notice

Нада быть острожным с full_audit:success, оно выводит много событий на каждый чих, поэтому надо указывать необходимые нам параметры, иначе лог-файл быстро вырастет, забьет систему и все начнет тормозить

full_audit:prefix = %u|%I|%S - добавляет дополнительную полезную информацию в лог-файл аудита.

%u - Пользователь

%I - IP адрес пользователя

%S - Расшареная папка на сервере

Полный список переменных можно будет найти на этой странице http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html в разделе VARIABLE SUBSTITUTIONS

Для включения аудита на каждую расшаренную папку надо добавить эту строку:

vfs objects = full_audit

Пример:

[public]
  comment = Public Stuff
  path = /home/samba/public
  public = yes
  writable = no
  write list = @staff
  vfs object = full_audit 

That's all about samba. So where all this audit logs are going now ? As you can see from these lines:

full_audit:facility = local5 full_audit:priority = notice they are going to system logger (syslog).

Configuring syslog By default Gentoo uses syslog-ng, which on my opinion is MUCH better, comparing to syslogd daemon. But I will explain how to configure them both.

Configuring syslog-ng

Locate file /etc/syslog-ng/syslog-ng.conf

Add these lines:

filter f_local5 {facility(local5);};
destination m_samba_audit { file("/var/log/samba/audit.log"); };
log { source(src); filter(f_local5);destination(m_samba_audit); flags(final); };

BEFORE line

log { source(src); destination(messages); };

This will tell syslog-ng to filter only LOCAL5 message and write them to /var/log/samba/audit.log and skip this audit records from being recorded in /var/log/messages

Configuring syslogd

In standard configuration of syslogd there is a line in file syslog.conf :

*.*;auth,authpriv.none           -/var/log/syslog

To filter audit messages away from main syslog file, change this line to:

*.*;local5,auth,authpriv.none           -/var/log/syslog

Add following line after

local5.notice /var/log/samba/audit.log

Restaring

Restart samba

# /etc/init.d/samba restart

and syslog, ususally this is done via this command

# /etc/init.d/syslogd restart

However in your distro may be different way.

Try to make some file changes in audit share and check /var/log/samba/audit.log, it should contain some records.

Log rotation with logrotate The last part, but not less important is to configure log rotation, not to end with FULL /var, or even worse / partition.

This setup is for syslog-ng, in case of syslogd change post rotate script to restart syslog.

Create new file /etc/logrotate.d/samba.audit

/var/log/samba/audit.log {
   weekly
   missingok
   rotate 7
   postrotate
      /etc/init.d/syslog-ng reload > /dev/null 2>&1 || true
   endscript
   compress
   notifempty
}

References

http://www.opennet.ru/base/net/samba_full_audit.txt.html

The syslog-ng 3.0 Administrator Guide

linux/samba/audit.txt · Последнее изменение: 2012/02/17 11:34 — linko22@gmail.com