DTrace: playing with mod_auth_pam and Apache 2Solaris 10: tips and tricks for system administration |
|
Sponsored LinksКатегорииLinksUnix Tutorial
Personal Development Ruslan Valiev Solaris Performance Team Damien Farnham Fintan Ryan Nicky Veitch Niall Mullen Sean McGrath DTrace Bryan Cantrill Brendan Gregg ZFS Tim Foster General Ben Rockwood Learning Solaris 10 Privacy policy |
Wednesday, December 21. 2005DTrace: playing with mod_auth_pam and Apache 2
One of our users has asked me to help with PAM authentication for Apache 2 on one of our remote servers.
It did seem like a rather trivial task - download mod_auth_pam, compile it for Apache 2, make sure everything works. The remote server uses NIS, I could freely log onto it. And you know what? It didn't work. The module compiled pretty easy, but I couldn't get it to work - error_log was reporting the same lines over and over again (I had to break the line to squeeze it into my blog format): CODE: [Tue Dec 20 16:48:44 2005] [error] [client xxx.xxx.xxx.xxx] \ PAM: user 'greys' - not authenticated: No account present for user Up to this point, everything was done by the user himself with small help from me. At this stage is was decided I'd have a look myself. To make things easier, I also wanted to: 1) Move all the experiments onto my own Solaris 10 box 2) Make it all work for local users first, and only then get NIS working as well Seeing the same errors on my box, I've decided to take a serious look at PAM. I've created Apache-related lines in /etc/pam.conf and added a debug option: CODE: httpd auth required pam_authtok_get.so.1 debug httpd auth required pam_unix_auth.so.1 debug To make it more convenient to track all the messages, I've updated /etc/syslog.conf to include the following: CODE: auth.debug /var/log/auth_log user.debug /var/log/user_log It got easier to see what was happening, at least I knew it was the /etc/pam.conf section I was thinking of. But the error was still there - my user definitely did exist in the system, only it wouldn't be recognized by Apache (and I've broken the lines yet again here): CODE: Dec 21 09:47:35 pele httpd[29143]: [ID 634615 user.debug] \ pam_authtok_get:pam_sm_authenticate: flags = 1 Dec 21 09:47:35 pele httpd[29143]: [ID 378613 user.debug] \ pam_dhkeys: user greys not found Dec 21 09:47:35 pele httpd[29143]: [ID 896952 user.debug] \ pam_unix_auth: entering pam_sm_authenticate() Dec 21 09:47:35 pele httpd[29143]: [ID 219349 user.debug] \ pam_unix_auth: user greys not found It was the right time to look at how exactly PAM and Apache 2 interacted when I was giving the username and password trying to access my page. I immediately thought of Brendan Gregg's opensnoop script for DTrace. And it was this script indeed which helped me see the problem: CODE: 60001 24744 httpd -1 2 /etc/pam_debug 60001 24744 httpd 11 0 /etc/pam.conf 60001 24744 httpd 11 0 /usr/lib/security/pam_authtok_get.so.1 60001 24744 httpd 11 0 /usr/lib/passwdutil.so.1 60001 24744 httpd 11 0 /usr/lib/libsldap.so.1 60001 24744 httpd 11 0 /usr/lib/security/pam_dhkeys.so.1 60001 24744 httpd 11 0 /usr/lib/security/pam_unix_cred.so.1 60001 24744 httpd 11 0 /lib/libbsm.so.1 60001 24744 httpd 11 0 /lib/libsecdb.so.1 60001 24744 httpd 11 0 /usr/lib/libproject.so.1 60001 24744 httpd 11 0 /lib/libproc.so.1 60001 24744 httpd 11 0 /lib/librtld_db.so.1 60001 24744 httpd 11 0 /lib/libelf.so.1 60001 24744 httpd 11 0 /lib/libctf.so.1 60001 24744 httpd 11 0 /usr/lib/security/pam_unix_auth.so.1 60001 24744 httpd -1 2 /var/run/syslog_door 60001 24744 httpd -1 13 /etc/shadow 60001 24744 httpd 11 0 /var/run/name_service_door 60001 24744 httpd 11 0 /etc/passwd 60001 24744 httpd -1 13 /etc/shadow 60001 24744 httpd -1 2 /var/run/syslog_door Apparently, httpd could not open /etc/shadow (-1 means error), obviously becase of permissions for the file. But just to make sure, I've looked for the error code (it's 13 as you can see): CODE: bash-3.00# grep 13 /usr/include/sys/errno.h #define EACCES 13 /* Permission denied */ So it all was suddenly clear, and I've proceeded like this: CODE: #groupadd shadows # chown root:shadows /etc/shadow # chmod 440 /etc/shadow All that's left to be done now was to make sure httpd.conf has a Group parameter set to this shadows group, and not nobody. pS: you might ask why didn't it work for NIS on the remote server in first place. This is because /etc/nsswitch.conf had not this: passwd: files nis, but this: passwd: compat, so NIS maps were consulted, but only based on + and - specifications in /etc/passwd and /etc/shadow files. This means we still needed to be able to read /etc/shadow, even though later PAM would consult NIS. Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Хозяин - барин! Сервак не мой, и я вообще говорил Sun'овский ONE Web или любой Netscape'овский веб-сервер юзать, он замечательно с LDAP умеет работать. Но хотели именно это.
Apache запускается (будет, по крайней мере, если меня послушают) под определённым юзером, и это только для конкретной одной задачи внутри интранета - так что если хотят NIS в Apache именно в такой конфигурации, то вот им решение. Хотя, я думаю, если сделать в nsswitch.conf строчку passwd: files nis, то этакий изврат с группой shadows не понадобится вовсе!
Имеются в виду модули, написанные на Perl? Я никогда не занимался этим вопросом прежде, так что любая полезная информация будет очень кстати ;) Но мне не понравилась идея с модулями, написанными на Perl - слишком много зависимостей. Если подобную вещь понадобится перенести на другой сервер, вся волокита повторится. С mod_auth_pam вроде попроще оказался вариант.
Ещё одна вещь - похоже на то, что нету ни одного модуля аутентификации, который бы регулярно обновлялся и дорабатывался? Или всё же что-то есть? Заранее спасибо!
Perl тут нипричём. Навскидку - в стандартную поставку Apache 2.0.x входит модуль mod_auth_ldap - http://httpd.apache.org/docs/2.0/mod/mod_auth_ldap.html
Написан полагаю на чистом Си ;)
Ну я тоже удивлюсь, если это не Си ;)
Глеб, а Вы вот эту страницу, посвященную DTrace, видели?
http://users.tpg.com.au/adsln4yb/dtrace.html
Добрый день, Дмитрий! Конечно же, я видел эту страницу. Я даже ссылку на скрипт opensnoop дал именно с этой страницы?
Ах да, извините, просмотрел ссылку под словом "opensnoop" :)
Наверное такая замечательная страница стоит того, чтобы ее отдельным постом "попеарили" :)
Автор, пиши ещё))
Очень интересный и полезный блог, читаю с удовольствием. Но почему так давно нет обновлений!??
Обновлений нет, потому что после праздников приходится впахивать на работе! ;) Но ситуация уже нормализуется, так что на днях продолжим :)
|





