Skip to content

Commit 4594d6f

Browse files
JordanSekkypierrecdn
authored andcommitted
Added TRUST_X_FORWARDED_HEADERS environment variable
The release of phpipam 1.6 [introduced a new config.php setting](https://github.com/phpipam/phpipam/releases/tag/v1.6.0) called `$trust_x_forwarded_headers`. This setting is false by default, and breaks integration between this docker image and reverse proxies, as the X_FORWARDED_FOR_* headers are no longer trusted.
1 parent a1a48b6 commit 4594d6f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ RUN cp ${WEB_REPO}/config.dist.php ${WEB_REPO}/config.php && \
6767
-e "s/\['user'\] = 'phpipam'/\['user'\] = getenv(\"MYSQL_ENV_MYSQL_USER\") ?: \"root\"/" \
6868
-e "s/\['name'\] = 'phpipam'/\['name'\] = getenv(\"MYSQL_ENV_MYSQL_DB\") ?: \"phpipam\"/" \
6969
-e "s/\['pass'\] = 'phpipamadmin'/\['pass'\] = getenv(\"MYSQL_ENV_MYSQL_ROOT_PASSWORD\")/" \
70+
-e "s/\$trust_x_forwarded_headers = false/\$trust_x_forwarded_headers = boolval(getenv(\"TRUST_X_FORWARDED_HEADERS\")) ?: false/" \
7071
-e "s/\['port'\] = 3306;/\['port'\] = 3306;\n\n\$password_file = getenv(\"MYSQL_ENV_MYSQL_PASSWORD_FILE\");\nif(file_exists(\$password_file))\n\$db\['pass'\] = preg_replace(\"\/\\\\s+\/\", \"\", file_get_contents(\$password_file));/" \
7172
-e "s/define('BASE', \"\/\")/define('BASE', getenv(\"PHPIPAM_BASE\"))/" \
7273
-e "s/\$gmaps_api_key.*/\$gmaps_api_key = getenv(\"GMAPS_API_KEY\") ?: \"\";/" \

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,17 @@ The secret can be created by running `echo my-secret-pw | docker secret create p
105105
Here is the list of the available environment variables in the phpipam container, pass them to docker using `-e`.
106106
None of them are actually needed to run the container, this is only to tweak the behavior.
107107

108-
| Environment variable | Default value | Description |
109-
| ------------------------------ |:-------------:| --------------------------------------------------------------------------------------------------------:|
110-
| MYSQL_ENV_MYSQL_HOST | mysql | The host used to reach the MySQL instance |
111-
| MYSQL_ENV_MYSQL_USER | root | The user to connect the MySQL instance |
112-
| MYSQL_ENV_MYSQL_ROOT_PASSWORD | (empty) | The MySQL password. Can be set using the Web UI during the first install |
113-
| MYSQL_ENV_MYSQL_DB | phpipam | The name of the MySQL DB to connect to |
114-
| MYSQL_ENV_MYSQL_PASSWORD_FILE | (empty) | A file containing the password (if not using MYSQL_ROOT_PASSWORD) this allows to leverage docker secrets |
115-
| PHPIPAM_BASE | / | The base URI under which phpipam runs. Useful when performing rewrites with a reverse-proxy |
116-
| GMAPS_API_KEY | (empty) | Google Maps API Key, used to display maps of your devices |
117-
| GMAPS_API_GEOCODE_KEY | (empty) | Google Maps Geocode API Key, used to find coordinates from an address/ a location of your device |
108+
| Environment variable | Default value | Description |
109+
| ----------------------------- |:-------------:| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
110+
| MYSQL_ENV_MYSQL_HOST | mysql | The host used to reach the MySQL instance |
111+
| MYSQL_ENV_MYSQL_USER | root | The user to connect the MySQL instance |
112+
| MYSQL_ENV_MYSQL_ROOT_PASSWORD | (empty) | The MySQL password. Can be set using the Web UI during the first install |
113+
| MYSQL_ENV_MYSQL_DB | phpipam | The name of the MySQL DB to connect to |
114+
| MYSQL_ENV_MYSQL_PASSWORD_FILE | (empty) | A file containing the password (if not using MYSQL_ROOT_PASSWORD) this allows to leverage docker secrets |
115+
| PHPIPAM_BASE | / | The base URI under which phpipam runs. Useful when performing rewrites with a reverse-proxy |
116+
| TRUST_X_FORWARDED_HEADERS | false | If operating behind a reverse proxy, set to `true` to accept the following headers: `X_FORWARDED_HOST`, `X_FORWARDED_PORT`, `X_FORWARDED_PROTO`, `X_FORWARDED_SSL`, and `X_FORWARDED_URI` |
117+
| GMAPS_API_KEY | (empty) | Google Maps API Key, used to display maps of your devices |
118+
| GMAPS_API_GEOCODE_KEY | (empty) | Google Maps Geocode API Key, used to find coordinates from an address/ a location of your device |
118119

119120
### Specific integration (HTTPS, multi-host containers, etc.)
120121

0 commit comments

Comments
 (0)