Use unix sockets for httpd -> Foreman and Pulp communication - #608
Conversation
ekohl
left a comment
There was a problem hiding this comment.
theforeman/puppet-pulpcore@04b9f5f may be an interesting reference.
048911f to
fd2c6c5
Compare
fd2c6c5 to
c98e2bd
Compare
|
I've rebased this now that #634 is merged, to be able to debug what's happening in the external proxy test case. |
|
Looks like Apache sends the literal |
|
@Gauravtalreja1 #608 was merged. Can you please rebase it to resolve the merge conflicts? |
|
#471 was merged, so if we rebase here and fix the hostnames, we should see if things work properly |
c98e2bd to
4622485
Compare
4622485 to
71b363f
Compare
As I understand it, there are other ways to solve this issue. Can you expand on why we want to go with the unix socket solution? Are there other things that this choice solves or provides? I am not opposed to the change, but I would find it helpful to capture more about this choice in the pull request description and in our documentation given this is an explicit design choice we want to have / enforce. |
- Add missing `when` guard for daemons_enable_cluster_mode so it doesn't fail on systems with SELinux disabled - Remove httpd_can_network_connect boolean — no longer needed since all backends (Foreman, Pulp API, Pulp Content) now use unix sockets instead of TCP - Remove uncertain TODO comment — the boolean works with /run/httpd.* socket paths that get httpd_var_run_t context Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
Same approach as Foreman: replace TCP proxy backends with unix sockets to eliminate IPv4/IPv6 address mismatch on IPv6-only hosts. - Add systemd socket units for pulp-api and pulp-content - Override container commands to bind Gunicorn to unix sockets at /run/httpd.pulp-api.sock and /run/httpd.pulp-content.sock - Mount /run into Pulp containers for socket file visibility - Update httpd backend defaults in base.yaml - Update tests to verify socket connectivity instead of TCP ports Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
- Use systemd socket activation for Pulp instead of --bind, remove /run volume mount (fd passing, not file access)
- Add pulp-api.socket and pulp-content.socket templates
- Match upstream foreman.socket: NoDelay=true (Puma default),
and, Backlog=4294967295 (default on EL10/v254+, needed for EL9/v252)
- Rebased and replaced %{HTTP_HOST} with static hostnames (foreman, pulpcore-api, pulpcore-content)
Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
71b363f to
1d354a8
Compare
WalkthroughThis change introduces systemd socket units for Foreman, Pulp API, and Pulp Content services, deployed via new Ansible templates and tasks, and adds explicit Requires dependencies in their container quadlet units. New listen-stream variables define UNIX socket paths, and httpd backend variables are derived from them in base vars. The httpd role's SELinux boolean configuration is updated to replace network-connect permission with cluster-mode and conditional network-relay permissions. Tests for Foreman and Pulp are updated to verify UNIX socket connectivity instead of TCP port reachability. Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@ehelms Good point, I've updated the PR description with the design rationale (with what I understand) for choosing unix sockets over binding to 127.0.0.1/localhost. |
|
I bet this is some cross play with #471 - but that test was green there, so it's something about the sockets 🙈 logs on the proxy say: I see no requests reaching the quadlet box. I think you need to put back that httpd network selinux boolean |
On proxy hosts, httpd reverse proxies /rhsm and other paths to the remote Foreman server over HTTPS. With unix sockets replacing httpd_can_network_connect, this outbound access was blocked by SELinux. Use httpd_can_network_relay instead of httpd_can_network_connect as it only allows connections to http_port_t ports (80, 443), following the principle of least privilege. Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/roles/pulp/tasks/main.yaml`:
- Around line 95-100: Both socket template tasks are missing restart
notifications, so changes to the unit files won’t restart already-running
sockets. Update the `Deploy Pulp API socket` and `Deploy Pulp Content socket`
tasks in `main.yaml` to notify dedicated handlers that restart `pulp-api.socket`
and `pulp-content.socket`, and place those handlers so they run before the
container restart handlers. This ensures template changes are applied
idempotently and the containers get a fresh socket file descriptor after any
socket unit update.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9c7415f2-e9c1-4b13-9b31-c7de5b013c88
📒 Files selected for processing (11)
src/roles/foreman/defaults/main.yamlsrc/roles/foreman/tasks/main.yamlsrc/roles/foreman/templates/foreman.socket.j2src/roles/httpd/tasks/main.ymlsrc/roles/pulp/defaults/main.yamlsrc/roles/pulp/tasks/main.yamlsrc/roles/pulp/templates/pulp-api.socket.j2src/roles/pulp/templates/pulp-content.socket.j2src/vars/base.yamltests/foreman_test.pytests/pulp_test.py
Ensure socket units restart on re-deploy when their templates are modified, so changes to ListenStream, Backlog, or other socket options take effect without a manual restart. Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
|
PRT Result |
|
PRT Result |
|
PRT fails with Edit: oooh, it used a v6 machine, but that probably can't reach quay.io… |
|
PRT Result |
ekohl
left a comment
There was a problem hiding this comment.
Thanks for taking this across the finish line.
|
Thanks everyone! |
Why are you introducing these changes? (Problem description, related links)
On hosts without IPv4 (IPv6-only), Apache resolves
localhostto::1but Puma/Gunicorn only listen on127.0.0.1, causing connection refused errors:This affects all three httpd backends: Foreman (port 3000), Pulp API (port 24817), and Pulp Content (port 24816).
Builds on the work started by @ekohl in #118 and #593. In foreman-installer, using a unix socket had reliability benefits, this brings the same approach to foremanctl.
Why unix sockets instead of binding to
127.0.0.1explicitly:SocketUser/SocketModeRequires=What are the changes introduced in this pull request?
Foreman (cherry-picked from #593, authored by @ekohl):
/run/httpd.foreman.sockSELinux fixes (on top of #593):
whenguard fordaemons_enable_cluster_modebooleanhttpd_can_network_connect, no longer needed with all backends on unix socketsPulp:
/run/httpd.pulp-api.sock) and Pulp Content (/run/httpd.pulp-content.sock)How to test this pull request
ss -tlnp | grep -E '(3000|24816|24817)'ls -laZ /run/httpd.*.sockcurl -k https://$(hostname -f)/pulp/api/v3/status/Steps to reproduce:
Checklist