Project

General

Profile

ApacheMySQLAuthentication » History » Version 16

Markus Döring, 08/22/2007 06:59 PM

1 8 Lutz Suhrbier
[[[PageOutline(2-9Table|of Contents,outline)]]]
2
3
4 1 Lutz Suhrbier
5 6 Lutz Suhrbier
# Apache [[MySQL]] Authentication for Debian Etch
6 1 Lutz Suhrbier
7 6 Lutz Suhrbier
This how-to describes the setup of redirecting the authentication of the Apache Web Server to a [[MySQL]] Database for Debian Etch.
8 3 Lutz Suhrbier
9 1 Lutz Suhrbier
10 6 Lutz Suhrbier
Usually, this is done by Apache's _auth-mysql_ module. But, the relating Debian package _libapache2-mod-auth-myaql_ is currently not maintained and therefore not in the stable release (http://packages.qa.debian.org/liba/libapache-mod-auth-mysql.html).
11
12
13
There are two possible solutions:
14
15
* Using [[MySQL]] authentication via PAM
16
17
* Compiling the Apache module _auth-mysql_
18
19
20
Debian recommends to use PAM->MySQL authentication. It works fine, but the current Debian package does not support (non-crypt) MD5-password storage.
21
22
23
Thus, finally self-compiling the auth-mysql module appears to be the best solution. But, we have to pay attention to possible security advices concerning the module.
24
25
26
27 1 Lutz Suhrbier
## PAM-MySQL Authentication
28 3 Lutz Suhrbier
29 6 Lutz Suhrbier
The recommended Debian way is to use the packages libapache2-mod-auth-pam and libpam-mysql instead.
30 3 Lutz Suhrbier
31
~~~
32 1 Lutz Suhrbier
# apt-get install libapache2-mod-auth-pam libpam-mysql
33
~~~
34
35 6 Lutz Suhrbier
The usage of the PAM authentication module has to be configured in Apache2. To use [[MySQL]] authentication with our [[ShibbolethIdPInstallDebianEtch|IdP configuration]], we change the shibboleth authentication location in the idp configuration script as follows:
36 1 Lutz Suhrbier
37
~~~
38 6 Lutz Suhrbier
  <Location /shibboleth-idp/SSO>
39
    AuthPAM_Enabled 	on
40
    AuthPAM_FallThrough off
41
    AuthUserFile /dev/null
42
    AuthBasicAuthoritative Off
43 5 Lutz Suhrbier
    AuthName               "Shibboleth IdP"
44 1 Lutz Suhrbier
    AuthType               Basic
45
    require                valid-user
46
  </Location>
47
~~~
48 3 Lutz Suhrbier
49 6 Lutz Suhrbier
With regard to the security advice of the file "/usr/share/doc/libapache2-mod-auth-pam/README.Debian" 
50 1 Lutz Suhrbier
51 3 Lutz Suhrbier
~~~
52 6 Lutz Suhrbier
SECURITY
53 3 Lutz Suhrbier
54
  To use with standard Debian configuration you have to add "www-data" user to
55
  "shadow" group. Be careful! It means it can be readable by anyone who can run
56
  its own CGI script!
57
58
  The passwords are sent by net as clear text. You should use SSL to protect
59
  them.
