全部產品
Search
文件中心

:ALIYUN::KMS::Key

更新時間:Feb 06, 2026

ALIYUN::KMS::Key類型用於建立一個主要金鑰。

文法

{
  "Type": "ALIYUN::KMS::Key",
  "Properties": {
    "KeyUsage": String,
    "Enable": Boolean,
    "PendingWindowInDays": Integer,
    "Description": String,
    "KeySpec": String,
    "EnableAutomaticRotation": Boolean,
    "RotationInterval": String,
    "ProtectionLevel": String,
    "DKMSInstanceId": String,
    "KeyUsage": String,
    "Policy": Map,
    "DeletionProtection": Boolean,
    "Tags": List
  }
}

屬性

屬性名稱

類型

必須

允許更新

描述

約束

DKMSInstanceId

String

專屬KMS的執行個體ID。

原KMS升級為專屬KMS,具體升級變動資訊參見【升級公告】KMS升級為專屬KMS

DeletionProtection

Boolean

是否開啟刪除保護。

取值:

  • true:開啟刪除保護。

  • false:關閉刪除保護。

Description

String

密鑰的描述。

長度為0~8192個字元。

Enable

Boolean

將密鑰設定為啟用或禁用狀態。

取值:

  • true(預設值):將密鑰設定為啟用狀態。

  • false:將密鑰設定為禁用狀態。

KeyUsage

String

密鑰的用途。

取值:

  • ENCRYPT/DECRYPT:資料加密和解密。

  • SIGN/VERIFY:產生和驗證數位簽章。

預設值:如果密鑰支援簽名驗簽,預設值為 SIGN/VERIFY,否則預設值為 ENCRYPT/DECRYPT。

EnableAutomaticRotation

Boolean

是否開啟密鑰自動輪轉。

取值:

  • true:開啟密鑰自動輪轉。

  • false(預設值):關閉密鑰自動輪轉。

KeySpec

String

密鑰的類型。

取值:

  • Aliyun_AES_256

  • Aliyun_SM4

  • RSA_2048

  • EC_P256

  • EC_P256K

  • EC_SM2

說明

在中國內地使用託管密碼機建立的密鑰,預設為Aliyun_SM4類型,其餘情況下預設為Aliyun_AES_256。

PendingWindowInDays

Integer

密鑰預刪除周期。在這段時間內,您可以撤銷刪除處於待刪除狀態的密鑰;預刪除時間過後無法撤銷刪除。

取值範圍:7~30。

預設值:30。

單位:天。

Policy

Map

密鑰策略。

JSON格式。最大長度為32768個位元組。

關於密鑰策略的詳細介紹,請參見密鑰策略概述。不輸入該參數時,使用預設憑據策略。

密鑰策略內容包含:

  • Version:密鑰策略的版本,目前版本僅支援設定為1。

  • Statement:密鑰策略的語句,每個密鑰策略包含一個或多個語句。

密鑰策略格式為:

