Skip to content

Commit 0d4fd14

Browse files
committed
fix: preserve client IPs for proxied requests
1 parent 384ca52 commit 0d4fd14

7 files changed

Lines changed: 55 additions & 2 deletions

File tree

docs/user/parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ There are multiple use cases from the users perspective that dictate what parame
5858
| `--content-export-path` | Extra file path that Pulp can use for content exports | |
5959
| `--external-authentication={ipa,ipa_with_api}` | Enable configuration for external authentication via IPA for web UI (or webUI and API for `ipa_with_api`), expects the target machine to [be enrolled into FreeIPA/IDM](https://docs.theforeman.org/3.16/Configuring_User_Authentication/index-katello.html#enrolling-foreman-server-in-freeipa-domain) | `--foreman-ipa-authentication`<br/> `--foreman-ipa-authentication-api` |
6060
| `--external-authentication-pam-service` | PAM service used for host-based access control in IPA | `--foreman-pam-service` |
61+
| `--foreman-trusted-proxies` | IP address or CIDR that Foreman trusts for `X-Forwarded-For` (for example a Capsule or load balancer in front of Foreman). May be specified multiple times; values are stored in the installation parameters and merged with `append_unique`. Localhost ranges (`127.0.0.0/8` and `::1`) are always included in Foreman settings. Example: `--foreman-trusted-proxies 10.10.10.20` when a Capsule at that address forwards client requests to Foreman. | `--foreman-trusted-proxies` |
6162

6263
#### Certs
6364

@@ -122,7 +123,6 @@ There are multiple use cases from the users perspective that dictate what parame
122123
| `--foreman-oauth-map-users` | | |
123124
| `--foreman-plugin-remote-execution-cockpit-ensure` | | |
124125
| `--foreman-telemetry-prometheus-enabled` | | |
125-
| `--foreman-trusted-proxies` | | |
126126

127127

128128
## Smart Proxy

src/playbooks/_foreman/metadata.obsah.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ variables:
1414
parameter: --initial-location
1515
foreman_puma_workers:
1616
help: Number of workers for Puma.
17+
foreman_trusted_proxies:
18+
help: >-
19+
IP address or CIDR Foreman should trust for X-Forwarded-For (e.g. Capsule).
20+
Can be specified multiple times. Localhost ranges are always included.
21+
parameter: --foreman-trusted-proxies
22+
action: append_unique
1723

1824
include:
1925
- _server_aliases

src/roles/foreman/templates/settings.yaml.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
- {{ foreman_alias }}
99
{% endfor %}
1010

11+
:trusted_proxies:
12+
- 127.0.0.0/8
13+
- "::1"
14+
{% for proxy in foreman_trusted_proxies %}
15+
- "{{ proxy }}"
16+
{% endfor %}
17+
1118
:ssl_certificate: /etc/foreman/client_cert.pem
1219
:ssl_ca_file: /etc/foreman/katello-default-ca.crt
1320
:ssl_priv_key: /etc/foreman/client_key.pem

src/roles/httpd/templates/foreman-ssl-vhost.conf.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
ProxyPass / {{ httpd_foreman_backend }}/ retry=0 timeout=900 upgrade=websocket
131131
ProxyPassReverse / {{ httpd_foreman_backend }}/
132132
{% else %}
133+
ProxyAddHeaders On
133134
{% if httpd_with_container_gateway %}
134135
## Container Gateway
135136
ProxyPass /v1/ {{ foreman_proxy_url }}/container_gateway/v1/
@@ -139,7 +140,6 @@
139140
ProxyPass /index/ {{ foreman_proxy_url }}/container_gateway/index/
140141
ProxyPassReverse /index/ {{ foreman_proxy_url }}/container_gateway/index/
141142
{% endif %}
142-
143143
ProxyPass /rhsm {{ httpd_foreman_url }}/rhsm disablereuse=on retry=0
144144
ProxyPassReverse /rhsm {{ httpd_foreman_url }}/rhsm
145145
ProxyPass /redhat_access {{ httpd_foreman_url }}/redhat_access disablereuse=on retry=0

src/vars/base.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ foreman_client_certificate: "{{ client_certificate }}"
2424
foreman_plugins: "{{ enabled_features | features_to_foreman_plugins }}"
2525
foreman_name: "{{ ansible_facts['fqdn'] }}"
2626
foreman_url: "https://{{ foreman_name }}"
27+
foreman_trusted_proxies: []
28+
2729

2830
foreman_listen_stream: /run/httpd.foreman.sock
2931
httpd_foreman_backend: "unix://{{ foreman_listen_stream }}|http://foreman"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
import yaml
3+
4+
pytestmark = pytest.mark.feature('katello')
5+
6+
TRUSTED_PROXIES_KEY = ':trusted_proxies'
7+
8+
9+
@pytest.fixture(scope="module")
10+
def foreman_settings_yaml(server):
11+
result = server.run(
12+
"podman secret inspect foreman-settings-yaml "
13+
"--format '{{.SecretData}}' --showsecret"
14+
)
15+
assert result.succeeded, result.stderr
16+
return yaml.safe_load(result.stdout)
17+
18+
19+
def test_foreman_settings_trusted_proxies_include_localhost(foreman_settings_yaml):
20+
trusted = foreman_settings_yaml[TRUSTED_PROXIES_KEY]
21+
assert '127.0.0.0/8' in trusted
22+
assert '::1' in trusted
23+
24+
25+
def test_foreman_settings_trusted_proxies_include_configured_entries(
26+
foreman_settings_yaml, obsah_params,
27+
):
28+
configured = obsah_params.get('foreman_trusted_proxies') or []
29+
trusted = foreman_settings_yaml[TRUSTED_PROXIES_KEY]
30+
for entry in configured:
31+
assert entry in trusted

tests/flavor/foreman-proxy-content/httpd_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ def test_pulpcore_vhost_exists(server):
77
assert conf.is_file
88

99

10+
def test_pulpcore_ssl_proxy_add_headers(server):
11+
conf = server.file("/etc/httpd/conf.d/pulpcore-ssl.conf")
12+
assert conf.exists
13+
assert conf.is_file
14+
assert "ProxyAddHeaders On" in conf.content_string
15+
16+
1017
def test_https_pulp_api_with_client_cert(curl_request):
1118
cmd = curl_request("pulp/api/v3/smart_proxy/v2/features")
1219
assert cmd.succeeded

0 commit comments

Comments
 (0)