บทที่ 16a ไคลเอนต์, กรุ๊ปแวร์ และ CLI Admin: #pIdentity

Kerberos SSO: ลงชื่อเข้าใช้โดยไม่ต้องใช้รหัสผ่านสำหรับพีซีในโดเมน, Outlook และแอปเมล

ด้วย Kerberos, พีซี Windows บนเครือข่ายบริษัทจะเข้าสู่ระบบโดยไม่ต้องแจ้งรหัสผ่าน: เว็บเมลและผู้ดูแลระบบผ่าน SPNEGO ("เข้าสู่ระบบด้วย Windows"), Outlook ผ่าน MAPI, EWS, ActiveSync และ Autodiscover ด้วย Negotiate, Thunderbird และแอปอีเมลอื่นๆ ผ่าน IMAP, SMTP, POP3 และ ManageSieve ด้วย SASL GSSAPI nextxch จะตรวจสอบความถูกต้องของตั๋ว (tickets) ด้วยคีย์ทับที่อัปโหลด ซึ่งใช้งานได้ทั้งบน Linux และบนเซิร์ฟเวอร์ Windows ที่ไม่ใช่สมาชิกโดเมน เมื่อ nextxchทำงานบนสมาชิกโดเมน จะสามารถใช้บัญชีเครื่องแทนคีย์ทับได้ โปรโตคอล NTLM จะไม่ได้รับการสนับสนุนโดยเจตนา

เคล็ดลับการดำเนินงานและหมายเหตุสถาปัตยกรรม

ชื่อโฮสต์ใน SPN ต้องเป็นชื่อเดียวกับที่ไคลเอนต์ใช้ (เช่น mail.example.com) และต้องแก้ไขผ่านเรเคิด A หลังจากการเปลี่ยนรหัสผ่านทุกครั้งของบัญชีบริการ ให้สร้างและอัปโหลดไฟล์ keytab อีกครั้ง; "Check Kerberos" จะแสดงเวอร์ชันคีย์และการเข้ารหัสของ SPN แต่ละรายการ

Active Directory: บัญชีบริการ, SPN และ keytab

PowerShell เป็นผู้ดูแลระบบโดเมน เรียกใช้ ktpass หนึ่งครั้งสำหรับ SPN แรก SPN ทั้งหมดในบัญชีเดียวกันจะใช้คีย์ร่วมกันและต้องการเพียง setspn เท่านั้น

Reference / Configuration
# 1. Service account (password never expires, AES only)
New-ADUser -Name svc-nextxch -AccountPassword (Read-Host -AsSecureString) `
  -Enabled $true -PasswordNeverExpires $true -KerberosEncryptionType AES256

# 2. Register the service principals (host name = name clients use)
setspn -S HTTP/mail.example.com  CORP\svc-nextxch
setspn -S imap/mail.example.com  CORP\svc-nextxch
setspn -S smtp/mail.example.com  CORP\svc-nextxch
setspn -S pop/mail.example.com   CORP\svc-nextxch
setspn -S sieve/mail.example.com CORP\svc-nextxch

# 3. Create the keytab (resets the account password)
ktpass -princ HTTP/mail.example.com@CORP.LOCAL -mapuser CORP\svc-nextxch `
  -crypto AES256-SHA1 -ptype KRB5_NT_PRINCIPAL -pass * -out nextxch.keytab

# 4. nextxch Admin > Identity sources > Kerberos
#    realm CORP.LOCAL, SPNs as above, upload the keytab, "Check Kerberos"

# Machine account mode (nextxch on domain member MAILSRV, no keytab):
setspn -S HTTP/mail.example.com CORP\MAILSRV$
setspn -S imap/mail.example.com CORP\MAILSRV$

MIT Kerberos, Heimdal und FreeIPA

สร้างพรันซิพาลและส่งออกคีย์ไปยัง keytab; FreeIPA: ipa service-add และ ipa-getkeytab

Reference / Configuration
# MIT / Heimdal
kadmin -q "addprinc -randkey HTTP/mail.firma.de@FIRMA.LOCAL"
kadmin -q "addprinc -randkey imap/mail.firma.de@FIRMA.LOCAL"
kadmin -q "addprinc -randkey smtp/mail.firma.de@FIRMA.LOCAL"
kadmin -q "ktadd -k /tmp/nextxch.keytab HTTP/mail.firma.de imap/mail.firma.de smtp/mail.firma.de"

