附註:

在 Oracle Linux 上安裝 FreeIPA 伺服器

簡介

FreeIPA 是一個開放原始碼的識別與認證管理系統,適用於 Linux 網路環境。伺服器包含 389 Directory Server 作為中央資料倉庫,提供完整的多主 LDAPv3 功能。

除了本教學課程的範圍之外,FreeIPA 也透過 ISC 連結伺服器提供用於單一登入認證的 MIT Kerberos、Dogtag 憑證授權機構以及選擇性的網域名稱管理。

本教學課程說明如何安裝 FreeIPA 並設定包含的 LDAP 目錄。

目標

在本自學課程中,您將學習如何:

必要條件

如需 FreeIPA 需求的詳細資訊,請參閱上游快速入門指南

部署 Oracle Linux

注意:如果是在您自己的租用戶中執行,請先閱讀 linux-virt-labs GitHub 專案 README.md 並完成先決條件,再部署實驗環境環境。

  1. 在 Luna Desktop 上開啟終端機。

  2. 複製 linux-virt-labs GitHub 專案。

    git clone https://github.com/oracle-devrel/linux-virt-labs.git
    
  3. 變更至工作目錄。

    cd linux-virt-labs/ol
    
  4. 安裝必要的集合。

    ansible-galaxy collection install -r requirements.yml
    
  5. 更新 Oracle Linux 執行處理組態。

    cat << EOF | tee instances.yml > /dev/null
    compute_instances:
      1:
        instance_name: "freeipa"
        type: "server"
    EOF
    
  6. 部署實驗環境環境。

    ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6" -e "@instances.yml" 
    

    自由實驗環境環境需要額外的變數 local_python_interpreter,此變數會設定在 localhost 上執行的播放 ansible_python_interpreter。由於環境會安裝 Oracle Cloud Infrastructure SDK for Python 的 RPM 套件 (位於 python3.6 模組底下),因此需要此變數。

    預設部署資源配置使用 AMD CPU 和 Oracle Linux 8。若要使用 Intel CPU 或 Oracle Linux 9,請在部署命令中新增 -e instance_shape="VM.Standard3.Flex"-e os_version="9"

    重要事項: 請等待播放手冊順利執行,然後到達暫停工作。在手冊的這個階段,Oracle Linux 的安裝已完成,實例已就緒。記下先前的播放,此播放會列印其部署節點的公用和專用 IP 位址,以及執行實驗室時所需的任何其他部署資訊。

確認伺服器 DNS 組態

FreeIPA 伺服器需要有可用的 DNS 設定。使用 ipa 命令行工具註冊的從屬端,會依 /etc/ipa/default.conf 檔案中定義的 xmlrpc_urldomain 參數查詢伺服器。

  1. 開啟終端機,並透過 SSH 連線至 freeipa 執行處理。

    ssh oracle@<ip_address_of_instance>
    
  2. 確認伺服器的主機名稱。

    sudo hostname
    

    輸出不應傳回 localhostlocalhost6

確認為完整網域的名稱 (FQDN)。

FreeIPA 的 FQDN 限制為 64 個字元,可在安裝期間進行驗證。如果 FQDN 超過 64 個字元,請使用 sudo hostnamectl set-hostname NAME (其中 NAME 是 FQDN) 來縮短 FQDN。

  1. 驗證 FQDN 及其長度。

    hostname -f
    
  2. 取得 FQDN 的長度

    echo $(hostname -f) | wc -m
    

確認名稱解析。

  1. 取得伺服器 IP 位址。

    ip -4 -o addr show ens3 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
    

    其中 ens3 是系統上網路介面的名稱。

  2. 請檢查轉送 DNS 組態。

    host $(hostname -f)
    

    另一種驗證轉送 DNS 組態的方式是使用 dig +short $(hostname -f) Ahostdig 都是 bind-utils 套裝軟體的一部分,提供不同的公用程式來查詢 DNS 名稱伺服器。

  3. 請檢查反向 DNS 組態 (PTR 記錄)。

    host $(hostname -i)
    

    另一種方法是使用 dig +short -x $(hostname -i)

開啟必要的防火牆連接埠

FreeIPA 需要開啟數個連接埠,才能與其服務進行通訊。

服務 連接埠 協定
HTTP/HTTPS 80,443 TCP
LDAP/LDAP 389,636 TCP
Kerberos 88,464 TCP 和 UDP
DNS 53 TCP 和 UDP
新浪微博 123 UDP

