GetSecretValue

Updated at:

Retrieves a secret value.

Operation description

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

  • If you do not specify a version number or version status, KMS returns the credential value of the version marked as ACSCurrent by default.

  • If the credential uses a custom master key to protect the credential value, the caller must also have the kms:Decrypt permission on the corresponding master key.

This topic provides an example of retrieving the credential value of a credential named secret001. The response shows that the credential value SecretData is testdata1.

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:GetSecretValue

get

*Secret

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

None
  • kms:Decrypt

Request parameters

Parameter

Type

Required

Description

Example

SecretName

string

Yes

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

Note

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

secret001

VersionStage

string

No

The version status. Default value: ACSCurrent.

If you specify this parameter, the secret value of the specified version status is returned. If you do not specify this parameter, the secret value of the ACSCurrent version status is returned.

Note

For ApsaraDB RDS secrets, PolarDB secrets, Redis/Tair secrets, dynamic RAM secrets, and dynamic ECS secrets, only the secret values corresponding to ACSPrevious and ACSCurrent can be retrieved.

ACSCurrent

VersionId

string

No

The version number.

Note

Specifying VersionId is not supported for ApsaraDB RDS secrets, PolarDB secrets, Redis/Tair secrets, dynamic RAM secrets, or dynamic ECS secrets. If you set this parameter, it is ignored.

v1

FetchExtendedConfig

boolean

No

Specifies whether to retrieve the extended configuration of the secret. Valid values:

  • true: Retrieves the extended configuration.

  • false (default): Does not retrieve the extended configuration.

Note

Generic secrets do not support extended configuration. If you set this parameter, it is ignored.

true

DryRun

string

No

Specifies whether to enable DryRun mode. Valid values:

  • true: Enables DryRun mode.

  • false (default): Disables DryRun mode.

DryRun mode is used to test API calls, verify whether you have the required permissions on the specified resources, and check whether the request parameters are configured correctly. When DryRun mode is enabled, KMS always returns a failure with the reason for the failure. Possible failure reasons include:

  • DryRunOperationError: The request would succeed if the DryRun parameter were not configured.

  • ValidationError: A parameter specified in the request is invalid.

  • AccessDeniedError: You do not have permission to perform this operation on the KMS resource.

false

Recipient

string

No

{ "AttestationDocument":"base64-encoded-attestion-document", "KeyEncryptionAlgorithm":"RSAES_OAEP_SHA_256" }

For details about common request parameters, see Common parameters.

Response elements

Element

Type

Description

Example

object

SecretDataType

string

The type of the secret value. Valid values:

  • text

  • binary

binary

CreateTime

string

The time when the secret was created.

2024-02-21T15:39:26Z

VersionId

string

The version number of the secret.

v1

NextRotationDate

string

The time of the next rotation.

Note

This parameter is returned when automatic rotation is enabled.

2024-07-06T18:22:03Z

SecretData

string

The secret value. KMS decrypts the stored ciphertext secret value and returns this parameter.

  • For generic secrets, the secret value you specified is returned.

  • For ApsaraDB RDS secrets and Redis/Tair secrets, the secret value is returned in the following format: {"AccountName":"","AccountPassword":""}.

  • For dynamic RAM secrets, the secret value is returned in the following format: {"AccessKeyId":"Adfdsfd","AccessKeySecret":"fdsfdsf","GenerateTimestamp": "2023-03-25T10:42:40Z"}.

  • For dynamic ECS secrets, the secret value is returned in one of the following formats:

    • Password-type secret: {"UserName":"ecs-user","Password":"H5asdasdsads****"}.

    • Public/private key-type secret (private key in PEM format): {"UserName":"ecs-user","PublicKey":"ssh-rsa ****mKwnVix9YTFY9Rs= imported-openssh-key","PrivateKey": "d6bee1cb-2e14-4277-ba6b-73786b21****"}.

  • For PolarDB secrets, the secret value is returned in the following format: {"AccountName":"","AccountPassword":""}.

testdata1

RotationInterval

string

The interval for automatic secret rotation.

The format is integer[unit], where integer indicates the duration and unit indicates the time unit. Valid values of unit: s (seconds). For example, a rotation interval of 7 days is expressed as 604800s.

Note

This parameter is returned when automatic rotation is enabled.

604800s

ExtendedConfig

string

The extended configuration of the secret.

Note

This parameter is returned only for ApsaraDB RDS secrets, PolarDB secrets, Redis/Tair secrets, dynamic RAM secrets, or dynamic ECS secrets when FetchExtendedConfig is set to true.

{\"SecretSubType\":\"SingleUser\", \"DBInstanceId\":\"rm-uf667446pc955****\", \"CustomData\":{} }

LastRotationDate

string

The time of the most recent rotation.

Note

This parameter is returned when the secret has been rotated at least once.

2023-07-05T08:22:03Z

RequestId

string

The ID of the request, which is a unique identifier generated by Alibaba Cloud for the request. You can use this ID to troubleshoot and locate issues.

6a3e9c36-1150-4881-84d3-eb8672fcafad

SecretName

string

The secret name.

secret001

AutomaticRotation

string

Indicates whether automatic rotation is enabled. Valid values:

  • Enabled: Automatic rotation is enabled.

  • Disabled: Automatic rotation is not enabled.

  • Invalid: The rotation status is abnormal and KMS cannot automatically rotate the secret.

Note

This parameter is returned only for ApsaraDB RDS secrets, PolarDB secrets, Redis/Tair secrets, dynamic RAM secrets, or dynamic ECS secrets.

Enabled

SecretType

string

The secret type. Valid values:

  • Generic: generic secret.

  • Rds: ApsaraDB RDS secret.

  • Redis: Redis/Tair secret.

  • RAMCredentials: dynamic RAM secret.

  • ECS: dynamic ECS secret.

  • PolarDB: PolarDB secret.

Generic

VersionStages

object

VersionStage

array

The status label of the secret version.

string

The status label of the secret version.

{ "VersionStage": [ "ACSCurrent" ] }

CiphertextForRecipient

string

***CipherForRecipient***

Examples

Success response

JSON format

{
  "SecretDataType": "binary",
  "CreateTime": "2024-02-21T15:39:26Z",
  "VersionId": "v1",
  "NextRotationDate": "2024-07-06T18:22:03Z",
  "SecretData": "testdata1",
  "RotationInterval": "604800s",
  "ExtendedConfig": "{\\\"SecretSubType\\\":\\\"SingleUser\\\", \\\"DBInstanceId\\\":\\\"rm-uf667446pc955****\\\",  \\\"CustomData\\\":{} }",
  "LastRotationDate": "2023-07-05T08:22:03Z",
  "RequestId": "6a3e9c36-1150-4881-84d3-eb8672fcafad",
  "SecretName": "secret001",
  "AutomaticRotation": "Enabled",
  "SecretType": "Generic",
  "VersionStages": {
    "VersionStage": [
      "{ \"VersionStage\": [ \t\"ACSCurrent\" \t] }"
    ]
  },
  "CiphertextForRecipient": "***CipherForRecipient***"
}

Error codes

HTTP status code

Error code

Error message

Description

403 Forbidden.DKMSInstanceStateInvalid The DKMS instance state is invalid. Your dedicated KMS instance is invalid.
403 Forbidden.DKMSInstanceNotFound The specified DKMS Instance is not found. Your dedicated KMS instance is not found.
404 Forbidden.KeyNotFound The specified Key is not found. The error message returned because the specified CMK does not exist.
404 Forbidden.ResourceNotFound Resource not found. The resource is not found.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.