# FreeIPA
ipa service-add HTTP/mail.firma.de
ipa service-add imap/mail.firma.de
ipa-getkeytab -s ipa.firma.local -p HTTP/mail.firma.de -k /tmp/nextxch.keytab
ipa-getkeytab -s ipa.firma.local -p imap/mail.firma.de -k /tmp/nextxch.keytab

# Test vom Client:
kinit anna && curl --negotiate -u : https://mail.firma.de/api/auth/kerberos

ทดสอบแบบ manual ด้วย Active Directory จริง

การทดสอบอัตโนมัติจะตรวจสอบความถูกต้องของตั๋วจาก keytabs ที่สร้างขึ้น พร้อมกับทดสอบด้วยตัวควบคุมโดเมนจริงในลักษณะนี้:

Reference / Configuration
# Auf einem Domänen-PC als normaler Benutzer:
klist purge
Invoke-WebRequest https://mail.firma.de/api/auth/kerberos -UseDefaultCredentials
klist                     # zeigt Ticket für HTTP/mail.firma.de
# Erwartet: 200 {"ok":true,"email":"anna@firma.de"}

# IMAP mit GSSAPI (Linux-Client in der Domäne):
kinit anna@FIRMA.LOCAL
curl -v --login-options AUTH=GSSAPI --negotiate -u : imaps://mail.firma.de/INBOX

การตั้งค่า ค่าเริ่มต้น และแนวปฏิบัติที่ดีที่สุด

การตั้งค่า / ตำแหน่ง คำอธิบาย ค่าเริ่มต้น แนวปฏิบัติที่ดีที่สุดในการผลิต
Keytab MIT-Format, wie es von ktpass, ktutil und kadmin geschrieben wird. Verschlüsselt mit dem Server-Schlüsselbund gespeichert und niemals erneut angezeigt; die Admin-Seite listet lediglich Principal, kvno und Verschlüsselung auf. Keytab-Modus ใช้ AES256 คีย์ RC4 ใช้ได้ แต่ "ตรวจสอบ Kerberos" จะเตือนเกี่ยวกับคีย์เหล่านั้น
Benutzerzuordnung Kerberos principal (anna@CORP.LOCAL) จะถูกแมปผ่านแหล่งที่มาของตัวตน: userPrincipalName, sAMAccountName หรือที่อยู่อีเมล ยอมรับเฉพาะขอบเขตที่กำหนดค่าไว้ (และขอบเขตอื่น ๆ ที่ได้รับอนุญาต) เท่านั้น Realm Pflicht ตั้งค่าและซิงค์แหล่งข้อมูลประจำตัว AD ก่อน จากนั้นจึงเปิดใช้งาน Kerberos
Browser เบราว์เซอร์จะส่งตั๋ว Kerberos เฉพาะไปยังที่อยู่อินทราเน็ตที่เชื่อถือได้เท่านั้น หากไม่มีสิ่งนั้น หน้าลงชื่อเข้าใช้ปกติจะปรากฏขึ้น Automatischer Versuch aus GPO "Site to Zone Assignment List": https://mail.example.com = 1 (intranet). Chrome/Edge: AuthServerAllowlist, Firefox: network.negotiate-auth.trusted-uris.
Outlook und ActiveSync MAPI, EWS, Autodiscover und ActiveSync bieten neben Basic auch "WWW-Authenticate: Negotiate". Outlook auf Domänen-PCs verwendet dann das Ticket des angemeldeten Benutzers. Negotiate + Basic ใน Outlook ภายใต้การตั้งค่าบัญชี > การตั้งค่าเพิ่มเติม > ความปลอดภัย ให้ปิด "ถามหารหัสผ่านเข้าสู่ระบบเสมอ"
Mail-Programme (GSSAPI) IMAP, ส่งผ่าน SMTP, POP3 และ ManageSieve รองรับ SASL GSSAPI (พร้อมการตรวจสอบสิทธิ์ร่วมกัน, RFC 4752) Thunderbird: การตั้งค่าบัญชี > เซิร์ฟเวอร์ > การตรวจสอบสิทธิ์ "Kerberos / GSSAPI" imap/, smtp/, pop/, sieve/ บนไคลเอนต์ Linux ให้เรียกใช้ kinit ก่อน จากนั้น klist จะแสดงทิกเก็ตสำหรับ imap/mail.example.com