全部產品
Search
文件中心

:GetSecretValue

更新時間:Jan 22, 2025

調用GetSecretValue介面擷取憑據值。

如果不指定版本號碼或版本狀態,則KMS預設返回被標記為ACSCurrent的版本憑據值。

如果憑據使用了使用者指定的密鑰來保護憑據值,則需要調用者同時具備相應主要金鑰的kms:Decrypt許可權。

本文將提供一個樣本,擷取一個名為secret001憑據的憑據值,返回結果顯示憑據值SecretDatatestdata1

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

請求參數

名稱

類型

是否必選

樣本值

描述

Action String GetSecretValue

要執行的操作。取值:GetSecretValue

SecretName String secret001

憑據名稱或憑據資源名稱(ARN)。

說明 訪問其他阿里雲帳號下的憑據時,必須輸入憑據ARN。憑據ARN的格式為acs:kms:${region}:${account}:secret/${secret-name}
VersionStage String ACSCurrent

版本狀態。預設值:ACSCurrent。

輸入該參數時返回指定版本狀態的憑據值,不輸入該參數時返回ACSCurrent版本狀態的憑據值。

說明 RDS憑據、PolarDB憑據、Redis/Tair憑據、RAM憑據和ECS憑據只能擷取ACSPrevious和ACSCurrent對應版本的憑據值。
VersionId String v1

版本號碼。

說明 RDS憑據、PolarDB憑據、Redis/Tair憑據、RAM憑據和ECS憑據不支援指定VersionId,設定該參數將被忽略。
FetchExtendedConfig Boolean true

是否擷取憑據的拓展配置。取值:

  • true:擷取
  • false(預設值):不擷取
說明 通用憑據不支援拓展配置,設定該參數將被忽略。
DryRun String false

是否開啟DryRun模式。

  • true:開啟
  • false(預設值):關閉

DryRun模式用於測試API調用,驗證您是否具有相應資源的許可權,以及請求參數是否配置正確。DryRun模式開啟後,KMS會始終返回失敗並提示失敗原因。失敗原因包含如下:

  • DryRunOperationError:不配置DryRun參數時,請求會成功。
  • ValidationError:請求中指定的參數有誤。
  • AccessDeniedError:您無權在KMS資源上執行該操作。

關於公用請求參數的詳情,請參見公用參數

返回資料

名稱

類型

樣本值

描述

SecretDataType String binary

憑據實值型別。取值:

  • text
  • binary
CreateTime String 2024-02-21T15:39:26Z

建立憑據的時間。

VersionId String v1

憑據的版本號碼。

NextRotationDate String 2024-07-06T18:22:03Z

下一次輪轉的時間。

說明 當自動輪轉開啟時,返回該參數。
SecretData String testdata1

憑據值。KMS將儲存的密文憑據值進行解密後返回該參數。

  • 通用憑據返回您指定的憑據值。
  • RDS憑據、Redis/Tair憑據返回的憑據值滿足格式:{"AccountName":"","AccountPassword":""}
  • RAM憑據返回的憑據值滿足格式:{"AccessKeyId":"Adfdsfd","AccessKeySecret":"fdsfdsf","GenerateTimestamp": "2023-03-25T10:42:40Z"}
  • ECS憑據返回的憑據值滿足以下格式:
    • 口令類型憑據:{"UserName":"ecs-user","Password":"H5asdasdsads****"}
    • 公私密金鑰類型憑據(私密金鑰格式為PEM):{"UserName":"ecs-user","PublicKey":"ssh-rsa ****mKwnVix9YTFY9Rs= imported-openssh-key","PrivateKey": "d6bee1cb-2e14-4277-ba6b-73786b21****"}
  • PolarDB憑據返回的憑據值滿足格式:{"AccountName":"","AccountPassword":""}
RotationInterval String 604800s

憑據自動輪轉的周期。

格式為integer[unit],其中integer表示時間長度,unit表示時間單位。 unit取值:s(秒)。例如:7天的輪轉周期為604800s。

說明 當自動輪轉開啟時,返回該參數。
ExtendedConfig String {\"SecretSubType\":\"SingleUser\", \"DBInstanceId\":\"rm-uf667446pc955****\", \"CustomData\":{} }

憑據的拓展配置。

說明 當FetchExtendedConfig取值為true時,僅RDS憑據、PolarDB憑據、Redis/Tair憑據、RAM憑據或ECS憑據返回該參數。
LastRotationDate String 2023-07-05T08:22:03Z

最近一次輪轉的時間。

說明 當憑據發生過輪轉時返回該參數。
RequestId String 6a3e9c36-1150-4881-84d3-eb8672fcafad

本次調用請求的ID,是由阿里雲為該請求產生的唯一識別碼,可用於排查和定位問題。

SecretName String secret001

憑據名稱。

AutomaticRotation String Enabled

是否開啟了自動輪轉。取值:

  • Enabled:開啟了自動輪轉。
  • Disabled:未開啟自動輪轉。
  • Invalid:輪轉狀態異常,KMS無法為您自動輪轉。
說明 僅RDS憑據、PolarDB憑據、Redis/Tair憑據、RAM憑據或ECS憑據返回該參數。
SecretType String Generic

憑據類型。取值:

  • Generic:通用憑據。
  • Rds:RDS憑據。
  • Redis:Redis/Tair憑據。
  • RAMCredentials:RAM憑據。
  • ECS:ECS憑據。
  • PolarDB:PolarDB憑據。
VersionStages Array of String { "VersionStage": [ "ACSCurrent" ] }

憑據版本的狀態標記。

樣本

請求樣本

http(s)://[Endpoint]/?Action=GetSecretValue
&SecretName=secret001
&VersionStage=ACSCurrent
&VersionId=v1
&FetchExtendedConfig=true
&DryRun=false
&公用請求參數

正常返回樣本

XML格式

HTTP/1.1 200 OK
Content-Type:application/xml

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

JSON格式

HTTP/1.1 200 OK
Content-Type:application/json

{
  "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] }" ]
}

錯誤碼

HttpCode

錯誤碼

錯誤資訊

描述

403 Forbidden.DKMSInstanceStateInvalid The DKMS instance state is invalid. 您的專屬KMS狀態為無效狀態。
403 Forbidden.DKMSInstanceNotFound The specified DKMS Instance is not found. 您指定的專屬kms執行個體未找到。
404 Forbidden.KeyNotFound The specified Key is not found. 指定的密鑰不存在。
404 Forbidden.ResourceNotFound Resource not found. 資源找不到

訪問錯誤中心查看更多錯誤碼。