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

Commit 588881a

Browse files
authored
Merge branch 'master' into form-component-container
2 parents 8e77e26 + eb13311 commit 588881a

File tree

10 files changed

+276
-50
lines changed

10 files changed

+276
-50
lines changed

src/_data/toc/cloud-guide.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ pages:
270270
url: /cloud/cdn/fastly-vcl-badreferer.html
271271
versionless: true
272272

273-
- label: Secure access to the Magento Admin UI
273+
- label: Custom VCL for IP allow list
274274
url: /cloud/cdn/fastly-vcl-whitelist.html
275275
versionless: true
276276

277-
- label: Custom VCL for blocking
277+
- label: Custom VCL for IP block list
278278
url: /cloud/cdn/fastly-vcl-blocking.html
279279
versionless: true
280280

src/_data/toc/extension-best-practices.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ pages:
6767

6868
- label: Creating an Access Control List (ACL) rule
6969
url: /ext-best-practices/tutorials/create-access-control-list-rule.html
70+
71+
- label: Creating an integration with an external API
72+
url: /ext-best-practices/tutorials/create-integration-with-api.html
73+

src/cloud/cdn/cloud-vcl-custom-snippets.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ You can create and manage custom VCL snippets from the Magento Admin UI or by us
4444

4545
### Example VCL snippet code {#vcl-curl}
4646

47-
The following example shows the custom VCL snippet that filters traffic by client IP address in JSON format.
47+
The following example shows the custom VCL snippet (JSON format) that filters traffic by client IP address:
4848

4949
```json
5050
{
@@ -59,7 +59,7 @@ The following example shows the custom VCL snippet that filters traffic by clien
5959
```
6060

