某天一套 Univention Corporate Server(UCS)5.0 的管理介面突然登不進去,畫面只有一行:
Internal server error.
{'desc': 'Connect error', 'info': 'error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed (certificate has expired)'}
接著 UCS 上的 LDAP、SSO、接 UCS 認證的其他系統也陸續出問題。原因是 UCS 的根憑證(Root CA)到期了。UCS 安裝時預設建立的根憑證有效期是 5 年,裝好之後很少有人記得它,一到期整個網域裡用 TLS 的服務都會一起出問題。
這篇整理檢查與更新的完整步驟,以官方的處理方式為主,加上我實際遇到的 SSO 問題。
症狀
管理介面登入失敗時,錯誤追蹤的關鍵在這幾行:
File "/usr/lib/python3/dist-packages/univention/uldap.py", line 416, in __starttls
self.lo.start_tls_s()
ldap.CONNECT_ERROR: {'desc': 'Connect error', 'info': '... certificate verify failed (certificate has expired)'}
UMC 要用主機帳號連 LDAP 查使用者,連線時走 StartTLS,憑證驗證失敗,登入就跟著失敗。
確認是哪一張憑證過期
# 主機憑證
openssl x509 -in /etc/univention/ssl/$(hostname -f)/cert.pem -noout -dates
# 根憑證
openssl x509 -in /etc/univention/ssl/ucsCA/CAcert.pem -noout -dates
# 主機憑證
notBefore=Jan 26 15:33:29 2025 GMT
notAfter=Jan 25 15:33:29 2030 GMT
# 根憑證
notBefore=Jul 27 13:03:48 2020 GMT
notAfter=Jul 26 13:03:48 2025 GMT
主機憑證還有好幾年,根憑證已經過期了。根憑證一過期,所有由它簽發的憑證都會被視為無效,即使主機憑證本身還沒到期。
也可以用 UCS 的工具列出所有憑證與到期日:
univention-certificate list
univention-certificate dump -name ucs.example.com
備份
以下操作都在 Primary Directory Node(舊稱 Master)上進行,先備份整個憑證目錄:
cp -a /etc/univention/ssl /etc/univention/ssl_$(date +%Y%m%d)
延長根憑證
用原本的 CA 私鑰重新簽出一張新的根憑證,有效期用 UCS 的預設天數:
cd /etc/univention/ssl/ucsCA
openssl x509 -in CAcert.pem -out NewCAcert.pem \
-days "$(ucr get ssl/default/days)" \
-passin file:/etc/univention/ssl/password \
-signkey private/CAkey.pem -sha256
mv NewCAcert.pem CAcert.pem
openssl x509 -in CAcert.pem -noout -dates
因為用的是同一把私鑰,已經發出去的主機憑證不用重新驗證簽章關係,信任鏈可以接續。
更新所有主機憑證
官方建議根憑證更新後,把網域裡所有主機的憑證也一併更新:
eval "$(ucr shell domainname ssl/default/days)"
cd /etc/univention/ssl
for i in *".${domainname}"; do
univention-certificate renew -name "$i" -days "${ssl_default_days}"
done
這個迴圈會把 /etc/univention/ssl 底下所有屬於這個網域的憑證都重新簽發,包含 SSO 用的 ucs-sso.example.com。我第一次處理時漏掉了這一步,後面 SSO 就一直出問題(見第七節)。
發佈根憑證並更新信任
# 提供使用者從入口網站下載根憑證
install -o root -g root -m 0644 /etc/univention/ssl/ucsCA/CAcert.pem /var/www/ucs-root-ca.crt
# 更新系統的信任憑證
update-ca-certificates -f
# 立即重新計算憑證狀態(不用等每天的排程)
/usr/sbin/univention-certificate-check-validity
重新啟動服務
用到 TLS 的服務都要重新啟動,不確定有哪些的話,直接重新開機最保險:
systemctl restart slapd apache2 \
univention-management-console-server univention-management-console-web-server \
univention-portal-server univention-saml
其他 UCS 主機
網域裡如果還有 Replica Directory Node 或 Managed Node,要把新的根憑證與它們各自的主機憑證複製過去(Backup Directory Node 會自動同步),以 replica1 為例:
eval "$(ucr shell domainname)"
cd /etc/univention/ssl/
scp ucsCA/CAcert.pem root@replica1:/etc/univention/ssl/ucsCA/
rsync -a "replica1.${domainname}" root@replica1:/etc/univention/ssl/
複製完,在那台主機上也執行 update-ca-certificates -f 並重新啟動服務。
SSO(SAML)要另外處理
UCS 5.0 的 Primary 與 Backup Directory Node 同時也是 SAML 身分提供者(IdP),用的是 ucs-sso.example.com 這張憑證。我當時只更新了根憑證和主機憑證,重設 SSO 設定時一直失敗:
Try to download idp metadata (1/60)
curl: (60) SSL certificate problem: certificate has expired
檢查 SSO 網址送出的憑證:
SSO_FQDN="$(ucr get ucs/server/sso/fqdn)"
echo | openssl s_client -servername "$SSO_FQDN" -connect "$SSO_FQDN:443" 2>/dev/null \
| openssl x509 -noout -dates -subject
果然還是舊的那張。依官方步驟,確認 ucs-sso 的憑證已經更新(第四節的迴圈有包含),再安裝給 SAML 服務使用:
eval "$(ucr shell domainname)"
install -o root -g samlcgi -m 0644 \
/etc/univention/ssl/"ucs-sso.${domainname}"/cert.pem \
/etc/simplesamlphp/"ucs-sso.${domainname}-idp-certificate.crt"
install -o root -g samlcgi -m 0640 \
/etc/univention/ssl/"ucs-sso.${domainname}"/private.key \
/etc/simplesamlphp/"ucs-sso.${domainname}-idp-certificate.key"
systemctl restart univention-saml
然後在每台有 UMC 的 UCS 主機上,重新取得 IdP 的 metadata:
ucr set umc/saml/idp-server="https://ucs-sso.$(ucr get domainname)/simplesamlphp/saml2/idp/metadata.php"
這次就能成功下載了。有接 UCS SSO 的外部服務(SAML 服務提供者),也要更新成新的憑證或重新匯入 metadata。
不使用 SSO 的話
如果環境裡根本沒有用到 SSO,也可以把 UMC 改回一般的帳號密碼登入,少一個要維護的東西:
ucr set umc/web/sso/enabled=false
ucr set portal/auth-mode='ucs'
systemctl restart univention-management-console-web-server univention-management-console-server univention-portal-server
UCS 5.2 起 SSO 改由 Keycloak 負責,升級到 5.2 之後再依新的架構規劃即可。
驗證
# 根憑證日期
openssl x509 -in /etc/univention/ssl/ucsCA/CAcert.pem -noout -dates
# LDAPS(7636)送出的憑證
echo | openssl s_client -connect localhost:7636 2>/dev/null | openssl x509 -noout -dates -issuer
# 用 StartTLS 連 LDAP
ldapsearch -x -ZZ -H ldap://$(hostname -f) \
-b "$(ucr get ldap/base)" -D "$(ucr get ldap/hostdn)" -y /etc/machine.secret -s base
# 加入狀態
univention-check-join-status
都正常之後,再登入管理介面確認,並測試接 UCS 認證的其他系統(郵件、VPN、Wi-Fi 等)是否恢復。
用戶端要更新根憑證
延長後的根憑證雖然沿用同一把私鑰,但憑證本身是新的一張。如果有用戶端(電腦、其他系統)是手動匯入舊的 UCS 根憑證來信任的,要改匯入新的那張,下載網址是:
https://ucs.example.com/ucs-root-ca.crt
預防
- 記下根憑證的到期日,提前半年排入行事曆
- 用監控系統定期檢查憑證到期日,例如 LibreNMS 的 HTTPS 憑證檢查、或自己寫腳本檢查
/etc/univention/ssl/ucsCA/CAcert.pem - UCS 管理介面的通知也會提醒憑證即將到期,不要忽略
結論
UCS 根憑證預設 5 年到期,一到期 LDAP、管理介面、SSO 全部一起出問題。處理的順序是:延長根憑證 → 更新所有主機憑證(包含 ucs-sso)→ 發佈並更新信任 → 重新啟動服務 → 處理 SSO 與其他主機。順序對了,其實不難;最怕的是只改一半,SSO 那邊就會一直卡住。
參考資料
- Univention Help:Renewing the SSL certificates
https://help.univention.com/t/renewing-the-ssl-certificates/37 - Univention Corporate Server Manual 5.0
https://docs.software-univention.de/manual/5.0/en/ - UCS 登入後導向密碼變更頁
https://blog.jason.tools/2025/10/ucs-password-change-redirect.html



