Creates a secret and stores its initial version.
Operation description
-
For information about the access policy required for a Resource Access Management (RAM) user or RAM role to call this operation, see Resource Access Management.
-
Specify the secret name, the secret value for the initial version, and the version number. The initial version is marked with the ACSCurrent stage label.
-
Key Management Service (KMS) uses the key that you specify to encrypt the secret value. The key and the secret must be in the same KMS instance. The key must be a symmetric key.
NoteKMS encrypts the secret value of each version. Metadata such as the secret name, version number, and version stage labels are not encrypted.
-
Before you encrypt the secret value, you must have the
kms:GenerateDataKeypermission on the key.
This topic provides an example of how to create an RDS secret. The secret is named mydbconninfo. The VersionId of the initial version is v1. The SecretData is {"Accounts":[{"AccountName":"user1","AccountPassword":"****"}]}.
Try it now
Test
RAM authorization
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| SecretName |
string |
Yes |
The name of the secret. The name must be unique in the same region. The name can be up to 192 characters in length and can contain letters, digits, underscores (_), forward slashes (/), plus signs (+), equal signs (=), periods (.), hyphens (-), and at signs (@). The following limits apply to secret names for different types of secrets:
|
mydbconninfo |
| VersionId |
string |
Yes |
The version number of the initial version. The version number must be unique within the secret. The version number can be up to 64 characters in length. |
v1 |
| EncryptionKeyId |
string |
No |
The ID of the key used to encrypt the secret value. Note
The key and the secret must be in the same KMS instance. The key must be a symmetric key. |
key-gzz63ff0db5hg3qje**** |
| SecretData |
string |
Yes |
The value of the secret. The value can be up to 30,720 bytes (30 KB) in length. KMS encrypts the secret value with the specified key and stores the encrypted value in the initial version.
|
{"Accounts":[{"AccountName":"user1","AccountPassword":"****"}]} |
| SecretDataType |
string |
No |
The type of the secret value. Valid values:
Note
If SecretType is set to Rds, Redis, PolarDB, RAMCredentials, or ECS, SecretDataType must be set to text. |
text |
| Description |
string |
No |
The description of the secret. |
mydbinfo |
| Tags |
string |
No |
The tags of the secret. Each tag consists of a key-value pair. A tag consists of a tag key and a tag value. The tag key and tag value can be up to 128 characters in length and can contain letters, digits, forward slashes (/), backslashes (\), underscores (_), hyphens (-), periods (.), plus signs (+), equal signs (=), colons (:), and at signs (@).
|
[{\"TagKey\":\"key1\",\"TagValue\":\"val1\"},{\"TagKey\":\"key2\",\"TagValue\":\"val2\"}] |
| SecretType |
string |
No |
The type of the secret. Valid values:
|
Rds |
| ExtendedConfig |
object |
No |
The extended configuration of the secret. This parameter specifies the properties of the secret of a specific type. The value can be up to 1,024 characters in length.
Note
If SecretType is set to Rds, Redis, PolarDB, RAMCredentials, or ECS, you must configure this parameter. |
{"SecretSubType":"SingleUser", "DBInstanceId":"rm-bp1b3dd3a506e****" ,"CustomData":{"Key1": "v1", "fds":"fdsf"}} |
| EnableAutomaticRotation |
boolean |
No |
Specifies whether to enable automatic rotation. Valid values:
Note
This parameter is valid only if SecretType is set to Rds, PolarDB, Redis, RAMCredentials, or ECS. If SecretType is set to Generic, automatic rotation is not supported. You can call the PutSecretValue operation to manually rotate the secret. |
true |
| RotationInterval |
string |
No |
The interval for automatic rotation. The value is in the range of 6 hours to 8,760 hours (365 days). Note
You must specify this parameter if you set EnableAutomaticRotation to true. You do not need to specify this parameter if you set EnableAutomaticRotation to false. |
30d |
| DKMSInstanceId |
string |
No |
The ID of the KMS instance. |
kst-bjj62d8f5e0sgtx8h**** |
| Policy |
string |
No |
The content of the secret policy. The value is in the JSON format. The value can be up to 32,768 bytes in length. For more information about secret policies, see Overview of secret policies. If you do not specify this parameter, the default secret policy is used. A secret policy contains the following parts:
The following is the format of a secret policy:
Details about 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 secret in the RAM console. Then, the RAM user or RAM role can use the secret. For more information, see Custom policies for KMS, Grant permissions to a RAM user, and Grant permissions to a RAM role. |
{"Version":"1","Statement": [{"Sid":"kms default secret policy","Effect":"Allow","Principal":{"RAM": ["acs:ram::119285303511****:*"]},"Action":["kms:*"],"Resource": ["*"] }] } |
For information about common request parameters, see Common parameters.
Response elements
|
Parameter |
Type |
Description |
Example |
|
object |
|||
| RequestId |
string |
The ID of the request, which is a unique identifier generated by Alibaba Cloud. You can use this ID to troubleshoot issues. |
3bf02f7a-015b-4f93-be0f-cc043fda2dd3 |
| AutomaticRotation |
string |
Indicates whether automatic rotation is enabled. Valid values:
Note
This parameter is returned if SecretType is set to Rds, Redis, PolarDB, RAMCredentials, or ECS. |
Enabled |
| SecretName |
string |
The name of the secret. |
mydbconninfo |
| VersionId |
string |
The version number of the secret. |
v1 |
| NextRotationDate |
string |
The time when the secret is next rotated. Note
This parameter is returned if automatic rotation is enabled. |
2023-07-06T18:22:03Z |
| SecretType |
string |
The type of the secret. Valid values:
|
Rds |
| RotationInterval |
string |
The interval for automatic rotation. Note
This parameter is returned if automatic rotation is enabled. |
604800s |
| Arn |
string |
The Alibaba Cloud Resource Name (ARN) of the secret. |
acs:kms:cn-hangzhou:154035569884****:secret/mydbconninfo |
| ExtendedConfig |
string |
The extended configuration of the secret. Note
This parameter is returned if SecretType is set to Rds, Redis, PolarDB, RAMCredentials, or ECS. |
{\"SecretSubType\":\"SingleUser\", \"DBInstanceId\":\"rm-uf667446pc955****\", \"CustomData\":"Key1": "v1", "fds":"fdsf"} } |
| DKMSInstanceId |
string |
The ID of the KMS instance. |
kst-bjj62d8f5e0sgtx8h**** |
Examples
Success response
JSON format
{
"RequestId": "3bf02f7a-015b-4f93-be0f-cc043fda2dd3",
"AutomaticRotation": "Enabled",
"SecretName": "mydbconninfo",
"VersionId": "v1",
"NextRotationDate": "2023-07-06T18:22:03Z",
"SecretType": "Rds",
"RotationInterval": "604800s",
"Arn": "acs:kms:cn-hangzhou:154035569884****:secret/mydbconninfo",
"ExtendedConfig": "{\\\"SecretSubType\\\":\\\"SingleUser\\\", \\\"DBInstanceId\\\":\\\"rm-uf667446pc955****\\\", \\\"CustomData\\\":\"Key1\": \"v1\", \"fds\":\"fdsf\"} }",
"DKMSInstanceId": "kst-bjj62d8f5e0sgtx8h****"
}
Error codes
|
HTTP status code |
Error code |
Error message |
Description |
|---|---|---|---|
| 400 | UnsupportedOperation | This action is not supported. | The operation is not supported. |
| 400 | Rejected.LimitExceeded | The request was rejected because user create resource limit was exceeded | The request is rejected because the number of created resources reaches the upper limit. |
| 400 | InvalidParameter | The specified parameter is not valid. | An invalid value is specified for the parameter. |
| 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.DKMSInstanceNotFound | The specified DKMS Instance is not found. | Your dedicated KMS instance is not found. |
| 404 | Forbidden.ResourceNotFound | The resource is not found. | The resource does not exist. |
| 409 | Rejected.ResourceExist | The resource already exists. | The resource already exists. |
| 409 | Rejected.ResourceInDeleteWindow | The secret is planned to be deleted. | The secret is to be deleted. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.