{"id":3737,"date":"2023-05-02T18:35:27","date_gmt":"2023-05-02T18:35:27","guid":{"rendered":"https:\/\/geekmungus.co.uk\/?p=3737"},"modified":"2023-05-02T18:35:27","modified_gmt":"2023-05-02T18:35:27","slug":"block-admin-page-using-aws-waf-example","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=3737","title":{"rendered":"Block Admin Page Using AWS WAF Example"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you are using the AWS Web Application Firewall (WAF) on your Application Load Balancer or other supported AWS entity, you probably don&#8217;t want any administrative interfaces of the web application presented directly to the Internet without some form of restriction; perhaps to a range of IPv4 addresses you want to restrict.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Adding a rule to your WebACL to block is pretty straightforward, you would just add the below section of code into your CloudFormation template within a WebACL. you also need to specify a trusted IP list, this can be in IPv4, IPv6 or both (although you may need two separate declarations for each IPv4 and IPv6).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The below is a Rule that you would add into the &#8220;Rules&#8221; section of a AWS::WAFv2::WebACL resource. The IP Set is separate from this WebACL resource. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n        - Name: AllowAdmin\r\n          Priority: 9\r\n          Statement:\r\n            AndStatement:\r\n              Statements:\r\n                - NotStatement:\r\n                    Statement:\r\n                      IPSetReferenceStatement: \r\n                        Arn: !GetAtt AllowedAdminIPSet.Arn\r\n                - ByteMatchStatement:\r\n                    FieldToMatch:\r\n                      UriPath: {}\r\n                    SearchString: \"\/admin\"\r\n                    PositionalConstraint: \"STARTS_WITH\"\r\n                    TextTransformations:\r\n                      - Priority: 0\r\n                        Type: NONE\n... \n AllowedAdminIPSet:\r\n    Type: AWS::WAFv2::IPSet\r\n    Properties:\r\n      Description: AdminIPSet\r\n      Name: AdminIPSet\r\n      Scope: REGIONAL\r\n      IPAddressVersion: IPV4\r\n      Addresses:\n        - 1.2.3.4\n        - 5.6.7.8<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The IP Set contains the IPv4 or IPv6 addresses you will allow access to the administrative interface from, if a client attempts to connect to the administrative interface and their source IP address is not one of those listed, the connection is blocked. You&#8217;ll notice that the IPSetReferencesStatement uses the !GetAtt function to query the AllowedAdminIPSet object for its ARN, you can&#8217;t just use a !Ref in this case, it must refer to the ARN of the IP Set to work.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a rel=\"noreferrer noopener\" href=\"https:\/\/unsplash.com\/@billy_huy\" data-type=\"URL\" data-id=\"https:\/\/unsplash.com\/@billy_huy\" target=\"_blank\">Image Attribution<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are using the AWS Web Application Firewall (WAF) on your Application Load Balancer or other supported AWS entity, you probably don&#8217;t want any administrative interfaces of the web application presented directly to the Internet without some form of restriction; perhaps to a range of IPv4 addresses you want to restrict. Adding a rule &#8230; <a title=\"Block Admin Page Using AWS WAF Example\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=3737\" aria-label=\"Read more about Block Admin Page Using AWS WAF Example\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":3734,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,3],"tags":[],"class_list":["post-3737","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","category-cloud"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3737"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3737\/revisions"}],"predecessor-version":[{"id":3738,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3737\/revisions\/3738"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/media\/3734"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}