注意
本文档适用于 Ceph 的开发版本。
STS精简版
自版本 Tentacle 起已弃用。
Ceph Object Gateway 支持 Amazon Secure Token Service (STS) API 的一个子集。STS 精简版是 STS 的扩展,它基于 STS 的一个 API 来减少对外部 IDP(如 Keystone 和 LDAP)的负载。
在外部 IDP 验证一组 AWS 凭证后,将返回一组临时安全凭证。这些临时凭证可用于进行后续的 S3 调用,这些调用将由 Ceph 中的 STS 引擎进行身份验证,从而减少 Keystone/LDAP 服务器上的负载。
本地用户也可以使用 STS 精简版 API 获取临时且权限受限的凭证。
STS精简版 REST API
以下 STS 精简版 REST API 是 Ceph Object Gateway 中 STS 精简版的一部分:
1. GetSessionToken: 返回一组 AWS 凭证对应的临时凭证。在与 Keystone/LDAP 完成初始身份验证后,返回的临时凭证可用于进行后续 S3 调用。这些临时凭证将拥有与 AWS 凭证相同的权限。
- 参数
DurationSeconds (Integer/ 可选): 凭证保持有效的持续时间(秒)。其默认值为 3600。其默认最大值为 43200,可通过 rgw sts max session duration 进行配置。
SerialNumber (String/ 可选): 与进行 GetSessionToken 调用的用户关联的 MFA 设备的 ID 号码。
TokenCode (String/ 可选): 如果需要 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精简版 配置
以下是 STS 精简版集成可用的配置选项:
[client.radosgw.gateway]
rgw sts key = {sts key for encrypting the session token}
rgw s3 auth use sts = true
如果需要将 STS 精简版与 Keystone 结合使用,可以使用上述 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
有关将 ldap 与 Ceph Object Gateway 集成的详细信息,请参见此处:与 OpenStack Keystone 集成
将 STS 精简版与 LDAP 结合使用的完整可配置项集是:
[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}
有关将 ldap 与 Ceph Object Gateway 集成的详细信息,请参见此处:LDAP 身份验证
注意: 默认情况下,STS 和 S3 API 存在于同一命名空间中,S3 和 STS API 都可以通过 Ceph Object Gateway 中的同一端点访问。
使用STS精简版与Keystone的示例
以下是使用 STS 精简版与 Keystone 所需的步骤。已使用 Boto 3.x 编写示例代码来展示 STS 精简版与 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