summaryrefslogtreecommitdiff
path: root/docs/docbook/projdoc/PAM-Authentication-And-Samba.xml
blob: ef1496c7a6803a43ef9c1e5f2b18d7f7b95bef4a (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
<chapter id="pam">
<chapterinfo>
	&author.jht;
	<author>
		<firstname>Stephen</firstname><surname>Langasek</surname>
		<affiliation>
			<address><email>vorlon@netexpress.net</email></address>
		</affiliation>
	</author>
    <pubdate> (Jun 21 2001) </pubdate>
</chapterinfo>
 
<title>PAM based Distributed Authentication</title>

<para>
This chapter you should help you to deploy winbind based authentication on any PAM enabled
Unix/Linux system. Winbind can be used to enable user level application access authentication
from any MS Windows NT Domain, MS Windows 200x Active Directory based domain, or any Samba
based domain environment. It will also help you to configure PAM based local host access
controls that are appropriate to your Samba configuration.
</para>

<sect1>
<title>Features and Benefits</title>

<para>
A number of Unix systems (eg: Sun Solaris), as well as the xxxxBSD family and Linux,
now utilize the Pluggable Authentication Modules (PAM) facility to provide all authentication, 
authorization and resource control services. Prior to the introduction of PAM, a decision
to use an alternative to the system password database (<filename>/etc/passwd</filename>) 
would require the provision of alternatives for all programs that provide security services.
Such a choice would involve provision of alternatives to such programs as: <command>login</command>, 
<command>passwd</command>, <command>chown</command>, etc.
</para>

<para>
PAM provides a mechanism that disconnects these security programs from the underlying
authentication/authorization infrastructure.  PAM is configured either through one file
<filename>/etc/pam.conf</filename> (Solaris), or by editing individual files that are
located in <filename>/etc/pam.d</filename>.
</para>

<para>
On PAM enabled Unix/Linux systems it is an easy matter to configure the system to use any
authentication backend, so long as the appropriate dynamically loadable library modules
are available for it. The backend may be local to the system, or may be centralised on a
remote server.
</para>

<para>
PAM support modules are available for:
</para>

<variablelist>
	<varlistentry><term><filename>/etc/passwd</filename></term><listitem><para>-</para>
		<para>
		There are several PAM modules that interact with this standard Unix user
		database. The most common are called: pam_unix.so, pam_unix2.so, pam_pwdb.so
		and pam_userdb.so.
		</para>
	</listitem></varlistentry>

	<varlistentry><term>Kerberos</term><listitem><para>-</para>
		<para>
		The pam_krb5.so module allows the use of any Kerberos compliant server.
		This tool is used to access MIT Kerberos, Heimdal Kerberos, and potentially
		Microsoft Active Directory (if enabled).
		</para>
	</listitem></varlistentry>

	<varlistentry><term>LDAP</term><listitem><para>-</para>
		<para>
		The pam_ldap.so module allows the use of any LDAP v2 or v3 compatible backend
		server. Commonly used LDAP backend servers include: OpenLDAP v2.0 and v2.1,
		Sun ONE iDentity server, Novell eDirectory server, Microsoft Active Directory.
		</para>
	</listitem></varlistentry>

	<varlistentry><term>NetWare Bindery</term><listitem><para>-</para>
		<para>
		The pam_ncp_auth.so module allows authentication off any bindery enabled
		NetWare Core Protocol based server.
		</para>
	</listitem></varlistentry>

	<varlistentry><term>SMB Password</term><listitem><para>-</para>
		<para>
		This module, called pam_smbpass.so, will allow user authentication off
		the passdb backend that is configured in the Samba &smb.conf; file.
		</para>
	</listitem></varlistentry>

	<varlistentry><term>SMB Server</term><listitem><para>-</para>
		<para>
		The pam_smb_auth.so module is the original MS Windows networking authentication
		tool. This module has been somewhat outdated by the Winbind module.
		</para>
	</listitem></varlistentry>

	<varlistentry><term>Winbind</term><listitem><para>-</para>
		<para>
		The pam_winbind.so module allows Samba to obtain authentication from any
		MS Windows Domain Controller. It can just as easily be used to authenticate
		users for access to any PAM enabled application.
		</para>
	</listitem></varlistentry>

	<varlistentry><term>RADIUS</term><listitem><para>-</para>
		<para>
		There is a PAM RADIUS (Remote Access Dial-In User Service) authentication
		module. In most cases the administrator will need to locate the source code
		for this tool and compile and install it themselves. RADIUS protocols are
		used by many routers and terminal servers.
		</para>
	</listitem></varlistentry>
</variablelist>

<para>
Of the above, Samba provides the pam_smbpasswd.so and the pam_winbind.so modules alone.
</para>

<para>
Once configured, these permit a remarkable level of flexibility in the location and use
of distributed samba domain controllers that can provide wide are network bandwidth
efficient authentication services for PAM capable systems. In effect, this allows the
deployment of centrally managed and maintained distributed authentication from a single
user account database.
</para>

</sect1>

<sect1>
<title>Technical Discussion</title>

<para>
All operating systems depend on the authentication sub-systems to provide for authenticated users
credentials accecptable to the platform. Unix requires the provision of a user identifier (UID)
as well as a group identifier (GID). These are both simple integer type numbers that are obtained
from a password backend such as <filename>/etc/passwd</filename>.
</para>

<para>
Users and groups on a Windows NT server are assigned a relative id (rid) which is unique for
the domain when the user or group is created. To convert the Windows NT user or group into
a  unix user or group, a mapping between rids and unix user and group ids is required. This
is one of the jobs that winbind performs.
</para>

<para>
As winbind users and groups are resolved from a server, user and group ids are allocated
from a specified range. This is done on a first come, first served basis, although all
existing users and groups will be mapped as soon as a client performs a user or  group 
enumeration command.  The allocated unix ids are stored in a database file under the Samba
lock directory and will be remembered.
</para>

<warning><para>
The rid to unix id database is the only location where the user and group  mappings are 
stored by winbindd.  If this file is deleted or corrupted, there is no way for winbindd
to determine which user and group ids correspond to Windows NT user and group rids.
</para></warning>

<para>
If the PAM authentication module (loadable link library file) is located in the
default location then it is not necessary to specify the path. In the case of
Linux, the default location is <filename>/lib/security</filename>. If the module
is located outside the default then the path must be specified as:

<screen>
auth  required  /other_path/pam_strange_module.so
</screen>
</para>

<para>
The following is an example <filename>/etc/pam.d/login</filename> configuration file. 
This example had all options been uncommented is probably not usable 
as it stacks many conditions before allowing successful completion 
of the login process. Essentially all conditions can be disabled 
by commenting them out except the calls to <filename>pam_pwdb.so</filename>.
</para>

<para><screen>
#%PAM-1.0
# The PAM configuration file for the `login' service
#
auth         required    pam_securetty.so
auth         required    pam_nologin.so
# auth       required    pam_dialup.so
# auth       optional    pam_mail.so
auth         required    pam_pwdb.so shadow md5
# account    requisite   pam_time.so
account      required    pam_pwdb.so
session      required    pam_pwdb.so
# session    optional    pam_lastlog.so
# password   required    pam_cracklib.so retry=3
password     required    pam_pwdb.so shadow md5
</screen></para>

<para>
PAM allows use of replacable modules. Those available on a sample system include:
</para>

<para><prompt>$</prompt><userinput>/bin/ls /lib/security</userinput>
<screen>
pam_access.so    pam_ftp.so          pam_limits.so     
pam_ncp_auth.so  pam_rhosts_auth.so  pam_stress.so     
pam_cracklib.so  pam_group.so        pam_listfile.so   
pam_nologin.so   pam_rootok.so       pam_tally.so      
pam_deny.so      pam_issue.so        pam_mail.so       
pam_permit.so    pam_securetty.so    pam_time.so       
pam_dialup.so    pam_lastlog.so      pam_mkhomedir.so  
pam_pwdb.so      pam_shells.so       pam_unix.so       
pam_env.so       pam_ldap.so         pam_motd.so       
pam_radius.so    pam_smbpass.so      pam_unix_acct.so  
pam_wheel.so     pam_unix_auth.so    pam_unix_passwd.so
pam_userdb.so    pam_warn.so         pam_unix_session.so
</screen></para>

<para>
The following example for the login program replaces the use of 
the <filename>pam_pwdb.so</filename> module which uses the system 
password database (<filename>/etc/passwd</filename>,
<filename>/etc/shadow</filename>, <filename>/etc/group</filename>) with 
the module <filename>pam_smbpass.so</filename> which uses the Samba 
database which contains the Microsoft MD4 encrypted password 
hashes. This database is stored in either 
<filename>/usr/local/samba/private/smbpasswd</filename>, 
<filename>/etc/samba/smbpasswd</filename>, or in 
<filename>/etc/samba.d/smbpasswd</filename>, depending on the 
Samba implementation for your Unix/Linux system. The 
<filename>pam_smbpass.so</filename> module is provided by 
Samba version 2.2.1 or later. It can be compiled by specifying the 
<option>--with-pam_smbpass</option> options when running Samba's
<command>configure</command> script.  For more information
on the <filename>pam_smbpass</filename> module, see the documentation
in the <filename>source/pam_smbpass</filename> directory of the Samba 
source distribution.
</para>

<para><screen>
#%PAM-1.0
# The PAM configuration file for the `login' service
#
auth        required    pam_smbpass.so nodelay
account     required    pam_smbpass.so nodelay
session     required    pam_smbpass.so nodelay
password    required    pam_smbpass.so nodelay
</screen></para>

<para>
The following is the PAM configuration file for a particular 
Linux system. The default condition uses <filename>pam_pwdb.so</filename>.
</para>

<para><screen>
#%PAM-1.0
# The PAM configuration file for the `samba' service
#
auth       required     pam_pwdb.so nullok nodelay shadow audit
account    required     pam_pwdb.so audit nodelay
session    required     pam_pwdb.so nodelay
password   required     pam_pwdb.so shadow md5
</screen></para>

<para>
In the following example the decision has been made to use the 
smbpasswd database even for basic samba authentication. Such a 
decision could also be made for the passwd program and would 
thus allow the smbpasswd passwords to be changed using the passwd 
program.
</para>

<para><screen>
#%PAM-1.0
# The PAM configuration file for the `samba' service
#
auth       required     pam_smbpass.so nodelay
account    required     pam_pwdb.so audit nodelay
session    required     pam_pwdb.so nodelay
password   required     pam_smbpass.so nodelay smbconf=/etc/samba.d/smb.conf
</screen></para>

<note><para>PAM allows stacking of authentication mechanisms. It is 
also possible to pass information obtained within one PAM module through 
to the next module in the PAM stack. Please refer to the documentation for 
your particular system implementation for details regarding the specific 
capabilities of PAM in this environment. Some Linux implmentations also 
provide the <filename>pam_stack.so</filename> module that allows all 
authentication to be configured in a single central file. The 
<filename>pam_stack.so</filename> method has some very devoted followers 
on the basis that it allows for easier administration. As with all issues in 
life though, every decision makes trade-offs, so you may want examine the 
PAM documentation for further helpful information.
</para></note>

<sect2>
<title>PAM Configuration in smb.conf</title>

<para>
There is an option in smb.conf called <ulink 
url="smb.conf.5.html#OBEYPAMRESTRICTIONS">obey pam restrictions</ulink>. 
The following is from the on-line help for this option in SWAT;
</para>

<para>
When Samba is configured to enable PAM support (i.e. 
<option>--with-pam</option>), this parameter will 
control whether or not Samba should obey PAM's account 
and session management directives. The default behavior 
is to use PAM for clear text authentication only and to 
ignore any account or session management. Note that Samba always 
ignores PAM for authentication in the case of 
<ulink url="smb.conf.5.html#ENCRYPTPASSWORDS">encrypt passwords = yes</ulink>. 
The reason is that PAM modules cannot support the challenge/response 
authentication mechanism needed in the presence of SMB 
password encryption. 
</para>

<para>Default: <parameter>obey pam restrictions = no</parameter></para>

</sect2>

<sect2>
<title>Password Synchronisation using pam_smbpass.so</title>

<para>
pam_smbpass is a PAM module which can be used on conforming systems to
keep the smbpasswd (Samba password) database in sync with the unix
password file. PAM (Pluggable Authentication Modules) is an API supported
under some Unices, such as Solaris, HPUX and Linux, that provides a
generic interface to authentication mechanisms.
</para>

<para>
	For more information on PAM, see <ulink url="http://ftp.kernel.org/pub/linux/libs/pam/">The linux PAM homepage</ulink>.
</para>

<para>
This module authenticates a local smbpasswd user database.  If you require
support for authenticating against a remote SMB server, or if you're
concerned about the presence of suid root binaries on your system, it is
recommended that you use pam_winbind instead.
</para>

<para>
Options recognized by this module are as follows:
<table frame="all">
	<title>Options recognized by pam_mkpass</title>
	<tgroup cols="2" align="left">
	<tbody>
		<row><entry>debug</entry><entry>log more debugging info</entry></row>
		<row><entry>audit</entry><entry>like debug, but also logs unknown usernames</entry></row>
		<row><entry>use_first_pass</entry><entry>don't prompt the user for passwords; take them from PAM_ items instead</entry></row>
		<row><entry>try_first_pass</entry><entry>try to get the password from a previous PAM module, fall back to prompting the user</entry></row>
		<row><entry>use_authtok</entry><entry>like try_first_pass, but *fail* if the new PAM_AUTHTOK has not been previously set. (intended for stacking password modules only)</entry></row>
		<row><entry>not_set_pass</entry><entry>don't make passwords used by this module available to other modules.</entry></row>
		<row><entry>nodelay</entry><entry>don't insert ~1 second delays on authentication failure.</entry></row>
		<row><entry>nullok</entry><entry>null passwords are allowed.</entry></row>
		<row><entry>nonull</entry><entry>null passwords are not allowed. Used to override the Samba configuration.</entry></row>
		<row><entry>migrate</entry><entry>only meaningful in an "auth" context; used to update smbpasswd file with a password used for successful authentication.</entry></row>
		<row><entry>smbconf=<replaceable>file</replaceable></entry><entry>specify an alternate path to the &smb.conf; file.</entry></row>
	</tbody>
</tgroup>
</table>
</para>

<para>
Thanks go to the following people:
<simplelist>
	<member><ulink url="mailto:morgan@transmeta.com">Andrew Morgan</ulink>, for providing the Linux-PAM
	framework, without which none of this would have happened</member>

	<member><ulink url="gafton@redhat.com">Christian Gafton</ulink> and Andrew Morgan again, for the
	pam_pwdb module upon which pam_smbpass was originally based</member>

	<member><ulink url="lkcl@switchboard.net">Luke Leighton</ulink> for being receptive to the idea,
	and for the occasional good-natured complaint about the project's status
	that keep me working on it :)</member>
