O recurso ALIYUN::RAM::Role cria uma função do RAM.
Sintaxe
{
"Type": "ALIYUN::RAM::Role",
"Properties": {
"RoleName": String,
"Description": String,
"AssumeRolePolicyDocument": Map,
"MaxSessionDuration": Integer,
"Policies": List,
"IgnoreExisting": Boolean,
"DeletionForce": Boolean,
"PolicyAttachments": Map
}
}
Propriedades
Nome da propriedade | Tipo | Obrigatório | Atualizável | Descrição | Restrições |
AssumeRolePolicyDocument | Map | Sim | Sim | Identidade que pode assumir esta função do RAM. | Política de confiança. Especifique uma ou mais entidades confiáveis capazes de assumir esta função do RAM. A entidade pode ser uma conta Alibaba Cloud, um serviço Alibaba Cloud ou um provedor de identidade. |
RoleName | String | Sim | Não | Nome da função do RAM. | Comprimento: 1 a 64 caracteres. Pode conter letras, números, pontos (.) e hifens (-). |
Description | String | Não | Não | Descrição da função do RAM. | Comprimento máximo: 1024 caracteres. |
MaxSessionDuration | Integer | Não | Sim | Duração máxima da sessão da função do RAM. | Intervalo de valores: 3600 a 43200 segundos. Valor padrão: 3600 segundos. |
Policies | List | Não | Sim | Políticas aplicáveis à função do RAM. | Para obter mais informações, consulte Visão geral da política de acesso. |
IgnoreExisting | Boolean | Não | Não | Indica se as funções existentes devem ser ignoradas. | Valores:
Nota Se o ROS não tiver criado a função, ela será ignorada durante atualizações e exclusões. |
DeletionForce | Boolean | Não | Sim | Indica se as políticas associadas à função devem ser desvinculadas forçadamente. | Valor padrão: false. |
PolicyAttachments | Map | Não | Sim | Nomes das políticas de sistema e personalizadas a serem anexadas. | Para obter mais informações, consulte Propriedades de PolicyAttachments. |
Sintaxe de AssumeRolePolicyDocument
"AssumeRolePolicyDocument": {
"Version": String,
"Statement": List
}
Propriedades de AssumeRolePolicyDocument
|
Nome da propriedade |
Tipo |
Obrigatório |
Permite atualizações |
Descrição |
Restrições |
|
Version |
String |
Sim |
Não |
Versão da política. |
Nenhuma |
|
Statement |
List |
Sim |
Não |
Regras específicas da política. |
Para obter mais informações, consulte Propriedades de Statement. |
Sintaxe de Statement
"Statement": [
{
"Condition": Map,
"Action": String,
"Effect": String,
"Principal": Map
}
]
Propriedades de Statement
Nome da propriedade | Tipo | Obrigatório | Atualizável | Descrição | Restrições |
Condition | Map | Não | Não | Condições. | Nenhuma |
Action | String | Não | Não | Ações específicas alvo da política. | Nenhuma |
Effect | String | Não | Não | Efeito da permissão. | Valores:
|
Principal | Map | Não | Não | Tipo de entidade confiável. | Para obter mais informações, consulte Propriedades de Principal. |
Sintaxe de Principal
"Principal": {
"Service": List,
"Federated": List,
"RAM": List
}
Propriedades de Principal
|
Nome da propriedade |
Tipo |
Obrigatório |
Atualizável |
Descrição |
Restrições |
|
Service |
List |
Não |
Não |
Serviços Alibaba Cloud. |
Nenhuma |
|
Federated |
List |
Não |
Não |
Provedor de identidade. |
Nenhuma |
|
RAM |
List |
Não |
Não |
Contas Alibaba Cloud. |
Nenhuma |
Sintaxe de Policies
"Policies": [
{
"Description": String,
"PolicyName": String,
"PolicyDocument": Map
}
]
Propriedades de Policies
|
Nome da propriedade |
Tipo |
Obrigatório |
Atualizável |
Descrição |
Restrições |
|
Description |
String |
Não |
Não |
Descrição. |
Comprimento: 1 a 1024 caracteres. |
|
PolicyName |
String |
Sim |
Não |
Nome da política de acesso. |
Comprimento: 1 a 128 caracteres. Pode conter letras, números e hifens (-). |
|
PolicyDocument |
Map |
Sim |
Sim |
Documento de política. |
Comprimento máximo: 2048 caracteres. Para obter mais informações, consulte Propriedades de PolicyDocument. |
Sintaxe de PolicyAttachments
"PolicyAttachments": {
"System": List,
"Custom": List
}
Propriedades de PolicyAttachments
|
Nome da propriedade |
Tipo |
Obrigatório |
Atualizável |
Descrição |
Restrições |
|
Custom |
List |
Não |
Sim |
Lista de nomes de políticas personalizadas. |
A quantidade de políticas deve ser menor ou igual a 5. |
|
System |
List |
Não |
Sim |
Lista de nomes de políticas de sistema. |
A quantidade de políticas deve ser menor ou igual a 20. |
Sintaxe de PolicyDocument
"PolicyDocument": {
"Version": String,
"Statement": List
}
Propriedades de PolicyDocument
|
Nome da propriedade |
Tipo |
Obrigatório |
Atualizável |
Descrição |
Restrições |
|
Version |
String |
Sim |
Não |
Versão da política de acesso. |
Nenhuma |
|
Statement |
List |
Sim |
Não |
Regras específicas da política de acesso. |
Nenhuma |
Valores de retorno
Fn::GetAtt
RoleId: ID da função.
RoleName: Nome da função.
Arn: Descritor de recurso da função.
Exemplos
Cenário 1: Criar uma função do RAM.
ROSTemplateFormatVersion: '2015-09-01'
Description: Test RAM Role
Parameters: {}
Resources:
Role:
Type: ALIYUN::RAM::Role
Properties:
RoleName: TestRole
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- actiontrail.aliyuncs.com
Version: '1'
Outputs:
RoleId:
Description: Id of ram role.
Value:
Fn::GetAtt:
- Role
- RoleId
Arn:
Description: Name of alicloud resource.
Value:
Fn::GetAtt:
- Role
- Arn
RoleName:
Description: Name of ram role.
Value:
Fn::GetAtt:
- Role
- RoleName
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": "Test RAM Role",
"Parameters": {
},
"Resources": {
"Role": {
"Type": "ALIYUN::RAM::Role",
"Properties": {
"RoleName": "TestRole",
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": [
"actiontrail.aliyuncs.com"
]
}
}
],
"Version": "1"
}
}
}
},
"Outputs": {
"RoleId": {
"Description": "Id of ram role.",
"Value": {
"Fn::GetAtt": [
"Role",
"RoleId"
]
}
},
"Arn": {
"Description": "Name of alicloud resource.",
"Value": {
"Fn::GetAtt": [
"Role",
"Arn"
]
}
},
"RoleName": {
"Description": "Name of ram role.",
"Value": {
"Fn::GetAtt": [
"Role",
"RoleName"
]
}
}
}
}
Cenário 2: Criar uma função do RAM, anexar uma política personalizada, permitir que serviços especificados assumam a função e definir operações de política.
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Create a RAM role, attach a custom policy allowing specified services to assume the role, and define policy operations.
Parameters:
RoleName:
Type: String
Label:
en: Role Name
Description:
en: The name of role, Change the name if it already exists,Consist of english letters, numbers or '-',not more than 64 characters.
ConstraintDescription:
en: No more than 64 characters,English letters, Numbers, or '-' are allowed.
Default: test-role
AllowedPattern: ^[a-zA-Z0-9\-]+$
MinLength: 1
MaxLength: 64
AssumeRolePrincipalServices:
Type: Json
Label:
en: Principal Services
Description:
en: The specifies role-trusted services that can be added more than once.
Default:
- ecs.aliyuncs.com
PolicyName:
Type: String
Label:
en: Policy Name
Description:
en: The policy name, Change the name if it already exists,<br>Consist of english letters, numbers or '-', 5-128 characters.
ConstraintDescription:
en: Consist of english letters, numbers or '-',5-128 characters.
Default: test-policy-name
AllowedPattern: ^[a-zA-Z0-9\-]+$
MinLength: 5
MaxLength: 128
SpecificAction:
Type: String
Label:
en: Specific Action
Description:
en: 'The specific action of the policy,Separated by English commas; <a href=''https://www.alibabacloud.com/help/document_detail/93738.html'' target=''_blank''><b><font color=''blue''>View Policy elements - Action</font></font></a><br>For example: <br>[oss.*,ecs.*: <font color=''green''>all the action of oss and ecs</font>]<br>[oss.*: <font color=''green''>all the action of oss</font>]<br>[oss.GetObjectUrl: <font color=''green''>action is GetObjectUrl of oss</font>]<br>.'
Default: oss.*,ecs.*
Resources:
RamManagedPolicy:
Type: ALIYUN::RAM::ManagedPolicy
Properties:
PolicyDocument:
Statement:
- Action:
Fn::Split:
- ','
- Ref: SpecificAction
Effect: Allow
Resource:
- '*'
Version: '1'
PolicyName:
Ref: PolicyName
RamRole:
Type: ALIYUN::RAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
Ref: AssumeRolePrincipalServices
Version: '1'
Policies:
- PolicyDocument:
Statement:
- Action:
- ros:*
Effect: Allow
Resource:
- '*'
Version: '1'
PolicyName:
Fn::Join:
- ''
- - Policy-
- Ref: ALIYUN::StackId
RoleName:
Ref: RoleName
RamAttachPolicyToRole:
Type: ALIYUN::RAM::AttachPolicyToRole
Properties:
PolicyName:
Fn::GetAtt:
- RamManagedPolicy
- PolicyName
PolicyType: Custom
RoleName:
Fn::GetAtt:
- RamRole
- RoleName
DependsOn:
- RamManagedPolicy
- RamRole
Outputs:
PolicyName:
Value:
Fn::GetAtt:
- RamManagedPolicy
- PolicyName
RoleArn:
Value:
Fn::GetAtt:
- RamRole
- Arn
RoleName:
Value:
Fn::GetAtt:
- RamRole
- RoleName
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- RoleName
- AssumeRolePrincipalServices
- PolicyName
- SpecificAction
Label:
default: RAM
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": {
"en": "Create a RAM role, attach a custom policy allowing specified services to assume the role, and define policy operations."
},
"Parameters": {
"RoleName": {
"Type": "String",
"Label": {
"en": "Role Name"
},
"Description": {
"en": "The name of role, Change the name if it already exists,Consist of english letters, numbers or '-',not more than 64 characters."
},
"ConstraintDescription": {
"en": "No more than 64 characters,English letters, Numbers, or '-' are allowed."
},
"Default": "test-role",
"AllowedPattern": "^[a-zA-Z0-9\\-]+$",
"MinLength": 1,
"MaxLength": 64
},
"AssumeRolePrincipalServices": {
"Type": "Json",
"Label": {
"en": "Principal Services"
},
"Description": {
"en": "The specifies role-trusted services that can be added more than once."
},
"Default": [
"ecs.aliyuncs.com"
]
},
"PolicyName": {
"Type": "String",
"Label": {
"en": "Policy Name"
},
"Description": {
"en": "The policy name, Change the name if it already exists,<br>Consist of english letters, numbers or '-', 5-128 characters."
},
"ConstraintDescription": {
"en": "Consist of english letters, numbers or '-',5-128 characters."
},
"Default": "test-policy-name",
"AllowedPattern": "^[a-zA-Z0-9\\-]+$",
"MinLength": 5,
"MaxLength": 128
},
"SpecificAction": {
"Type": "String",
"Label": {
"en": "Specific Action"
},
"Description": {
"en": "The specific action of the policy,Separated by English commas; <a href='https://www.alibabacloud.com/help/document_detail/93738.html' target='_blank'><b><font color='blue'>View Policy elements - Action</font></font></a><br>For example: <br>[oss.*,ecs.*: <font color='green'>all the action of oss and ecs</font>]<br>[oss.*: <font color='green'>all the action of oss</font>]<br>[oss.GetObjectUrl: <font color='green'>action is GetObjectUrl of oss</font>]<br>."
},
"Default": "oss.*,ecs.*"
}
},
"Resources": {
"RamManagedPolicy": {
"Type": "ALIYUN::RAM::ManagedPolicy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": {
"Fn::Split": [
",",
{
"Ref": "SpecificAction"
}
]
},
"Effect": "Allow",
"Resource": [
"*"
]
}
],
"Version": "1"
},
"PolicyName": {
"Ref": "PolicyName"
}
}
},
"RamRole": {
"Type": "ALIYUN::RAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": {
"Ref": "AssumeRolePrincipalServices"
}
}
}
],
"Version": "1"
},
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": [
"ros:*"
],
"Effect": "Allow",
"Resource": [
"*"
]
}
],
"Version": "1"
},
"PolicyName": {
"Fn::Join": [
"",
[
"Policy-",
{
"Ref": "ALIYUN::StackId"
}
]
]
}
}
],
"RoleName": {
"Ref": "RoleName"
}
}
},
"RamAttachPolicyToRole": {
"Type": "ALIYUN::RAM::AttachPolicyToRole",
"Properties": {
"PolicyName": {
"Fn::GetAtt": [
"RamManagedPolicy",
"PolicyName"
]
},
"PolicyType": "Custom",
"RoleName": {
"Fn::GetAtt": [
"RamRole",
"RoleName"
]
}
},
"DependsOn": [
"RamManagedPolicy",
"RamRole"
]
}
},
"Outputs": {
"PolicyName": {
"Value": {
"Fn::GetAtt": [
"RamManagedPolicy",
"PolicyName"
]
}
},
"RoleArn": {
"Value": {
"Fn::GetAtt": [
"RamRole",
"Arn"
]
}
},
"RoleName": {
"Value": {
"Fn::GetAtt": [
"RamRole",
"RoleName"
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"RoleName",
"AssumeRolePrincipalServices",
"PolicyName",
"SpecificAction"
],
"Label": {
"default": "RAM"
}
}
]
}
}
}
Cenário 3: Criar uma função do RAM para gerenciar o ActionTrail, armazenar logs de auditoria em um bucket do OSS especificado e configurar um projeto do SLS.
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Create RAM roles to manage operation auditing, with audit logs stored in a designated OSS bucket, and configure an SLS project for further log processing and analysis.
Parameters:
RoleName:
Type: String
Label:
en: Role Name
Description:
en: Ram role name, 1 to 64 characters in length, beginning with English letters or numbers, hyphens allowed, unique in the account.
ConstraintDescription:
en: 1 to 64 characters in length, beginning with English letters or numbers, hyphens allowed.
Default: ActionTrailTestRole
MinLength: 1
MaxLength: 64
TrailName:
Type: String
Label:
en: Trail Name
Description:
en: Trail Name, 6 to 36 characters in length, must start with a letter, and can contain letters, numbers, dashes (-), and underscores (_), unique in the account
Default: TestTrail
EventRW:
Type: String
Label:
en: Event RW
Description:
en: Read and write types of delivery events
Default: Write
AllowedValues:
- Write
- Read
- All
OssBucketName:
Type: String
Label:
en: Bucket Name
Description:
en: Tracking OSS storage space written
AssociationProperty: ALIYUN::OSS::Bucket::BucketName
AssociationPropertyMetadata:
RegionId: ${RegionId}
OssKeyPrefix:
Type: String
Label:
en: Key Prefix
Description:
en: Track the prefix of the OSS storage space file name written, can be empty. 6 to 32 characters in length, must start with a letter, and can contain letters, numbers, dashes (-), slashes (/), and underscores (_)
Default: ''
SlsProjectName:
Type: String
Label:
en: Project Name
Description:
en: Log service items to track delivery targets
Resources:
Role:
Type: ALIYUN::RAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- actiontrail.aliyuncs.com
Version: '1'
Policies:
- PolicyDocument:
Statement:
- Action:
- oss:ListObjects
- oss:PutObject
- oss:GetBucketLocation
Effect: Allow
Resource:
- '*'
- Action:
- log:PostLogStoreLogs
- log:CreateLogstore
Effect: Allow
Resource:
- '*'
- Action:
- mns:PublishMessage
Effect: Allow
Resource:
- '*'
Version: '1'
PolicyName:
Fn::Sub: ActionTrailPolicy-${ALIYUN::StackId}
RoleName:
Ref: RoleName
Trail:
Type: ALIYUN::ACTIONTRAIL::Trail
Properties:
EventRW:
Ref: EventRW
Name:
Ref: TrailName
OssBucketName:
Ref: OssBucketName
OssKeyPrefix:
Ref: OssKeyPrefix
RoleName:
Fn::GetAtt:
- Role
- RoleName
SlsProjectArn:
Fn::Sub: acs:log:${ALIYUN::Region}::project/${SlsProjectName}
SlsWriteRoleArn:
Fn::Sub: acs:ram::${ALIYUN::TenantId}:role/${Role.RoleName}
DependsOn: Role
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- RoleName
Label:
default: RAM
- Parameters:
- TrailName
- EventRW
Label:
default: Trail
- Parameters:
- OssBucketName
- OssKeyPrefix
Label:
default: OSS
- Parameters:
- SlsProjectName
Label:
default: SLS
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": {
"en": "Create RAM roles to manage operation auditing, with audit logs stored in a designated OSS bucket, and configure an SLS project for further log processing and analysis."
},
"Parameters": {
"RoleName": {
"Type": "String",
"Label": {
"en": "Role Name"
},
"Description": {
"en": "Ram role name, 1 to 64 characters in length, beginning with English letters or numbers, hyphens allowed, unique in the account."
},
"ConstraintDescription": {
"en": "1 to 64 characters in length, beginning with English letters or numbers, hyphens allowed."
},
"Default": "ActionTrailTestRole",
"MinLength": 1,
"MaxLength": 64
},
"TrailName": {
"Type": "String",
"Label": {
"en": "Trail Name"
},
"Description": {
"en": "Trail Name, 6 to 36 characters in length, must start with a letter, and can contain letters, numbers, dashes (-), and underscores (_), unique in the account"
},
"Default": "TestTrail"
},
"EventRW": {
"Type": "String",
"Label": {
"en": "Event RW"
},
"Description": {
"en": "Read and write types of delivery events"
},
"Default": "Write",
"AllowedValues": [
"Write",
"Read",
"All"
]
},
"OssBucketName": {
"Type": "String",
"Label": {
"en": "Bucket Name"
},
"Description": {
"en": "Tracking OSS storage space written"
},
"AssociationProperty": "ALIYUN::OSS::Bucket::BucketName",
"AssociationPropertyMetadata": {
"RegionId": "${RegionId}"
}
},
"OssKeyPrefix": {
"Type": "String",
"Label": {
"en": "Key Prefix"
},
"Description": {
"en": "Track the prefix of the OSS storage space file name written, can be empty. 6 to 32 characters in length, must start with a letter, and can contain letters, numbers, dashes (-), slashes (/), and underscores (_)"
},
"Default": ""
},
"SlsProjectName": {
"Type": "String",
"Label": {
"en": "Project Name"
},
"Description": {
"en": "Log service items to track delivery targets"
}
}
},
"Resources": {
"Role": {
"Type": "ALIYUN::RAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": [
"actiontrail.aliyuncs.com"
]
}
}
],
"Version": "1"
},
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": [
"oss:ListObjects",
"oss:PutObject",
"oss:GetBucketLocation"
],
"Effect": "Allow",
"Resource": [
"*"
]
},
{
"Action": [
"log:PostLogStoreLogs",
"log:CreateLogstore"
],
"Effect": "Allow",
"Resource": [
"*"
]
},
{
"Action": [
"mns:PublishMessage"
],
"Effect": "Allow",
"Resource": [
"*"
]
}
],
"Version": "1"
},
"PolicyName": {
"Fn::Sub": "ActionTrailPolicy-${ALIYUN::StackId}"
}
}
],
"RoleName": {
"Ref": "RoleName"
}
}
},
"Trail": {
"Type": "ALIYUN::ACTIONTRAIL::Trail",
"Properties": {
"EventRW": {
"Ref": "EventRW"
},
"Name": {
"Ref": "TrailName"
},
"OssBucketName": {
"Ref": "OssBucketName"
},
"OssKeyPrefix": {
"Ref": "OssKeyPrefix"
},
"RoleName": {
"Fn::GetAtt": [
"Role",
"RoleName"
]
},
"SlsProjectArn": {
"Fn::Sub": "acs:log:${ALIYUN::Region}::project/${SlsProjectName}"
},
"SlsWriteRoleArn": {
"Fn::Sub": "acs:ram::${ALIYUN::TenantId}:role/${Role.RoleName}"
}
},
"DependsOn": "Role"
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"RoleName"
],
"Label": {
"default": "RAM"
}
},
{
"Parameters": [
"TrailName",
"EventRW"
],
"Label": {
"default": "Trail"
}
},
{
"Parameters": [
"OssBucketName",
"OssKeyPrefix"
],
"Label": {
"default": "OSS"
}
},
{
"Parameters": [
"SlsProjectName"
],
"Label": {
"default": "SLS"
}
}
]
}
}
}
Para obter mais exemplos, consulte modelos públicos que incluem este recurso.