Oracle Linux 提供 freeipa-4 服務來開啟這些所需的連接埠。如需詳細資訊,請參閱 /usr/lib/firewalld/services/freeipa-4.xmlfreeipa-4 服務會取代已不再使用的 freeipa-ldapfreeipa-ldaps 服務。

  1. 新增 firewalld 服務。

    sudo firewall-cmd --permanent --add-service=freeipa-4
    
  2. 重新載入 firewalld 服務,讓變更生效。

    sudo firewall-cmd --reload
    

安裝必要的套裝程式

  1. 啟用 FreeIPA 模組串流和設定檔。

    Oracle Linux 8:

    sudo dnf module enable -y idm:DL1
    

    Oracle Linux 9 和 Oracle Linux 10:

    由於 FreeIPA 套裝軟體是 AppStream 儲存庫的一部分,因此不需要在 Oracle Linux 9 上執行任何動作。

  2. 安裝沒有整合 DNS 服務之 FreeIPA 伺服器的套裝軟體。

    sudo dnf install -y ipa-server
    

    備註:本教學課程不使用整合式 DNS 服務。如有需要,請將套裝軟體 ipa-server-dns 增加到安裝清單。

安裝並設定 FreeIPA 伺服器

  1. 執行安裝公用程式。

    sudo ipa-server-install
    

    命令檔會從提供安裝日誌檔位置以及 FreeIPA 伺服器包含項目的摘要開始。

    輸出範例:

    [oracle@freeipa ~]$ sudo ipa-server-install
       
    The log file for this installation can be found in /var/log/ipaserver-install.log
    ==============================================================================
    This program will set up the IPA Server.
    Version 4.9.8
       
    This includes:
      * Configure a stand-alone CA (dogtag) for certificate management
      * Configure the NTP client (chronyd)
      * Create and configure an instance of Directory Server
      * Create and configure a Kerberos Key Distribution Center (KDC)
      * Configure Apache (httpd)
      * Configure SID generation
      * Configure the KDC to enable PKINIT
    ...
    

    接著,命令檔會使用數個提示來設定伺服器的組態。終端機會顯示括號內提示的預設回應,而按 Enter 則接受預設回應。

  2. 接受 no 的預設回應以設定整合的 DNS 服務。

    Do you want to configure integrated DNS (BIND)? [no]:
    
  3. 接受預設主機、網域和範圍名稱。

    這些值是在此實驗開始時驗證的。建議的組態是範圍名稱與主要 DNS 網域名稱和所有大寫字母相符。

    Enter the fully qualified domain name of the computer
    on which you're setting up server software. Using the form
    <hostname>.<domainname>
    Example: master.example.com.
       
       
    Server host name [freeipa.lv.vcn.oraclevcn.com]: 
       
    The domain name has been determined based on the host name.
       
    Please confirm the domain name [lv.vcn.oraclevcn.com]: 
       
    The kerberos protocol requires a Realm name to be defined.
    This is typically the domain name converted to uppercase.
       
    Please provide a realm name [LV.VCN.ORACLEVCN.COM]:
    
  4. 輸入並確認「目錄伺服器」超級使用者和 FreeIPA admin 使用者的密碼。

    「目錄伺服器」超級使用者會對應到目錄內的 cn=Directory Manager

    Certain directory server operations require an administrative user.
    This user is referred to as the Directory Manager and has full access
    to the Directory for system management tasks and will be added to the
    instance of directory server created for IPA.
    The password must be at least 8 characters long.
       
    Directory Manager password: 
    Password (confirm): 
       
    The IPA server requires an administrative user, named 'admin'.
    This user is a regular system account used for IPA server administration.
       
    IPA admin password: 
    Password (confirm): 
    
  5. 接受設定 NETBIOS 網域名稱和 no 的預設值,以設定 chrony。

    NetBIOS domain name [LV]: 
       
    Do you want to configure chrony with NTP server or pool address? [no]:
    
  6. 命令檔會顯示伺服器組態的摘要。

  7. 輸入 yes 以接受伺服器組態。

    Continue to configure the system with these values? [no]: yes
    
  8. 指令碼會繼續設定伺服器。

    這項作業可能需要幾分鐘的時間才能完成.

    ...
    Client configuration complete.
    The ipa-client-install command was successful
       
    Please add records in this file to your DNS system: /tmp/ipa.system.records.mv9i0ec2.db
    ==============================================================================
    Setup complete
       
    Next steps:
    	1. You must make sure these network ports are open:
    		TCP Ports:
    		  * 80, 443: HTTP/HTTPS
    		  * 389, 636: LDAP/LDAPS
    		  * 88, 464: kerberos
    		UDP Ports:
    		  * 88, 464: kerberos
    		  * 123: ntp
       
    	2. You can now obtain a kerberos ticket using the command: 'kinit admin'
    	   This ticket will allow you to use the IPA tools (e.g., ipa user-add)
    	   and the web user interface.
       
    Be sure to back up the CA certificates stored in /root/cacert.p12
    These files are required to create replicas. The password for these
    files is the Directory Manager password
    The ipa-server-install command was successful
    

    完成時,命令檔會提供:

    • 摘要。
    • 要新增至 DNS 系統的記錄清單。
    • 建議備份產生的 CA 憑證。

    已使用 freeipa-4 firewalld 服務開啟必要的網路連接埠。

