Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/10-configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,24 @@ image:
memory_limit: {memroy_limit_value}
...
```


## Checking the deployed build

Every application endpoint serves `/build.json` (from the frontend container) and `/build.php` (from the application container). They return the deployed build hash and build timestamp:

```json
{"self":"application","build":"{build_hash}","stamp":"{build_timestamp}"}
```

The endpoints need no configuration and are not public. They respond only to requests that did not pass through a public network: the client address, every `X-Forwarded-For` entry, and `X-Real-IP` must be private (`127.0.0.0/8`, `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`). Such requests skip the endpoint's `auth:`. All other requests are rejected with `403`, even with valid basic auth credentials.

* Locally, open `http://{endpoint host}/build.json` or `http://{endpoint host}/build.php` in a browser or run `curl` against it.
* In AWS, send the request from inside the VPC directly to the frontend, for example, from the frontend container:

```bash
curl -s -H 'Host: {endpoint host}' http://127.0.0.1/build.json
curl -s -H 'Host: {endpoint host}' http://127.0.0.1/build.php
```

Requests to the public endpoint URL, including the ones sent from AWS through the NAT gateway, are rejected.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ geo $is_whitelisted_ip {
{% endif %}
}

{% include "nginx/modules/build-info.http.conf.twig" %}

{% if _realIpTrusted is not empty %}
{% include "nginx/modules/real-ip.http.conf.twig" with {
realIpConfigs: _realIpTrusted,
Expand Down
16 changes: 16 additions & 0 deletions generator/src/templates/nginx/http/build.conf.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
{#
Build info is served only to requests that did not pass through a public network,
see nginx/modules/build-info.http.conf.twig. Such requests skip the endpoint's own auth.
#}
location =/build.json {
if ($spryker_build_info_allowed = 0) {
return 403;
}
allow all;
auth_basic off;

root /usr/share/nginx/;
try_files $uri =404;
}

location =/build.php {
if ($spryker_build_info_allowed = 0) {
return 403;
}
allow all;
auth_basic off;

root /home/spryker;
include fastcgi.conf;
{# Variable is necessary for https://www.nginx.com/blog/dns-service-discovery-nginx-plus/#domain-name-upstream-group #}
Expand Down
29 changes: 29 additions & 0 deletions generator/src/templates/nginx/modules/build-info.http.conf.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% set privateIpListRegex = '~^(?:[ ]*(?:127(?:[.][0-9]{1,3}){3}|10(?:[.][0-9]{1,3}){3}|172[.](?:1[6-9]|2[0-9]|3[01])(?:[.][0-9]{1,3}){2}|192[.]168(?:[.][0-9]{1,3}){2})[ ]*(?:,|$))+$' %}
# Build info (/build.json, /build.php) is served only to requests that did not pass through a public network:
# the client address, every X-Forwarded-For entry and X-Real-IP must be private (127/8, 10/8, 172.16/12, 192.168/16).
# Public traffic in AWS comes from the private address of the load balancer, which appends the public client address
# to X-Forwarded-For. Requests from inside the VPC and from the local docker/sdk gateway carry only private addresses.
geo $spryker_build_info_client_is_private {
default 0;
127.0.0.0/8 1;
10.0.0.0/8 1;
172.16.0.0/12 1;
192.168.0.0/16 1;
}

map $http_x_forwarded_for $spryker_build_info_forwarded_for_is_private {
default 0;
"" 1;
"{{ privateIpListRegex | raw }}" 1;
}

map $http_x_real_ip $spryker_build_info_real_ip_is_private {
default 0;
"" 1;
"{{ privateIpListRegex | raw }}" 1;
}

map "$spryker_build_info_client_is_private$spryker_build_info_forwarded_for_is_private$spryker_build_info_real_ip_is_private" $spryker_build_info_allowed {
default 0;
"111" 1;
}
Loading