注意
本文档适用于 Ceph 开发版本。
STS Lite
Ceph 对象网关为 Amazon 安全令牌服务 (STS) API 的子集提供支持。STS Lite 是 STS 的扩展,并基于其一个 API 来减少外部身份提供者(如 Keystone 和 LDAP)的负载。
在使用外部身份提供者通过 AWS 凭证进行身份验证后,会返回一组临时安全凭证。这些临时凭证可用于进行后续的 S3 调用,这些调用将由 Ceph 中的 STS 引擎进行身份验证,从而减少 Keystone/LDAP 服务器的负载。
还可以使用 STS Lite API 为本地用户获取临时且有限的特权凭证。
STS Lite REST API
以下 STS Lite REST API 是 Ceph 对象网关中 STS Lite 的一部分:
1. GetSessionToken: 为一组 AWS 凭证返回一组临时凭证。在初始使用 Keystone/LDAP 进行身份验证后,返回的临时凭证可用于进行后续的 S3 调用。临时凭证将与 AWS 凭证具有相同的权限。
- 参数:
DurationSeconds(整数/可选): 凭证应保持有效的秒数。其默认值为 3600。其默认最大值为 43200,该值可以通过 rgw sts max session duration 进行配置。
SerialNumber(字符串/可选): 与进行 GetSessionToken 调用的用户关联的多因素认证 (MFA) 设备的 ID 号。
TokenCode(字符串/可选): 如果需要 MFA,则由 MFA 设备提供的值。
需要一个管理员用户将策略附加到允许使用其永久凭证调用 GetSessionToken API,并允许仅使用 GetSessionToken 返回的临时凭证调用后续的 S3 操作。
附加策略的用户需要具有管理员权限。例如:
radosgw-admin caps add --uid="TESTER" --caps="user-policy=*"
以下是需要附加到用户 ‘TESTER1’ 的策略:
user_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Deny\",\"Action\":\"s3:*\",\"Resource\":[\"*\"],\"Condition\":{\"BoolIfExists\":{\"sts:authentication\":\"false\"}}},{\"Effect\":\"Allow\",\"Action\":\"sts:GetSessionToken\",\"Resource\":\"*\",\"Condition\":{\"BoolIfExists\":{\"sts:authentication\":\"false\"}}}]}"
STS Lite 配置
以下是为 STS Lite 集成提供的可配置选项:
[client.radosgw.gateway]
rgw sts key = {sts key for encrypting the session token}
rgw s3 auth use sts = true
如果需要在 Keystone 中使用 STS Lite,则上述 STS 可配置选项可以与 Keystone 可配置选项一起使用。可配置选项的完整集为:
[client.{your-rgw-name}]
rgw_sts_key = {sts key for encrypting/ decrypting the session token, exactly 16 hex characters}
rgw_s3_auth_use_sts = true
rgw keystone url = {keystone server url:keystone server admin port}
rgw keystone admin project = {keystone admin project name}
rgw keystone admin tenant = {keystone service tenant name}
rgw keystone admin domain = {keystone admin domain name}
rgw keystone api version = {keystone api version}
rgw keystone implicit tenants = {true for private tenant for each new user}
rgw keystone admin password = {keystone service tenant user name}
rgw keystone admin user = keystone service tenant user password}
rgw keystone accepted roles = {accepted user roles}
rgw keystone token cache size = {number of tokens to cache}
rgw s3 auth use keystone = true
与 Ceph 对象网关集成 LDAP 的详细信息可以在这里找到:与 OpenStack Keystone 集成
使用 LDAP 的 STS Lite 的完整可配置选项集为:
[client.{your-rgw-name}]
rgw_sts_key = {sts key for encrypting/ decrypting the session token, exactly 16 hex characters}
rgw_s3_auth_use_sts = true
rgw_s3_auth_use_ldap = true
rgw_ldap_uri = {LDAP server to use}
rgw_ldap_binddn = {Distinguished Name (DN) of the service account}
rgw_ldap_secret = {password for the service account}
rgw_ldap_searchdn = {base in the directory information tree for searching users}
rgw_ldap_dnattr = {attribute being used in the constructed search filter to match a username}
rgw_ldap_searchfilter = {search filter}
与 Ceph 对象网关集成 LDAP 的详细信息可以在这里找到:LDAP 身份验证
注意:默认情况下,STS 和 S3 API 共存于同一命名空间,并且 Ceph 对象网关中的 S3 和 STS API 都可以通过同一端点访问。
示例展示如何使用 Keystone 与 STS Lite
使用 Keystone 使用 STS Lite 的步骤如下。使用 Boto 3.x 编写了一个示例代码,以展示 STS Lite 与 Keystone 的集成。
生成 EC2 凭证:
openstack ec2 credentials create
+------------+--------------------------------------------------------+
| Field | Value |
+------------+--------------------------------------------------------+
| access | b924dfc87d454d15896691182fdeb0ef |
| links | {u'self': u'http://192.168.0.15/identity/v3/users/ |
| | 40a7140e424f493d8165abc652dc731c/credentials/ |
| | OS-EC2/b924dfc87d454d15896691182fdeb0ef'} |
| project_id | c703801dccaf4a0aaa39bec8c481e25a |
| secret | 6a2142613c504c42a94ba2b82147dc28 |
| trust_id | None |
| user_id | 40a7140e424f493d8165abc652dc731c |
+------------+--------------------------------------------------------+
使用步骤 1 中创建的凭证,使用 GetSessionToken API 获取一组临时凭证。
import boto3
access_key = <ec2 access key>
secret_key = <ec2 secret key>
client = boto3.client('sts',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
endpoint_url=<STS URL>,
region_name='',
)
response = client.get_session_token(
DurationSeconds=43200
)
步骤 2 中获得的临时凭证可用于进行 S3 调用:
s3client = boto3.client('s3',
aws_access_key_id = response['Credentials']['AccessKeyId'],
aws_secret_access_key = response['Credentials']['SecretAccessKey'],
aws_session_token = response['Credentials']['SessionToken'],
endpoint_url=<S3 URL>,
region_name='')
bucket = s3client.create_bucket(Bucket='my-new-shiny-bucket')
response = s3client.list_buckets()
for bucket in response["Buckets"]:
print("{name}\t{created}".format(
name = bucket['Name'],
created = bucket['CreationDate'],
))
可以执行类似的步骤来使用 GetSessionToken 与 LDAP。
限制与解决方案
1. Keystone 目前仅支持 S3 请求,因此为了成功地对 STS 请求进行身份验证,需要在 boto 的以下文件 - botocore/auth.py 中添加以下解决方案:
代码块下方添加的 13-16 行作为解决方案:
class SigV4Auth(BaseSigner):
"""
Sign a request with Signature V4.
"""
REQUIRES_REGION = True
def __init__(self, credentials, service_name, region_name):
self.credentials = credentials
# We initialize these value here so the unit tests can have
# valid values. But these will get overridden in ``add_auth``
# later for real requests.
self._region_name = region_name
if service_name == 'sts':
self._service_name = 's3'
else:
self._service_name = service_name
由 Ceph 基金会带给您
Ceph 文档是一个社区资源,由非盈利的 Ceph 基金会资助和托管Ceph Foundation. 如果您想支持这一点和我们的其他工作,请考虑加入现在加入.