60 6 Lutz Suhrbier
~~~
61
we should add the user www-data to the shadow group.
62 3 Lutz Suhrbier
63 6 Lutz Suhrbier
~~~
64
# adduser www-data shadow
65
~~~
66 3 Lutz Suhrbier
67 6 Lutz Suhrbier
Next, we have to configure the PAM-MySQL module for Apache2.
68 3 Lutz Suhrbier
69 6 Lutz Suhrbier
Edit _/etc/pam.d/apache2_, add the following line setting the values such as they match your configuration
70 3 Lutz Suhrbier
71
~~~
72 9 Lutz Suhrbier
auth sufficient pam_mysql.so verbose=1 user=webuser passwd=  host=160.45.63.30 db=drupal5 table=drupal5._shared_users usercolumn=drupal5._shared_users.name passwdcolumn=drupal5._shared_users.pass crypt=3
73 1 Lutz Suhrbier
~~~
74 9 Lutz Suhrbier
75 6 Lutz Suhrbier
More detailed information about the possible values can be retrieved reading _/usr/share/doc/libpam-mysql/README.gz_
76 3 Lutz Suhrbier
77 6 Lutz Suhrbier
~~~
78
# zless /usr/share/doc/libpam-mysql/README.gz
79
~~~
80
81 3 Lutz Suhrbier
Finally, restart apache2 and see if it works.
82 2 Lutz Suhrbier
83 1 Lutz Suhrbier
84
85
86 9 Lutz Suhrbier
## Compiling and Installing Apache's _auth-mysql_ module
87 1 Lutz Suhrbier
88 7 Lutz Suhrbier
Regarding this objective, we mainly rely on the following documentation http://forum.nuxwin.com/index.php/topic,736.msg3590.html#msg3590 (in french).
89 1 Lutz Suhrbier
90 7 Lutz Suhrbier
91
We need to install the following packages in order to compile and install the module:
92
93 1 Lutz Suhrbier
~~~
94 7 Lutz Suhrbier
 apt-get install apache2-prefork-dev libmysqlclient15-dev gcc patch
95 1 Lutz Suhrbier
~~~
96 7 Lutz Suhrbier
97
Create the directory _/usr/src/auth_mysql_ and change to it:
98
99
~~~
100
# mkdir /usr/src/auth_mysql
101
# cd /usr/src/auth_mysql
102
~~~
103
104
Download the module's source files and the relating patch for Apache 2.2
105
106
~~~
107
# wget http://download.nuxwin.com/apache2.2-modules/auth_mysql/mod_auth_mysql-3.0.0.tar.gz
108
# wget http://download.nuxwin.com/apache2.2-modules/auth_mysql/patch/apache2.2.diff
109
~~~
110
111
Unpack the sources and apply the patch file to the sources:
112
113
~~~
114
tar xzf mod_auth_mysql-3.0.0.tar.gz
115
# cp apache2.2.diff mod_auth_mysql-3.0.0/
116
# cd mod_auth_mysql-3.0.0
117
# patch -p0 < apache2.2.diff mod_auth_mysql.c
118
~~~
119
120
Compiling the module and check the output produced:
121
122
~~~
123
# apxs2 -c -L/usr/lib/mysql -I/usr/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c
124
125
/usr/share/apr-1.0/build/libtool --silent --mode=compile --tag=disable-static i486-linux-gnu-gcc -prefer-pic -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -DLINUX=2 -D_REENTRANT -I/usr/include/apr-1.0 -I/usr/include/openssl -I/usr/include/postgresql -I/usr/include/xmltok -pthread     -I/usr/include/apache2  -I/usr/include/apr-1.0   -I/usr/include/apr-1.0 -I/usr/include/postgresql -I/usr/include/mysql  -c -o mod_auth_mysql.lo mod_auth_mysql.c && touch mod_auth_mysql.slo
126
/usr/share/apr-1.0/build/libtool --silent --mode=link --tag=disable-static i486-linux-gnu-gcc -o mod_auth_mysql.la  -L/usr/lib/mysql -lmysqlclient -lm -lz -rpath /usr/lib/apache2/modules -module -avoid-version    mod_auth_mysql.lo
127
~~~
128
129
Install the module and check the output produced:
130
131
@-LLIBDIR'
132
133
flag during linking and do at least one of the following:
134
135
   - add LIBDIR to the @
