要实现此限制,可以使用 AWS Security Group 和 Network ACL 进行配置。以下是一些示例代码,可以根据您的特定需求进行修改:
{
"GroupDescription": "Allow access from company's IPs only",
"GroupName": "company-sg",
"IpPermissions": [
{
"FromPort": 80,
"ToPort": 80,
"IpProtocol": "tcp",
"IpRanges": [
{
"CidrIp": "10.0.0.0/8" // Replace with your company IP address range
}
]
}
],
"VpcId": "vpc-12345678" // Replace with your VPC ID
}
{
"Associations": [
{
"NetworkAclAssociationId": "acl-assoc-12345678",
"NetworkAclId": "acl-12345678",
"SubnetId": "subnet-12345678" // Replace with your subnet ID
}
],
"Entries": [
{
"CidrBlock": "0.0.0.0/0",
"Egress": true,
"Protocol": -1,
"RuleAction": "allow",
"RuleNumber": 100
},
{
"CidrBlock": "10.0.0.0/8", // Replace with your company IP address range
"Egress": false,
"Protocol": -1,
"RuleAction": "allow",
"RuleNumber": 110
}
],
"Tags": [],
"VpcId": "vpc-12345678" // Replace with your VPC ID
}
通过这些配置,我们可以限制来自公司 IP 地址范围内的访问。