Sets a key policy for a key in a KMS instance.
Operation description
-
For information about the access policy required for a RAM user or RAM role to call this API operation, see Resource Access Management.
-
For more information about key policies, see Key policy overview.
Try it now
Test
RAM authorization
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| KeyId |
string |
Yes |
The ID or Alibaba Cloud Resource Name (ARN) of the key. Note
To access a key of another Alibaba Cloud account, you must specify the ARN of the key. The key ARN is in the format of |
key-hzz630494463ejqjx**** |
| PolicyName |
string |
No |
The name of the key policy. The name can only be `default`. |
default |
| Policy |
string |
Yes |
The key policy. The policy is in the JSON format. The policy can be up to 32,768 bytes in length. A key policy contains the following elements:
The following code provides an example of a key policy:
The following section describes the elements in a Statement:
Note
After you grant permissions to a RAM user or RAM role of another Alibaba Cloud account, you must use the Alibaba Cloud account to which the RAM user or RAM role belongs to grant the RAM user or RAM role the permissions to use the key in the RAM console. For more information, see Custom policies for KMS, Grant permissions to a RAM user, and Grant permissions to a RAM role. |
{"Statement":[{"Action":["kms:*"],"Effect":"Allow","Principal":{"RAM":["acs:ram::119285303511****:*"]},"Resource":["*"],"Sid":"kms default key policy"},{"Action":["kms:List*","kms:Describe*","kms:Create*","kms:Enable*","kms:Disable*","kms:Get*","kms:Set*","kms:Update*","kms:Delete*","kms:Cancel*","kms:TagResource","kms:UntagResource","kms:ImportKeyMaterial","kms:ScheduleKeyDeletion"],"Effect":"Allow","Principal":{"RAM":["acs:ram::119285303511****:user/for_test_policy"]},"Resource":["*"]}],"Version":"1"} |
Response parameters
|
Parameter |
Type |
Description |
Example |
|
object |
|||
| RequestId |
string |
The ID of the request, which is a unique identifier generated by Alibaba Cloud. You can use the ID to troubleshoot issues. |
381D5D33-BB8F-395F-8EE4-AE3BB4B523C8 |
Examples
Success response
JSON format
{
"RequestId": "381D5D33-BB8F-395F-8EE4-AE3BB4B523C8"
}
Error codes
|
HTTP status code |
Error code |
Error message |
Description |
|---|---|---|---|
| 400 | MissingParameter | The parameter needed but no provided. | The required parameters are not specified. |
| 400 | InvalidParameter | The specified parameter is not valid. | An invalid value is specified for the parameter. |
| 400 | Forbidden.NoPermission | This operation is forbidden by permission system. | You are not authorized to perform this operation. |
| 400 | Forbidden.KeyPolicyUnSupported | The specified key does not support key policy. | The specified key does not support key policies. |
| 400 | Rejected.ShareQuotaExceedLimit | Instance Share Quota Exceed Limit. | The instance share quota exceeds the limit. |
| 500 | InternalFailure | Internal Failure | An internal error occurred. |
| 403 | Forbidden.DKMSInstanceStateInvalid | The DKMS instance state is invalid. | Your dedicated KMS instance is invalid. |
| 404 | Forbidden.KeyNotFound | The specified Key is not found. | The error message returned because the specified CMK does not exist. |
| 404 | Forbidden.ResourceNotFound | Policy not found. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.