{"id":2267,"date":"2021-04-06T18:21:14","date_gmt":"2021-04-06T15:21:14","guid":{"rendered":"https:\/\/artem.services\/?p=2172"},"modified":"2022-06-08T21:06:14","modified_gmt":"2022-06-08T18:06:14","slug":"2267","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=2267&lang=en","title":{"rendered":"\u00a0AWS &#8212; S3: Allow public access to objects over VPN"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-214\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo.png\" alt=\"\" width=\"975\" height=\"450\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo.png 975w, https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo-300x138.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo-768x354.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo-954x440.png 954w\" sizes=\"(max-width: 975px) 100vw, 975px\" \/><\/p>\n<h3>Goal:<\/h3>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"2\"><span class=\"Q4iAWc\">Allow public read access for all objects in the <strong>S3<\/strong> bucket only using a <strong>VPN<\/strong> connection, objects must be non-public to connect from the world.<\/span><\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"1\" data-number-of-phrases=\"2\"><span class=\"Q4iAWc\"><strong>OpenVPN<\/strong> is used as a <strong>VPN<\/strong> service, which can be deployed anywhere, so we will build an allow a rule to check the <strong>IP<\/strong> address.<\/span><\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"2\"><span class=\"Q4iAWc\">First you need to find out the list of networks that belong to the endpoints of the S3 service in the region we need, so as not to wrap all traffic through the VPN.<\/span><\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"1\" data-number-of-phrases=\"2\"><span class=\"Q4iAWc\">To do this, download <a href=\"https:\/\/ip-ranges.amazonaws.com\/ip-ranges.json\" target=\"_blank\" rel=\"noopener\">the current list of networks<\/a> and parse it:<\/span><\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\njq &#039;.prefixes[] | select(.region==&quot;eu-central-1&quot;) | select(.service==&quot;S3&quot;) | .ip_prefix&#039; &lt; ip-ranges.json\r\n<\/pre>\n<p>&nbsp;<\/p>\n<blockquote><p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Where, &quot;<strong>eu-central-1<\/strong>&quot; is the region where the necessary S3 bucket is located.<\/span><\/span><\/span><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">You should get an output like:<\/span><\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&quot;52.219.170.0\/23&quot;\r\n&quot;52.219.168.0\/24&quot;\r\n&quot;3.5.136.0\/22&quot;\r\n&quot;52.219.72.0\/22&quot;\r\n&quot;52.219.44.0\/22&quot;\r\n&quot;52.219.169.0\/24&quot;\r\n&quot;52.219.140.0\/24&quot;\r\n&quot;54.231.192.0\/20&quot;\r\n&quot;3.5.134.0\/23&quot;\r\n&quot;3.65.246.0\/28&quot;\r\n&quot;3.65.246.16\/28&quot;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Now we translate the subnet mask into a 4-byte format and add the parameters to the <strong>OpenVPN<\/strong> server configuration as &quot;<strong>push<\/strong>&quot; parameters:<\/span><\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npush &quot;route 52.219.170.0 255.255.254.0&quot;\r\npush &quot;route 52.219.168.0 255.255.255.0&quot;\r\npush &quot;route 3.5.136.0 255.255.252.0&quot;\r\npush &quot;route 52.219.72.0 255.255.252.0&quot;\r\npush &quot;route 52.219.44.0 255.255.252.0&quot;\r\npush &quot;route 52.219.169.0 255.255.255.0&quot;\r\npush &quot;route 52.219.140.0 255.255.255.0&quot;\r\npush &quot;route 54.231.192.0 255.255.240.0&quot;\r\npush &quot;route 3.5.134.0 255.255.254.0&quot;\r\npush &quot;route 3.65.246.0 255.255.255.240&quot;\r\npush &quot;route 3.65.246.16 255.255.255.240&quot;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">We restart the <strong>OpenVPN<\/strong> server service and after reconnecting we should get a list of required networks and traffic that will go through the <strong>VPN<\/strong> connection.<\/span><\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Now it remains to add the following policy to the <strong>S3<\/strong> bucket:<\/span><\/span><\/span><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n{\r\n    &quot;Version&quot;: &quot;2012-10-17&quot;,\r\n    &quot;Statement&quot;: [\r\n        {\r\n            &quot;Sid&quot;: &quot;Allow only from VPN&quot;,\r\n            &quot;Effect&quot;: &quot;Allow&quot;,\r\n            &quot;Principal&quot;: &quot;*&quot;,\r\n            &quot;Action&quot;: [\r\n                &quot;s3:GetObject&quot;,\r\n                &quot;s3:ListBucket&quot;\r\n            ],\r\n            &quot;Resource&quot;: [\r\n                &quot;arn:aws:s3:::artem-services&quot;,\r\n                &quot;arn:aws:s3:::artem-services\/*&quot;\r\n            ],\r\n            &quot;Condition&quot;: {\r\n                &quot;IpAddress&quot;: {\r\n                    &quot;aws:SourceIp&quot;: &quot;1.2.3.4&quot;\r\n                }\r\n            }\r\n        }\r\n    ]\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<blockquote><p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">Where, &quot;<strong>artem-services<\/strong>&quot; is the name of the <strong>S3<\/strong> bucket and &quot;<strong>1.2.3.4<\/strong>&quot; is the <strong>IP<\/strong> address of the <strong>OpenVPN<\/strong> server.<\/span><\/span><\/span><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Goal: Allow public read access for all objects in the S3 bucket only using a VPN connection, objects must be non-public to connect from the world. OpenVPN is used as a VPN service, which can be deployed anywhere, so we will build an allow a rule to check the IP address. &nbsp; First you need &hellip; <a href=\"https:\/\/artem.services\/?p=2267&#038;lang=en\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c<span class=\"screen-reader-text\"> &quot;\u00a0AWS &#8212; S3: Allow public access to objects over VPN&quot;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[599],"tags":[543,1337,483,1843],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2267"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2267"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2267\/revisions"}],"predecessor-version":[{"id":2269,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2267\/revisions\/2269"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}