Agrega una o más reglas de entrada a un security group. Puede utilizar esta operación para especificar permisos de acceso de entrada para un security group, lo que permite autorizar o denegar que otros dispositivos envíen tráfico de entrada a las instancias del security group y habilita un control de acceso a la red detallado.
Descripción de la operación
Antes de comenzar
Límite de cantidad: El número total de reglas de security group (incluidas las reglas de entrada y de salida) en todos los security groups asociados con una sola tarjeta de interfaz de red (NIC) no puede exceder 1,000. Para obtener más información, consulte Límites de security groups.
Configuración de prioridad: La prioridad (Priority) de las reglas de entrada de security group varía de 1 a 100. Un número menor indica una prioridad mayor. Si dos reglas de security group tienen la misma prioridad, la regla de denegación (drop) tiene precedencia. El acceso se deniega primero.
Notas
Si la regla de security group especificada ya existe, la llamada se realiza correctamente, pero no se agrega ninguna regla.
Cómo determinar una regla
Se requieren los siguientes parámetros para determinar una regla de entrada de security group:
Configuración de origen: Especifique uno de los siguientes: SourceCidrIp (dirección IPv4), Ipv6SourceCidrIp (dirección IPv6), SourcePrefixListId (ID de lista de prefijos) o SourceGroupId (security group de origen).
Rango de puertos de destino: PortRange.
Tipo de protocolo: IpProtocol.
Política de acceso: Policy.
Los security groups avanzados no admiten la autorización de acceso desde otros security groups. Los security groups básicos admiten un máximo de 20 security groups autorizados.
Ejemplos de solicitud
Los siguientes ejemplos muestran cómo agregar reglas de entrada con diferentes orígenes a un security group en la región China (Hangzhou):
-
Agregar permisos de acceso para un rango de direcciones IP específico.
"RegionId":"cn-hangzhou", // Especifique la región. "SecurityGroupId":"sg-bp67acfmxazb4p****", // Especifique el security group. "Permissions":[ { "SourceCidrIp":"10.0.0.0/8", // Especifique la dirección IPv4 de origen. "PortRange":"22/22", // Especifique el rango de puertos. "IpProtocol":"TCP", // Especifique el tipo de protocolo. "Policy":"Accept" // Especifique la política de acceso. } ] -
Agregar permisos de acceso para otro security group y una lista de prefijos.
"RegionId":"cn-hangzhou", "SecurityGroupId":"sg-bp67acfmxazb4p****", "Permissions":[ { "SourceGroupId":"sg-bp17vs63txqxbd****", // Especifique el security group de origen. "PortRange":"22/22", "IpProtocol":"TCP", "Policy":"Drop" },{ "SourcePrefixListId":"pl-x1j1k5ykzqlixdcy****", // Especifique la lista de prefijos de origen. "PortRange":"22/22", "IpProtocol":"TCP", "Policy":"Drop" } ]
Pruébelo ahora
Test
Autorización de RAM
|
Action |
Nivel de acceso |
Tipo de recurso |
Clave de condición |
Acción dependiente |
|
ecs:AuthorizeSecurityGroup |
create |
*All Resource
|
|
Ninguna |
Parámetros de la solicitud
|
Parámetro |
Tipo |
Obligatorio |
Descripción |
Ejemplo |
| RegionId |
string |
Sí |
El ID de la región del security group. Puede llamar a DescribeRegions para consultar la lista de regiones más reciente. |
cn-hangzhou |
| RegionId |
string |
Sí |
El ID de la región del security group. Puede llamar a DescribeRegions para consultar la lista de regiones más reciente. |
cn-hangzhou |
| RegionId |
string |
Sí |
El ID de la región del security group. Puede llamar a DescribeRegions para consultar la lista de regiones más reciente. |
cn-hangzhou |
| ClientToken |
string |
No |
Un token de cliente que se utiliza para garantizar la idempotencia de la solicitud. Puede utilizar el cliente para generar el token, pero debe asegurarse de que el token sea único entre diferentes solicitudes. El valor de ClientToken solo puede contener caracteres ASCII y no puede exceder los 64 caracteres de longitud. Para obtener más información, consulte Cómo garantizar la idempotencia. |
123e4567-e89b-12d3-a456-426655440000 |
| ClientToken |
string |
No |
Un token de cliente que se utiliza para garantizar la idempotencia de la solicitud. Puede utilizar el cliente para generar el token, pero debe asegurarse de que el token sea único entre diferentes solicitudes. El valor de ClientToken solo puede contener caracteres ASCII y no puede exceder los 64 caracteres de longitud. Para obtener más información, consulte Cómo garantizar la idempotencia. |
123e4567-e89b-12d3-a456-426655440000 |
| SecurityGroupId |
string |
Sí |
El ID del security group. |
sg-bp67acfmxazb4p**** |
| SecurityGroupId |
string |
Sí |
El ID del security group. |
sg-bp67acfmxazb4p**** |
| Permissions |
array<object> |
No |
Las reglas del security group. Longitud del arreglo: de 1 a 100. |
|
|
object |
No |
La regla del security group. |
||
| Policy |
string |
No |
Configuración de permisos de acceso. Valores válidos:
Valor predeterminado: accept. |
accept |
| Priority |
string |
No |
La prioridad de la regla del security group. Un valor menor indica una prioridad mayor. Valores válidos: de 1 a 100. Valor predeterminado: 1. |
1 |
| IpProtocol |
string |
No |
El protocolo de capa de red o de transporte. Se admiten dos tipos de valores:
|
ALL |
| SourceCidrIp |
string |
No |
El bloque CIDR IPv4 de origen para el que desea configurar permisos de acceso. Se admiten configuraciones de formato CIDR y rangos de direcciones en formato IPv4. |
10.0.0.0/8 |
| Ipv6SourceCidrIp |
string |
No |
El bloque CIDR IPv6 de origen para el que desea configurar permisos de acceso. Se admiten configuraciones de formato CIDR y rangos de direcciones en formato IPv6. Nota
Este parámetro solo es válido para instancias de ECS conectadas a VPC que admiten IPv6. Este parámetro y |
2001:250:6000::*** |
| SourceGroupId |
string |
No |
El ID del security group de origen para el que desea configurar permisos de acceso.
|
sg-bp67acfmxazb4p**** |
| SourcePrefixListId |
string |
No |
El ID de la lista de prefijos de origen para la que desea configurar permisos de acceso. Puede llamar a DescribePrefixLists para consultar los ID de listas de prefijos disponibles. Notas: Si especifica Para obtener más información, consulte Límites de security groups. |
pl-x1j1k5ykzqlixdcy**** |
| PortRange |
string |
No |
El rango de puertos de destino que corresponden al protocolo del security group. Valores válidos:
Para obtener más información sobre los puertos comunes, consulte Escenarios comunes para puertos. |
80/80 |
| DestCidrIp |
string |
No |
El bloque CIDR IPv4 de destino. Se admiten bloques CIDR y rangos de direcciones IPv4. Este parámetro se utiliza para admitir reglas de quintupla. Para obtener más información, consulte Reglas de quintupla de security group. |
10.0.0.0/8 |
| Ipv6DestCidrIp |
string |
No |
El bloque CIDR IPv6 de destino. Se admiten formatos CIDR y rangos de direcciones en formato IPv6. Este parámetro se utiliza para admitir reglas de quintupla. Para obtener más información, consulte Reglas de quintupla de security group. Nota
Este parámetro solo es válido para instancias de ECS conectadas a VPC que admiten IPv6. Este parámetro y |
2001:250:6000::*** |
| SourcePortRange |
string |
No |
El rango de puertos de origen que corresponden al protocolo del security group. Valores válidos:
Este parámetro se utiliza para admitir reglas de quintupla. Para obtener más información, consulte Reglas de quintupla de security group. |
7000/8000 |
| SourceGroupOwnerAccount |
string |
No |
La cuenta de Alibaba Cloud propietaria del security group de origen cuando configura una regla de security group entre cuentas.
|
test@aliyun.com |
| SourceGroupOwnerId |
integer |
No |
El ID de la cuenta de Alibaba Cloud propietaria del security group de origen cuando configura una regla de security group entre cuentas.
|
1234567890 |
| NicType |
string |
No |
El tipo de tarjeta de interfaz de red (NIC) para una regla de security group de tipo de red clásica. Valores válidos:
Para las reglas de security group de VPC, no necesita establecer el parámetro de tipo de tarjeta de interfaz de red (NIC). El valor predeterminado es intranet y solo se admite intranet. Cuando configura security groups para que tengan acceso mutuo (solo se especifica DestGroupId), solo se admite intranet. Valor predeterminado: internet. |
intranet |
| Description |
string |
No |
La descripción de la regla del security group. La descripción debe tener una longitud de 1 a 512 caracteres. |
Esta es la descripción |
| PortRangeListId |
string |
No |
El ID de la libreta de direcciones de puertos.
Puede invocar
|
prl-2ze9743**** |
Policy
deprecated
|
string |
No |
Obsoleto. Utilice |
accept |
Priority
deprecated
|
string |
No |
Obsoleto. Utilice |
1 |
IpProtocol
deprecated
|
string |
No |
Obsoleto. Utilice |
ALL |
SourceCidrIp
deprecated
|
string |
No |
Obsoleto. Utilice |
10.0.0.0/8 |
Ipv6SourceCidrIp
deprecated
|
string |
No |
Obsoleto. Utilice |
2001:250:6000::*** |
SourceGroupId
deprecated
|
string |
No |
Obsoleto. Utilice |
sg-bp67acfmxazb4p**** |
SourcePrefixListId
deprecated
|
string |
No |
Obsoleto. Utilice |
pl-x1j1k5ykzqlixdcy**** |
PortRange
deprecated
|
string |
No |
Obsoleto. Utilice |
22/22 |
DestCidrIp
deprecated
|
string |
No |
Obsoleto. Utilice |
10.0.0.0/8 |
Ipv6DestCidrIp
deprecated
|
string |
No |
Obsoleto. Utilice |
null |
SourcePortRange
deprecated
|
string |
No |
Obsoleto. Utilice |
22/22 |
SourceGroupOwnerAccount
deprecated
|
string |
No |
Obsoleto. Utilice |
test@aliyun.com |
SourceGroupOwnerId
deprecated
|
integer |
No |
Obsoleto. Utilice |
1234567890 |
NicType
deprecated
|
string |
No |
Obsoleto. Utilice |
intranet |
Description
deprecated
|
string |
No |
Obsoleto. Utilice |
Esta es la descripción |
Elementos de la respuesta
|
Elemento |
Tipo |
Descripción |
Ejemplo |
|
object |
|||
| RequestId |
string |
El ID de la solicitud. |
473469C7-AA6F-4DC5-B3DB-A3DC0DE3**** |
Ejemplos
Respuesta exitosa
JSON Formato
{
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****"
}
Códigos de error
|
Código de estado HTTP |
Código de error |
Mensaje de error |
Descripción |
|---|---|---|---|
| 400 | OperationDenied | The specified IpProtocol does not exist or IpProtocol and PortRange do not match. | The specified IP protocol does not exist or does not match the specified port range. |
| 400 | InvalidIpProtocol.Malformed | The specified parameter PortRange is not valid. | The specified IpProtocol or PortRange parameter is invalid. |
| 400 | InvalidSourceCidrIp.Malformed | The specified parameter SourceCidrIp is not valid. | The specified source CIDR block is invalid. |
| 400 | InvalidPolicy.Malformed | The specified parameter Policy is not valid. | The specified Policy parameter is invalid. |
| 400 | InvalidNicType.ValueNotSupported | The specified NicType does not exist. | The specified NicType parameter does not exist. |
| 400 | InvalidNicType.Mismatch | The specified NicType conflicts with the authorization record. | The specified NIC type does not match the existing rule. |
| 400 | InvalidSourceGroupId.Mismatch | Specified security group and source group are not in the same VPC. | The specified source and destination security groups do not belong to the same VPC. |
| 400 | InvalidSourceGroup.NotFound | Specified source security group does not exist. | The specified inbound security group rule does not exist, or required parameters are not specified. |
| 400 | InvalidPriority.Malformed | The parameter Priority is invalid. | The specified Priority parameter is invalid. |
| 400 | InvalidPriority.ValueNotSupported | The specified parameter %s is invalid. | The specified Priority parameter is invalid. |
| 400 | InvalidSecurityGroupDiscription.Malformed | The specified security group rule description parameter %s is not valid. | The specified security group rule description is invalid. |
| 400 | InvalidSecurityGroup.InvalidNetworkType | The specified security group network type is not support this operation, please check the security group network types. For VPC security groups, ClassicLink must be enabled. | The operation is not supported while the security group is of the current network type. If the network type is VPC, ClassicLink must be enabled. |
| 400 | MissingParameter.Source | One of the parameters SourceCidrIp, Ipv6SourceCidrIp, SourceGroupId or SourcePrefixListId in %s must be specified. | At least one of the SourceCidrIp, SourceGroupId, and SourcePrefixListId parameters must be specified. |
| 400 | InvalidParam.PortRange | The specified parameter %s is not valid. It should be two integers less than 65535 in ?/? format. | The format of the port range is invalid. Specify the port range in the format of a slash separating two integers. |
| 400 | InvalidIpProtocol.ValueNotSupported | The parameter %s must be specified with case insensitive TCP, UDP, ICMP, GRE or All. | The specified Protocol parameter is invalid. You must set Protocol to a vaule that is case-insensitive, such as TCP, UDP, ICMP, GRE, and All. |
| 400 | InvalidSecurityGroupId.Malformed | The specified parameter SecurityGroupId is not valid. | The specified SecurityGroupId parameter is invalid. |
| 400 | InvalidParamter.Conflict | The specified SourceCidrIp should be different from the DestCidrIp. | The value of SourceCidrIp must be different from that of DestCidrIp. |
| 400 | InvalidSourcePortRange.Malformed | The specified parameter SourcePortRange is not valid. | The specified SourcePortRange parameter is invalid. |
| 400 | InvalidPortRange.Malformed | The specified parameter PortRange must set. | The PortRange parameter must be specified. |
| 400 | InvalidParam.SourceIp | The Parameters SourceCidrIp and Ipv6SourceCidrIp in %s cannot be set at the same time. | The SourceCidrIp and Ipv6SourceCidrIp parameters cannot be specified at the same time. |
| 400 | InvalidParam.DestIp | The Parameters DestCidrIp and Ipv6DestCidrIp in %s cannot be set at the same time. | The DestCidrIp and Ipv6DestCidrIp parameters cannot be specified at the same time. |
| 400 | InvalidParam.Ipv6DestCidrIp | The specified parameter %s is not valid. | The specified Ipv6DestCidrIp parameter is invalid. |
| 400 | InvalidParam.Ipv6SourceCidrIp | The specified parameter %s is not valid. | The specified Ipv6SourceCidrIp parameter is invalid. |
| 400 | InvalidParam.Ipv4ProtocolConflictWithIpv6Address | IPv6 address cannot be specified for IPv4-specific protocol. | IPv6 addresses cannot be specified for instances that use the IPv4 protocol. |
| 400 | InvalidParam.Ipv6ProtocolConflictWithIpv4Address | IPv4 address cannot be specified for IPv6-specific protocol. | IPv4 addresses cannot be specified for instances that use the IPv6 protocol. |
| 400 | InvalidParameter.Ipv6CidrIp | The specified Ipv6CidrIp is not valid. | The specified Ipv6CidrIp parameter is invalid. |
| 400 | InvalidGroupAuthParameter.OperationDenied | The security group can not authorize to enterprise level security group. | Security groups cannot be referenced as authorization objects (destinations or sources) in rules of advanced security groups. |
| 400 | InvalidDestCidrIp.Malformed | The specified parameter DestCidrIp is not valid. | The specified DestCidrIp parameter is invalid. |
| 400 | InvalidParameter.Conflict | IPv6 and IPv4 addresses cannot exist at the same time. | IPv6 and IPv4 addresses cannot be both specified. |
| 400 | InvalidParam.PrefixListAddressFamilyMismatch | The address family of the specified prefix list does not match the specified CidrIp. | The address family of the specified prefix list does not match that of the specified CIDR block. |
| 400 | NotSupported.ClassicNetworkPrefixList | The prefix list is not supported when the network type of security group is classic. | Security groups in the classic network do not support prefix lists. |
| 400 | AuthorizedGroupRule.LimitExceed | You have reached the limit on the number of group authorization rules that you can add to a security group.When authorization object of rule is security group, the limit is 20. | Up to 20 rules in which security groups are specified as authorization objects can be present in a basic security group. |
| 400 | InvalidParam.SourceCidrIp | The specified parameter %s is not valid. | The specified SourceCidrIp parameter is invalid. |
| 400 | InvalidParam.DestCidrIp | The specified parameter %s is not valid. | The specified DestCidrIp parameter is invalid. |
| 400 | MissingParameter | %s | A parameter is not specified. |
| 400 | InvalidParam.Permissions | The specified parameter Permissions cannot coexist with other parameters. | The specified Permissions parameter and other parameters are mutually exclusive. |
| 400 | InvalidParam.DuplicatePermissions | There are duplicate permissions in the specified parameter Permissions. | The specified Permissions parameter contains duplicate permissions. |
| 400 | InvalidGroupParameter.OperationDenied | The attributes Policy, SourceGroupId, DestGroupId of enterprise level security groups are not allowed to be set or modified. | The attributes Policy, SourceGroupId, DestGroupId of enterprise level security groups are not allowed to be set or modified. |
| 400 | InvalidParam.ProtocolNotSupportPortRangeList | The specified protocol does not support the port range list. | The specified protocol does not support the port list. |
| 400 | InvalidPortRangeListId.NotFound | The specified port range list was not found. | The specified port list was not found. |
| 401 | InvalidOperation.SecurityGroupNotAuthorized | The specified security group is not authorized to operate. | You do not have permission to operate the current security group. |
| 500 | InternalError | The request processing has failed due to some unknown error. | |
| 403 | InvalidSourceGroupId.Mismatch | NicType is required or NicType expects intranet. | The NicType parameter is not specified or is not set to intranet. |
| 403 | MissingParameter | The input parameter SourceGroupId or SourceCidrIp cannot be both blank. | At least one of the SourceGroupId and SourceCidrIp parameters must be specified. |
| 403 | AuthorizationLimitExceed | The limit of authorization records in the security group reaches. | |
| 403 | InvalidParamter.Conflict | The specified SecurityGroupId should be different from the SourceGroupId. | The destination security group is the same as the source security group. |
| 403 | InvalidNetworkType.Mismatch | The specified SecurityGroup network type should be same with SourceGroup network type (vpc or classic). | The network type of the destination security group is different from that of the source security group. |
| 403 | InvalidNetworkType.Conflict | The specified SecurityGroup network type should be same with SourceGroup network type (vpc or classic). | The network type of the destination security group is different from that of the source security group. |
| 403 | InvalidOperation.ResourceManagedByCloudProduct | %s | You cannot modify security groups managed by cloud services. |
| 403 | LimitExceed.PrefixListAssociationResource | The number of resources associated with the prefix list exceeds the limit. | The maximum number of resources that can be associated with the prefix list has been exceeded. |
| 404 | InvalidSecurityGroupId.NotFound | The specified SecurityGroupId does not exist. | The specified security group does not exist in this account. Check whether the security group ID is correct. |
| 404 | InvalidSourceGroupId.NotFound | The SourceGroupId provided does not exist in our records. | The specified SourceGroupId parameter does not exist. |
| 404 | InvalidPrefixListId.NotFound | The specified prefix list was not found. | The prefix list does not exist. |
Consulte Códigos de error para ver la lista completa.
Notas de la versión
Consulte Notas de la versión para ver la lista completa.