Help Center/ Identity and Access Management/ API Reference/ API/ Access Key Management/ Obtaining Temporary Access Keys and Security Tokens of an Agency
Updated on 2024-11-18 GMT+08:00

Obtaining Temporary Access Keys and Security Tokens of an Agency

Function

This API is used to obtain temporary access keys (AK/SK pairs) and security tokens of an agency.

Temporary access keys and security tokens are issued by the system to IAM users, and can be valid for 15 minutes to 24 hours. Temporary access keys and security tokens are granted permissions based on the principle of least privilege (PoLP). Temporary access keys and security tokens must be used together, and the x-security-token field must be included in the request header. For details, see How Do I Use a Temporary AK/SK to Sign Requests?

The API can be called using either a global endpoint or a region-specific endpoint. For IAM endpoints, see Regions and Endpoints.

Debugging

You can debug this API in API Explorer.

URI

POST /v3.0/OS-CREDENTIAL/securitytokens

Request Parameters

Table 1 Parameters in the request header

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Fill application/json;charset=utf8 in this field.

Authorization

No

String

Specify either X-Auth-Token or Authorization (recommended). An Authorization header is generated after the AK/SK signature is authenticated. For more information, see AK/SK Signing and Authentication Algorithm.

X-Auth-Token

No

String

Token with the Agent Operator permissions. Specify either X-Auth-Token or Authorization.

Table 2 Parameters in the request body

Parameter

Mandatory

Type

Description

auth

Yes

Object

Authentication information.

Table 3 auth

Parameter

Mandatory

Type

Description

identity

Yes

Object

Authentication parameters.

Table 4 auth.identity

Parameter

Mandatory

Type

Description

methods

Yes

Array of strings

Authentication method. Set this parameter to ["assume_role"].

assume_role

Yes

Object

Details about the delegating account and agency.

policy

No

Object

Custom policy that defines the permissions assigned to the temporary access keys and security tokens (currently, the policy only applies to OBS).

If this parameter is specified, the permissions assigned to the temporary access keys and security tokens are the intersection of permissions assigned to the specified agency and defined by this parameter. The value of policy can contain a maximum of 2,048 characters.

For details about the format and grammar of IAM policies, see Policies.

Table 5 auth.identity.assume_role

Parameter

Mandatory

Type

Description

agency_name

Yes

String

Agency name. For details about how to obtain the agency name, see Obtaining Account, IAM User, Group, Project, Region, and Agency Information.

domain_id

No

String

Account ID of the delegating party. Either domain_id or domain_name must be set. You are advised to specify domain_id.

domain_name

No

String

Account name of the delegating party. Either domain_id or domain_name must be set. You are advised to specify domain_id.

duration_seconds

No

Integer

Validity period (in seconds) of the AK/SK and security token. The value range is from 15 minutes to 24 hours. The default value is 15 minutes.

session_user

No

Object

Enterprise user information of the delegating party.

Table 6 auth.identity.assume_role.session_user

Parameter

Mandatory

Type

Description

name

No

String

Enterprise user name of the delegating party.

The name must consist of 5 to 64 characters, containing only letters (case-sensitive), digits, spaces, hyphens (-), underscores (_), and periods (.) and must start with a letter.

Table 7 auth.identity.policy

Parameter

Mandatory

Type

Description

Version

Yes

String

Policy version. When creating a custom policy, set this parameter to 1.1.

NOTE:

1.1: Policy. A policy defines the permissions required to perform actions on a specific cloud resource under certain conditions.

Statement

Yes

Array of objects

Statement of the policy. A policy can contain a maximum of eight statements.

Table 8 auth.identity.policy.Statement

Parameter

Mandatory

Type

Description

Action

Yes

Array of strings

Specific permissions on a resource. For details about supported actions, see "Permissions and Supported Actions" in the API Reference of cloud services.

NOTE:
  • Format: Service name:Resource type:Action, for example, vpc:ports:create
  • Service name: indicates the product name, such as ecs, evs, or vpc. Only lowercase letters are allowed. Resource types and actions are not case-sensitive. You can use an asterisk (*) to represent all actions.

Effect

Yes

String

Effect of the permission. The value can be Allow or Deny. If both Allow and Deny statements are found in a policy, the authentication starts from the Deny statements.

Options:

  • Allow
  • Deny

Condition

No

Map<String,Map<String,Array<String>>>

Conditions for the permissions to take effect. For details about conditions, see Creating a Custom Policy.

NOTE:

Take the condition in the sample request as an example, the values of the condition key (obs:prefix) and string (public) must be equal (StringEquals).

 "Condition": {
              "StringEquals": {
                "obs:prefix": [
                  "public"
                ]
              }
            }

Resource

No

Array of strings

Cloud resource.

NOTE:
  • Format: Service name:Region:Domain ID:Resource type:Resource path. Wildcard characters (*) are supported. For example, obs:*:*:bucket:* indicates all OBS buckets.
  • The region segment can be * or a region accessible to the user. The specified resource must belong to the corresponding service that actually exists.

Response Parameters

Table 9 Parameters in the response body

Parameter

Type

Description

credential

Object

Authentication result.

Table 10 credential

Parameter

Type

Description

expires_at

String

Expiration time of access keys and security tokens. The response is UTC time.

access

String

AK.

secret

String

SK.

securitytoken

String

Obtained access keys in ciphertext.

Example Request

  • Request with session_user specified (including the enterprise user name of the delegating party)
    POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
    {
        "auth": {
            "identity": {
                "methods": [
                    "assume_role"
                ],
                "assume_role": {
                    "domain_name": "IAMDomainA",
                    "agency_name": "IAMAgency",
                    "duration_seconds": 3600,
                    "session_user": {
                        "name": "SessionUserName"
                    }
                }
            }
        }
    }
  • Request with policy specified to define the permissions assigned to the obtained temporary access keys and security tokens (currently, the policy applies only to OBS). If this parameter is specified, the permissions assigned to the temporary access keys and security tokens are the intersection of permissions assigned to the specified agency and defined by this parameter.
    POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
    {
        "auth": {
            "identity": {
                "methods": [
                    "assume_role"
                ],
                "policy": {
                          "Version": "1.1",
    		       "Statement": [{
    			 "Effect": "allow",
    			 "Action": [
                             "obs:object:*"
                             ],
    			 "Resource": ["obs:*:*:object:*"],
    			 "Condition": {
    			    "StringEquals": {
    				"obs:prefix": ["public"]
    				}
    			}
    		}]
                 },
                "assume_role": {
                    "domain_name": "IAMDomainA",
                    "agency_name": "IAMAgency",
                    "duration_seconds": 3600
    
                }
            }
        }
    }
  • Request without session_user and policy specified
    POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
    {
        "auth": {
            "identity": {
                "methods": [
                    "assume_role"
                ],
                "assume_role": {
                    "domain_name": "IAMDomainA",
                    "agency_name": "IAMAgency",
                    "duration_seconds": 3600
                }
            }
        }
    }

Example Response

Status code: 201

The request is successful.

The responses to all the preceding requests are the same regardless of whether session_user is specified or not. If session_user is specified, the security token contains the corresponding enterprise user information.

{
    "credential": {
        "access": "E6DX0TF2ZREQ4Z...",
        "expires_at": "2020-01-08T02:56:19.587000Z",
        "secret": "w9ePum0qdfac39ErLD0UdjofYkqort6Iw....",
        "securitytoken": "gQpjbi1ub3J0aC0..."
    }
}

Status Codes

Status Code

Description

201

The request is successful.

400

Invalid parameters.

401

Authentication failed.

403

Access denied.

500

Internal server error.

Error Codes

None