{
    "Version": "1",
    "Statement": [
        {
            "Sid": "Enable RAM User Permissions",
            "Effect": "Allow",
            "Principal": {
              "RAM": "acs:ram::112890462****:root"
            }
            "Action": [
                "kms:*"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

ProtectionLevel

String

密鑰的保護層級。

取值:

  • SOFTWARE(預設值)

  • HSM

RotationInterval

String

自動輪轉的時間周期。例如:365d

格式為integer[unit],其中integer表示時間長度,unit表示時間單位。

合法的unit單位取值如下:

  • d:天

  • h:小時

  • m:分鐘

  • s:秒

7d或者604800s均表示7天的周期。

取值範圍:7~730天。

Tags

List

標籤。

最多支援添加20個標籤。

更多資訊,請參見Tags屬性

Tags文法

"Tags": [
  {
    "Key": String,
    "Value": String
  }
]  

Tags屬性

屬性名稱

類型

必須

允許更新

描述

約束

Key

String

標籤鍵。

長度為1~128個字元,不能以aliyunacs:開頭,不能包含http://或者https://

Value

String

標籤值。

長度為0~128個字元,不能以aliyunacs:開頭,不能包含http://或者https://

傳回值

Fn::GetAtt

KeyId:密鑰的通用唯一識別碼。

樣本

情境 1 :使用已有KMS建立KMS密鑰

快速建立

Metadata: {}
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  KMSInstance:
    Type: String
    Description:
      en: KMS Instance Id.
Resources:
  KMS-Key-bhs-registry-secret:
    Type: ALIYUN::KMS::Key
    Properties:
      DKMSInstanceId:
        Ref: KMSInstance
      DeletionProtection: false
      Enable: true
      EnableAutomaticRotation: true
      KeySpec: Aliyun_AES_256
      KeyUsage: ENCRYPT/DECRYPT
      PendingWindowInDays: 7
      RotationInterval: 30d
{
  "Metadata": {
  },
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "KMSInstance": {
      "Type": "String",
      "Description": {
        "en": "KMS Instance Id."
      }
    }
  },
  "Resources": {
    "KMS-Key-bhs-registry-secret": {
      "Type": "ALIYUN::KMS::Key",
      "Properties": {
        "DKMSInstanceId": {
          "Ref": "KMSInstance"
        },
        "DeletionProtection": false,
        "Enable": true,
        "EnableAutomaticRotation": true,
        "KeySpec": "Aliyun_AES_256",
        "KeyUsage": "ENCRYPT/DECRYPT",
        "PendingWindowInDays": 7,
        "RotationInterval": "30d"
      }
    }
  }
}

情境 2 :建立KMS建立並建立KMS密鑰

快速建立

Metadata: {}
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ProductVersion:
    Type: String
    Description:
      en: KMS Instance commodity type (software/software-small/hardware/hardware-small).
    AllowedValues:
      - software
      - software-small
      - hardware
      - hardware-small
    Required: true
Resources:
  KMSInstance:
    Type: ALIYUN::KMS::Instance
    Properties:
      ProductVersion:
        Ref: ProductVersion
  KMSKey:
    Type: ALIYUN::KMS::Key
    Properties:
      DKMSInstanceId:
        Ref: KMSInstance
      DeletionProtection: false
      Enable: true
      EnableAutomaticRotation: true
      KeySpec: Aliyun_AES_256
      KeyUsage: ENCRYPT/DECRYPT
      PendingWindowInDays: 7
      RotationInterval: 30d
  KMSAlias:
    Type: ALIYUN::KMS::Alias
    Properties:
      AliasName: bhs-registry-secretDev
      KeyId:
        Fn::GetAtt:
          - KMSKey
          - KeyId
{
  "Metadata": {
  },
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ProductVersion": {
      "Type": "String",
      "Description": {
        "en": "KMS Instance commodity type (software/software-small/hardware/hardware-small)."
      },
      "AllowedValues": [
        "software",
        "software-small",
        "hardware",
        "hardware-small"
      ],
      "Required": true
    }
  },
  "Resources": {
    "KMSInstance": {
      "Type": "ALIYUN::KMS::Instance",
      "Properties": {
        "ProductVersion": {
          "Ref": "ProductVersion"
        }
      }
    },
    "KMSKey": {
      "Type": "ALIYUN::KMS::Key",
      "Properties": {
        "DKMSInstanceId": {
          "Ref": "KMSInstance"
        },
        "DeletionProtection": false,
        "Enable": true,
        "EnableAutomaticRotation": true,
        "KeySpec": "Aliyun_AES_256",
        "KeyUsage": "ENCRYPT/DECRYPT",
        "PendingWindowInDays": 7,
        "RotationInterval": "30d"
      }
    },
    "KMSAlias": {
      "Type": "ALIYUN::KMS::Alias",
      "Properties": {
        "AliasName": "bhs-registry-secretDev",
        "KeyId": {
          "Fn::GetAtt": [
            "KMSKey",
            "KeyId"
          ]
        }
      }
    }
  }
}

更多樣本,請參考包含此資源的公用模板。