All Products
Search
Document Center

Resource Access Management:SetAccessKeyPolicy

Last Updated:Jul 31, 2026

Settings the network access restriction policy for an AccessKey pair of an Alibaba Cloud account or a Resource Access Management (RAM) user.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ram:SetAccessKeyPolicy

update

*User

acs:ram::{#AccountId}:user/{#UserName}

None None

Request parameters

Parameter

Type

Required

Description

Example

UserPrincipalName

string

No

The logon name of the RAM user.

If this parameter is left empty, the network access restriction policy is set for the specified AccessKey pair of the current user by default.

test@example.onaliyun.com

UserAccessKeyId

string

Yes

The AccessKey ID.

LTAI*******************

AccessKeyPolicy

string

Yes

The network access restriction policy.

A JSON-formatted string. For more information, see the AccessKeyPolicy structure description.

{"Status":"Inactive","Statements":[{"Value":"AllowAllVPC","Type":"VPCWhiteList","IPList":["::/0","0.0.0.0/0"]}]}

AccessKeyPolicy structure description

The AccessKeyPolicy parameter is a JSON-formatted string. The complete structure is as follows:

{
  "Version": 1,
  "Status": "Active",
  "Statements": [
    {
      "Type": "ClassicWhiteList",
      "IPList": ["203.0.113.1", "2001:db8:85a3::8a2e:370:7334", "198.51.100.0/24"]
    },
    {
      "Type": "VPCWhiteList",
      "Value": "vpc-bp1234567890abcdef",
      "IPList": ["172.16.0.0/16"]
    }
  ]
}

Top-level fields

FieldTypeRequiredDescription
VersionIntegerNoThe policy version number. Currently fixed to 1.
StatusStringYesThe policy status. Valid values: Active (enabled), Inactive (disabled).
StatementsArrayYesThe list of network whitelist rules. This can be an empty array [] but cannot be null.

Statement object

Each Statement represents a network whitelist rule. Two types are supported:

FieldTypeDescription
TypeStringThe rule type. Valid values: ClassicWhiteList (classic network whitelist), VPCWhiteList (VPC network whitelist).
ValueStringThe VPC identifier. Used only for the VPCWhiteList type.
IPListArrayThe IP address whitelist. IPv4 addresses, IPv6 addresses, and CIDR notation are supported.

Rule type details.

1. Classic network whitelist (ClassicWhiteList)

Restricts the AccessKey pair to only initiate API calls from specified public IP addresses.

  • Type: Fixed to ClassicWhiteList.

  • Value: Do not specify this field. Leave it empty.

  • IPList: Required. The list of allowed IP addresses. IPv4 and IPv6 addresses are supported. CIDR notation is supported (for example, 203.0.113.5/30).

Default behavior: If no ClassicWhiteList rule is configured in Statements, all classic network access is denied.

Constraint: If IPList contains the IPv4 allow-all address 0.0.0.0/0, it must also contain the IPv6 allow-all address ::/0, and vice versa. Allowing only a single protocol stack is not permitted.

Example:

{
  "Type": "ClassicWhiteList",
  "IPList": ["203.0.113.5/30", "198.51.100.0/24"]
}

2. VPC network whitelist (VPCWhiteList)

Restricts the AccessKey pair to only initiate API calls from a specified VPC. You can further restrict access to specified IP addresses within the VPC.

  • Type: Fixed to VPCWhiteList.

  • Value: Required. Set this field to one of the following values:
    • A specific VPC instance ID that starts with vpc- (for example, vpc-bp1234567890abcdef).

    • AllowAllVPC: Allows all VPCs.

  • IPList: Required. The IP address whitelist within the VPC. CIDR notation is supported (for example, 10.0.0.0/24).

Default behavior: If no VPCWhiteList rule is configured in Statements, all VPC network access is denied.

Constraints:

  • If Value is set to AllowAllVPC, IPList must contain both 0.0.0.0/0 and ::/0 (allow-all), and only these two entries are allowed.

  • If Value is set to a specific VPC ID, IPList cannot contain 0.0.0.0/0 or ::/0.

Example — Specified VPC:

{
  "Type": "VPCWhiteList",
  "Value": "vpc-bp1234567890abcdef",
  "IPList": ["172.16.0.0/16"]
}

Example — Allow all VPCs:

{
  "Type": "VPCWhiteList",
  "Value": "AllowAllVPC",
  "IPList": ["0.0.0.0/0", "::/0"]
}

Quantity limits

LimitUpper limit
Total length of AccessKeyPolicyThe JSON string cannot exceed 160,000 characters.
Number of Statements entriesUp to 8 entries.
Number of IPList entries per StatementUp to 50 entries.

Complete request examples.

Example 1: Allow only specific public IP addresses

{
  "Version": 1,
  "Status": "Active",
  "Statements": [
    {
      "Type": "ClassicWhiteList",
      "IPList": ["203.0.113.5/30", "198.51.100.0/24"]
    }
  ]
}

Example 2: Allow only calls from a specified VPC

{
  "Version": 1,
  "Status": "Active",
  "Statements": [
    {
      "Type": "VPCWhiteList",
      "Value": "vpc-bp1234567890abcdef",
      "IPList": ["172.16.0.0/16"]
    }
  ]
}

Example 3: Configure both classic network and VPC network whitelists

{
  "Version": 1,
  "Status": "Active",
  "Statements": [
    {
      "Type": "VPCWhiteList",
      "Value": "vpc-bp1234567890abcdef",
      "IPList": ["172.16.0.0/16"]
    },
    {
      "Type": "ClassicWhiteList",
      "IPList": ["203.0.113.0/30"]
    }
  ]
}

Example 4: Disable the policy (retain rules without enforcing them)

{
  "Version": 1,
  "Status": "Inactive",
  "Statements": [
    {
      "Type": "ClassicWhiteList",
      "IPList": ["203.0.113.5/30"]
    }
  ]
}

Example 5: Clear all whitelist rules

{
  "Version": 1,
  "Status": "Inactive",
  "Statements": []
}

Response elements

Element

Type

Description

Example

object

AccessKeyPolicy

string

The network access restriction policy.

A JSON-formatted string. For more information, see the AccessKeyPolicy structure description.

{"Status":"Inactive","Statements":[{"Value":"AllowAllVPC","Type":"VPCWhiteList","IPList":["::/0","0.0.0.0/0"]}]}

RequestId

string

The request ID.

30C9068D-FBAA-4998-9986-8A562FED0BC3

AccessKeyId

string

The AccessKey ID.

LTAI*******************

Examples

Success response

JSON format

{
  "AccessKeyPolicy": "{\"Status\":\"Inactive\",\"Statements\":[{\"Value\":\"AllowAllVPC\",\"Type\":\"VPCWhiteList\",\"IPList\":[\"::/0\",\"0.0.0.0/0\"]}]}",
  "RequestId": "30C9068D-FBAA-4998-9986-8A562FED0BC3",
  "AccessKeyId": "LTAI*******************"
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.