PutSecretValue

Updated at:

Stores a new version of a secret value for a generic secret.

Operation description

  • For details about the access policy that must be granted to a Resource Access Management (RAM) user or RAM role to call this API operation, see Access control.

  • Only generic secrets support this API operation. Each generic secret can store up to 10 secret versions. If the limit is exceeded, KMS automatically deletes the earliest secret version.

  • By default, a newly stored secret value is marked with ACSCurrent, and the previous version marked with ACSCurrent is marked with ACSPrevious. You can override this default behavior by specifying the VersionStages parameter.

  • This API operation is used to store a new version of a secret value, not to modify the secret value of an existing version. When you store a new version, you must specify a version ID. KMS performs operations based on the following rules:

    • If the version ID does not exist in the secret: A new version is created and the secret value is stored.

    • If the version ID already exists in the secret: If the secret value in the request is the same as the secret value corresponding to the version ID in the secret, the request is ignored and a success response is returned (the request is idempotent). If the secret values are different, the request is rejected and a failure response is returned.

This topic provides an example of storing a new version of a secret value for the secret named secret001. The version ID VersionId of the new secret version is v3, and the secret value SecretData is importantdata.

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

kms:PutSecretValue

update

*Secret

acs:kms:{#regionId}:{#accountId}:secret/{#SecretName}

None
  • kms:GenerateDataKey

Request parameters

Parameter

Type

Required

Description

Example

VersionId

string

Yes

The version ID of the secret. The version ID must be unique within the secret.

v3

SecretName

string

Yes

The name or Alibaba Cloud Resource Name (ARN) of the secret.

Note

When you access a secret that belongs to another Alibaba Cloud account, you must specify the ARN of the secret. The ARN of a secret is in the acs:kms:${region}:${account}:secret/${secret-name} format.

secret001

SecretData

string

Yes

The secret value. The secret value is encrypted and stored in the specified new version.

importantdata

SecretDataType

string

No

The type of the secret value. Valid values:

  • text (default)

  • binary

text

VersionStages

string

No

The version stages that are attached to the secret version when it is stored. If you do not specify this parameter, KMS attaches ACSCurrent to the new version by default.

["ACSCurrent","ACSNext"]

For more information about common request parameters, see Common parameters.

Response elements

Element

Type

Description

Example

object

RequestId

string

The ID of the request. The ID is a unique identifier generated by Alibaba Cloud for the request and can be used for troubleshooting.

f94ec9d3-2d10-4922-9a5c-5dcd5ebcb5e8

SecretName

string

The name of the secret.

secret001

VersionId

string

The version ID of the secret.

v3

VersionStages

object

VersionStage

array

The version stage of the secret.

string

The version stage of the secret.

{ "VersionStage": [ "ACSCurrent", "ACSNext" ] }

Examples

Success response

JSON format

{
  "RequestId": "f94ec9d3-2d10-4922-9a5c-5dcd5ebcb5e8",
  "SecretName": "secret001",
  "VersionId": "v3",
  "VersionStages": {
    "VersionStage": [
      "{ \"VersionStage\": [ \"ACSCurrent\", \"ACSNext\" ] }"
    ]
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidParameter some of the specified parameters "\" is not valid
400 Rejected.LimitExceeded exceed secret limits error
500 InternalFailure Internal Failure
403 Forbidden.NoPermission This operation is forbidden by permission system
404 Forbidden.ResourceNotFound Resource not found
409 Rejected.ResourceExist The request was rejected becasue key already exsit

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.