내용으로 건너뛰기

Need IAM policies to block specific ports and IP ranges at user and resource level

0

Need IAM policies to block specific ports and IP ranges at user and resource level with code.

질문됨 3년 전996회 조회

2개 답변
0

Hi, there exist specific conditions in IAM policies to bock ranges of IP addresses. See https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_aws_deny-ip.html

Example from the page:

{
    "Version": "2012-10-17",
    "Statement": {
        "Effect": "Deny",
        "Action": "*",
        "Resource": "*",
        "Condition": {
            "NotIpAddress": {
                "aws:SourceIp": [
                    "192.0.2.0/24",
                    "203.0.113.0/24"
                ]
            },
            "Bool": {"aws:ViaAWSService": "false"}
        }
    }
}

In the example, the blocker is broads with Deny for Action:* and Resource:*. You can tune that to your own use case with more specific actions and resources, depending on what you want to block exactly.

AFAIK, ports can be blocked via security groups but not by IAM policies

전문가

답변함 3년 전

전문가

검토됨 3년 전

전문가

검토됨 3년 전

  • You can’t block with security groups. You can only allow.

  • Agree with Gary . To block port, network acl is needed.

  • @Didier As Gary mentioned, in AWS, you don't explicitly "block" ports using security groups. Instead, you only "allow" specific traffic. By default, a security group denies all inbound traffic and allows all outbound traffic unless rules are added to allow specific types of inbound traffic. I would suggest you update your answer so we don't confuse other users.

  • what does this line mean? "Bool": {"aws:ViaAWSService": "false"}

  • and above policy is for blocking specific IP addresses or allow?

0

You can block HTTP (port 80) requests to services. Example:

{
  "Id": "ExamplePolicy",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowSSLRequestsOnly",
      "Action": "s3:*",
      "Effect": "Deny",
      "Resource": [
        "arn:aws:s3:::DOC-EXAMPLE-BUCKET",
        "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"
      ],
      "Condition": {
        "Bool": {
          "aws:SecureTransport": "false"
        }
      },
      "Principal": "*"
    }
  ]
}
AWS
전문가

답변함 3년 전

  • Thanks for the answer but if I want to block port for EC2 instance will it be possible using IAM policy?

  • No. You must use Security Groups (allow only), Network ACLS, or something like a Network Firewall. If you are blocking at the HTTP/HTTPS level, you could use AWS WAF if your front the EC2 Instances with an ALB. AWS IAM is about protecting AWS APIs (authentication and authorization). All of the policy examples above are protecting these APIs, not instances. There is some gray area where you can use IAM policies to control access to Session Manager and the ability to login to an instance, but IAM policies are not network firewall rules.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.