標籤:Rancher

如何將 Rancher 串上 FreeIPA 驗證

因工作需求,最近在研究如何使用 Rancher[1] 來管理 Kubernetes[2] 叢集,於是打算在 Homelab 上也建一組,想說前幾個禮拜還在研究 FreeIPA[3] 乾脆把他們湊一堆好了 XD

準備 Service Account

在開始將 FreeIPA 驗證接進 Rancher 之前,Rancher 要求先在 IPA 裡面建立一個 Service Account 來提供 Rancher 查詢 Domain 下的使用者與群組,但這個建立 Service Account 的步驟無法從 FreeIPA Web 界面執行,必須手動將這個 Account 加入 LDAP 中[4],首先到 IPA master 上執行下列步驟:(假設 IPA domain 為 example.com

$ cat - <<-EOF > add-srvacct-rancher.ldif
dn: uid=rancher,cn=sysaccounts,cn=etc,dc=example,dc=com
changetype: add
objectclass: account
objectclass: simplesecurityobject
uid: rancher
userPassword: 2Brq/Ux4rs:2Dnt3#%Rx
nsIdleTimeout: 0
EOF
$ ldapmodify -x -D 'cn=Directory Manager' -W < add-srvacct-rancher.ldif
Enter LDAP Password: # Enter Dircetory Manager password
adding new entry "uid=rancher,cn=sysaccounts,cn=etc,dc=example,dc=com"
$

其中 dc=example,dc=com 記得換成自己的 IPA domain,以及自己產生 userPassword(筆者是使用密碼產生器產生)後記下,待會會在 Rancher 設定用到。

設定 Rancher

首先登入有 administrator 權限的帳號,並依照以下步驟設定 FreeIPA Authenticate:

  1. 在 Global 域中選擇 Security -> Authentication
  2. 選擇 FreeIPA
  3. 填入 FreeIPA 伺服器資訊
  4. 在 Service Account 相關資訊中填入剛剛建立的 Service Account
    • Service Account Distinguished Name(記得換成 IPA domain)
      • uid=rancher,cn=sysaccounts,cn=etc,dc=example,dc=com
    • Service Account Password
      • 剛剛建立的 userPassword
  5. 填入使用者資料庫相關資訊
    • User Search Base(記得換成 IPA domain)
      • cn=users,cn=accounts,dc=example,dc=com
    • Group Search Base(記得換成 IPA domain)
      • cn=groups,cn=accounts,dc=example,dc=com
  6. Customize Schema 的部分我會選擇調整使用者的帳號資訊對應
    • Username Attribute(使用者顯示名稱)
      • displayName
    • Login Attribute(使用者帳號)
      • uid
    • Search Attribute(搜尋欄位,在搜尋使用者時會去尋找的欄位,預設是姓名跟帳號)
      • uid
  7. 在 Test and enable authentication 中填入要與目前帳號綁定的 FreeIPA 帳號資訊
    • 根據 Rancher 的說明[5],在這裡填入的 FreeIPA 帳號(external principal)會自動對應到目前用來設定的管理員帳號(local principal),並會在設定成功之後自動改用 external principal 登入 Rancher
  8. 在設定完成後點擊 Authenticate with FreeIPA 即可完成設定

設定完成後發現會被 Rancher 自動以剛剛 test authentication 的帳號登入,並且同時又是剛剛設定時使用的管理員帳號,從 Preference 頁面可以看到這個現象,但不要緊張,只是因為 Rancher 把這兩個帳號綁定了,共用 local ID。

後記

這次的篇幅稍短,介紹的內容也是偏簡單,僅對於 FreeIPA 如何建立 Service Account 的部分有特別需要撰寫 ldif 來手動加入 LDAP。 不知道大家對於這種篇幅及類型的文章接受度如何,就先當作是嘗試看看,同時也是在回應筆者朋友兼大神 小飛機 提出的看法[6]「資訊太多,透過文字消化資訊和整理思緒」並為自己而寫,因此打算開始嘗試這種廢文體短篇筆記型的內容,同時用比較輕鬆的態度來發文看看 XD


  1. 管理 Kubernetes 叢集的工具,提供多叢集、ACL、自動部署、Web 界面等特點,該公司還有出很多 K8s 相關的其他工具,詳見官方網站 ↩︎

  2. Kubernetes 是用於自動部署、擴展和管理「容器化(containerized)應用程式」的開源系統,詳見其官方網站 ↩︎

  3. FreeIPA 是免費的開源身份管理系統,IPA 分別代表 Identity、Policy、Audit,同時也是 Red Hat Identity Manager 的上游開源專案,詳見其官方網站 ↩︎

  4. FreeIPA 的 HowTo/LDAP 頁面亦有提及如何新增 Service Account/System Account ↩︎

  5. https://rancher.com/docs/rancher/v2.x/en/admin-settings/authentication/#external-authentication-configuration-and-principal-users ↩︎

  6. 請見小飛機大大的文章《成為一名技術留跡者↩︎