</simplelist>.
</para>

<para>
The following are examples of the use of pam_smbpass.so in the format of Linux
<filename>/etc/pam.d/</filename> files structure. Those wishing to implement this
tool on other platforms will need to adapt this appropriately.
</para>

<sect3>
<title>Password Synchonisation Configuration</title>

<para>
A sample PAM configuration that shows the use of pam_smbpass to make
sure private/smbpasswd is kept in sync when /etc/passwd (/etc/shadow)
is changed.  Useful when an expired password might be changed by an
application (such as ssh).
</para>

<para><screen>
#%PAM-1.0
# password-sync
#
auth       requisite    pam_nologin.so
auth       required     pam_unix.so
account    required     pam_unix.so
password   requisite    pam_cracklib.so retry=3
password   requisite    pam_unix.so shadow md5 use_authtok try_first_pass
password   required     pam_smbpass.so nullok use_authtok try_first_pass
session    required     pam_unix.so
</screen></para>
</sect3>

<sect3>
<title>Password Migration Configuration</title>

<para>
A sample PAM configuration that shows the use of pam_smbpass to migrate
from plaintext to encrypted passwords for Samba.  Unlike other methods,
this can be used for users who have never connected to Samba shares:
password migration takes place when users ftp in, login using ssh, pop
their mail, etc.
</para>

