Ubuntu 16.04 上 Ejabberd extauth 設定
Ejabberd 支援通過執行外部程式自定義外部認證邏輯, ejabberd 的網頁上提供了一些第三方程式碼可供參考.詳細的說明在 ejabberd Developers Guide.
以 ejabberd Developers Guide 中提供的 python 範例為基礎進行改進, 首先修改 python 版本為 python3.
1 |
修改為
1 |
對於 python3 不同於 python2 的部分做如下修改:
1 | ... |
修改為
1 | ... |
之後可對auth()
, isuser()
, setpass()
做改動以適應自己的認證邏輯.其中isuser()
和setpass()
可以保留return True
.
最後將修改好的檔案丟去/etc/ejabberd/extauth.py
, 修改 owner 為ejabberd
, 添加執行權限.
在/etc/ejabberd/ejabberd.yml
找到auth_method: internal
修改為:
1 | auth_method: |
在其下方增加:
1 | extauth_program: "/etc/ejabberd/extauth.py" |
通過ejabberdcctl
重新啟動ejabberd
使設定生效.
若出現extauth script has exitted abruptly with reason 'normal'
, 在排除檔案 owner 和執行權限有誤的情況下, 可能為apparmor
所致 (帶有 SELinux 的作業系統中可能為 SELinux 所致, 可以通過sudo setenforce 0
臨時關閉 SELinux 測試) , 查看/var/log/syslog
可看到相關 log.
1 | Sep 19 11:31:45 localhost kernel: [ 5031.995813] audit: type=1400 audit(1505827901.939:57): apparmor="DENIED" operation="exec" profile="/usr/sbin/ejabberdctl" name="/var/lib/ejabberd/extauth.py" pid=4419 comm="sh" requested_mask="x" denied_mask="x" fsuid=100 ouid=100 |
臨時解決方法是移除apparmor
.
1 | $ sudo apt-get purge --auto-remove apparmor |