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 | 否 | 是 | 是否开启删除保护。 | 取值:
|
Description | String | 否 | 是 | 密钥的描述。 | 长度为0~8192个字符。 |
Enable | Boolean | 否 | 是 | 将密钥设置为启用或禁用状态。 | 取值:
|
KeyUsage | String | 否 | 否 | 密钥的用途。 | 取值:
默认值:如果密钥支持签名验签,默认值为 SIGN/VERIFY,否则默认值为 ENCRYPT/DECRYPT。 |
EnableAutomaticRotation | Boolean | 否 | 是 | 是否开启密钥自动轮转。 | 取值:
|
KeySpec | String | 否 | 否 | 密钥的类型。 | 取值:
说明 在中国内地使用托管密码机创建的密钥,默认为Aliyun_SM4类型,其余情况下默认为Aliyun_AES_256。 |
PendingWindowInDays | Integer | 否 | 否 | 密钥预删除周期。在这段时间内,您可以撤销删除处于待删除状态的密钥;预删除时间过后无法撤销删除。 | 取值范围:7~30。 默认值:30。 单位:天。 |
Policy | Map | 否 | 否 | 密钥策略。 | JSON格式。最大长度为32768个字节。 关于密钥策略的详细介绍,请参见密钥策略概述。不输入该参数时,使用默认凭据策略。 密钥策略内容包含:
密钥策略格式为: |
ProtectionLevel | String | 否 | 否 | 密钥的保护级别。 | 取值:
|
RotationInterval | String | 否 | 是 | 自动轮转的时间周期。例如: | 格式为 合法的
7d或者604800s均表示7天的周期。 取值范围:7~730天。 |
Tags | List | 否 | 是 | 标签。 | 最多支持添加20个标签。 更多信息,请参见Tags属性。 |
Tags语法
"Tags": [
{
"Key": String,
"Value": String
}
] Tags属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
Key | String | 是 | 否 | 标签键。 | 长度为1~128个字符,不能以 |
Value | String | 否 | 否 | 标签值。 | 长度为0~128个字符,不能以 |
返回值
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"
]
}
}
}
}
}更多示例,请参考包含此资源的公共模板。