Another set of updates.
[sfrench/samba-autobuild/.git] / docs / docbook / projdoc / DOMAIN_MEMBER.xml
1 <chapter id="domain-member">
2
3 <chapterinfo>
4         &author.jeremy;
5         &author.jerry;
6         &author.jht;
7 </chapterinfo>
8
9 <title>Domain Membership</title>
10
11 <para>
12 Domain Membership is a subject of vital concern, Samba must be able to participate
13 as a member server in a Microsoft Domain security context, and Samba must be capable of
14 providing Domain machine member trust accounts, otherwise it would not be capable of offering
15 a viable option for many users.
16 </para>
17
18 <para>
19 This chapter covers background information pertaining to domain membership, Samba
20 configuration for it, and MS Windows client procedures for joining a domain.  Why is
21 this necessary? Because both are areas in which there exists within the current MS
22 Windows networking world and particularly in the Unix/Linux networking and administration
23 world, a considerable level of mis-information, incorrect understanding, and a lack of
24 knowledge. Hopefully this chapter will fill the voids.
25 </para>
26
27 <sect1>
28 <title>Features and Benefits</title>
29
30 <para>
31 MS Windows workstations and servers that want to participate in domain security need to
32 be made Domain members. Participating in Domain security is often called 
33 <emphasis>Single Sign On</emphasis> or SSO for short. This chapter describes the process
34 that must be followed to make a workstation (or another server - be it an MS Windows NT4 / 200x
35 server) or a Samba server a member of an MS Windows Domain security context.
36 </para>
37
38 <para>
39 Samba-3 can join an MS Windows NT4 style domain as a native member server, an MS Windows
40 Active Directory Domain as a native member server, or a Samba Domain Control network.
41 </para>
42
43 </sect1>
44
45 <sect1>
46 <title>MS Windows Workstation/Server Machine Trust Accounts</title>
47
48 <para>
49 A machine trust account is an account that is used to authenticate a client machine
50 (rather than a user) to the Domain Controller server.  In Windows terminology,
51 this is known as a "Computer Account."
52 </para>
53
54 <para>
55 The password of a machine trust account acts as the shared secret for
56 secure communication with the Domain Controller.  This is a security
57 feature to prevent an unauthorized machine with the same NetBIOS name
58 from joining the domain and gaining access to domain user/group
59 accounts.  Windows NT, 200x, XP Professional clients use machine trust
60 accounts, but Windows 9x / Me / XP Home clients do not.  Hence, a
61 Windows 9x / Me / XP Home  client is never a true member of a domain
62 because it does not possess a machine trust account, and thus has no
63 shared secret with the domain controller.
64 </para>
65
66 <para>
67 A Windows NT4 PDC stores each machine trust account in the Windows
68 Registry. The introduction of MS Windows 2000 saw the introduction of Active Directory,
69 the new repository for machine trust accounts.
70 </para>
71
72 <para>
73 A Samba PDC, however, stores each machine trust account in two parts,
74 as follows:
75
76 <itemizedlist>
77         <listitem><para>
78         A Domain Security Account (stored in the <emphasis>passdb backend</emphasis>
79         that has been configured in the &smb.conf; file. The precise nature of the
80         account information that is stored depends on the type of backend database
81         that has been chosen.
82         </para>
83
84         <para>
85         The older format of this data is the <filename>smbpasswd</filename> database
86         which contains the unix login ID, the Unix user identifier (UID), and the
87         LanMan and NT encrypted passwords. There is also some other information in
88         this file that we do not need to concern ourselves with here.
89         </para>
90
91         <para>
92         The two newer database types are called <emphasis>ldapsam, tdbsam</emphasis>.
93         Both store considerably more data than the older <filename>smbpasswd</filename>
94         file did. The extra information enables new user account controls to be used.
95         </para></listitem>
96
97         <listitem><para>
98         A corresponding Unix account, typically stored in <filename>/etc/passwd</filename>.
99         Work is in progress to allow a simplified mode of operation that does not require
100         Unix user accounts, but this may not be a feature of the early releases of Samba-3.
101         </para></listitem>
102 </itemizedlist>
103 </para>
104
105 <para>
106 There are two ways to create machine trust accounts:
107 </para>
108
109 <itemizedlist>
110         <listitem><para>
111         Manual creation. Both the Samba and corresponding Unix account are created by hand.
112         </para></listitem>
113         
114         <listitem><para>
115         "On-the-fly" creation. The Samba machine trust account is automatically created by
116         Samba at the time the client is joined to the domain. (For security, this is the
117         recommended method.) The corresponding Unix account may be created automatically or manually. 
118         </para></listitem>
119 </itemizedlist>
120
121 <sect2>
122 <title>Manual Creation of Machine Trust Accounts</title>
123
124 <para>
125 The first step in manually creating a machine trust account is to manually create the
126 corresponding Unix account in <filename>/etc/passwd</filename>.  This can be done using
127 <command>vipw</command> or other 'add user' command that is normally used to create new
128 Unix accounts.  The following is an example for a Linux based Samba server:
129 </para>
130
131 <para>
132 <prompt>root# </prompt><command>/usr/sbin/useradd -g 100 -d /dev/null -c <replaceable>"machine nickname"</replaceable> -s /bin/false <replaceable>machine_name</replaceable>$ </command>
133 </para>
134
135 <para>
136 <prompt>root# </prompt><command>passwd -l <replaceable>machine_name</replaceable>$</command>
137 </para>
138
139 <para>
140 On *BSD systems, this can be done using the 'chpass' utility:
141 </para>
142
143 <para>
144 <prompt>root# </prompt><command>chpass -a "<replaceable>machine_name</replaceable>$:*:101:100::0:0:Workstation <replaceable>machine_name</replaceable>:/dev/null:/sbin/nologin"</command>
145 </para>
146
147 <para>
148 The <filename>/etc/passwd</filename> entry will list the machine name 
149 with a "$" appended, won't have a password, will have a null shell and no 
150 home directory. For example a machine named 'doppy' would have an 
151 <filename>/etc/passwd</filename> entry like this:
152 </para>
153
154 <para>
155 doppy$:x:505:501:<replaceable>machine_nickname</replaceable>:/dev/null:/bin/false
156 </para>
157
158 <para>
159 Above, <replaceable>machine_nickname</replaceable> can be any
160 descriptive name for the client, i.e., BasementComputer.
161 <replaceable>machine_name</replaceable> absolutely must be the NetBIOS
162 name of the client to be joined to the domain.  The "$" must be
163 appended to the NetBIOS name of the client or Samba will not recognize
164 this as a machine trust account.
165 </para>
166
167 <para>
168 Now that the corresponding Unix account has been created, the next step is to create 
169 the Samba account for the client containing the well-known initial 
170 machine trust account password.  This can be done using the <ulink 
171 url="smbpasswd.8.html"><command>smbpasswd(8)</command></ulink> command 
172 as shown here:
173 </para>
174
175 <para>
176 <programlisting>
177 <prompt>root# </prompt><userinput>smbpasswd -a -m <replaceable>machine_name</replaceable></userinput>
178 </programlisting>
179 </para>
180
181 <para>
182 where <replaceable>machine_name</replaceable> is the machine's NetBIOS
183 name.  The RID of the new machine account is generated from the UID of 
184 the corresponding Unix account.
185 </para>
186
187 <warning>
188         <title>Join the client to the domain immediately</title>
189
190         <para>
191         Manually creating a machine trust account using this method is the 
192         equivalent of creating a machine trust account on a Windows NT PDC using 
193         the "Server Manager".  From the time at which the account is created
194         to the time which the client joins the domain and changes the password,
195         your domain is vulnerable to an intruder joining your domain using
196         a machine with the same NetBIOS name.  A PDC inherently trusts
197         members of the domain and will serve out a large degree of user 
198         information to such clients.  You have been warned!
199         </para>
200 </warning>
201 </sect2>
202
203
204 <sect2>
205 <title>"On-the-Fly" Creation of Machine Trust Accounts</title>
206
207 <para>
208 The second (and recommended) way of creating machine trust accounts is
209 simply to allow the Samba server to create them as needed when the client
210 is joined to the domain.
211 </para>
212
213 <para>Since each Samba machine trust account requires a corresponding
214 Unix account, a method for automatically creating the
215 Unix account is usually supplied; this requires configuration of the
216 <ulink url="smb.conf.5.html#ADDMACHINESCRIPT">add machine script</ulink> 
217 option in <filename>smb.conf</filename>.  This
218 method is not required, however; corresponding Unix accounts may also
219 be created manually.
220 </para>
221
222
223 <para>
224 Below is an example for a RedHat Linux system.
225 </para>
226
227 <para><programlisting>
228 [global]
229    # &lt;...remainder of parameters...&gt;
230    add machine script = /usr/sbin/useradd -d /dev/null -g 100 -s /bin/false -M %u 
231 </programlisting></para>
232
233 </sect2>
234
235
236 <sect2><title>Joining the Client to the Domain</title>
237
238 <para>
239 The procedure for joining a client to the domain varies with the version of Windows.
240 </para>
241
242 <itemizedlist>
243         <listitem><para><emphasis>Windows 2000</emphasis></para>
244
245         <para>
246         When the user elects to join the client to a domain, Windows prompts for
247         an account and password that is privileged to join the domain. A Samba administrative
248         account (i.e., a Samba account that has root privileges on the Samba server) must be
249         entered here; the operation will fail if an ordinary user account is given. 
250         The password for this account should be set to a different password than the associated
251         <filename>/etc/passwd</filename> entry, for security reasons.
252         </para>
253
254         <para>
255         The session key of the Samba administrative account acts as an
256         encryption key for setting the password of the machine trust
257         account. The machine trust account will be created on-the-fly, or
258         updated if it already exists.
259         </para></listitem>
260
261         <listitem><para><emphasis>Windows NT</emphasis></para>
262
263         <para>
264         If the machine trust account was created manually, on the
265         Identification Changes menu enter the domain name, but do not
266         check the box "Create a Computer Account in the Domain."  In this case,
267         the existing machine trust account is used to join the machine to
268         the domain.
269         </para>
270
271         <para>
272         If the machine trust account is to be created
273         on-the-fly, on the Identification Changes menu enter the domain
274         name, and check the box "Create a Computer Account in the Domain."  In
275         this case, joining the domain proceeds as above for Windows 2000
276         (i.e., you must supply a Samba administrative account when
277         prompted).
278         </para></listitem>
279
280         <listitem><para><emphasis>Samba</emphasis></para>
281         <para>Joining a samba client to a domain is documented in 
282         the <link linkend="domain-member">Domain Member</link> chapter.
283         </para></listitem>
284 </itemizedlist>
285
286 </sect2>
287 </sect1>
288
289 <sect1>
290 <title>Domain Member Server</title>
291
292 <para>
293 This mode of server operation involves the samba machine being made a member
294 of a domain security context. This means by definition that all user authentication
295 will be done from a centrally defined authentication regime. The authentication
296 regime may come from an NT3/4 style (old domain technology) server, or it may be
297 provided from an Active Directory server (ADS) running on MS Windows 2000 or later.
298 </para>
299
300 <para>
301 <emphasis>
302 Of course it should be clear that the authentication back end itself could be from any
303 distributed directory architecture server that is supported by Samba. This can be
304 LDAP (from OpenLDAP), or Sun's iPlanet, of NetWare Directory Server, etc.
305 </emphasis>
306 </para>
307
308 <para>
309 Please refer to the section on Howto configure Samba as a Primary Domain Controller
310 and for more information regarding how to create a domain machine account for a
311 domain member server as well as for information regarding how to enable the samba
312 domain member machine to join the domain and to be fully trusted by it.
313 </para>
314
315 <sect2>
316 <title>Joining an NT4 type Domain with Samba-3</title>
317
318 <para>
319 <emphasis>Assumptions:</emphasis>
320 <programlisting>
321         NetBIOS name: SERV1
322         Win2K/NT domain name: DOM
323         Domain's PDC NetBIOS name: DOMPDC
324         Domain's BDC NetBIOS names: DOMBDC1 and DOMBDC2
325 </programlisting>
326 </para>
327
328 <para>
329 First, you must edit your &smb.conf; file to tell Samba it should
330 now use domain security.
331 </para>
332
333 <para>
334 Change (or add) your <ulink url="smb.conf.5.html#SECURITY">
335 <parameter>security =</parameter></ulink> line in the [global] section 
336 of your &smb.conf; to read:
337 </para>
338
339 <para>
340 <programlisting>
341         <command>security = domain</command>
342 </programlisting>
343 </para>
344
345 <para>
346 Next change the <ulink url="smb.conf.5.html#WORKGROUP"><parameter>
347 workgroup =</parameter></ulink> line in the [global] section to read: 
348 </para>
349
350 <para>
351 <programlisting>
352         <command>workgroup = DOM</command>
353 </programlisting>
354 </para>
355
356 <para>
357 as this is the name of the domain we are joining.
358 </para>
359
360 <para>
361 You must also have the parameter <ulink url="smb.conf.5.html#ENCRYPTPASSWORDS">
362 <parameter>encrypt passwords</parameter></ulink> set to <constant>yes
363 </constant> in order for your users to authenticate to the NT PDC.
364 </para>
365
366 <para>
367 Finally, add (or modify) a <ulink url="smb.conf.5.html#PASSWORDSERVER">
368 <parameter>password server =</parameter></ulink> line in the [global]
369 section to read: 
370 </para>
371
372 <para>
373 <programlisting>
374         <command>password server = DOMPDC DOMBDC1 DOMBDC2</command>
375 </programlisting>
376 </para>
377
378 <para>
379 These are the primary and backup domain controllers Samba 
380 will attempt to contact in order to authenticate users. Samba will 
381 try to contact each of these servers in order, so you may want to 
382 rearrange this list in order to spread out the authentication load 
383 among domain controllers.
384 </para>
385
386 <para>
387 Alternatively, if you want smbd to automatically determine 
388 the list of Domain controllers to use for authentication, you may 
389 set this line to be:
390 </para>
391
392 <para>
393 <programlisting>
394         <command>password server = *</command>
395 </programlisting>
396 </para>
397
398 <para>
399 This method, allows Samba to use exactly the same mechanism that NT does. This 
400 method either broadcasts or uses a WINS database in order to
401 find domain controllers to authenticate against.
402 </para>
403
404 <para>
405 In order to actually join the domain, you must run this command:
406 </para>
407
408 <para>
409 <programlisting>
410         <prompt>root# </prompt><userinput>net join -S DOMPDC -U<replaceable>Administrator%password</replaceable></userinput>
411 </programlisting>
412 </para>
413
414 <para>
415 If the <userinput>-S DOMPDC</userinput> argument is not given then
416 the domain name will be obtained from smb.conf.
417 </para>
418
419 <para>
420 As we are joining the domain DOM and the PDC for that domain 
421 (the only machine that has write access to the domain SAM database) 
422 is DOMPDC. The <replaceable>Administrator%password</replaceable> is 
423 the login name and password for an account which has the necessary 
424 privilege to add machines to the domain.  If this is successful 
425 you will see the message:
426 </para>
427
428 <para>
429 <computeroutput>Joined domain DOM.</computeroutput>
430 or <computeroutput>Joined 'SERV1' to realm 'MYREALM'</computeroutput>
431 </para>
432
433 <para>
434 in your terminal window. See the <ulink url="net.8.html">
435 net(8)</ulink> man page for more details.
436 </para>
437
438 <para>
439 This process joins the server to the domain without having to create the machine
440 trust account on the PDC beforehand.
441 </para>
442
443 <para>
444 This command goes through the machine account password 
445 change protocol, then writes the new (random) machine account 
446 password for this Samba server into a file in the same directory 
447 in which an smbpasswd file would be stored - normally :
448 </para>
449
450 <para>
451 <filename>/usr/local/samba/private/secrets.tdb</filename>
452 </para>
453
454 <para>
455 This file is created and owned by root and is not 
456 readable by any other user. It is the key to the domain-level 
457 security for your system, and should be treated as carefully 
458 as a shadow password file.
459 </para>
460
461 <para>
462 Finally, restart your Samba daemons and get ready for 
463 clients to begin using domain security!
464 </para>
465
466 </sect2>
467
468 <sect2>
469 <title>Why is this better than security = server?</title>
470
471 <para>
472 Currently, domain security in Samba doesn't free you from 
473 having to create local Unix users to represent the users attaching 
474 to your server. This means that if domain user <constant>DOM\fred
475 </constant> attaches to your domain security Samba server, there needs 
476 to be a local Unix user fred to represent that user in the Unix 
477 filesystem. This is very similar to the older Samba security mode 
478 <ulink url="smb.conf.5.html#SECURITYEQUALSSERVER">security = server</ulink>, 
479 where Samba would pass through the authentication request to a Windows 
480 NT server in the same way as a Windows 95 or Windows 98 server would.
481 </para>
482
483 <para>
484 Please refer to the <ulink url="winbind.html">Winbind 
485 paper</ulink> for information on a system to automatically
486 assign UNIX uids and gids to Windows NT Domain users and groups.
487 </para>
488
489 <para>
490 The advantage to domain-level security is that the 
491 authentication in domain-level security is passed down the authenticated 
492 RPC channel in exactly the same way that an NT server would do it. This 
493 means Samba servers now participate in domain trust relationships in 
494 exactly the same way NT servers do (i.e., you can add Samba servers into 
495 a resource domain and have the authentication passed on from a resource
496 domain PDC to an account domain PDC).
497 </para>
498
499 <para>
500 In addition, with <command>security = server</command> every Samba 
501 daemon on a server has to keep a connection open to the 
502 authenticating server for as long as that daemon lasts. This can drain 
503 the connection resources on a Microsoft NT server and cause it to run 
504 out of available connections. With <command>security = domain</command>, 
505 however, the Samba daemons connect to the PDC/BDC only for as long 
506 as is necessary to authenticate the user, and then drop the connection, 
507 thus conserving PDC connection resources.
508 </para>
509
510 <para>
511 And finally, acting in the same manner as an NT server 
512 authenticating to a PDC means that as part of the authentication 
513 reply, the Samba server gets the user identification information such 
514 as the user SID, the list of NT groups the user belongs to, etc. 
515 </para>
516
517 <note>
518 <para>
519 Much of the text of this document 
520 was first published in the Web magazine <ulink url="http://www.linuxworld.com">         
521 LinuxWorld</ulink> as the article <ulink
522 url="http://www.linuxworld.com/linuxworld/lw-1998-10/lw-10-samba.html">Doing 
523 the NIS/NT Samba</ulink>.
524 </para>
525 </note>
526
527 </sect2>
528 </sect1>
529
530 <sect1>
531 <title>Samba ADS Domain Membership</title>
532
533 <para>
534 This is a rough guide to setting up Samba 3.0 with kerberos authentication against a
535 Windows2000 KDC. 
536 </para> 
537
538 <sect2>
539 <title>Setup your <filename>smb.conf</filename></title>
540
541 <para>
542 You must use at least the following 3 options in smb.conf:
543 </para>
544
545 <para><programlisting>
546         realm = your.kerberos.REALM
547         security = ADS
548         encrypt passwords = yes
549 </programlisting></para>
550
551 <para>
552 In case samba can't figure out your ads server using your realm name, use the 
553 <command>ads server</command> option in <filename>smb.conf</filename>:
554 <programlisting>
555         ads server = your.kerberos.server
556 </programlisting>
557 </para>
558
559 <note><para>
560 You do *not* need a smbpasswd file, and older clients will be authenticated as if
561 <command>security = domain</command>, although it won't do any harm and allows you
562 to have local users not in the domain. I expect that the above required options will
563 change soon when we get better active directory integration.
564 </para></note>
565
566 </sect2>
567   
568 <sect2>
569 <title>Setup your <filename>/etc/krb5.conf</filename></title>
570
571 <para>
572 Note: you will need the krb5 workstation, devel, and libs installed
573 </para>
574
575 <para>
576 The minimal configuration for <filename>krb5.conf</filename> is:
577 </para>
578
579 <para><programlisting>
580         [realms]
581             YOUR.KERBEROS.REALM = {
582                 kdc = your.kerberos.server
583             }
584 </programlisting></para>
585
586 <para>
587 Test your config by doing a <userinput>kinit
588 <replaceable>USERNAME</replaceable>@<replaceable>REALM</replaceable></userinput> and
589 making sure that your password is accepted by the Win2000 KDC.
590 </para>
591
592 <note><para>
593 The realm must be uppercase or you will get "Cannot find KDC for requested
594 realm while getting initial credentials" error
595 </para></note>
596
597 <note><para>
598 Time between the two servers must be synchronized.  You will get a
599 "kinit(v5): Clock skew too great while getting initial credentials" if the time
600 difference is more than five minutes. 
601 </para></note>
602
603 <para>
604 You also must ensure that you can do a reverse DNS lookup on the IP
605 address of your KDC. Also, the name that this reverse lookup maps to
606 must either be the netbios name of the KDC (ie. the hostname with no
607 domain attached) or it can alternatively be the netbios name
608 followed by the realm. 
609 </para>
610
611 <para>
612 The easiest way to ensure you get this right is to add a 
613 <filename>/etc/hosts</filename> entry mapping the IP address of your KDC to 
614 its netbios name. If you don't get this right then you will get a 
615 "local error" when you try to join the realm.
616 </para>
617
618 <para>
619 If all you want is kerberos support in &smbclient; then you can skip
620 straight to <link linkend="ads-test-smbclient">Test with &smbclient;</link> now. 
621 <link linkend="ads-create-machine-account">Creating a computer account</link> 
622 and <link linkend="ads-test-server">testing your servers</link>
623 is only needed if you want kerberos support for &smbd; and &winbindd;.
624 </para>
625
626 </sect2>
627
628 <sect2 id="ads-create-machine-account">
629 <title>Create the computer account</title>
630
631 <para>
632 As a user that has write permission on the Samba private directory
633 (usually root) run:
634 <programlisting>
635         <userinput>net join -U Administrator%password</userinput>
636 </programlisting>
637 </para>
638
639 <sect3>
640 <title>Possible errors</title>
641
642 <para>
643 <variablelist>
644         <varlistentry><term>"ADS support not compiled in"</term>
645         <listitem><para>Samba must be reconfigured (remove config.cache) and recompiled
646         (make clean all install) after the kerberos libs and headers are installed.
647         </para></listitem></varlistentry>
648
649         <varlistentry><term>net join prompts for user name</term>
650         <listitem><para>You need to login to the domain using <userinput>kinit
651         <replaceable>USERNAME</replaceable>@<replaceable>REALM</replaceable></userinput>.
652         <replaceable>USERNAME</replaceable> must be a user who has rights to add a machine
653         to the domain.  </para></listitem></varlistentry>
654 </variablelist>
655 </para>
656
657 </sect3>
658
659 </sect2>
660
661 <sect2 id="ads-test-server">
662 <title>Test your server setup</title>
663
664 <para>
665 If the join was successful, you will see a new computer account with the
666 NetBIOS name of your Samba server in Active Directory (in the "Computers"
667 folder under Users and Computers.
668 </para>
669
670 <para>
671 On a Windows 2000 client try <userinput>net use * \\server\share</userinput>. You should
672 be logged in with kerberos without needing to know a password. If
673 this fails then run <userinput>klist tickets</userinput>. Did you get a ticket for the
674 server? Does it have an encoding type of DES-CBC-MD5 ? 
675 </para>
676
677 </sect2>
678
679 <sect2 id="ads-test-smbclient">
680 <title>Testing with &smbclient;</title>
681
682 <para>
683 On your Samba server try to login to a Win2000 server or your Samba
684 server using &smbclient; and kerberos. Use &smbclient; as usual, but
685 specify the <parameter>-k</parameter> option to choose kerberos authentication.
686 </para>
687
688 </sect2>
689
690 <sect2>
691 <title>Notes</title>
692
693 <para>
694 You must change administrator password at least once after DC 
695 install, to create the right encoding types
696 </para>
697
698 <para>
699 w2k doesn't seem to create the _kerberos._udp and _ldap._tcp in
700 their defaults DNS setup. Maybe fixed in service packs?
701 </para>
702
703 </sect2>
704
705 </sect1>
706 </chapter>