全部产品
Search
文档中心

资源编排:ALIYUN::KMS::Key

更新时间:Feb 05, 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"
          ]
        }
      }
    }
  }
}

更多示例,请参考包含此资源的公共模板。