136
137
138
Create the module's load configuration file:
139
140
~~~
141
# echo "LoadModule mysql_auth_module /usr/lib/apache2/modules/mod_auth_mysql.so" > /etc/apache2/mods-available/auth_mysql.load
142
~~~
143
144
Enable the module and restart apache2:
145
146
~~~
147
# a2enmod auth_mysql
148
# /etc/init.d/apache2 force-reload
149
~~~
150
151
You can check your configuration observing the following log-files
152
153
* /var/log/apache2/access.log
154
155
* /var/log/apache2/error.log
156
157
* /var/log/auth.log
158 10 Markus Döring
159
160 1 Lutz Suhrbier
161 11 Markus Döring
### Subversion w/ mod_auth_mysql
162 1 Lutz Suhrbier
163 11 Markus Döring
Configure Apache to use mod_auth_mysql for subversion:
164
165
httpd.conf
166
167
~~~
168
<VirtualHost *>
169 13 Markus Döring
<Location /svn>
170
  DAV            svn
171
  SVNPath        /var/lib/svn/edit
172
  SVNIndexXSLT   /svnindex/svnindex.xsl
173 1 Lutz Suhrbier
174 13 Markus Döring
  AuthType  Basic 
175 15 Markus Döring
  AuthName  "EDIT Subversion, use BDTracker account"
176
  AuthzSVNAccessFile  /var/lib/svn/access-edit.conf
177
  Satisfy Any
178
  Require valid-user
179 13 Markus Döring
180
  # how to authenticate a user
181 1 Lutz Suhrbier
  AuthBasicAuthoritative Off
182 13 Markus Döring
  AuthMySQLHost 192.168.2.10
183 15 Markus Döring
  AuthMySQLUser xxx
184 13 Markus Döring
  AuthMySQLPassword XXX
185 1 Lutz Suhrbier
  AuthMySQLDB drupal5
186
  AuthMySQLUserTable _shared_users
187
  AuthMySQLNameField name
188
  AuthMySQLPasswordField pass
189
  AuthMySQLPwEncryption md5
190
</Location>
191
192
</VirtualHost>   
193 15 Markus Döring
~~~
194
195
or for multiple repositories:
196
197
~~~
198
<Location /svn>
199
 DAV            svn
200
 SVNParentPath  /var/lib/svn
201
 SVNIndexXSLT   /svnindex/svnindex.xsl
202
 SVNListParentPath on
203
204
 AuthType  Basic
205
 AuthName  "BGBM Subversion - EDIT BDTracker account"
206
 AuthzSVNAccessFile /var/lib/svn/access.conf
207
 Satisfy Any
208
 Require valid-user
209
210
 # how to authenticate a user
211
 AuthBasicAuthoritative Off
212
 AuthMySQLAuthoritative on
213
 AuthMySQLHost 192.168.2.10
214
 AuthMySQLUser xxx
215
 AuthMySQLPassword xxx
216
 AuthMySQLDB drupal5
217
 AuthMySQLUserTable _shared_users
218
 AuthMySQLNameField name
219
 AuthMySQLPasswordField pass
220
 AuthMySQLPwEncryption md5
221
222
</Location>
223 11 Markus Döring
~~~
224
225
226
227 1 Lutz Suhrbier
### Trac w/ mod_auth_mysql
228 11 Markus Döring
229
Configure Apache to use mod_auth_mysql for Trac:
230
231
httpd.conf
232
233
234
~~~
235 12 Markus Döring
<Location "/trac">
236
    SetHandler mod_python
237
    PythonHandler trac.web.modpython_frontend
238
    PythonOption TracEnv /var/trac/test
239
    PythonOption TracUriRoot /trac
240
</Location>
241 1 Lutz Suhrbier
242 12 Markus Döring
<Location "/trac/login">
243
  AuthName "EDIT Trac"
244
  AuthType Basic
245 1 Lutz Suhrbier
246 12 Markus Döring
  AuthBasicAuthoritative off
247
  AuthMySQLAuthoritative on
248 11 Markus Döring
249 12 Markus Döring
  AuthMySQLHost 192.168.2.10
250
  AuthMySQLUser xxx
251
  AuthMySQLPassword xxx
252
  AuthMySQLDB drupal5
253
  AuthMySQLUserTable _shared_users
254
  AuthMySQLNameField name
255
  AuthMySQLPasswordField pass
256
  AuthMySQLPwEncryption md5
257
258
  Require valid-user
259
</Location>
260
261 1 Lutz Suhrbier
~~~