測試 FreeIPA 伺服器

FreeIPA 安裝包含命令行用戶端和用於與伺服器互動的 WebUI。使用 WebUI 在本教學課程的範圍之外。

存取控制介面 (CLI)

  1. 對 Kerberos 範圍認證 admin 使用者。

    kinit admin
    

    出現提示時,請輸入安裝和組態步驟期間所建立之 admin 使用者的密碼。然後,kinit 命令會產生 Kerberos 許可證。

  2. 列出票券的資訊

    klist
    

    輸出範例:

    [oracle@freeipa ~]$ sudo klist
    Ticket cache: KCM:0
    Default principal: admin@LV.VCN.ORACLEVCN.COM
    
    Valid starting       Expires              Service principal
    09/28/2022 14:05:46  09/29/2022 13:05:53  krbtgt/LV.VCN.ORACLEVCN.COM@LV.VCN.ORACLEVCN.COM
    
  3. 取得 FreeIPA 伺服器上所有現有使用者的清單。

    ipa user-find
    

    結果會傳回 admin 使用者,這是目前唯一存在的使用者。

    輸出範例:

    [oracle@freeipa ~]$ sudo ipa user-find
    --------------
    1 user matched
    --------------
      User login: admin
      Last name: Administrator
      Home directory: /home/admin
      Login shell: /bin/bash
      Principal alias: admin@LV.VCN.ORACLEVCN.COM, root@LV.VCN.ORACLEVCN.COM
      UID: 872200000
      GID: 872200000
      Account disabled: False
    ----------------------------
    Number of entries returned 1
    ----------------------------
    

安全設定值與強化

以下是一些安全地使用 FreeIPA 伺服器的方法。

停用匿名連結

FreeIPA LDAP 伺服器會啟用匿名連結作為預設值,因此會顯示特定的組態設定值和目錄值。

nsslapd-allow-anonymous-access 屬性控制此行為。可接受的值包括:

