Configures a policy for a key in a Key Management Service (KMS) instance.
For more information about key policies, see Overview.
Debugging
Request parameters
Parameter |
Type |
Required |
Example |
Description |
Action | String | Yes | SetKeyPolicy | The operation that you want to perform. Set the value to SetKeyPolicy. |
KeyId | String | Yes | key-hzz630494463ejqjx**** | The ID or Alibaba Cloud Resource Name (ARN) of the key. Note When you access a key within another Alibaba Cloud account, you must enter the ARN of the key. The key ARN is in the acs:kms:${region}:${account}:key/${keyid} format. |
PolicyName | String | No | default | The name of the key policy. Set the value to default. |
Policy | String | Yes | {"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"} | The content of the key policy. The value is in the JSON format. The value can be up to 32,768 bytes in length. A key policy contains the following content:
Example:
Statement description:
Note If you grant a RAM user or RAM role of other Alibaba Cloud accounts permissions to use a key, you must use the Alibaba Cloud account of the RAM user or RAM role to grant the RAM user or RAM role permissions to use the key in RAM. For more information, see Custom policies, Grant permissions to a RAM user, and Grant permissions to a RAM role. |
Response parameters
Parameter |
Type |
Example |
Description |
RequestId | String | 381D5D33-BB8F-395F-8EE4-AE3BB4B523C8 | The request ID. |
Description
Sample requests
http(s)://[Endpoint]/?Action=SetKeyPolicy
&KeyId=key-hzz630494463ejqjx****
&PolicyName=default
&Policy={"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"}
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<SetKeyPolicyResponse>
<RequestId>381D5D33-BB8F-395F-8EE4-AE3BB4B523C8</RequestId>
</SetKeyPolicyResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"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 key does not support key policies. |
400 | Rejected.ShareQuotaExceedLimit | Instance Share Quota Exceed Limit. | The access management quota is exceeded. |
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 specified key does not exist. |
404 | Forbidden.ResourceNotFound | Policy not found. | The policy is not found. |
500 | InternalFailure | Internal Failure | An internal error has occurred. |
For a list of error codes, see Service error codes.