Skip to content

Commit 03e22c5

Browse files
authored
Merge pull request ceph#64592 from ArbitCode/wip-raja-get-caller-identity-docs
doc/radosgw: get caller identity docs
2 parents 139f5a3 + c78dca1 commit 03e22c5

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

doc/radosgw/STS.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ The following STS REST APIs have been implemented in Ceph Object Gateway:
6060
**WebIdentityToken** (String/ Required): The OpenID Connect/ OAuth2.0 token, which the
6161
application gets in return after authenticating its user with an IDP.
6262

63+
#. GetCallerIdentity: Returns details about the IAM user or role whose credentials are used to call the operation.
64+
65+
Response:
66+
**Account** (The account ID that owns or contains the calling entity.
67+
68+
**Arn** The ARN associated with the calling entity.
69+
70+
**UserId** The unique identifier of the calling entity(user or assumed role).
71+
72+
.. note:: No permissions are required to perform GetCallerIdentity.
73+
6374
Before invoking AssumeRoleWithWebIdentity, an OpenID Connect Provider entity (which the web application
6475
authenticates with), needs to be created in RGW.
6576

@@ -228,6 +239,85 @@ Examples
228239
s3bucket = s3client.create_bucket(Bucket=bucket_name)
229240
resp = s3client.list_buckets()
230241
242+
243+
#. The following is an example of GetCallerIdentity API call assuming a role, which shows steps to create a role,
244+
assuming a role to get temporary credentials and getting caller identity using those credentials.
245+
246+
.. code-block:: python
247+
248+
import boto3
249+
import json
250+
251+
USER_ID = 'tester'
252+
ACCESS_KEY = 'TESTER'
253+
SECRET_KEY = 'test123'
254+
ENDPOINT_URL = 'http://localhost:8000'
255+
REGION = 'us-east-1'
256+
257+
ROLE_NAME = 'S3Access'
258+
ROLE_SESSION_NAME = 'Bob'
259+
DURATION_SECONDS = 3600
260+
261+
iam_client = boto3.client('iam',
262+
aws_access_key_id=ACCESS_KEY,
263+
aws_secret_access_key=SECRET_KEY,
264+
endpoint_url=ENDPOINT_URL,
265+
region_name=REGION
266+
)
267+
268+
trust_policy = json.dumps({
269+
"Version": "2012-10-17",
270+
"Statement": [{
271+
"Effect": "Allow",
272+
"Principal": { "AWS": [f"arn:aws:iam:::user/{USER_ID}"] },
273+
"Action": ["sts:AssumeRole"]
274+
}]
275+
})
276+
277+
role_response = iam_client.create_role(
278+
RoleName=ROLE_NAME,
279+
Path='/xxx/policy/',
280+
AssumeRolePolicyDocument=trust_policy
281+
)
282+
283+
sts_client = boto3.client('sts',
284+
aws_access_key_id=ACCESS_KEY,
285+
aws_secret_access_key=SECRET_KEY,
286+
endpoint_url=ENDPOINT_URL,
287+
region_name=REGION
288+
)
289+
290+
response = sts_client.assume_role(
291+
RoleArn=role_response['Role']['Arn'],
292+
RoleSessionName=ROLE_SESSION_NAME,
293+
DurationSeconds=DURATION_SECONDS
294+
)
295+
creds = response['Credentials']
296+
297+
session_sts = boto3.client('sts',
298+
aws_access_key_id=creds['AccessKeyId'],
299+
aws_secret_access_key=creds['SecretAccessKey'],
300+
aws_session_token=creds['SessionToken'],
301+
endpoint_url=ENDPOINT_URL,
302+
region_name=REGION
303+
)
304+
identity = session_sts.get_caller_identity()
305+
306+
#. The following is an example of GetCallerIdentity API call with user credentials
307+
308+
.. code-block:: python
309+
310+
import boto3
311+
312+
sts = boto3.client('sts',
313+
aws_access_key_id=<access_key>,
314+
aws_secret_access_key=<secret_key>,
315+
endpoint_url='http://localhost:8000',
316+
region_name='us-east-1'
317+
)
318+
319+
identity = sts.get_caller_identity()
320+
231321
How to obtain thumbprint of an OpenID Connect Provider IDP
232322
==========================================================
233323

0 commit comments

Comments
 (0)