增加一條安全性群組入方向規則。指定安全性群組入方向的存取權限,允許或者拒絕其他裝置發送入方向流量到安全性群組裡的執行個體。
描述
我們定義入方向流量的發起端為源端(Source),資料轉送的接收端為目的端(Destination),如下圖所示。
調用該介面時,您需要瞭解:
-
一個安全性群組的安全性群組規則最多為 100 條。
-
安全性群組規則分為接受訪問(
accept)和拒絕訪問(drop)兩類。 -
安全性群組規則優先順序(
Priority)可選範圍為 [1, 100]。數字越小,代表優先順序越高。 -
優先順序相同的安全性群組規則,以拒絕訪問(
drop)的規則優先。 -
源端裝置可以是指定 IP 位址範圍(
SourceCidrIp),也可以是其他安全性群組(SourceGroupId)中的執行個體。 -
以下任意一組參數可以確定一條安全性群組規則,只指定一個參數無法確定一條安全性群組規則。如果匹配的安全性群組規則已存在,此次
AuthorizeSecurityGroup調用失敗。
請求參數
| 名稱 | 類型 | 是否必需 | 描述 |
|---|---|---|---|
| Action | String | 是 | 系統規定參數。取值:AuthorizeSecurityGroup |
| RegionId | String | 是 | 安全性群組所屬地域 ID。您可以調用 DescribeRegions 查看最新的阿里雲地域列表。 |
| SecurityGroupId | String | 是 | 目的端安全性群組 ID。 |
| IpProtocol | String | 是 | 傳輸層協議。取值大小寫敏感。取值範圍:
|
| PortRange | String | 是 | SecurityGroupId 方開放的傳輸層協議相關的通信埠範圍。取值範圍:
|
| SourcePortRange | String | 否 | 源端安全性群組開放的傳輸層協議相關的通信埠範圍。取值範圍:
|
| NicType | String | 否 | 網卡類型。取值範圍:
SourceGroupId 且沒有指定 SourceCidrIp 時,參數 NicType 取值只能為 intranet。 預設值:internet |
| Policy | String | 否 | 設定存取權限。取值範圍:
|
| DestCidrIp | String | 否 | 目的端 IP 位址範圍。支援 CIDR 格式和 IPv4 格式的 IP 位址範圍。 預設值:0.0.0.0/0 |
| SourceCidrIp | String | 否 | 源端 IP 位址範圍。支援 CIDR 格式和 IPv4 格式的 IP 位址範圍。 預設值:0.0.0.0/0 |
| SourceGroupId | String | 否 | 需要設定存取權限的源端安全性群組 ID。至少設定一項 SourceGroupId 或者 SourceCidrIp 參數。 如果指定了 如果同時指定了 |
| SourceGroupOwnerAccount | String | 否 | 跨賬戶設定安全性群組規則時,源端安全性群組所屬的阿里雲賬戶。
|
| SourceGroupOwnerId | String | 否 | 跨賬戶設定安全性群組規則時,源端安全性群組所屬的阿里雲賬戶 ID。
|
| Priority | String | 否 | 安全性群組規則優先順序。取值範圍:[1, 100] 預設值:1 |
| Description | String | 否 | 安全性群組規則的描述資訊。長度為 [1, 512] 個字元。 |
返回參數
全是公共返回參數。參閱 公共返回參數。
樣本
設定指定 IP 位址段的存取權限。此時,經典網路型別安全組的網卡類型(NicType)可設定公網(internet)和 內網(intranet)。VPC 類型安全性群組的網卡類型(NicType)只可設定內網(intranet)。
https://ecs.aliyuncs.com/?Action=AuthorizeSecurityGroup
&SecurityGroupId=sg-F876FF7BA
&SourceCidrIp=0.0.0.0/0
&IpProtocol=tcp
&PortRange=1/65535
&NicType=intranet
&Policy=accept
&<公共請求參數>
請求樣本二
設定其他安全性群組的存取權限。此時,網卡類型(NicType)只能為內網(intranet)。經典網路型別安全組之間互訪時,可以設定同一地域中其他安全性群組對您的安全性群組的存取權限。這個安全性群組可以是您的也可以是其他阿里雲賬戶(SourceGroupOwnerAccount)的。VPC 類型安全性群組之間互訪時,可以設定同一 VPC 內其他安全性群組訪問該安全性群組的存取權限。
https://ecs.aliyuncs.com/?Action=AuthorizeSecurityGroup
&SecurityGroupId=sg-F876FF7BA
&SourceGroupId=sg-1651FBB64
&SourceGroupOwnerAccount=test@aliyun.com
&IpProtocol=tcp
&PortRange=1/65535
&NicType=intranet
&Policy=drop
&<公共請求參數>
XML 格式
<AuthorizeSecurityGroupResponse>
<RequestId>CEF72CEB-54B6-4AE8-B225-F876FF7BA984</RequestId>
</AuthorizeSecurityGroupResponse>
JSON 格式
{
"RequestId":"CEF72CEB-54B6-4AE8-B225-F876FF7BA984"
}
錯誤碼
以下為本介面特有的錯誤碼。更多錯誤碼,請訪問 API 錯誤中心 。
| 錯誤碼 | 錯誤資訊 | HTTP 狀態碼 | 說明 |
|---|---|---|---|
| InvalidIpProtocol.Malformed | The specified parameter “PortRange” is not valid. | 400 | 指定的參數 IpProtocol 不合法。 |
| InvalidPriority.Malformed | The specified parameter “Priority” is not valid. | 400 | 指定的參數 Priority 不合法。 |
| InvalidSourceCidrIp.Malformed | The specified parameter “SourceCidrIp” is not valid. | 400 | 指定的參數 SourceCidrIp 不合法。 |
| InvalidDestCidrIp.Malformed | The specified parameter “DestCidrIp” is not valid. | 400 | 指定的參數 DestCidrIp 不合法。 |
| InvalidPolicy.Malformed | The specified parameter “Policy” is not valid. | 400 | 指定的參數 Policy不合法。 |
| InvalidNicType.ValueNotSupported | The specified NicType does not exist. | 400 | 指定的參數 NicType不存在。 |
| InvalidSourceGroupId.Mismatch | Specified security group and source group are not in the same VPC. | 400 | 指定的安全性群組的網路類型是 VPC,源端安全性群組必須在同一個 VPC 裡。 |
| InvalidNicType.Mismatch | Specified nic type conflicts with the authorization record. | 400 | 指定網卡類型 NicType 與安全性群組規則不符合。 |
| InvalidSourceGroup.NotFound | The specified SourceGroupId does not exist. | 400 | 指定的源端安全性群組 SourceGroupId 不存在。 |
| InvalidPriority.ValueNotSupported | The specified Priority is invalid. | 400 | 指定的參數 Priority 不合法。 |
| InvalidSecurityGroupDiscription.Malformed | The specified security group rule description is not valid. | 400 | 安全性群組規則的描述 Description 不合法。 |
| OperationDenied | The specified IpProtocol does not exist or IpProtocol and PortRange do not match. | 400 | 指定的參數 IpProtocol 不存在。或者指定的 IP 協議和通信埠範圍不匹配。 |
| AuthorizationLimitExceed | The maximum number of authorization rules in the security group is exceeded. | 403 | 單個安全性群組的安全性群組規則最多為 100 條。 |
| InvalidSourceGroupId.Mismatch | NicType is required or NicType expects intranet. | 403 | 需要明確 NicType 參數。或者 NicType 必須為 intranet。 |
| InvalidNetworkType.Mismatch | The specified SecurityGroup network type should be same with SourceGroup network type (vpc or classic). | 403 | 安全性群組規則中的兩個安全性群組網路類型必須相同,即必須同時為經典網路或者 VPC。 |
| InvalidParamter.Conflict | The specified SecurityGroupId should be different from the SourceGroupId. | 403 | 參數 SecurityGroupId和 SourceGroupId不能相同。 |
| MissingParameter | The input parameter “SourceGroupId” or “SourceCidrIp” cannot be both blank. | 403 | 需要指定參數 SourceGroupId 或者 SourceCidrIp。 |
| InvalidSourceGroupId.NotFound | The SourceGroupId provided does not exist in our records. | 404 | 指定的 SourceGroup不存在。 |
| InvalidSecurityGroupId.NotFound | The specified SecurityGroupId does not exist. | 404 | 指定的 SecurityGroupId不存在。 |
| InvalidRegionId.NotFound | The specified RegionId does not exist. | 404 | 指定的 RegionId 不存在。 |