<para><screen>
#%PAM-1.0
# password-migration
#
auth       requisite   pam_nologin.so
# pam_smbpass is called IF pam_unix succeeds.
auth       requisite   pam_unix.so
auth       optional    pam_smbpass.so migrate
account    required    pam_unix.so
password   requisite   pam_cracklib.so retry=3
password   requisite   pam_unix.so shadow md5 use_authtok try_first_pass
password   optional    pam_smbpass.so nullok use_authtok try_first_pass
session    required    pam_unix.so
</screen></para>
</sect3>

<sect3>
<title>Mature Password Configuration</title>

<para>
A sample PAM configuration for a 'mature' smbpasswd installation.
private/smbpasswd is fully populated, and we consider it an error if
the smbpasswd doesn't exist or doesn't match the Unix password.
</para>

<para><screen>
#%PAM-1.0
# password-mature
#
auth       requisite    pam_nologin.so
auth       required     pam_unix.so
account    required     pam_unix.so
password   requisite    pam_cracklib.so retry=3
password   requisite    pam_unix.so shadow md5 use_authtok try_first_pass
password   required     pam_smbpass.so use_authtok use_first_pass
session    required     pam_unix.so
</screen></para>
</sect3>

<sect3>
<title>Kerberos Password Integration Configuration</title>

