在現代網路環境中,集中式身分驗證管理至關重要。本文將引導您設定 RADIUS 伺服器,並整合 LDAP/LDAPS 後端,特別是與 Active Directory 的整合,以強化網路安全性。此設定流程涉及 Samba 和 Kerberos 的組態,確保 Linux 主機能順利加入 AD 網域並驗證服務。文章也會探討 FreeRADIUS 的設定,包含關鍵組態檔的修改,例如 smb.confkrb5.confnsswitch.conf,以及 FreeRADIUS 的 mschapeap 模組設定。此外,還會介紹如何使用 Unlang 語言在 FreeRADIUS 中建立更精細的存取控制規則,例如區分 VPN 使用者和網路管理員的許可權。最後,文章將提供實際案例,說明如何在防火牆、路由器和交換器上實施 RADIUS 認證,並探討如何運用 EAP-TLS 提升驗證安全性。

RADIUS 搭配 LDAP/LDAPS 後端驗證設定

在進行 RADIUS 搭配 LDAP/LDAPS 後端驗證設定時,需要進行一系列的組態與測試,以確保 Linux 主機能夠順利加入 Active Directory (AD) 網域並進行身分驗證。

編輯 Samba 設定檔

首先,編輯 /etc/samba/smb.conf 檔案,並更新以下設定:

[global]
workgroup = COHERENTSEC
security = ADS
realm = COHERENTSECURITY.COM
winbind refresh tickets = Yes
winbind use default domain = yes
vfs objects = acl_xattr
map acl inherit = Yes
store dos attributes = Yes
dedicated keytab file = /etc/krb5.keytab
kerberos method = secrets and keytab

[homes]
comment = Home Directories
browseable = no
writeable = yes

內容解密:

  • workgrouprealm 設定為對應的 AD 網域。
  • security = ADS 表示使用 Active Directory 進行身分驗證。
  • winbind refresh ticketswinbind use default domain 設定與 Winbind 服務相關,用於處理 Kerberos 票據和預設網域。
  • vfs objectsmap acl inheritstore dos attributes 與檔案系統的 ACL 和屬性相關。
  • [homes] 部分設定使用者主目錄的存取許可權。

編輯 Kerberos 設定檔

接下來,編輯 /etc/krb5.conf 檔案:

