5 Secure Token Service is a web service in AWS that returns a set of temporary security credentials for authenticating federated users.
6 The link to official AWS documentation can be found here: https://docs.aws.amazon.com/STS/latest/APIReference/Welcome.html.
8 Ceph Object Gateway implements a subset of STS APIs that provide temporary credentials for identity and access management.
9 These temporary credentials can be used to make subsequent S3 calls which will be authenticated by the STS engine in Ceph Object Gateway.
10 Permissions of the temporary credentials can be further restricted via an IAM policy passed as a parameter to the STS APIs.
15 The following STS REST APIs have been implemented in Ceph Object Gateway:
17 1. AssumeRole: Returns a set of temporary credentials that can be used for
18 cross-account access. The temporary credentials will have permissions that are
19 allowed by both - permission policies attached with the Role and policy attached
20 with the AssumeRole API.
23 **RoleArn** (String/ Required): ARN of the Role to Assume.
25 **RoleSessionName** (String/ Required): An Identifier for the assumed role
28 **Policy** (String/ Optional): An IAM Policy in JSON format.
30 **DurationSeconds** (Integer/ Optional): The duration in seconds of the session.
31 Its default value is 3600.
33 **ExternalId** (String/ Optional): A unique Id that might be used when a role is
34 assumed in another account.
36 **SerialNumber** (String/ Optional): The Id number of the MFA device associated
37 with the user making the AssumeRole call.
39 **TokenCode** (String/ Optional): The value provided by the MFA device, if the
40 trust policy of the role being assumed requires MFA.
42 2. AssumeRoleWithWebIdentity: Returns a set of temporary credentials for users that
43 have been authenticated by a web/mobile app by an OpenID Connect /OAuth2.0 Identity Provider.
44 Currently Keycloak has been tested and integrated with RGW.
47 **RoleArn** (String/ Required): ARN of the Role to Assume.
49 **RoleSessionName** (String/ Required): An Identifier for the assumed role
52 **Policy** (String/ Optional): An IAM Policy in JSON format.
54 **DurationSeconds** (Integer/ Optional): The duration in seconds of the session.
55 Its default value is 3600.
57 **ProviderId** (String/ Optional): Fully qualified host component of the domain name
58 of the IDP. Valid only for OAuth2.0 tokens (not for OpenID Connect tokens).
60 **WebIdentityToken** (String/ Required): The OpenID Connect/ OAuth2.0 token, which the
61 application gets in return after authenticating its user with an IDP.
63 Before invoking AssumeRoleWithWebIdentity, an OpenID Connect Provider entity (which the web application
64 authenticates with), needs to be created in RGW.
66 The trust between the IDP and the role is created by adding a condition to the role's trust policy, which
67 allows access only to applications which satisfy the given condition.
68 All claims of the JWT are supported in the condition of the role's trust policy.
69 An example of a policy that uses the 'aud' claim in the condition is of the form::
71 '''{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Federated":["arn:aws:iam:::oidc-provider/<URL of IDP>"]},"Action":["sts:AssumeRoleWithWebIdentity"],"Condition":{"StringEquals":{"<URL of IDP> :app_id":"<aud>"}}}]}'''
73 The app_id in the condition above must match the 'aud' claim of the incoming token.
75 An example of a policy that uses the 'sub' claim in the condition is of the form::
77 "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Federated\":[\"arn:aws:iam:::oidc-provider/<URL of IDP>\"]},\"Action\":[\"sts:AssumeRoleWithWebIdentity\"],\"Condition\":{\"StringEquals\":{\"<URL of IDP> :sub\":\"<sub>\"\}\}\}\]\}"
79 Similarly, an example of a policy that uses 'azp' claim in the condition is of the form::
81 "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Federated\":[\"arn:aws:iam:::oidc-provider/<URL of IDP>\"]},\"Action\":[\"sts:AssumeRoleWithWebIdentity\"],\"Condition\":{\"StringEquals\":{\"<URL of IDP> :azp\":\"<azp>\"\}\}\}\]\}"
83 A shadow user is created corresponding to every federated user. The user id is derived from the 'sub' field of the incoming web token.
84 The user is created in a separate namespace - 'oidc' such that the user id doesn't clash with any other user ids in rgw. The format of the user id
85 is - <tenant>$<user-namespace>$<sub> where user-namespace is 'oidc' for users that authenticate with oidc providers.
87 RGW now supports Session tags that can be passed in the web token to AssumeRoleWithWebIdentity call. More information related to Session Tags can be found here
93 The following configurable options have to be added for STS integration::
95 [client.radosgw.gateway]
96 rgw sts key = {sts key for encrypting the session token}
97 rgw s3 auth use sts = true
99 Note: By default, STS and S3 APIs co-exist in the same namespace, and both S3
100 and STS APIs can be accessed via the same endpoint in Ceph Object Gateway.
105 1. The following is an example of AssumeRole API call, which shows steps to create a role, assign a policy to it
106 (that allows access to S3 resources), assuming a role to get temporary credentials and accessing s3 resources using
107 those credentials. In this example, TESTER1 assumes a role created by TESTER, to access S3 resources owned by TESTER,
108 according to the permission policy attached to the role.
110 .. code-block:: python
114 iam_client = boto3.client('iam',
115 aws_access_key_id=<access_key of TESTER>,
116 aws_secret_access_key=<secret_key of TESTER>,
117 endpoint_url=<IAM URL>,
121 policy_document = '''{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":["arn:aws:iam:::user/TESTER1"]},"Action":["sts:AssumeRole"]}]}'''
123 role_response = iam_client.create_role(
124 AssumeRolePolicyDocument=policy_document,
129 role_policy = '''{"Version":"2012-10-17","Statement":{"Effect":"Allow","Action":"s3:*","Resource":"arn:aws:s3:::*"}}'''
131 response = iam_client.put_role_policy(
133 PolicyName='Policy1',
134 PolicyDocument=role_policy
137 sts_client = boto3.client('sts',
138 aws_access_key_id=<access_key of TESTER1>,
139 aws_secret_access_key=<secret_key of TESTER1>,
140 endpoint_url=<STS URL>,
144 response = sts_client.assume_role(
145 RoleArn=role_response['Role']['Arn'],
146 RoleSessionName='Bob',
150 s3client = boto3.client('s3',
151 aws_access_key_id = response['Credentials']['AccessKeyId'],
152 aws_secret_access_key = response['Credentials']['SecretAccessKey'],
153 aws_session_token = response['Credentials']['SessionToken'],
154 endpoint_url=<S3 URL>,
157 bucket_name = 'my-bucket'
158 s3bucket = s3client.create_bucket(Bucket=bucket_name)
159 resp = s3client.list_buckets()
161 2. The following is an example of AssumeRoleWithWebIdentity API call, where an external app that has users authenticated with
162 an OpenID Connect/ OAuth2 IDP (Keycloak in this example), assumes a role to get back temporary credentials and access S3 resources
163 according to permission policy of the role.
165 .. code-block:: python
169 iam_client = boto3.client('iam',
170 aws_access_key_id=<access_key of TESTER>,
171 aws_secret_access_key=<secret_key of TESTER>,
172 endpoint_url=<IAM URL>,
176 oidc_response = iam_client.create_open_id_connect_provider(
177 Url=<URL of the OpenID Connect Provider,
179 <Client id registered with the IDP>
182 <Thumbprint of the IDP>
186 policy_document = '''{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Federated":["arn:aws:iam:::oidc-provider/localhost:8080/auth/realms/demo"]},"Action":["sts:AssumeRoleWithWebIdentity"],"Condition":{"StringEquals":{"localhost:8080/auth/realms/demo:app_id":"customer-portal"}}}]}'''
187 role_response = iam_client.create_role(
188 AssumeRolePolicyDocument=policy_document,
193 role_policy = '''{"Version":"2012-10-17","Statement":{"Effect":"Allow","Action":"s3:*","Resource":"arn:aws:s3:::*"}}'''
195 response = iam_client.put_role_policy(
197 PolicyName='Policy1',
198 PolicyDocument=role_policy
201 sts_client = boto3.client('sts',
202 aws_access_key_id=<access_key of TESTER1>,
203 aws_secret_access_key=<secret_key of TESTER1>,
204 endpoint_url=<STS URL>,
208 response = client.assume_role_with_web_identity(
209 RoleArn=role_response['Role']['Arn'],
210 RoleSessionName='Bob',
211 DurationSeconds=3600,
212 WebIdentityToken=<Web Token>
215 s3client = boto3.client('s3',
216 aws_access_key_id = response['Credentials']['AccessKeyId'],
217 aws_secret_access_key = response['Credentials']['SecretAccessKey'],
218 aws_session_token = response['Credentials']['SessionToken'],
219 endpoint_url=<S3 URL>,
222 bucket_name = 'my-bucket'
223 s3bucket = s3client.create_bucket(Bucket=bucket_name)
224 resp = s3client.list_buckets()
226 How to obtain thumbprint of an OpenID Connect Provider IDP
227 ==========================================================
228 1. Take the OpenID connect provider's URL and add /.well-known/openid-configuration
229 to it to get the URL to get the IDP's configuration document. For example, if the URL
230 of the IDP is http://localhost:8000/auth/realms/quickstart, then the URL to get the
231 document from is http://localhost:8000/auth/realms/quickstart/.well-known/openid-configuration
233 2. Use the following curl command to get the configuration document from the URL described
238 -H "Content-Type: application/x-www-form-urlencoded" \
239 "http://localhost:8000/auth/realms/quickstart/.well-known/openid-configuration" \
242 3. From the response of step 2, use the value of "jwks_uri" to get the certificate of the IDP,
243 using the following code::
246 -H "Content-Type: application/x-www-form-urlencoded" \
247 "http://$KC_SERVER/$KC_CONTEXT/realms/$KC_REALM/protocol/openid-connect/certs" \
250 3. Copy the result of "x5c" in the response above, in a file certificate.crt, and add
251 '-----BEGIN CERTIFICATE-----' at the beginning and "-----END CERTIFICATE-----"
254 4. Use the following OpenSSL command to get the certificate thumbprint::
256 openssl x509 -in certificate.crt -fingerprint -noout
258 5. The result of the above command in step 4, will be a SHA1 fingerprint, like the following::
260 SHA1 Fingerprint=F7:D7:B3:51:5D:D0:D3:19:DD:21:9A:43:A9:EA:72:7A:D6:06:52:87
262 6. Remove the colons from the result above to get the final thumbprint which can be as input
263 while creating the OpenID Connect Provider entity in IAM::
265 F7D7B3515DD0D319DD219A43A9EA727AD6065287
270 More information for role manipulation can be found here
273 OpenID Connect Provider in RGW
274 ==============================
276 More information for OpenID Connect Provider entity manipulation
280 Keycloak integration with Radosgw
281 =================================
283 Steps for integrating Radosgw with Keycloak can be found here
288 STSLite has been built on STS, and documentation for the same can be found here