OpenLDAP:修订间差异
(→安裝) |
(→密碼設定) |
||
(未显示同一用户的55个中间版本) | |||
第2行: | 第2行: | ||
== 安裝 == | == 安裝 == | ||
由於OpenLDAP 2.4在2007年十月發行,至今只有一直發行minor release,所以通常都可以透過系統的套件裝到合理的版本: | 由於OpenLDAP 2.4在2007年十月發行,至今只有一直發行minor release,所以通常都可以透過系統的套件裝到合理的版本: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="bash"> | ||
sudo apt -y install slapd | |||
</syntaxhighlight> | </syntaxhighlight> | ||
另外會安裝常用的工具<code> | 另外會安裝<code>ldap-utils</code>,主要是因為CLI下 常用的工具 不在OpenLDAP內提供,而是透過第三方的方式操作(像是<code>ldapmodify</code>、<code>ldapdelete</code> 這些指令) : | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="bash"> | ||
sudo apt -y install ldap-utils | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== 設定 == | == 基本概念 == | ||
這邊會提到一些OpenLDAP與一般LDAP比較不一樣的地方,以及一些值得提出來的基本概念。 | |||
=== 管理員帳號名稱 === | |||
在OpenLDAP的文件的範例中,都是以<code>cn=Manager</code>當作是管理權限帳號。但透過網路搜尋可以看到很多人是使用<code>cn=admin</code>,甚至是<code>cn=root</code>的帳號。在這份文件裡面我們採用了OpenLDAP文件範例的慣例來設計。 | |||
=== 管理員帳號本體 === | |||
在OpenLDAP的設定檔中,你可以用<code>rootdn</code>與<code>rootpw</code>設定管理員帳號與密碼,但這個方式將密碼寫死在設定檔內,對於有政策需要定期更換密碼時會比較困難。 | |||
在這種情境下我們會考慮只設定<code>rootdn</code>而不設定<code>rootpw</code>,另外建立一個物件,掛上<code>organizationalRole</code>,並賦予<code>simpleSecurityObject</code>這個類別,將密碼放在資料庫內管理: | |||
<pre> | |||
dn: cn=Manager,dc=example,dc=com | |||
objectClass: organizationalRole | |||
objectClass: simpleSecurityObject | |||
cn: Manager | |||
userPassword: {CRYPT}$1$xxxxxxxx$yyyyyyyyyyyyyyyyyyyyyy | |||
</pre> | |||
== 設定 檔 == | |||
=== /etc/default/slapd === | |||
Ubuntu 16.04內的版本預設會使用目錄結構設定檔(預設讀取<code>/etc/ldap/slapd.d/</code>整個目錄),但這跟網路上一般使用單檔設定不同(通常會是<code>/etc/ldap/slapd.conf</code>),所以我們要告知slapd使用檔案設定檔。 | Ubuntu 16.04內的版本預設會使用目錄結構設定檔(預設讀取<code>/etc/ldap/slapd.d/</code>整個目錄),但這跟網路上一般使用單檔設定不同(通常會是<code>/etc/ldap/slapd.conf</code>),所以我們要告知slapd使用檔案設定檔。 | ||
第24行: | 第45行: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== /etc/ldap/slapd.conf === | |||
我們要將<code>slapd.conf</code>的 範本複製 到<code>/etc/ldap/slapd.conf</code>之後 修改(範本在<code>/usr/share/slapd/slapd.conf</code>這邊),裡面有一些變數需要設定: | |||
* <code>@BACKEND@</code>設為<code>mdb</code>。 | * <code>@BACKEND@</code>設為<code>mdb</code>。 | ||
第32行: | 第54行: | ||
其中的<code>dc=example,dc=com</code>為範例,可以依照實際組織設定。 | 其中的<code>dc=example,dc=com</code>為範例,可以依照實際組織設定。 | ||
另外因為使用mdb,需要 | ==== mdb ==== | ||
另外因為使用mdb,需要 將bdb(指BerkeleyDB)相關的<code>dbconfig</code>的參數都刪除掉 。 | |||
==== 密碼設定 ==== | |||
網路上大多數的文章 ( 過舊的文章)都會推薦使用<code>{SSHA}</code>,但 這 只是salted-SHA1,計算速度很快。目前OpenLDAP內建的演算法都沒有足夠的抵抗能力,需要透過外部支援降低被攻擊的可能性。 | |||
考慮到支援度,APR1-MD5是還算堪用的演算法,可以讓攻擊的計算速度慢一千倍(相比於SSHA)<ref>{{Cite web |url=https://gist.github.com/epixoip/a83d38f412b4737e99bbef804a270c40 |title=8x Nvidia GTX 1080 Hashcat Benchmarks |accessdate=2018-03-30}}</ref>,所以透過以下的設定要求透過系統底層的<code>crypt()</code>使用APR1-MD5: | |||
<pre> | |||
password-hash "{CRYPT}" | |||
password-crypt-salt-format "$1$%.8s" | |||
</pre> | |||
如果支援度沒有問題,可以考慮bcrypt的方式(<code>$2$</code>),對於暴力計算的抵抗力會更好。 | |||
==== rootdn與rootpw ==== | |||
設定<code>rootdn</code>的dn會有完整的管理權限,不需要另外使用ACL授權。而<code>rootdn</code>的密碼剛開始需要用<code>rootpw</code>設定,可以用下面的指令產生<code>rootpw</code>: | |||
<syntaxhighlight lang="bash"> | |||
slappasswd -h '{CRYPT}' -c '$1$%.8s' | |||
</syntaxhighlight> | |||
然後把設定寫入<code>/etc/ldap/slapd.conf</code>內: | |||
<pre> | |||
rootdn "cn=Manager,dc=example,dc=com" | |||
rootpw "{CRYPT}$1$xxxxxxxx$yyyyyyyyyyyyyyyyyyyyyy" | |||
</pre> | |||
== 資料初始化設定 == | |||
預設資料庫內應該是空的(可以透過<code>ldapsearch -x</code>的指令確認),所以會需要塞一 些 資訊進去。資料初始化會透過<code>ldapmodify</code>指令進行,這會需要安裝前面提到的<code>ldap-utils</code>。 | |||
=== Domain === | |||
先加入domain本身,檔案寫到<code>init-domain.ldif</code>,然後透過<code>ldapmodify -x -D 'cn=Manager,dc=example,dc=com' -W -f init-domain.ldif</code>加入即可:(需要修改<code>dn</code>與<code>dc</code>的值) | |||
<pre> | |||
dn: dc=example,dc=com | |||
changetype: add | |||
objectclass: top | |||
objectclass: domain | |||
dc: example | |||
</pre> | |||
=== People === | |||
再來是產生<code>ou=People,dc=example,dc=com</code>: | |||
<pre> | |||
dn: ou=People,dc=example,dc=com | |||
changetype: add | |||
objectClass: organizationalUnit | |||
ou: People | |||
</pre> | |||
=== Groups === | |||
再來 是 產生<code>ou=Groups,dc=example,dc=com</code>: | |||
<pre> | |||
dn: ou=Groups,dc=example,dc=com | |||
changetype: add | |||
objectClass: organizationalUnit | |||
ou: Groups | |||
</pre> | |||
=== Manager === | |||
這是管理員的身份 , 可以不在資料庫內設定,而是透過<code>slapd.conf</code>內的ACL與<code>rootpw</code>設定。 | |||
<pre> | |||
dn: cn=Manager,dc=example,dc=com | |||
changetype: add | |||
objectClass: organizationalRole | |||
objectClass: simpleSecurityObject | |||
cn: Manager | |||
userPassword: {CRYPT}$1$xxxxxxxx$yyyyyyyyyyyyyyyyyyyy | |||
</pre> | |||
增加完成後可以拿掉<code>/etc/ldap/slapd.conf</code>內的<code>rootpw</code>設定。 | |||
== Replication == | |||
這邊先放設定: | |||
<pre> | |||
# Replication | |||
readonly on | |||
syncrepl rid=100 | |||
binddn="cn=syncuser,dc=example,dc=com" | |||
bindmethod=simple | |||
credentials="password" | |||
interval=00:00:01:00 | |||
provider=ldaps://ldap-master.example.com:636 | |||
retry="60 +" | |||
searchbase="dc=example,dc=com" | |||
tls_cacert=/etc/ssl/certs/ca-certificates.crt | |||
type=refreshAndPersist | |||
</pre> | |||
這邊<code>ldaps</code>的部分表示走SSL,可以 用[[Let's Encrypt]]的憑證會比較容易處理(不需要另外開CA授權 )。 | |||
== 常用指令 == | |||
{{Main|LDAP}} | |||
== 相關連結 == | |||
* [[LDAP]] | |||
== 參考資料 == | |||
{{Reflist|2}} | |||
== 外部連結 == | == 外部連結 == |
2023年5月31日 (三) 06:56的最新版本
OpenLDAP是一套LDAP伺服器软体。
安装
由于OpenLDAP 2.4在2007年十月发行,至今只有一直发行minor release,所以通常都可以透过系统的套件装到合理的版本:
sudo apt -y install slapd
另外会安装ldap-utils
,主要是因为CLI下常用的工具不在OpenLDAP内提供,而是透过第三方的方式操作(像是ldapmodify
、ldapdelete
这些指令):
sudo apt -y install ldap-utils
基本概念
这边会提到一些OpenLDAP与一般LDAP比较不一样的地方,以及一些值得提出来的基本概念。
管理员帐号名称
在OpenLDAP的文件的范例中,都是以cn=Manager
当作是管理权限帐号。但透过网路搜寻可以看到很多人是使用cn=admin
,甚至是cn=root
的帐号。在这份文件里面我们采用了OpenLDAP文件范例的惯例来设计。
管理员帐号本体
在OpenLDAP的设定档中,你可以用rootdn
与rootpw
设定管理员帐号与密码,但这个方式将密码写死在设定档内,对于有政策需要定期更换密码时会比较困难。
在这种情境下我们会考虑只设定rootdn
而不设定rootpw
,另外建立一个物件,挂上organizationalRole
,并赋予simpleSecurityObject
这个类别,将密码放在资料库内管理:
dn: cn=Manager,dc=example,dc=com objectClass: organizationalRole objectClass: simpleSecurityObject cn: Manager userPassword: {CRYPT}$1$xxxxxxxx$yyyyyyyyyyyyyyyyyyyyyy
设定档
/etc/default/slapd
Ubuntu 16.04内的版本预设会使用目录结构设定档(预设读取/etc/ldap/slapd.d/
整个目录),但这跟网路上一般使用单档设定不同(通常会是/etc/ldap/slapd.conf
),所以我们要告知slapd使用档案设定档。
这要修改/etc/default/slapd
的内容,将SLAPD_CONF
参数从空的值改为/etc/ldap/slapd.conf
:
# Default location of the slapd.conf file or slapd.d cn=config directory. If
# empty, use the compiled-in default (/etc/ldap/slapd.d with a fallback to
# /etc/ldap/slapd.conf).
SLAPD_CONF=/etc/ldap/slapd.conf
/etc/ldap/slapd.conf
我们要将slapd.conf
的范本复制到/etc/ldap/slapd.conf
之后修改(范本在/usr/share/slapd/slapd.conf
这边),里面有一些变数需要设定:
@BACKEND@
设为mdb
。@SUFFIX@
设为dc=example,dc=com
。@ADMIN@
设为cn=Manager,dc=example,dc=com
。
其中的dc=example,dc=com
为范例,可以依照实际组织设定。
mdb
另外因为使用mdb,需要将bdb(指BerkeleyDB)相关的dbconfig
的参数都删除掉。
密码设定
网路上大多数的文章(过旧的文章)都会推荐使用{SSHA}
,但这只是salted-SHA1,计算速度很快。目前OpenLDAP内建的演算法都没有足够的抵抗能力,需要透过外部支援降低被攻击的可能性。
考虑到支援度,APR1-MD5是还算堪用的演算法,可以让攻击的计算速度慢一千倍(相比于SSHA)[1],所以透过以下的设定要求透过系统底层的crypt()
使用APR1-MD5:
password-hash "{CRYPT}" password-crypt-salt-format "$1$%.8s"
如果支援度没有问题,可以考虑bcrypt的方式($2$
),对于暴力计算的抵抗力会更好。
rootdn与rootpw
设定rootdn
的dn会有完整的管理权限,不需要另外使用ACL授权。而rootdn
的密码刚开始需要用rootpw
设定,可以用下面的指令产生rootpw
:
slappasswd -h '{CRYPT}' -c '$1$%.8s'
然后把设定写入/etc/ldap/slapd.conf
内:
rootdn "cn=Manager,dc=example,dc=com" rootpw "{CRYPT}$1$xxxxxxxx$yyyyyyyyyyyyyyyyyyyyyy"
资料初始化设定
预设资料库内应该是空的(可以透过ldapsearch -x
的指令确认),所以会需要塞一些资讯进去。资料初始化会透过ldapmodify
指令进行,这会需要安装前面提到的ldap-utils
。
Domain
先加入domain本身,档案写到init-domain.ldif
,然后透过ldapmodify -x -D 'cn=Manager,dc=example,dc=com' -W -f init-domain.ldif
加入即可:(需要修改dn
与dc
的值)
dn: dc=example,dc=com changetype: add objectclass: top objectclass: domain dc: example
People
再来是产生ou=People,dc=example,dc=com
:
dn: ou=People,dc=example,dc=com changetype: add objectClass: organizationalUnit ou: People
Groups
再来是产生ou=Groups,dc=example,dc=com
:
dn: ou=Groups,dc=example,dc=com changetype: add objectClass: organizationalUnit ou: Groups
Manager
这是管理员的身份,可以不在资料库内设定,而是透过slapd.conf
内的ACL与rootpw
设定。
dn: cn=Manager,dc=example,dc=com changetype: add objectClass: organizationalRole objectClass: simpleSecurityObject cn: Manager userPassword: {CRYPT}$1$xxxxxxxx$yyyyyyyyyyyyyyyyyyyy
增加完成后可以拿掉/etc/ldap/slapd.conf
内的rootpw
设定。
Replication
这边先放设定:
# Replication readonly on syncrepl rid=100 binddn="cn=syncuser,dc=example,dc=com" bindmethod=simple credentials="password" interval=00:00:01:00 provider=ldaps://ldap-master.example.com:636 retry="60 +" searchbase="dc=example,dc=com" tls_cacert=/etc/ssl/certs/ca-certificates.crt type=refreshAndPersist
这边ldaps
的部分表示走SSL,可以用Let's Encrypt的凭证会比较容易处理(不需要另外开CA授权)。
常用指令
相关连结
参考资料
- ↑ 8x Nvidia GTX 1080 Hashcat Benchmarks. [2018-03-30].