我正在尝试使用基于 Keystone 的身份验证通过 curl 访问 Swift(遵循此处的 Keystone API 文档)。
第 1 章:获取令牌:
curl -d '{"auth": {"passwordCredentials": {
"username": "USERNAME", "password": "PASSWORD"}}}' \
-H "Content-Type: application/json" \
http://identity:35357/v2.0/tokens
回复:
{
"access": {
"token": {
"expires": "2014-02-27T11:35:11Z",
"id": "TOKENID"
},
"serviceCatalog": [],
"user": {
"username": "USERNAME",
"roles_links": [],
"id": "USERID",
"roles": [],
"name": "NAME"
}
}
}
请注意,与API 文档中所说的相反,响应中缺少租户信息。
第 2 章:身份验证
curl -H "X-Auth-Token: TOKENID" http://swift/v1/AUTH_TENANTID/bucket
回复:401 Unauthorized
第 3 章:故障排除
在查看 Keystone auth_token 中间件后,我发现它在尝试从令牌数据中获取租户时失败:
def get_tenant_info():
"""Returns a (tenant_id, tenant_name) tuple from context."""
def essex():
"""Essex puts the tenant ID and name on the token."""
return (token['tenant']['id'], token['tenant']['name'])
def pre_diablo():
"""Pre-diablo, Keystone only provided tenantId."""
return (token['tenantId'], token['tenantId'])
def default_tenant():
"""Pre-grizzly, assume the user's default tenant."""
return (user['tenantId'], user['tenantName'])
for method in [essex, pre_diablo, default_tenant]:
try:
return method()
except KeyError:
pass
raise InvalidUserToken('Unable to determine tenancy.')
由于令牌数据中没有租户信息,因此总是失败。我可能做错了什么?