Keystone 負(fù)責(zé) OpenStack 的認(rèn)證和授權(quán)管理。當(dāng)用戶的 Credentials 被驗(yàn)證后,keystone 會(huì)給用戶分配一個(gè) Authentication token 作為用戶憑據(jù)去訪問其他組件的 API。
Token 分類
OpenStack Token 按授權(quán)范圍分有以下幾種:
Unscoped tokens
* contains neither a service catalog, any roles, a project scope, nor a domain scope
* use to generate scoped tokensProject-scoped tokens
* operate in a specific tenancy of the cloudDomain-scoped tokens
* domain-level administrator to operate a domainSystem-scoped tokens
* operate system-level resources,e.g. endpoints, service, hypervisors
按生成方式分:
UUID tokens
* 32 bytes in length and must be persistedPKI tokens
* CA certificate issued by external CAPKIZ tokens
* zipped PKI tokenFernet tokens
* do not need to be persisted
* AES256 encryption is used to protect the information stored in the token
* integrity is verified with a SHA256 HMAC signature
Token 認(rèn)證流程
其中 OpenStack API 接受到用戶 token 后向 keystone 認(rèn)證的步驟4、5是通過 keystone 提供的 WSGI middleware —— keystonemiddleware 實(shí)現(xiàn)的:
- 在各個(gè)組件的 api-paste.ini 配置文件中引入 auth_token filter:
- 在組件配置文件如 nova.conf 中配置 keystone 參數(shù):
Token 變遷史
OpenStack D 版本時(shí),僅有 UUID 類型的 Token,UUID token 簡單易用,卻容易給 Keystone 帶來性能問題,每當(dāng) OpenStack API 收到用戶請求,都需要向 Keystone 驗(yàn)證該 token 是否有效。隨著集群規(guī)模的擴(kuò)大,Keystone 需處理大量驗(yàn)證 token 的請求,在高并發(fā)下容易出現(xiàn)性能問題,而且需要持久化到數(shù)據(jù)庫中,與日俱增積累的大量 token 引起數(shù)據(jù)庫性能下降,所以用戶需經(jīng)常清理數(shù)據(jù)庫的 過期 token。
于是 PKI(Public Key Infrastructrue) token 在 G 版本應(yīng)運(yùn)而生,和 UUID 相比,PKI token 攜帶更多用戶信息的同時(shí)還附上了數(shù)字簽名,以支持本地認(rèn)證,從而避免了和 keystone 交互過程。而因?yàn)?PKI token 攜帶了更多的信息,包括 service catalog,隨著 OpenStack 的 Region 數(shù)增多,service catalog 攜帶的 endpoint 數(shù)量越多,PKI token 也相應(yīng)增大,很容易超出 HTTP Server 允許的最大 HTTP Header(默認(rèn)為 8 KB),導(dǎo)致 HTTP 請求失敗。PKI 的過期管理和安全問題也需要用戶考慮,給實(shí)際應(yīng)用帶來了額外的開銷。
PKIZ token 就是 PKI token 的改進(jìn)壓縮版,但壓縮效果有限,無法良好的處理 token size 過大問題。PKI 和 PKIZ 類型的 token 由于安全性和使用上的不便,在 P 版本已被廢棄。
為了解決前面種種問題,社區(qū)引入了 Fernet token,它攜帶了少量的用戶信息,實(shí)際 token 大小約為 255 Byte,采用了對稱加密,無需存于數(shù)據(jù)庫中,解析傳輸效率很高,現(xiàn)在已成為 keystone 的默認(rèn) token 類型。
Token 類型比較
| Token 類型 | UUID | PKI | PKIZ | Fernet |
|---|---|---|---|---|
| 大小 | 32 Byte | KB 級別 | KB 級別 | 約 255 Byte |
| 支持本地認(rèn)證 | 不支持 | 支持 | 支持 | 不支持 |
| Keystone 負(fù)載 | 大 | 小 | 小 | 大 |
| 存儲(chǔ)于數(shù)據(jù)庫 | 是 | 是 | 是 | 否 |
| 攜帶信息 | 無 | user, catalog 等 | user, catalog 等 | user 等 |
| 涉及加密方式 | 無 | 非對稱加密 | 非對稱加密 | 對稱加密(AES) |
| 是否壓縮 | 否 | 否 | 是 | 否 |
| 需要預(yù)配置 | 否 | 是 | 是 | 是 |
| 版本支持 | D | G | J | K |