Recipe 6.1 Using System Account Information for Web Authentication
Problem
You want all the users on your Unixish system to be able to
authenticate themselves over the Web using their already-assigned
usernames and passwords.
Solution
Set up a realm using
mod_auth and name
/etc/passwd as the
AuthUserFile:
<Directory "/home">
AuthType Basic
AuthName HomeDir
AuthUserFile /etc/passwd
Require valid-user
Satisfy All
</Directory>
Discussion
We must stress that using system account information for web
authentication is a very bad idea, unless your site is also secured
using SSL. For one thing, any intruder who happens to obtain one of
your users' credentials not only can access the
protected files over the Web, but can actually log onto your system
where it's possible to do significant damage. For
another, web logins don't have the same security
controls as most operating systems; over the Web, an intruder can
keep hammering away at a username with password after password
without the system taking any defensive measures; all
mod_auth will do is record a message in the
Apache error log.However, most operating systems will enter a
paranoid mode and at least ignore login attempts for a while after
some number of failures.
If you still want to do this, either because you consider the risk
acceptable or because it doesn't apply in your
situation, the httpd.conf directives in the
Solution will do the trick. The syntax and order of the fields in a
credential record used by mod_auth happens (and
not by accident) to match the standard layout of the
/etc/passwd lines. mod_auth
uses a simple text file format in which each line starts with a
username and password and may optionally contain additional fields,
with the fields delimited by colons. For example:
smith:$apr1$GLWeF/..$8hOXRFUpHhBJHpOUdNFe51
mod_auth ignores any additional fields after the
password, which is what allows the /etc/passwd
file to be used. Note that the password in the example is encrypted.
You can manage Apache mod_auth credential files
with the htpasswd utility, but
don't use this utility on the
/etc/passwd file! Use the normal account
maintenance tools for that.
Note that this technique will not work if shadow passwords are in
use, because the password field of /etc/passwd
contains nothing useful in that situation. Instead, the passwords are
stored in the file /etc/shadow, which is
readable only by root, while Apache runs as an unprivileged user.
Furthermore, most modern Unixish operating systems use the
/etc/shadow means of user authentication by
default.
See Also
|