6161
{: .bs-callout-warning}
62-
In this example, the VCL code is formatted as a JSON payload that can be saved to a file and submitted in a Fastly API request. If you submit the VCL code snippet from the Magento Admin UI, or as a JSON string using the Fastly API, you must escape special characters to prevent validation errors. See the example in [Secure the Magento Admin UI]({{ site.baseurl }}/cloud/cdn/fastly-vcl-whitelist.html#vcl).
62+
In this example, the VCL code is formatted as a JSON payload that can be saved to a file and submitted in a Fastly API request. When sending the snippet as JSON for an API request, you must use a backslash to escape special characters in the code to prevent JSON validation errors. See [Using dynamic VCL snippets](https://docs.fastly.com/vcl/vcl-snippets/) in the Fastly VCL documentation. If you submit the VCL snippet from the Magento Admin UI, you do not have to escape special characters.
6363

6464
The VCL logic in the `content` field performs the following actions:
6565

@@ -90,8 +90,7 @@ The *Custom VCL snippets* view shows only the snippets added through the Magento
9090

9191
See the following examples that show how to create and manage custom VCL snippets from the Magento Admin UI:
9292

93-
- [Secure access to the Magento Admin UI]({{ site.baseurl }}/cloud/cdn/fastly-vcl-whitelist.html)
94-
- [Set up redirects to WordPress using Fastly]({{ site.baseurl }}/cloud/cdn/fastly-vcl-wordpress.html)
93+
- [Custom VCL for IP allowlist]({{ site.baseurl }}/cloud/cdn/fastly-vcl-whitelist.html)
9594
- [Block referral spam]({{ site.baseurl }}/cloud/cdn/fastly-vcl-badreferer.html)
9695

9796
## Manage custom VCL snippets using the API
@@ -306,4 +305,4 @@ Use these commands to manage snippets that you added using the Fastly API. If yo
306305
<!-- Link definitions -->
307306

308307
[Manage custom VCL snippets]: {{site.baseurl}}/common/images/cloud/cloud-fastly-edit-snippets.png
309-
{:width="650px"}
308+
{:width="650px"}

src/cloud/cdn/fastly-vcl-badreferer.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ We recommend adding custom VCL configurations to a Staging environment where you
1717

1818
- Configure the {{ site.var.data.ece }} environment for Fastly services. See [Set up Fastly]({{ site.baseurl }}/cloud/cdn/configure-fastly.html).
1919

20-
- Get Admin credentials for your {{ site.data.var.ece }} environment.
20+
- Admin credentials to access the Magento Admin UI for your {{ site.data.var.ece }} environment
2121

22-
- Review your site logs for fake referral URLs and make a list of domains to block.
22+
- Review your site logs for fake referral URLs, and make a list of domains to block.
2323

2424
## Create a referrer block list
2525

@@ -59,43 +59,41 @@ For more information about Edge Dictionaries, see [Creating and using Edge Dicti
5959

6060
## Create a custom VCL snippet to block referrer spam
6161

62-
The following custom VCL snippet code (JSON format) checks incoming requests and blocks requests from any referrer site included in the `referrer_blocklist` edge dictionary.
62+
The following custom VCL snippet code (JSON format) shows the logic to check and block requests. The VCL snippet captures the host of a referrer website into a header, and then compares the host name to the list of URLs in the `referrer_blocklist` dictionary. If the host name matches, the request is blocked with a `403 Forbidden` error.
6363

6464
```json
6565
{
6666
"name": "block_bad_referrer",
6767
"dynamic": "0",
6868
"type": "recv",
6969
"priority": "5",
70-
"content": "set req.http.Referer-Host = regsub(req.http.Referer, \"^https?://?([^:/\\s]+).*$\", \"\\1\"); if (table.lookup(referrer_blocklist, req.http.Referer-Host)) { error 403 \"Forbidden\"; }"
70+
"content": "set req.http.Referer-Host = regsub(req.http.Referer, \"^https?:\/\/?([^:\/s]+).*$\", \"\\1\"); if (table.lookup(referrer_blocklist, req.http.Referer-Host)) { error 403 \"Forbidden\"; }"
7171
}
7272
```
7373

74-
Review the example code and change values as needed:
74+
Before creating a snippet based on this example, review the values to determine whether you need to make any changes:
7575

7676
- `name` — Name for the VCL snippet. For this example, we used `block_bad_referrer`.
7777

7878
- `dynamic` — Value 0 indicates a [regular snippet](https://docs.fastly.com/guides/vcl-snippets/using-regular-vcl-snippets) to upload to the versioned VCL for the Fastly configuration.
7979

80-
- `priority` — Determines when the VCL snippet runs. The priority is `5` to run this snippet code before any of the default Magento VCL snippets (`magentomodule_*`) assigned a priority of 50.
80+
- `priority` — Determines when the VCL snippet runs. The priority is `5` to run this snippet code before any of the default Magento VCL snippets (`magentomodule_*`) assigned a priority of 50. You must set the priority for each custom snippet higher or lower than 50 depending on when you want your snippet to run. Snippets with lower priority numbers run first.
8181

8282
- `type` — Specifies a location to insert the snippet in the VCL version. In this example, the VCL snippet is a `recv` snippet. When the snippet is inserted into the VCL version, it is added to the `vcl_recv` subroutine, below the default Fastly VCL code and above any objects.
8383

8484
- `content` — The snippet of VCL code to run in one line, without line breaks.
8585

86-
In this example, the VCL code logic captures the host of a referrer website into a header, and then compares the host name to the list of URLs in the `referrer_blocklist` dictionary.
86+
After reviewing and updating the code for your environment, use either of the following methods to add the custom VCL snippet to your Fastly service configuration:
8787

88-
If the host name matches, the request is blocked with a `403 Forbidden` error.
88+
- [Add the custom VCL snippet from the Magento Admin](#add-the-custom-vcl-snippet). This method is recommended if you can access the Magento Admin UI. (Requires [Fastly version 1.2.58]({{site.baseurl}}/cloud/cdn/configure-fastly.html#upgrade) or later.)
8989

90-
See the [Fastly VCL reference](https://docs.fastly.com/vcl/reference/) for information about creating Fastly VCL code snippets.
91-
92-
Add the custom VCL snippet to your Fastly service configuration from the Magento Admin UI (requires Fastly module 1.2.58 or later). If you cannot access the Admin UI, save the JSON code example in a file and upload it using the Fastly API. See [Creating a VCL snippet using the Fastly API]({{ site.baseurl }}/cloud/cdn/cloud-vcl-custom-snippets.html(#manage-custom-vcl-snippets-using-the-api).
90+
- Save the JSON code example to a file (for example, `allowlist.json`) and [upload it using the Fastly API]({{site.baseurl}}/cloud/cdn/cloud-vcl-custom-snippets.html#manage-custom-vcl-snippets-using-the-api). Use this method if you cannot access the Magento Admin UI.
9391

9492
## Add the custom VCL snippet
9593

9694
{% include cloud/admin-ui-login-step.md %}
9795

98-
1. Click **Stores** > **Settings** > **Configuration** > **Advanced** > **System**.
96+
1. Click **Stores** > Settings > **Configuration** > **Advanced** > **System**.
9997

10098
1. Expand **Full Page Cache** > **Fastly Configuration** > **Custom VCL Snippets**.
10199

src/cloud/cdn/fastly-vcl-blocking.md

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can use the Fastly CDN module for Magento 2 to create an Edge ACL with a lis
1515
**Prerequisites:**
1616

1717
- List of client IP addresses to block
18-
- Account access and URL for the Magento Admin UI for the Staging or Production environment
18+
- Admin credentials to access the Magento Admin UI for your {{ site.data.var.ece }} environment
1919
- Fastly API credentials for Staging and Production environments
2020

2121
## Create Edge ACL for blocking client IPs {#edge-acl}
@@ -31,16 +31,16 @@ If you want to manage access for both Staging and Production sites, create the E
3131
1. Enter IP address values in the list. Any client IPs added to this list will be blocked access from the site.
3232
1. Optionally, select the **Negated** checkbox if needed.
3333

34-
You will reference the Edge ACL by name in your VCL snippet code.
34+
You reference the Edge ACL by name in your VCL snippet code.
3535

36-
## Create blocklist.json {#vcl}
36+
## Create the custom VCL for the block list {#vcl}
3737

3838
{:.bs-callout-info}
39-
This example shows advanced users how to create custom VCL code snippet to configure blocking rules that can be uploaded to the Fastly service using the Fastly API. You can also configure a blocklist or allowlist from the {{ site.data.var.ee }} Admin UI. See [Blocking](https://github.com/fastly/fastly-magento2/blob/master/Documentation/Guides/BLOCKING.md) in the Fastly CDN for Magento 2 module documentation.
39+
This example shows advanced users how to create a VCL code snippet to configure custom blocking rules that can be uploaded to the Fastly service. You can configure a block list or allow list based on country from the {{ site.data.var.ee }} Admin UI using the [Blocking](https://github.com/fastly/fastly-magento2/blob/master/Documentation/Guides/BLOCKING.md) feature available in the Fastly CDN for Magento 2 module.
4040

4141
After you define the Edge ACL, you can use it to create the VCL snippet to block access to the IP addresses specified in the ACL. You can use the same VCL snippet in both Staging and Production environments, but you must upload the snippet to each environment separately.
4242

43-
Create a `blocklist.json` file with the following VCL code in JSON format:
43+
The following custom VCL snippet code (JSON format) shows the logic to block incoming requests with a client IP address that matches an address in the blocklist ACL.
4444

4545
```json
4646
{
@@ -52,24 +52,62 @@ Create a `blocklist.json` file with the following VCL code in JSON format:
5252
}
5353
```
5454

55-
Review the following parameter values and update your code snippet if necessary:
55+
Before creating a snippet based on this example, review the values to determine whether you need to make any changes:
5656

5757
- `name`: Name for the VCL snippet. For this example, we used the name `blocklist`.
58-
- `priority`: Determines the VCL snippet call order. Set the priority to 5 to immediately run and check for blocked IP addresses. This priority runs before any of the uploaded and default Magento VCL snippets (`magentomodule_`) that have a priority of 50.
58+
59+
- `priority`: Determines when the VCL snippet runs. The priority is `5` to immediately run and check whether a Magento Admin UI requests are coming from an allowed IP address. The snippet runs before any of the default Magento VCL snippets (`magentomodule_*`) assigned a priority of 50. You must set the priority for each custom snippet higher or lower than 50 depending on when you want your snippet to run. Snippets with lower priority numbers run first.
60+
5961
- `type`: Specifies the type of VCL snippet that determines the location of the snippet in the generated VCL code. In this example, we use `recv`, which inserts the VCL code in the `vcl_recv` subroutine, below the boilerplate VCL and above any objects. See the [Fastly VCL snippet reference](https://docs.fastly.com/api/config#api-section-snippet) for the list of snippet types.
62+
6063
- `content`: The snippet of VCL code to run, which checks the client IP address. If the IP is in the Edge ACL, it is blocked from access with a `403 Forbidden` error for the entire website. All other client IP addresses are allowed access.
6164

62-
{:.bs-callout-info}
63-
The default VCL snippets include a prepended name of `magentomodule_` with a priority of 50. **Do not use the `magentomodule_` name** for your custom VCL Snippets. You must also set the priority for each custom snippet higher or lower than 50 depending on when you want your snippet to run. Lower priority numbers execute first.
65+
After reviewing and updating the code for your environment, use either of the following methods to add the custom VCL snippet to your Fastly service configuration:
66+
67+
- [Add the custom VCL snippet from the Magento Admin](#add-the-custom-vcl-snippet). This method is recommended if you can access the Magento Admin UI. (Requires [Fastly version 1.2.58]({{site.baseurl}}/cloud/cdn/configure-fastly.html#upgrade) or later.)
68+
69+
- Save the JSON code example to a file (for example, `blocklist.json`) and [upload it using the Fastly API]({{site.baseurl}}/cloud/cdn/cloud-vcl-custom-snippets.html#manage-custom-vcl-snippets-using-the-api). Use this method if you cannot access the Magento Admin UI.
70+
71+
## Add the custom VCL snippet
72+
73+
{% include cloud/admin-ui-login-step.md %}
74+
75+
1. Click **Stores** > Settings > **Configuration** > **Advanced** > **System**.
76+
77+
1. Expand **Full Page Cache** > **Fastly Configuration** > **Custom VCL Snippets**.
6478

65-
## Finish adding the VCL {#complete}
79+
1. Click **Create Custom Snippet**.
6680

67-
After saving the VCL snippet, add the VCL snippet to the Fastly service configuration. See [Add VCL snippets using the Fastly API]({{ site.baseurl }}/cloud/cdn/cloud-vcl-custom-snippets.html#add-vcl-snippets-using-the-fastly-api).
81+
1. Add the VCL snippet values:
82+
83+
- **Name**`blocklist`
84+
85+
- **Type**`recv`
86+
87+
- **Priority**`5`
88+
89+
- Add the **VCL** snippet content:
90+
91+
```conf
92+
if ( client.ip ~ blocklist) { error 403 "Forbidden"; }
93+
```
94+
95+
1. Click **Create** to generate the VCL snippet file with the name pattern `type_priority_name.vcl`, for example `recv_5_blocklist.vcl`
96+
97+
1. After the page reloads, click **Upload VCL to Fastly** in the *Fastly Configuration* section to add the file to the Fastly service configuration.
98+
99+
1. After the uploads, refresh the cache according to the notification at the top of the page.
100+
101+
Fastly validates the updated version of the VCL code during the upload process. If the validation fails, edit the custom VCL snippet to fix the issue. Then, upload the VCL again.
68102
69103
## Additional VCL examples for blocking requests
70104
71105
The following examples show how to block requests using inline condition statements instead of an ACL list.
72106
107+
{: .bs-callout-warning}
108+
In these examples, the VCL code is formatted as a JSON payload that can be saved to a file and submitted in a Fastly API request. You can submit the [VCL snippet from the Admin UI](#add-the-custom-vcl-snippet), or as a JSON string using the Fastly API. If you use the Fastly API with a JSON string, you must use a backslash to escape special characters to prevent validation errors.
109+
See [Using dynamic VCL snippets](https://docs.fastly.com/vcl/vcl-snippets/) in the Fastly VCL documentation.
110+
73111
### VCL code sample: Block by country code
74112
75113
This example uses the two-character ISO 3166-1 country code for the country associated with the IP address.

0 commit comments

Comments
 (0)