在不允許匿名連結時,建議使用 rootdse 而非 off,因為使用 off 也會阻止外部用戶端檢查伺服器組態。讀取根 DSE 檔案以取得連線詳細資訊,以匿名方式連線非網域從屬端 (例如 LDAP 和 Web 從屬端)。

  1. 檢查是否啟用匿名連結。

    ldapsearch -x -h $(hostname -f) -b dc=lv,dc=vcn,dc=oraclevcn,dc=com
    
    • -x 設定簡單或匿名驗證。
    • -h 設定 LDAP 伺服器主機。
    • -b 會設定搜尋的基礎 DN。

    金鑰設定值 (包括 FreeIPA 伺服器的基礎 dn) 儲存在 /etc/ipa/default.conf 檔案中。

    輸出範例:

    ...
    # Default SMB Group, groups, accounts, lv.vcn.oraclevcn.com
    dn: cn=Default SMB Group,cn=groups,cn=accounts,dc=lv,dc=vcn,dc=oraclevc
     n,dc=com
    cn: Default SMB Group
    description: Fallback group for primary group RID, do not add users to this gr
     oup
    objectClass: top
    objectClass: ipaobject
    objectClass: posixgroup
    objectClass: ipantgroupattrs
    ipaUniqueID: 0c9cf178-4324-11ed-bf0b-02001704fe22
    gidNumber: 921600001
    ipaNTSecurityIdentifier: S-1-5-21-2697967063-3375457457-2974965896-1001
      
    # search result
    search: 2
    result: 0 Success
      
    # numResponses: 110
    # numEntries: 109
    

    搜尋結果會傳回 LDAP 目錄的整個樹狀結構。

  2. 修改組態並停用匿名連結。

    ldapmodify 命令會接受 LDIF 檔案,其中含有從標準輸入進行或讀取作業的變更。

    1. 建立 LDIF 檔案。

      cat << 'EOF' | tee ~/disable_anon_bind.ldif > /dev/null
      dn: cn=config
      changetype: modify
      replace: nsslapd-allow-anonymous-access
      nsslapd-allow-anonymous-access: rootdse
      EOF
      

      您可以單獨使用破折號 - 字元來區隔多個屬性,以變更多個屬性。每項額外變更都以屬性變更類型為開頭,並提供必要的屬性。

    2. 套用 LDIF 變更。

      ldapmodify -x -D "cn=Directory Manager" -W -H ldap:// -ZZ -f ~/disable_anon_bind.ldif
      
      • -x 設定簡單或匿名驗證。
      • -D 設定連結 DN。
      • -W 會提示輸入 LDAP admin 密碼。
      • -H 使用「LDAP 統一資源識別碼 (URI)」進行連線,而非使用 LDAP 伺服器主機。
      • -ZZ 會啟動 TLS 要求並強制回應成功。

      注意:由於使用自行簽署的憑證,因此需要 -ZZ

      輸出範例:

      [oracle@freeipa ~]$ ldapmodify -x -D "cn=Directory Manager" -W -H ldap:// -ZZ -f ~/disable_anon_bind.ldif
      Enter LDAP Password: 
      modifying entry "cn=config"
      
    3. 重新開始 FreeIPA 伺服器。

      sudo systemctl restart ipa.service
      
  3. 透過匿名查詢目錄來驗證修改。

    ldapsearch -x -h $(hostname -f) -b dc=lv,dc=vcn,dc=oraclevcn,dc=com
    

    請注意回應 Anonymous access is not allowed

    輸出範例:

    [oracle@freeipa ~]$ ldapsearch -x -h freeipa.lv.vcn.oraclevcn.com -b dc=lv,dc=vcn,dc=oraclevcn,dc=com
    # extended LDIF
    #
    # LDAPv3
    # base <dc=lv,dc=vcn,dc=oraclevcn,dc=com> with scope subtree
    # filter: (objectclass=*)
    # requesting: ALL
    #
      
    # search result
    search: 2
    result: 48 Inappropriate authentication
    text: Anonymous access is not allowed.
      
    # numResponses: 1
    
  4. 驗證使用認證來查詢目錄。

    ldapsearch -D uid=admin,cn=users,cn=accounts,dc=lv,dc=vcn,dc=oraclevcn,dc=com -W -H ldap://
    

    輸出範例:

    ...
    # freeipa.lv.vcn.oraclevcn.com + 389, subordinate-ids, dna, ipa, etc, 
     lv.vcn.oraclevcn.com
    dn: dnaHostname=freeipa.lv.vcn.oraclevcn.com+dnaPortNum=389,cn=subord
     inate-ids,cn=dna,cn=ipa,cn=etc,dc=lv,dc=vcn,dc=oraclevcn,dc=com
    objectClass: dnaSharedConfig
    objectClass: top
    dnaHostname: freeipa.lv.vcn.oraclevcn.com
    dnaPortNum: 389
    dnaSecurePortNum: 636
    dnaRemainingValues: 32766
      
    # search result
    search: 2
    result: 0 Success
      
    # numResponses: 475
    # numEntries: 474
    

驗證已啟用 TLS

從 Oracle Linux 8 開始,FreeIPA 會使用全系統加密原則。如需詳細資訊,請參閱 crypto-policies(7) 線上手冊。

  1. 列出目前的系統加密政策 。

    cat /etc/crypto-policies/config
    
  2. 列出密碼編譯原則詳細資訊。

    cat /usr/share/crypto-policies/$(cat /etc/crypto-policies/config)/nss.txt
    

    輸出範例:

    [oracle@freeipa ~]$ cat /usr/share/crypto-policies/$(cat /etc/crypto-policies/config)/nss.txt
    library=
    name=Policy
    NSS=flags=policyOnly,moduleDB
    config="disallow=ALL allow=HMAC-SHA256:HMAC-SHA1:HMAC-SHA384:HMAC-SHA512:CURVE25519:SECP256R1:SECP384R1:SECP521R1:aes256-gcm:chacha20-poly1305:aes256-cbc:aes128-gcm:aes128-cb   > c:SHA256:SHA384:SHA512:SHA224:ECDHE-RSA:ECDHE-ECDSA:RSA:DHE-RSA:ECDSA:RSA-PSS:RSA-PKCS:tls-version-min=tls1.2:dtls-version-min=dtls1.2:DH-MIN=2048:DSA-MIN=2048:RSA-MIN=2048"
    

    請注意,DEFAULT 原則至少使用 TLS 1.2

檢查 FreeIPA 伺服器狀態

