Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit e414f6f

Browse files
author
Lori Krell
authored
Merge pull request #1180 from magento/lk_cloud-fastly-codefix
Update Fastly VCL code sample
2 parents d8d9910 + 5bce7ee commit e414f6f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

guides/v2.0/cloud/configure/cloud-vcl-custom-snippets.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,25 @@ The curl command would look like the following:
214214

215215
[Validate and activate](#validate) the version to activate the snippet.
216216

217-
### Create a whitelist VCL {#block-ip}
217+
### Create a whitelist VCL {#whitelist-ip}
218218
You may want to create a whitelist of IPs to allow accessing your Magento Admin console. You can create an Edge ACL list of the whitelisted IPs with a VCL snippet. The code checks the IP of the incoming IP address. If it matches a member of the ACL, it is allowed access. All other IPs receive a 403 Forbidden error.
219219

220220
Of note for this snippet, you want to set the priority to 5 to immediately run and check for whitelisted IPs. This priority runs the snippet immediately and before any of the uploaded and default Magento VCL snippets (magentomodule) that have a priority of 50. The name for the Edge ACL is also `whitelist`. If the domain matches the dictionary, it is allowed access to a path of `/admin`. If you changed your Magento Admin path, use that value in this code example.
221221

222+
In the code sample, the condition `!req.http.Fastly-FF` is important when using Origin Shielding.
223+
222224
* Name: `whitelist_admin`
223225
* Type: `recv`, puts the code in the subroutine vcl_recv
224226
* Priority: 5
225227
* Content:
226228

227-
if (req.url ~ "^/admin" && ! (client.ip ~ whitelist)) {
229+
if ((req.url ~ "^/admin") && !(client.ip ~ whitelist) && !req.http.Fastly-FF) {
228230
error 403 "Forbidden";
229231
}
230232

231233
The curl command would look like the following:
232234

233-
curl -H "Fastly-Key: {FASTLY_API_TOKEN}" -H 'Content-Type: application/json' -H "Accept: application/json" -X POST https://api.fastly.com/service/{Service ID}/version/{Editable Version #}/snippet -d '{"name": "block_bad_ips", "type": "recv", "dynamic": 0, "priority": 5, "content": "if (req.url ~ "^/admin" && ! (client.ip ~ whitelist)) { error 403 "Forbidden"; }"}
235+
curl -H "Fastly-Key: {FASTLY_API_TOKEN}" -H 'Content-Type: application/json' -H "Accept: application/json" -X POST https://api.fastly.com/service/{Service ID}/version/{Editable Version #}/snippet -d '{"name": "block_bad_ips", "type": "recv", "dynamic": 0, "priority": 5, "content": "if ((req.url ~ "^/admin") && !(client.ip ~ whitelist) && !req.http.Fastly-FF) { error 403 "Forbidden"; }"}
234236

235237
[Validate and activate](#validate) the version to activate the snippet.
236238

0 commit comments

Comments
 (0)