[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log

[libdefaults]
default_realm = COHERENTSECURITY.COM
dns_lookup_realm = false
dns_lookup_kdc = false

[realms]
COHERENTSECURITY.COM = {
    kdc = dc01.coherentsecurity.com:88
    admin_server = dc01.coherentsecurity.com:749
    kpasswordserver = dc01.coherentsecurity.com
    default_domain = COHERENTSECURITY.COM
}

[domain_realm]
.coherentsecurity.com = COHERENTSECURITY.COM

[kdc]
profile = /var/kerberos/krb5kdc/kdc.conf

[appdefaults]
pam = {
    debug = false
    ticket_lifetime = 36000
    renew_lifetime = 36000
    forwardable = true
    krb4_convert = false
}

內容解密:

  • [logging] 部分設定 Kerberos 的日誌記錄。
  • [libdefaults] 設定預設的 Kerberos 網域和其他引數。
  • [realms] 定義了 Kerberos 網域的詳細資訊,包括 KDC 和管理伺服器的位置。
  • [domain_realm] 將網域名稱對映到 Kerberos 網域。
  • [appdefaults] 設定 PAM 的 Kerberos 認證引數。

編輯名稱服務交換設定檔

編輯 /etc/nsswitch.conf 檔案,加入 winbind

passwd: files systemd winbind
group: files systemd winbind
shadow: files winbind
protocols: db files winbind
services: db files winbind
netgroup: nis winbind
automount: files winbind

內容解密:

  • winbind 加入到名稱服務交換設定中,以便使用 Winbind 服務進行身分驗證和群組查詢。

加入 AD 網域並驗證服務

  1. 重新啟動 Linux 主機。
  2. 加入 AD 網域:net ads join –U Administrator
  3. 重新啟動 smbdwinbind 服務:systemctl restart smbd winbind
  4. 檢查服務狀態:sudo ps –e | grep smbdsudo ps –e | grep nmbd
  5. 列出網域中的使用者和群組:wbinfo -uwbinfo -g

DNS 設定與測試

確保 Linux 主機的 DNS 設定正確,可以解析 AD 網域控制器的名稱。測試 DNS 解析:

dig +short _ldap._tcp.coherentsecurity.com SRV

驗證身分驗證功能:

wbinfo -a administrator%Passw0rd!
ntlm_auth –-request-nt-key –-domain=coherentsecurity.com --username=Administrator

組態 FreeRADIUS

  1. 編輯 /etc/freeradius/3.0/mods-available/mschap 檔案,更新以下設定:

chap { with_ntdomain_hack = yes }

ntlm_auth = “/usr/bin/ntlm_auth –request-nt-key –username=%{%{Stripped-User-Name}:-%{%{User-Name}:-None}} –challenge=%{%{mschap:Challenge}:-00} –nt-response=%{%{mschap:NT-Response}:-00} –domain=%{mschap:NT-Domain}”

   #### 內容解密:
   - `with_ntdomain_hack` 設定為 `yes` 以解決挑戰/回應握手問題。
   - 更新 `ntlm_auth` 命令以使用正確的引數進行身分驗證。

2. 編輯 `/etc/freeradius/3.0/mods-available/eap` 檔案,更新以下設定:
   ```markdown
eap {
    default_eap_type = peap
}

tls-config tls-common {
    random_file = /dev/urandom
}

內容解密:

  • 將預設的 EAP 方法設為 PEAP。
  • 更新 random_file 設定以使用 /dev/urandom

完成以上設定後,RADIUS 伺服器應該能夠使用 LDAP/LDAPS 後端進行身分驗證。客戶端可以使用 CHAP 或 PEAP 方法進行身分驗證。

RADIUS 服務在 Linux 上的應用

在網路存取裝置(例如 VPN 閘道器或無線系統)上,我們啟用 MS-CHAP 認證或 MS-CHAPv2(支援透過 RADIUS 變更密碼)。現在,讓我們探討如何使用 Unlang 語言設定規則,以同時控制 VPN 存取和該 VPN 伺服器的管理存取。

Unlang - 無語言

FreeRADIUS 支援一種簡易的處理語言,稱為 Unlang(無語言)。這讓我們能夠建立規則,新增額外的控制措施到 RADIUS 認證流程和最終決策中。

Unlang 語法

Unlang 語法通常出現在虛擬伺服器檔案中——在我們的例子中,就是 /etc/freeradius/3.0/sites-enabled/default。它可以出現在 authorizeauthenticatepost-authpreacctaccountingpre-proxypost-proxysession 等區段中。

在大多數常見的佈署中,我們可能會尋找傳入的 RADIUS 變數或屬性值(AV)對——例如 Service-Type,它可能是 AdministrativeAuthenticate-Only。在 Unlang 程式碼中,將其與群組成員資格進行比對——例如,網路管理員、VPN 使用者或無線使用者。

簡單範例

對於 VPN-Only 或管理存取這兩個防火牆登入需求的簡單情況,您可能會看到如下規則:

if (&NAS-IP-Address == "192.168.122.20") {
    if (Service-Type == "Administrative" && LDAP-Group == "Network Admins") {
        update reply {
            Cisco-AVPair = "shell:priv-lvl=15"
        }
        accept
    }
    elsif (Service-Type == "Authenticate-Only" && LDAP-Group == "VPN Users") {
        accept
    }
    else {
        reject
    }
}

內容解密:

  1. if (&NAS-IP-Address == "192.168.122.20"):檢查 NAS 裝置的 IP 位址是否為 192.168.122.20
  2. if (Service-Type == "Administrative" && LDAP-Group == "Network Admins"):檢查服務型別是否為管理存取且使用者屬於 Network Admins 群組。
  3. update reply { Cisco-AVPair = "shell:priv-lvl=15" }:更新回應中的 Cisco-AVPair 屬性,將許可權等級設為 15。
  4. accept:接受認證請求。
  5. elsif (Service-Type == "Authenticate-Only" && LDAP-Group == "VPN Users"):檢查服務型別是否為僅驗證且使用者屬於 VPN Users 群組。
  6. reject:拒絕認證請求。

RADIUS 使用案例

在本文中,我們將探討多種裝置型別和各種認證選項,以及如何使用 RADIUS 來滿足這些需求。讓我們從 VPN 閘道器開始,使用標準的使用者 ID 和密碼認證。

VPN 認證使用使用者 ID 和密碼

首先,將您的 VPN 閘道器(通常是防火牆)新增為 RADIUS 的客戶端——將其新增到 /etc/freeradius/3.0/clients.conf 檔案中,如下所示:

client hqfw01 {
    ipaddr = 192.168.122.1
    vendor = cisco
    secret = pzg64yr43njm5eu
}

接下來,設定防火牆指向 RADIUS 進行 VPN 使用者認證。對於 Cisco Adaptive Security Appliance(ASA)防火牆,您需要進行以下變更:

! 建立一個名為 "RADIUS" 的 AAA 群組,使用 RADIUS 協定
aaa-server RADIUS protocol radius

! 新增伺服器作為該群組的成員
aaa-server RADIUS (inside) host <RADIUS Server IP 01>
    key <some key 01>
    radius-common-pw <some key 01>
    no mschapv2-capable
    acl-netmask-convert auto-detect

aaa-server RADIUS (inside) host <RADIUS Server IP 02>
    key <some key 02>
    radius-common-pw <some key 02>
    no mschapv2-capable
    acl-netmask-convert auto-detect

! 更新 tunnel-group 以使用 RADIUS 伺服器群組進行認證
tunnel-group VPNTUNNELNAME general-attributes
    authentication-server-group RADIUS
    default-group-policy VPNPOLICY

設定解說:

  1. 將 VPN 閘道器新增為 RADIUS 客戶端,並指定其 IP 位址、供應商和分享金鑰。
  2. 在防火牆上設定 RADIUS 認證,指定 RADIUS 伺服器的 IP 位址和分享金鑰。
  3. 更新 tunnel-group 以使用 RADIUS 伺服器群組進行認證。

RADIUS 應用案例分析

在前述章節中,我們已經瞭解了 RADIUS 的基本架構與運作原理。現在,讓我們進一步探討 RADIUS 在真實世界中的應用案例,特別是在網路裝置的管理存取控制方面。

網路裝置的管理存取控制

為了提高網路安全性,我們需要對網路裝置(如防火牆、路由器和交換器)進行嚴格的管理存取控制。RADIUS 在這方面扮演了重要的角色。

防火牆的管理存取控制

首先,我們來看看如何在防火牆上實施 RADIUS 認證。假設我們已經設定好 RADIUS 伺服器,並且希望將其用作防火牆管理存取的認證方法。

我們需要新增一個網路政策,以區分 VPN 使用者和網路管理員。具體做法是:

  • 對 VPN 使用者,新增一個 AV 對(Attribute-Value Pair),其屬性為 Service-Type,值為 Authenticate Only
  • 對網路管理員,新增一個 AV 對,其屬性為 Service-Type,值為 Administrative

在 RADIUS 伺服器端,我們需要建立兩個群組:VPN UsersNetwork Administrators,並將使用者分配到相應的群組中。這樣,管理員就可以同時擁有 VPN 存取和管理存取許可權,而普通 VPN 使用者則只能擁有 VPN 存取許可權。

為了實作上述功能,我們需要在防火牆上進行相應的設定。以下是一個 ASA 防火牆的設定範例:

aaa authentication enable console RADIUS LOCAL
aaa authentication http console RADIUS LOCAL
aaa authentication ssh console RADIUS LOCAL
aaa accounting enable console RADIUS
aaa accounting ssh console RADIUS
aaa authentication login-history

內容解密:

  1. aaa authentication enable console RADIUS LOCAL:設定啟用模式(enable mode)的認證方式,首先使用 RADIUS,若失敗則使用本地認證。
  2. aaa authentication http console RADIUS LOCAL:設定 HTTP 管理介面的認證方式,首先使用 RADIUS,若失敗則使用本地認證。
  3. aaa authentication ssh console RADIUS LOCAL:設定 SSH 管理介面的認證方式,首先使用 RADIUS,若失敗則使用本地認證。
  4. aaa accounting enable console RADIUS:啟用對啟用模式的記帳功能,使用 RADIUS 伺服器進行記帳。
  5. aaa accounting ssh console RADIUS:啟用對 SSH 工作階段的記帳功能,使用 RADIUS 伺服器進行記帳。
  6. aaa authentication login-history:記錄登入歷史。

這些設定確保了管理存取的安全性,並且能夠區分不同型別的使用者。

路由器和交換器的管理存取控制

接下來,我們來看看如何在路由器和交換器上實施 RADIUS 認證。以下是 Cisco 路由器和 HP ProCurve 交換器的設定範例:

Cisco 路由器設定範例

radius server RADIUS01
 address ipv4 <radius server ip 01> auth-port 1812 acct-port 1813
 key <some key>

radius server RADIUS02
 address ipv4 <radius server ip 02> auth-port 1812 acct-port 1813
 key <some key>

aaa group server radius RADIUSGROUP
 server name RADIUS01
 server name RADIUS02

ip radius source-interface <Layer 3 interface name>

aaa new-model
aaa authentication login RADIUSGROUP group radius local
aaa authorization exec RADIUSGROUP group radius local
aaa authorization network RADIUSGROUP group radius local

line vty 0 97
 access-class ACL-MGT in
 login authentication RADIUSG1
 transport input ssh

HP ProCurve 交換器設定範例

radius-server host <server ip> key <some key 01>

aaa server-group radius "RADIUSG1" host <server ip 01>

radius-server dead-time 5
radius-server timeout 3
radius-server retransmit 2

aaa authentication num-attempts 3
aaa authentication ssh login radius server-group "RADIUSG1" local
aaa authentication ssh enable radius server-group "RADIUSG1" local

內容解密:

  1. Cisco 路由器設定
    • 定義 RADIUS 伺服器並設定相關引數,如 IP 位址、驗證埠和記帳埠。
    • 建立 RADIUS 伺服器群組,並將伺服器加入群組。
    • 設定 AAA 認證和授權,使用 RADIUS 群組進行驗證和授權。
    • 在 VTY 線路(虛擬終端線路)上套用 ACL(存取控制列表)並設定登入驗證。
  2. HP ProCurve 交換器設定
    • 設定 RADIUS 伺服器的主機 IP 位址和金鑰。
    • 建立 RADIUS 伺服器群組並新增伺服器。
    • 設定 RADIUS 相關引數,如無回應逾時時間、重傳次數等。
    • 設定 SSH 登入和啟用模式的認證方式,使用 RADIUS 群組進行驗證。

EAP-TLS 的應用

最後,讓我們來看看 EAP-TLS(Extensible Authentication Protocol-Transport Layer Security)在 RADIUS 中的應用。EAP-TLS 使用憑證進行客戶端和 RADIUS 伺服器之間的相互驗證,從而提高認證的安全性。

在上述範例中,我們已經看到了如何使用 RADIUS 對網路裝置進行管理存取控制。透過結合 EAP-TLS,我們可以進一步增強認證的安全性,防止未經授權的存取。