ALIYUN::RAM::Role类型用于创建RAM角色。

语法

{
  "Type": "ALIYUN::RAM::Role",
  "Properties": {
    "RoleName": String,
    "Description": String,
    "AssumeRolePolicyDocument": Map,
    "MaxSessionDuration": Integer,
    "Policies": List
  }
}

属性

属性名称 类型 必须 允许更新 描述 约束
RoleName String RAM角色名称。 最大长度为64个字符,可包含英文字母、数字、英文句点(.)、下划线(_)和短划线(-)。
Description String RAM角色描述。 最大长度为1024个字符。
AssumeRolePolicyDocument Map 可以扮演此RAM角色的身份。 更多信息,请参见AssumeRolePolicyDocument属性
MaxSessionDuration Integer RAM角色最大会话时间。 取值范围:3600秒~43200秒。

默认值:3600秒。

Policies List 适用RAM角色的策略。 更多信息,请参见Policies属性

AssumeRolePolicyDocument语法

"AssumeRolePolicyDocument": {
  "Version": String,
  "Statement": List
}

AssumeRolePolicyDocument属性

属性名称 类型 必须 允许更新 描述 约束
Version String 策略版本
Statement List 策略具体规则

Statement语法

"Statement": [
  {
    "Condition": Map,
    "Action": String,
    "Effect": String,
    "Principal": Map
  }
]

Statement属性

属性名称 类型 必须 允许更新 描述 约束
Condition Map 限制条件
Action String 策略针对的具体操作
Effect String 权限效力 取值:
  • Allow:允许。
  • Deny:拒绝。
Principal Map 可信实体类型 更多信息,请参见Principal属性

Principal语法

"Principal": {
  "Service": List,
  "Federated": List,
  "RAM": List
}

Principal属性

属性名称 类型 必须 允许更新 描述 约束
Service List 阿里云服务
Federated List 身份提供商
RAM List 阿里云账号

Policies语法

"Policies": [
  {
    "Description": String,
    "PolicyName": String,
    "PolicyDocument": Map
  }
]

Policies属性

属性名称 类型 必须 允许更新 描述 约束
Description String 描述 长度为1~1024个字符。
PolicyName String 权限策略名称 长度为1~128个字符,可包含英文字母、数字和短划线(-)。
PolicyDocument Map 权限策略内容 最大长度为2048个字符。

更多信息,请参见PolicyDocument属性

PolicyDocument语法

"PolicyDocument": {
  "Version": String,
  "Statement": List
}

PolicyDocument属性

属性名称 类型 必须 允许更新 描述 约束
Version String 权限策略版本
Statement List 权限策略具体规则

Statement语法

"Statement": [
  {
    "Condition": Map,
    "Action": List,
    "Resource": List,
    "Effect": String
  }
]

Statement属性

属性名称 类型 必须 允许更新 描述 约束
Condition Map 授权生效的限制条件。
Action List 权限策略针对的具体操作。
Resource List 权限策略针对的具体资源。
Effect String 授权效力。 取值:
  • Allow:允许。
  • Deny:拒绝。

返回值

Fn::GetAtt

  • RoleId:角色ID。
  • RoleName:角色名称。
  • Arn:角色的资源描述符。

示例

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "RoleName": {
      "Type": "String",
      "Description": "Specifies the role name, containing up to 64 characters."
    },
    "Description": {
      "Type": "String",
      "Description": "Remark information, up to 1024 characters or Chinese characters.",
      "MaxLength": 1024
    },
    "Policies": {
      "Type": "Json",
      "Description": "Describes what actions are allowed on what resources."
    },
    "MaxSessionDuration": {
      "Type": "Number",
      "Description": "The maximum session duration of the RAM role.\nValid values: 3600 to 43200. Unit: seconds. Default value: 3600.\nThe default value is used if the parameter is not specified.",
      "MinValue": 3600,
      "MaxValue": 43200
    },
    "AssumeRolePolicyDocument": {
      "Type": "Json",
      "Description": "The RAM assume role policy that is associated with this role."
    }
  },
  "Resources": {
    "Role": {
      "Type": "ALIYUN::RAM::Role",
      "Properties": {
        "RoleName": {
          "Ref": "RoleName"
        },
        "Description": {
          "Ref": "Description"
        },
        "Policies": {
          "Ref": "Policies"
        },
        "MaxSessionDuration": {
          "Ref": "MaxSessionDuration"
        },
        "AssumeRolePolicyDocument": {
          "Ref": "AssumeRolePolicyDocument"
        }
      }
    }
  },
  "Outputs": {
    "RoleName": {
      "Description": "Name of ram role.",
      "Value": {
        "Fn::GetAtt": [
          "Role",
          "RoleName"
        ]
      }
    },
    "Arn": {
      "Description": "Name of alicloud resource.",
      "Value": {
        "Fn::GetAtt": [
          "Role",
          "Arn"
        ]
      }
    },
    "RoleId": {
      "Description": "Id of ram role.",
      "Value": {
        "Fn::GetAtt": [
          "Role",
          "RoleId"
        ]
      }
    }
  }
}

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  RoleName:
    Type: String
    Description: 'Specifies the role name, containing up to 64 characters.'
  Description:
    Type: String
    Description: 'Remark information, up to 1024 characters or Chinese characters.'
    MaxLength: 1024
  Policies:
    Type: Json
    Description: Describes what actions are allowed on what resources.
  MaxSessionDuration:
    Type: Number
    Description: |-
      The maximum session duration of the RAM role.
      Valid values: 3600 to 43200. Unit: seconds. Default value: 3600.
      The default value is used if the parameter is not specified.
    MinValue: 3600
    MaxValue: 43200
  AssumeRolePolicyDocument:
    Type: Json
    Description: The RAM assume role policy that is associated with this role.
Resources:
  Role:
    Type: 'ALIYUN::RAM::Role'
    Properties:
      RoleName:
        Ref: RoleName
      Description:
        Ref: Description
      Policies:
        Ref: Policies
      MaxSessionDuration:
        Ref: MaxSessionDuration
      AssumeRolePolicyDocument:
        Ref: AssumeRolePolicyDocument
Outputs:
  RoleName:
    Description: Name of ram role.
    Value:
      'Fn::GetAtt':
        - Role
        - RoleName
  Arn:
    Description: Name of alicloud resource.
    Value:
      'Fn::GetAtt':
        - Role
        - Arn
  RoleId:
    Description: Id of ram role.
    Value:
      'Fn::GetAtt':
        - Role
        - RoleId