FreeIPA 伺服器包含 ipactl 公用程式,可檢視已設定服務的狀態。相同的公用程式也可以啟動、停止及重新啟動整個 FreeIPA 伺服器。如果您需要 startstoprestart 個別元件,請使用 systemctl COMMAND name.service

  1. 顯示所有服務的狀態。

    sudo ipactl status
    

    輸出範例:

    [oracle@freeipa ~]$ sudo ipactl status
    Directory Service: RUNNING
    krb5kdc Service: RUNNING
    kadmin Service: RUNNING
    httpd Service: RUNNING
    ipa-custodia Service: RUNNING
    pki-tomcatd Service: RUNNING
    ipa-otpd Service: RUNNING
    ipa: INFO: The ipactl command was successful
    

    使用 sudo ipactl --help 可查看其他命令選項。

建立使用者和群組

在 FreeIPA 伺服器基本安裝與組態完成之後,下一步就是處理識別管理,此管理包含建立使用者與群組。執行此動作之前,請先產生 Kerberos 記號。

  1. 產生使用者 admin 的記號。

    kinit admin
    
  2. 取得現有的記號清單。

    klist
    

    Kerberos 記號預設有效期為 24 小時。由於先前在標題為「存取命令行介面 (CLI)」的步驟中執行這些命令,清單會顯示原始記號,而非建立新記號。

  3. 新增使用者群組。

    FreeIPA 將使用者群組定義為一組具有標準密碼制定原則、權限及其他特性的使用者。

    使用者群組可包含:

    • 使用者
    • 其他使用者群組
    • FreeIPA 以外的外部使用者

   ipa group-add foo

輸出範例:

[oracle@freeipa ~]$ ipa group-add foo
-----------------
Added group "foo"
-----------------
  Group name: foo
  GID: 1326400003

FreeIPA 伺服器支援三種群組類型:

群組 foo 是 POSIX 使用者群組。若要指定不同的群組類型,請使用下列其中一個選項:

  1. 取得所有現有使用者群組的清單。

    ipa group-find
    

    輸出範例:

    [oracle@freeipa ~]$ ipa group-find
    ----------------
    5 groups matched
    ----------------
      Group name: admins
      Description: Account administrators group
      GID: 1326400000
       
      Group name: editors
      Description: Limited admins who can edit other users
      GID: 1326400002
       
      Group name: foo
      GID: 1326400003
       
      Group name: ipausers
      Description: Default group for all users
      
      Group name: trust admins
      Description: Trusts administrators group
    ----------------------------
    Number of entries returned 5
    ----------------------------
    

    FreeIPA 伺服器會在安裝期間建立下列使用者群組。

    • admins
    • ipausers
    • trust admins

    警告:請勿刪除 admin 群組,因為其包含預設的 admin 使用者。FreeIPA 伺服器需要 admin 群組才能正確運作。

  2. 新增使用者帳戶。

    ipa user-add
    

    該指令執行互動式指令碼,提示最少的資料集 FreeIPA 建立使用者帳戶。

    輸出範例:

    [oracle@freeipa ~]$ ipa user-add
    First name: Oracle
    Last name: User
    User login [ouser]: oracle
    -------------------
    Added user "oracle"
    -------------------
      User login: oracle
      First name: Oracle
      Last name: User
      Full name: Oracle User
      Display name: Oracle User
      Initials: OU
      Home directory: /home/oracle
      GECOS: Oracle User
      Login shell: /bin/sh
      Principal name: oracle@LV.VCN.ORACLEVCN.COM
      Principal alias: oracle@LV.VCN.ORACLEVCN.COM
      Email address: oracle@lv.vcn.oraclevcn.com
      UID: 1326400004
      GID: 1326400004
      Password: False
      Member of groups: ipausers
      Kerberos keys available: False
    

    或者,使用數個選項執行指令,即可在非互動式模式下建立使用者帳戶。若要取得可用選項的清單,請執行 ipa user-add --help

  3. 新增使用者至新使用者群組。

    ipa group-add-member foo --users=oracle
    

    輸出範例:

    [oracle@freeipa ~]$ ipa group-add-member foo --users=oracle
      Group name: foo
      GID: 1326400003
      Member users: oracle
    -------------------------
    Number of members added 1
    -------------------------
    

ipa 指令的功能比所顯示的還多。如需其他命令,請執行 ipa help commands 以取得完整清單。

接下來的步驟

最後,本實驗介紹了安裝與使用 FreeIPA 伺服器的基本知識。使用以下連結進一步探索,或閱讀產品手冊頁面,因為 FreeIPA 除了此處所涵蓋的功能之外,還有許多其他功能。

其他學習資源

docs.oracle.com/learn 上探索其他實驗室,或在 Oracle Learning YouTube 頻道上存取更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。

如需產品文件,請造訪 Oracle Help Center