All Products
Search
Document Center

Key Management Service:GetSecretValue

Last Updated:Jun 10, 2026

Mengambil nilai rahasia dari versi tertentu suatu rahasia.

Deskripsi operasi

  • For information about the required access policy for a RAM user or RAM role to call this API operation, see Resource Access Management.

  • If you do not specify a version number or stage, KMS returns the secret value of the version that is marked as ACSCurrent.

  • If a user-specified key is used to protect the secret value, the caller must have the kms:Decrypt permission on the corresponding master key.

This topic provides an example of how to obtain the value of a secret named secret001. The response shows that the secret value of SecretData is testdata1.

Coba sekarang

Coba API ini di OpenAPI Explorer tanpa perlu penandatanganan manual. Panggilan yang berhasil akan secara otomatis menghasilkan contoh kode SDK sesuai dengan parameter Anda. Unduh kode tersebut dengan kredensial bawaan yang aman untuk penggunaan lokal.

Test

RAM authorization

Tidak ada otorisasi untuk operasi ini. Jika Anda mengalami masalah saat menjalankan operasi ini, hubungi dukungan teknis.

Parameter permintaan

Parameter

Type

Required

Description

Example

SecretName

string

Yes

Nama atau Nama Sumber Daya Alibaba Cloud (ARN) rahasia.

Catatan

Saat Anda mengakses rahasia di akun Alibaba Cloud lain, Anda harus menentukan ARN rahasia. ARN rahasia dalam format acs:kms:${region}:${account}:secret/${secret-name}.

secret001

VersionStage

string

No

Label tahap yang menandai versi rahasia. Nilai default adalah ACSCurrent.

Jika Anda menentukan parameter ini, nilai rahasia dari versi dengan label tahap yang ditentukan akan dikembalikan. Jika Anda tidak menentukan parameter ini, nilai rahasia dari versi yang ditandai dengan ACSCurrent akan dikembalikan.

Catatan

Untuk rahasia RDS, rahasia PolarDB Basis Data Relasional Cloud-Native, rahasia Redis/Tair, rahasia RAM, dan rahasia ECS, Anda hanya dapat memperoleh nilai rahasia dari versi yang ditandai dengan ACSPrevious dan ACSCurrent.

ACSCurrent

VersionId

string

No

Nomor versi.

Catatan

Anda tidak dapat menentukan parameter VersionId untuk rahasia RDS, rahasia PolarDB Basis Data Relasional Cloud-Native, rahasia Redis/Tair, rahasia RAM, atau rahasia ECS. Jika Anda menetapkan parameter ini, pengaturan tersebut akan diabaikan.

v1

FetchExtendedConfig

boolean

No

Apakah akan mengambil konfigurasi tambahan rahasia. Nilai valid:

  • true: mengambil konfigurasi tambahan.

  • false (default): tidak mengambil konfigurasi tambahan.

Catatan

Rahasia generik tidak mendukung konfigurasi tambahan. Jika Anda menetapkan parameter ini untuk rahasia generik, pengaturan tersebut akan diabaikan.

true

DryRun

string

No

Apakah akan mengaktifkan fitur dry run.

  • true: mengaktifkan fitur dry run.

  • false (default): menonaktifkan fitur dry run.

Fitur dry run digunakan untuk menguji panggilan API. Fitur ini memverifikasi apakah Anda memiliki izin yang diperlukan pada Sumber daya dan apakah parameter permintaan valid. Jika Anda mengaktifkan fitur dry run, KMS selalu mengembalikan tanggapan kegagalan yang menunjukkan penyebab kegagalan. Penyebab kegagalan yang mungkin adalah sebagai berikut:

  • DryRunOperationError: Permintaan akan berhasil jika parameter DryRun tidak ditentukan.

  • ValidationError: Parameter yang ditentukan di permintaan tidak valid.

  • AccessDeniedError: Anda tidak memiliki izin untuk melakukan operasi ini pada Sumber daya KMS.

false

Untuk informasi selengkapnya tentang parameter permintaan umum, lihat Parameter umum.

Elemen respons

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 when the secret is next rotated.

Catatan

This parameter is returned only if automatic rotation is enabled.

2024-07-06T18:22:03Z

SecretData

string

The value of the secret. The value is decrypted from the ciphertext by KMS and returned.

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

  • For an RDS secret or a Redis/Tair secret, the value is in the following format: {"AccountName":"","AccountPassword":""}.

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

  • For an ECS secret, the value is in one of the following formats:

    • For a password-based credential: {"UserName":"ecs-user","Password":"H5asdasdsads****"} .

    • For a key pair-based credential (the private key is in the PEM format): {"UserName":"ecs-user","PublicKey":"ssh-rsa ****mKwnVix9YTFY9Rs= imported-openssh-key","PrivateKey": "d6bee1cb-2e14-4277-ba6b-73786b21****"} .

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

testdata1

RotationInterval

string

The interval for automatic rotation.
The value is in the integer[unit] format. integer indicates the length of the time. unit indicates the time unit. The unit can be s (second). For example, a rotation period of 7 days is 604800s.

Catatan

This parameter is returned only if automatic rotation is enabled.

604800s

ExtendedConfig

string

The extended configuration of the secret.

Catatan

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

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

LastRotationDate

string

The time when the secret was last rotated.

Catatan

This parameter is returned only if the secret was rotated.

2023-07-05T08:22:03Z

RequestId

string

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

6a3e9c36-1150-4881-84d3-eb8672fcafad

SecretName

string

The name of the secret.

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.

Catatan

This parameter is returned only for an RDS secret, PolarDB secret, Redis/Tair secret, RAM secret, or ECS secret.

Enabled

SecretType

string

The type of the secret. Valid values:

  • Generic: a generic secret.

  • Rds: an RDS secret.

  • Redis: a Redis/Tair secret.

  • RAMCredentials: a RAM secret.

  • ECS: an ECS secret.

  • PolarDB: a PolarDB secret.

Generic

VersionStages

array

The stage labels that mark the secret version.

string

The stage label that marks the secret version.

{ "VersionStage": [ "ACSCurrent" ] }

Contoh

Respons sukses

JSONformat

{
  "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\": [ \t\"ACSCurrent\" \t] }"
  ]
}

Kode kesalahan

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.

Lihat Error Codes untuk daftar lengkap.

Catatan rilis

Lihat Release Notes untuk daftar lengkap.