Quản lý security group rule
/v2.0/security-group-rules/v2.0/security-group-rules/v2.0/security-group-rules/{rule_id}Rule chỉ có kiểu allow. Không có rule deny: lưu lượng không khớp rule nào sẽ bị drop, và vì group là stateful, phản hồi cho một kết nối được phép sẽ được cho phép mà không cần thêm rule.
Nguồn: security-group-rules
Liệt kê rule
curl -ks -H 'Content-Type: application/json' -H 'X-Auth-Token: gAAAAA<...>' \
'https://api.vietnix.cloud:9696/v2.0/security-group-rules?security_group_id=b7e4d2c1-8f3a-4b6d-9c05-1e2f3a4b5c60'
Thêm rule
Tham số
security_group_ruleobjectbắt buộcObject bọc rule.
9 trường
security_group_idstringbắt buộcbodyID của group mà rule thuộc về. Bắt buộc.
directionstringbắt buộcbodyingress hoặc egress. Bắt buộc.
2 giá trị
ingressÁp dụng cho lưu lượng đi vào VM.egressÁp dụng cho lưu lượng đi ra khỏi VM.
ethertypestringbắt buộcbodyIPv4 hoặc IPv6. Bắt buộc.
2 giá trị
IPv4Lưu lượng IPv4.IPv6Lưu lượng IPv6.
protocolstringbodytcp, udp, icmp, icmpv6 hoặc null cho mọi giao thức.
5 giá trị
tcpTransmission Control Protocol.udpUser Datagram Protocol.icmpICMP cho IPv4.icmpv6ICMP cho IPv6.anyMọi giao thức. Đây là giá trị được dùng khi protocol là null.
port_range_minintegerbodyĐiểm bắt đầu của dải port. Chỉ hợp lệ với tcp và udp.
port_range_maxintegerbodyĐiểm kết thúc của dải port. Chỉ hợp lệ với tcp và udp.
remote_ip_prefixstringbodyCIDR nguồn hoặc đích. Dùng 0.0.0.0/0 cho mọi địa chỉ IPv4. Không thể kết hợp với remote_group_id.
remote_group_idstringbodyCho phép lưu lượng từ security group khác thay vì một CIDR.
descriptionstringbodyMô tả tự do.
Request mẫu — cho phép SSH từ một mạng
curl -ks -X POST -H 'Content-Type: application/json' -H 'X-Auth-Token: gAAAAA<...>' \
-d '{
"security_group_rule": {
"security_group_id": "b7e4d2c1-8f3a-4b6d-9c05-1e2f3a4b5c60",
"direction": "ingress",
"ethertype": "IPv4",
"protocol": "tcp",
"port_range_min": 22,
"port_range_max": 22,
"remote_ip_prefix": "203.0.113.0/24",
"description": "SSH from office network"
}
}' https://api.vietnix.cloud:9696/v2.0/security-group-rules
Response mẫu
JSON body
{
"security_group_rule": {
"id": "5c9f3a21-7d4e-4b8f-a0c6-3e2d1b0a9f88",
"security_group_id": "b7e4d2c1-8f3a-4b6d-9c05-1e2f3a4b5c60",
"direction": "ingress",
"ethertype": "IPv4",
"protocol": "tcp",
"port_range_min": 22,
"port_range_max": 22,
"remote_ip_prefix": "203.0.113.0/24",
"remote_group_id": null,
"description": "SSH from office network",
"tenant_id": "f5d834d636c642c7bfe8af86139c6f26"
}
}
Mã trạng thái
| Mã | Mô tả |
|---|---|
| 201 - Created | Rule đã được tạo. |
| 400 - Bad Request | Protocol, dải port hoặc CIDR không hợp lệ; hoặc cả remote_ip_prefix và remote_group_id đều được đặt. |
| 401 - Unauthorized | Cần xác thực trước khi gửi request. |
| 403 - Forbidden | Policy không cho phép user hiện tại thực hiện thao tác này. |
| 404 - Not Found | Security group không tồn tại. |
| 409 - Conflict | Rule tương tự đã tồn tại trong group. |
Xoá rule
curl -ks -X DELETE -H 'Content-Type: application/json' -H 'X-Auth-Token: gAAAAA<...>' \
https://api.vietnix.cloud:9696/v2.0/security-group-rules/{rule_id}
| Mã | Mô tả |
|---|---|
| 204 - No Content | Rule đã bị xoá. |
| 401 - Unauthorized | Cần xác thực trước khi gửi request. |
| 403 - Forbidden | Policy không cho phép user hiện tại thực hiện thao tác này. |
| 404 - Not Found | Rule không tồn tại. |
Rule có hiệu lực ngay trên mọi port dùng group; không cần khởi động lại VM. Nếu kết nối vẫn thất bại, hãy kiểm tra direction, ethertype và xem firewall trong guest có chặn port đó không.