Advertisement
Guest User

Untitled

a guest
Jun 15th, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.86 KB | None | 0 0
  1. [TUTORIAL] AD integration with Ubuntu 14.04 and winbind
  2. So it seems the internet is not short of winbind/smb documentation, but I have yet to find a cohesive start to finish guide for the setup process. So here goes nothing! This guide is for people looking to set up a Linux machine that will authenticate in a 1 forest, 1 domain Active Directory environment.
  3.  
  4. A bit of advice: be patient. This was one of the most frustrating things I have ever set up, mostly due to old/fragmented help around the internet. I strongly recommend against using Ubuntu's official guide, it's outdated and borderline useless. Hopefully I can save someone from a concussion with this.
  5.  
  6. 1. Install winbind and other helper packages.
  7.  
  8. Here are the versions I used while writing this:
  9.  
  10. winbindd: 4.1.6-Ubuntu
  11. samba: 4.1.6-Ubuntu
  12. smbd: 4.1.6-Ubuntu
  13. nmdb: 4.1.6-Ubuntu
  14.  
  15. The command to install all required packages:
  16. Code:
  17.  
  18. # apt-get install winbind samba libnss-winbind libpam-winbind krb5-config krb5-locales krb5-user
  19.  
  20. Of course, you'll need to install the dependencies as well. Just say yes to whatever apt-get comes up with.
  21.  
  22. 2. Setup Kerberos authentication.
  23. AD uses standard (for once) Kerberos for authentication, which easily fits in with Linux.
  24.  
  25. The environment I'm working in is as follows:
  26. Domain controller: ad.bfs.com (10.0.0.20)
  27. DNS server: 10.0.0.20
  28. NetBIOS domain name: BFS
  29.  
  30. Kerberos configuration is located at:
  31. Code:
  32.  
  33. /etc/krb5.conf
  34.  
  35.  
  36. The following is my working krb5.conf:
  37. Code:
  38.  
  39. [libdefaults]
  40. ticket_lifetime = 24000
  41. default_realm = AD.BFS.COM
  42. default_tgs_entypes = rc4-hmac des-cbc-md5
  43. default_tkt__enctypes = rc4-hmac des-cbc-md5
  44. permitted_enctypes = rc4-hmac des-cbc-md5
  45. dns_lookup_realm = true
  46. dns_lookup_kdc = true
  47. dns_fallback = yes
  48.  
  49. [realms]
  50. AD.BFS.COM = {
  51. kdc = ad.bfs.com:88
  52. default_domain = ad.bfs.com
  53. }
  54.  
  55. [domain_realm]
  56. .ad.bfs.com = AD.BFS.COM
  57. ad.bfs.com = AD.BFS.COM
  58.  
  59. [appdefaults]
  60. pam = {
  61. debug = false
  62. ticket_lifetime = 36000
  63. renew_lifetime = 36000
  64. forwardable = true
  65. krb4_convert = false
  66. }
  67.  
  68. [logging]
  69. default = FILE:/var/log/krb5libs.log
  70. kdc = FILE:/var/log/krb5kdc.log
  71. admin_server = FILE:/var/log/kadmind.log
  72.  
  73. Capitalization matters! The realm name is just your domain controller's address in all caps.
  74.  
  75. 3. Kerbs authentication
  76.  
  77. Once saved, test the setup with the following command. In this test, I'm looking for myself (brian) in the Kerbs realm of AD.BFS.COM controlled by the server at ad.bfs.com.
  78.  
  79. Code:
  80.  
  81. # kinit brian@AD.BFS.COM
  82.  
  83. This should return a password prompt for your test user, NOT the root user. If you get an error message of any kind, be sure your DC is online and reachable at the specified address + port and the username exists in the directory.
  84.  
  85. Once you successfully authenticate with the DC, we now need to authenticate an account with binding privileges. In my case, it's my ad-brian account.
  86.  
  87. Code:
  88.  
  89. # kinit ad-brian@AD.BFS.COM
  90.  
  91. This should go down like the test user, and you should receive a password prompt for the specified user, and receive nothing back upon completion.
  92.  
  93. 4. winbind setup (the real fun begins now)
  94. The default configuration given to you be Ubuntu is lengthy and a bit difficult to read. A much simpler one is given below, you will need to tune my configuration to suit your needs.
  95.  
  96. The file is located at:
  97. Code:
  98.  
  99. /etc/samba/smb.conf
  100.  
  101. Code:
  102.  
  103. [global]
  104.  
  105. netbios name = BFS-SCANNER
  106. workgroup = BFS
  107. security = ADS
  108. realm = AD.BFS.COM
  109. encrypt passwords = yes
  110.  
  111. idmap config *:backend = rid
  112. idmap config *:range = 5000-100000
  113.  
  114. winbind allow trusted domains = no
  115. winbind trusted domains only = no
  116. winbind use default domain = yes
  117. winbind enum users = yes
  118. winbind enum groups = yes
  119. winbind refresh tickets = yes
  120.  
  121. template shell = /bin/bash
  122.  
  123. If you must modify this file, I strongly recommend against messing with the idmap section unless you know exactly what you're doing. This by itself is the mother of all bitches to get working if you don't know what you're doing. The rid backend I'm using will work just fine for most workstations. As long as you keep the range consistent between Linux machines, the resulting uid/gid's will stay uniform between machines.
  124.  
  125. 5. Configure nss to make domain accounts locally available.
  126. The nss configuration is located at:
  127. Code:
  128.  
  129. /etc/nsswitch.conf
  130.  
  131. All you need to do is append winbind to the end of the passwd and group lines. Like this:
  132.  
  133. Code:
  134.  
  135. passwd: compat winbind
  136. group: compat winbind
  137. shadow: compat
  138.  
  139. hosts: files dns
  140. networks: files
  141.  
  142. protocols: db files
  143. services: db files
  144. ethers: db files
  145. rpc: db files
  146.  
  147. netgroup: nis
  148.  
  149. 6. Joining the domain.
  150. Easiest part of the whole tutorial:
  151. Code:
  152.  
  153. # net ads join -k
  154.  
  155. You may get a DNS error, but the important bit is the successful domain joining message. As long as it informs you of this, you are fine.
  156.  
  157.  
  158. Once joined, start or restart the following three services with this command:
  159. Code:
  160.  
  161. # service winbind restart; service nmbd restart; service smbd restart
  162.  
  163. Note: it helps to define this chain as a function for easy refreshed in the future.
  164.  
  165. winbind will crap out on you if you aren't joined to a domain, so no shortcuts.
  166.  
  167. 7. Testing winbind setup.
  168. Hopefully you've made it this far, this is about when you'll start hitting enormous brick walls. Chin up!
  169.  
  170. The rid backend will enumerate all domain accounts and groups and add them to a local database (not /etc/passwd). You need to first verify rid has correctly mapped out UID's and other info.
  171.  
  172. Code:
  173.  
  174. # wbinfo -u
  175. # wbinfo -g
  176. # wbinfo -i brian
  177. # getent passwd
  178. # getend group
  179.  
  180. All 5 commands must return correct information before you can proceed. If this were some Ubuntu guide, I'd just leave it at that. Thankfully, it's not.
  181.  
  182. wbinfo -u: all domain users
  183. wbinfo -g: all domain groups
  184. wbinfo -i brian: user information for brian
  185. Code:
  186.  
  187. brian:*:6106:5513:Brian:/home/BFS/brian:/bin/bash
  188.  
  189. getent passwd: all locally available accounts. Domain accounts will be at the bottom.
  190. getent group: all locally available groups. Domain groups will be at the bottom.
  191.  
  192. If wbinfo -u and -g are successful, but you get this for wbinfo -i brian:
  193. Code:
  194.  
  195. failed to call wbcGetpwnam: WBC_ERR_DOMAIN_NOT_FOUND
  196. Could not get info for user brian
  197.  
  198. that likely indicates something wrong in the idmap section and is very bad. The above configuration posted is confirmed to work fine with Ubuntu 14.04 and the versions listed above. It could also mean the user you asked for does not exist.
  199.  
  200. If wbinfo -i brian returns this:
  201. Code:
  202.  
  203. brian:*:4294967295:4294967295:Brian:/home/BFS/brian:/bin/bash
  204.  
  205. This is also very bad. winbind is not properly enumerating UID/GID's from the domain. If you nss configuration is alright, then this is almost certainly caused by bad idmap options. Again, the smb.conf file posted above is confirmed to work.
  206.  
  207. The same goes for getent passwd and groups. If the id's on the users or groups are 4294967295 and not within the range specified, this is wrong and will not function correctly. Take another look at your idmap section.
  208.  
  209. Just in case you did, it should be noted the idmap backend = ad does not do what you think it does. This will attempt to pull all user information from the directory, including UID, login shell, etc. If you did not set these for each user in the domain on the DC, this won't work since there will be nothing to pull down! The UNIX attributes tab for each user is where you will need to go if you insist on going this route. I will stick with the rid method in this tutorial. The Samba page gives the options needed to use each backend correctly.
  210.  
  211. After each configuration file edit, be it smb.conf, nsswitch.conf, etc. you need to restart all Samba services:
  212.  
  213. Code:
  214.  
  215. # redo() { service winbind restart; service nmbd restart; service smbd restart; }
  216. # redo
  217. winbind stop/waiting
  218. winbind start/running, process 30540
  219. nmbd stop/waiting
  220. nmbd start/running, process 30556
  221. smbd stop/waiting
  222. smbd start/running, process 30568
  223. #
  224.  
  225. 8. PAM integration.
  226. If you made it this far congratulations! The worst is now over! PAM configuration is nice and easy, just run:
  227. Code:
  228.  
  229. pam-auth-update
  230.  
  231. and ensure the Winbind NT/Active Directory authentication box is checked. PAM by default does not create new home directories, so run this to append to your PAM configuration:
  232. Code:
  233.  
  234. echo 'session required pam_mkhomedir.so skel=/etc/skel umask=0022' >> /etc/pam.d/common-account
  235.  
  236. To test your new domain authentication setup, simply try logging in:
  237. Code:
  238.  
  239. # login
  240. BFS-SCANNER login: brian
  241. Password:
  242.  
  243. [stuff]
  244.  
  245. brian@BFS-SCANNER:~$ pwd
  246. /home/BFS/brian
  247. brian@BFS-SCANNER:~$
  248.  
  249. Yay! I have a home directory and login using my domain credentials!!
  250.  
  251. One tiny downside to this setup is that passwd for domain accounts does not appear to work. I get an error every time, but that's minor anyways. Also, I strongly recommend version locking your winbind, samba, libnss-winbind, and libpam-winbind packages. It is a well-known fact the Samba team loves to drop random syntax changes between versions, and this will almost certainly break your setup. If it works, then leave it at that and don't touch it, you never know what might break from an update.
  252.  
  253. Good luck everyone! If I missed anything, tell me and I'll add it.
  254.  
  255.  
  256. --------------------------------------------------------------------------------------------------
  257.  
  258. [libdefaults]
  259. default_realm = GENERALITAT.GVA.ES
  260. default_tgs_enctypes = AES256-CTS AES128-CTS RC4-HMAC DES-CBC-MD5 DES-CBC-CRC
  261. default_tkt_enctypes = AES256-CTS AES128-CTS RC4-HMAC DES-CBC-MD5 DES-CBC-CRC
  262. preferred_enctypes = AES256-CTS AES128-CTS RC4-HMAC DES-CBC-MD5 DES-CBC-CRC
  263. dns_lookup_kdc = true
  264. pkinit_kdc_hostname = <DNS>
  265. pkinit_anchors = DIR:/var/lib/pbis/trusted_certs
  266. pkinit_cert_match = &&<EKU>msScLogin<PRINCIPAL>
  267. pkinit_eku_checking = kpServerAuth
  268. pkinit_win2k_require_binding = false
  269. pkinit_identities = PKCS11:/opt/pbis/lib/libpkcs11.so
  270. [domain_realm]
  271. .generalitat.gva.es = GENERALITAT.GVA.ES
  272. .centrales.agp.gva.es = CENTRALES.AGP.GVA.ES
  273. .centros.tra.gva.es = CENTROS.TRA.GVA.ES
  274. .cic.ad = CIC.AD
  275. .indi.gva.es = INDI.GVA.ES
  276. .cap.just.gva.es = CAP.JUST.GVA.ES
  277. .territorio.vivienda = TERRITORIO.VIVIENDA
  278. .nt.tra.gva.es = NT.TRA.GVA.ES
  279. .ivaj.gva.es = IVAJ.GVA.ES
  280. .presidencia.ad = PRESIDENCIA.AD
  281. .gov.gva.es = GOV.GVA.ES
  282. .invassat.local = INVASSAT.LOCAL
  283. .ocupacio.gva.es = OCUPACIO.GVA.ES
  284. .cencal = CENCAL
  285. .barbate.ha.gva.es = BARBATE.HA.GVA.ES
  286. .dwnt46.ha.gva.es = DWNT46.HA.GVA.ES
  287. .alicante.local = ALICANTE.LOCAL
  288. .coput.gva.es = COPUT.GVA.ES
  289. .avapsa.nt.tra.gva.es = AVAPSA.NT.TRA.GVA.ES
  290. .dtadona.nt.tra.gva.es = DTADONA.NT.TRA.GVA.ES
  291. .dta01.nt.tra.gva.es = DTA01.NT.TRA.GVA.ES
  292. .dtdv01.nt.tra.gva.es = DTDV01.NT.TRA.GVA.ES
  293. .cbasev.nt.tra.gva.es = CBASEV.NT.TRA.GVA.ES
  294. .dta00.nt.tra.gva.es = DTA00.NT.TRA.GVA.ES
  295. .dta02.nt.tra.gva.es = DTA02.NT.TRA.GVA.ES
  296. .dtc01.nt.tra.gva.es = DTC01.NT.TRA.GVA.ES
  297. .dgss.nt.tra.gva.es = DGSS.NT.TRA.GVA.ES
  298. .dtv1.nt.tra.gva.es = DTV1.NT.TRA.GVA.ES
  299. [realms]
  300. GENERALITAT.GVA.ES = {
  301. auth_to_local = RULE:[1:$0\$1](^GENERALITAT\.GVA\.ES\\.*)s/^GENERALITAT\.GVA\.ES\\//
  302. auth_to_local = RULE:[1:$0\$1](^CENTRALES\.AGP\.GVA\.ES\\.*)s/^CENTRALES\.AGP\.GVA\.ES/CENTRALES/
  303. auth_to_local = RULE:[1:$0\$1](^CENTROS\.TRA\.GVA\.ES\\.*)s/^CENTROS\.TRA\.GVA\.ES/CENTROS/
  304. auth_to_local = RULE:[1:$0\$1](^CIC\.AD\\.*)s/^CIC\.AD/CIC/
  305. auth_to_local = RULE:[1:$0\$1](^INDI\.GVA\.ES\\.*)s/^INDI\.GVA\.ES/INDI/
  306. auth_to_local = RULE:[1:$0\$1](^CAP\.JUST\.GVA\.ES\\.*)s/^CAP\.JUST\.GVA\.ES/CAP/
  307. auth_to_local = RULE:[1:$0\$1](^TERRITORIO\.VIVIENDA\\.*)s/^TERRITORIO\.VIVIENDA/AMBIENTE/
  308. auth_to_local = RULE:[1:$0\$1](^NT\.TRA\.GVA\.ES\\.*)s/^NT\.TRA\.GVA\.ES/SCV01/
  309. auth_to_local = RULE:[1:$0\$1](^IVAJ\.GVA\.ES\\.*)s/^IVAJ\.GVA\.ES/IVAJ/
  310. auth_to_local = RULE:[1:$0\$1](^PRESIDENCIA\.AD\\.*)s/^PRESIDENCIA\.AD/PRESIDENCIA/
  311. auth_to_local = RULE:[1:$0\$1](^GOV\.GVA\.ES\\.*)s/^GOV\.GVA\.ES/GOV/
  312. auth_to_local = RULE:[1:$0\$1](^INVASSAT\.LOCAL\\.*)s/^INVASSAT\.LOCAL/INVASSAT/
  313. auth_to_local = RULE:[1:$0\$1](^OCUPACIO\.GVA\.ES\\.*)s/^OCUPACIO\.GVA\.ES/SERVEF/
  314. auth_to_local = RULE:[1:$0\$1](^CENCAL\\.*)s/^CENCAL/CENCAL/
  315. auth_to_local = RULE:[1:$0\$1](^BARBATE\.HA\.GVA\.ES\\.*)s/^BARBATE\.HA\.GVA\.ES/BARBATE/
  316. auth_to_local = RULE:[1:$0\$1](^DWNT46\.HA\.GVA\.ES\\.*)s/^DWNT46\.HA\.GVA\.ES/DWNT46/
  317. auth_to_local = RULE:[1:$0\$1](^ALICANTE\.LOCAL\\.*)s/^ALICANTE\.LOCAL/ALICANTE/
  318. auth_to_local = RULE:[1:$0\$1](^COPUT\.GVA\.ES\\.*)s/^COPUT\.GVA\.ES/COP_VAL/
  319. auth_to_local = RULE:[1:$0\$1](^AVAPSA\.NT\.TRA\.GVA\.ES\\.*)s/^AVAPSA\.NT\.TRA\.GVA\.ES/AVAPSA/
  320. auth_to_local = RULE:[1:$0\$1](^DTADONA\.NT\.TRA\.GVA\.ES\\.*)s/^DTADONA\.NT\.TRA\.GVA\.ES/DTADONA/
  321. auth_to_local = RULE:[1:$0\$1](^DTA01\.NT\.TRA\.GVA\.ES\\.*)s/^DTA01\.NT\.TRA\.GVA\.ES/DTA01/
  322. auth_to_local = RULE:[1:$0\$1](^DTDV01\.NT\.TRA\.GVA\.ES\\.*)s/^DTDV01\.NT\.TRA\.GVA\.ES/DTVD01/
  323. auth_to_local = RULE:[1:$0\$1](^CBASEV\.NT\.TRA\.GVA\.ES\\.*)s/^CBASEV\.NT\.TRA\.GVA\.ES/CBASEV/
  324. auth_to_local = RULE:[1:$0\$1](^DTA00\.NT\.TRA\.GVA\.ES\\.*)s/^DTA00\.NT\.TRA\.GVA\.ES/DTTYASA1/
  325. auth_to_local = RULE:[1:$0\$1](^DTA02\.NT\.TRA\.GVA\.ES\\.*)s/^DTA02\.NT\.TRA\.GVA\.ES/DTA02/
  326. auth_to_local = RULE:[1:$0\$1](^DTC01\.NT\.TRA\.GVA\.ES\\.*)s/^DTC01\.NT\.TRA\.GVA\.ES/DTC01/
  327. auth_to_local = RULE:[1:$0\$1](^DGSS\.NT\.TRA\.GVA\.ES\\.*)s/^DGSS\.NT\.TRA\.GVA\.ES/DGSS/
  328. auth_to_local = RULE:[1:$0\$1](^DTV1\.NT\.TRA\.GVA\.ES\\.*)s/^DTV1\.NT\.TRA\.GVA\.ES/DTV1/
  329. auth_to_local = DEFAULT
  330. }
  331. [appdefaults]
  332. pam = {
  333. mappings = GENERALITAT\\(.*) $1@GENERALITAT.GVA.ES
  334. forwardable = true
  335. validate = true
  336. }
  337. httpd = {
  338. mappings = GENERALITAT\\(.*) $1@GENERALITAT.GVA.ES
  339. reverse_mappings = (.*)@GENERALITAT\.GVA\.ES GENERALITAT\$1
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement