允许 Castellan 支持不同类型的 Keystone 认证

蓝图: https://blueprints.launchpad.net/castellan/+spec/remove-keystone-dependency

问题描述

目前在 Castellan 中,为了通过 Barbican 密钥管理器获得访问权限,必须提供包含有效的 Keystone 认证令牌上下文

正在开发的 Swift 密钥管理系统[1] 将访问 Castellan 以从 Barbican 获取密钥,但希望拥有一个具有访问所有密钥权限的 Keystone 服务用户,并在未来能够拥有独立的访问权限。对于服务用户,将使用包含 Keystone 用户名密码上下文。Castellan 必须支持这一点。

提议的变更

提议的更改是允许 Castellan 能够检查 Barbican 密钥管理器的上下文,并能够确定要使用的 Keystone 认证函数类型。

将有一种新的分层上下文对象,它将从用户/服务传递到 Castellan。它将代替 oslo.context 使用。

分层上下文将由 凭证 对象作为父类组成,子类将是

1.) 令牌凭证,用于使用令牌进行认证。

2.) 密码凭证,用于使用用户名和密码进行认证。

3.) 证书凭证,用于使用证书进行认证。

首先检查上下文以查看它是什么类型的对象,然后确定要使用的 Keystone 认证类型。

注意

oslo.context 仍然需要支持,直到将来弃用它。 租户项目 ID 应该向后兼容。补丁 https://review.openstack.org/#/c/235671/ 添加了项目 ID 的检查,它允许避免 租户项目 ID 之间的混淆,并且是在将 Keystone 认证中间件对象作为上下文传递时所必需的。

Swift 密钥管理系统中的示例用法

from castellan.common.objects import symmetric_key
from castellan import credential
from castellan import key_manager

CONF = <swift conf>

# If keystone auth-middleware exists then it provides the authentication
# for the logged in user[2].
ks_context = env.get('keystone.token_auth').user

# Depending on how the configuration is setup, then a different 'credential` object
# will be created and processed by Castellan. More information on this can be
# found in examples below.
context = credential.credential_factory(context=ks_context, conf=CONF)

# create a key
key = symmetric_key.SymmetricKey('aes', 128, '==8hykeh')
manager = key_manager.API(configuration=CONF)
stored_key_id = manager.store(context, key)

Swift 配置必须更改为包含 Castellan 将用于认证的某些变量。

对于基于密码的认证,用户必须在 Swift 配置中提供以下内容

[castellan]
auth_type = 'password'
username = 'swift'
password = 'xswift'
project_id = '1a4a0618b306462c9830f876b0bd6af2'
domain_id = '5abc43'

注意

以上是它如何在 Swift 密钥管理系统中使用的示例。仅用于演示目的。

认证类型 变量将用于确定 Castellan 应该创建哪种类型的 凭证。可能的认证类型将是 令牌密码证书。Castellan 将包含一个上下文工厂来处理不同的认证类型。以下是上下文工厂的示例。

def credential_factory(context=None, conf=None):
    if CONF.castellan.auth_type == 'token':
        if context:
            auth_token = context.auth_token
        else:
            auth_token = CONF.castellan.auth_token

        context = catstellan.KeystoneTokenContext(auth_token,
                                                  CONF.castellan.auth_url,
                                                  CONF.castellan.project_id)
    elif CONF.castellan.auth_type == 'password':
        context = castellan.PasswordContext(CONF.castellan.username,
                                            CONF.castellan.password,
                                            CONF.castellan.auth_url,
                                            CONF.castellan.project_id,
                                            CONF.castellan.domain_id)
    elif CONF.castellan.auth_type == 'certificate':
        context = castellan.CertificateContext(CONF.castellan.public_key,
                                               CONF.castellan.private_key)

    return context

备选方案

可以使用用户名和密码派生 Keystone 认证令牌。可以创建一个包含认证令牌的 oslo.context 对象并将其传递给 Castellan 调用。

数据模型影响

REST API 影响

安全影响

如果正在使用 v3.Password,则必须存储用户名、密码、项目 ID 和域信息(ID 或名称)。

通知与审计影响

Python 和命令行客户端影响

其他最终用户影响

性能影响

其他部署者影响

开发人员影响

开发者有更多可以传递给 Castellan 的上下文选项。

实现

负责人

主要负责人

diazjf

其他贡献者

rellerreller

工作项

1. 为 Barbican 密钥管理器在 Castellan 中支持多种 Keystone 认证类型。 2. 添加关于如何为 Barbican 密钥管理器生成上下文的文档。

依赖项

测试

需要添加新的单元测试和功能测试。

文档影响

必须更新 Castellan 文档以包含这些更改。

参考资料

[1] https://github.com/openstack/swift-specs/blob/master/specs/in_progress/at_rest_encryption.rst [2] https://github.com/openstack/keystonemiddleware/blob/1047cececf68c3c22add66b6a8a1c499a667c036/keystonemiddleware/auth_token/__init__.py#L171-L174