<para>
A sample PAM configuration that shows pam_smbpass used together with
pam_krb5.  This could be useful on a Samba PDC that is also a member of
a Kerberos realm.
</para>

<para><screen>
#%PAM-1.0
# kdc-pdc
#
auth       requisite   pam_nologin.so
auth       requisite   pam_krb5.so
auth       optional    pam_smbpass.so migrate
account    required    pam_krb5.so
password   requisite   pam_cracklib.so retry=3
password   optional    pam_smbpass.so nullok use_authtok try_first_pass
password   required    pam_krb5.so use_authtok try_first_pass
session    required    pam_krb5.so
</screen></para>
</sect3>

</sect2>
</sect1>

<sect1>
<title>Distributed Authentication</title>

<para>
The astute administrator will realize from this that the 
combination of <filename>pam_smbpass.so</filename>, 
<command>winbindd</command>, and a distributed 
passdb backend, such as ldap, will allow the establishment of a
centrally managed, distributed 
user/password database that can also be used by all 
PAM (eg: Linux) aware programs and applications. This arrangement 
can have particularly potent advantages compared with the 
use of Microsoft Active Directory Service (ADS) in so far as 
reduction of wide area network authentication traffic.
</para>

</sect1>

<sect1>
<title>Common Errors</title>

<para>
PAM can be a very fickle and sensitive to configuration glitches. Here we look at a few cases from
the Samba mailing list.
</para>

	<sect2>
	<title>pam_winbind problem</title>

	<para>
	I have the following PAM configuration:
	</para>

<para>
<screen>
auth required /lib/security/pam_securetty.so
auth sufficient /lib/security/pam_winbind.so
auth sufficient /lib/security/pam_unix.so use_first_pass nullok
auth required /lib/security/pam_stack.so service=system-auth
auth required /lib/security/pam_nologin.so
account required /lib/security/pam_stack.so service=system-auth
account required /lib/security/pam_winbind.so
password required /lib/security/pam_stack.so service=system-auth
</screen>
</para>

	<para>
	When I open a new console with [ctrl][alt][F1], then I cant log in with my user "pitie".
	I've tried with user "scienceu+pitie" also.
	</para>

	<para>
	Answer: The problem may lie with your inclusion of <parameter>pam_stack.so
	service=system-auth</parameter>. That file often contains a lot of stuff that may
	duplicate what you're already doing. Try commenting out the pam_stack lines
	for auth and account and see if things work. If they do, look at
	<filename>/etc/pam.d/system-auth</filename> and copy only what you need from it into your
	<filename>/etc/pam.d/login</filename> file.  Alternatively, if you want all services to use
	winbind, you can put the winbind-specific stuff in <filename>/etc/pam.d/system-auth</filename>.
	</para>

	</sect2>

</sect1>

</chapter>