Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow puma/systemd deployment #1883

Merged
merged 4 commits into from
Sep 6, 2023
Merged

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Sep 4, 2023

No description provided.

@evgeni
Copy link
Member Author

evgeni commented Sep 4, 2023

I guess something is incompatible with systemd 5.x 😿

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

For unix sockets: we did find it was needed to set the hostname: https://github.com/theforeman/puppet-foreman/blob/af5dbe295525aa375c1ecc15225a40e95ef36053/manifests/config/apache.pp#L132

That part is what it supposedly connected to. https://stackoverflow.com/questions/51243332/apache-proxy-pass-to-unix-domain-socket/73741715#73741715 uses %{HTTP_HOST} which may actually be better than what we do.

So changing the proxy_pass url to `unix:///path/to/socket|http://

$apache_backend_config = {
'proxy_preserve_host' => true,
'proxy_add_headers' => true,
'request_headers' => ['set X_FORWARDED_PROTO "https"'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Foreman we also unset SSL client cert parameters. Is that not needed here because Redmine ignores those?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was my assumption, nothing uses client auth here, so no need to unset.

@evgeni evgeni force-pushed the redmine-move branch 4 times, most recently from d218598 to 5672c3f Compare September 5, 2023 09:39
@evgeni evgeni marked this pull request as ready for review September 5, 2023 09:59
@evgeni
Copy link
Member Author

evgeni commented Sep 5, 2023

Two TODOs for the future (will become issues in this repo once this PR is merged):

@ekohl
Copy link
Member

ekohl commented Sep 5, 2023

  • switch to a unix socket (this will require some selinux mangling, as the socket by default is created as var_run_t and Apache can't write to that, so we'll need to make it be created as httpd_var_run_t)

There's this context:

/var/run/apache.*                                  all files          system_u:object_r:httpd_var_run_t:s0 

So would using /run/apache.redmine.sock automatically get the correct context? Manual way suggests it would:

# touch /var/run/apache.redmine.sock
# ls -lZ /var/run/apache.redmine.sock
-rw-r--r--. 1 root root unconfined_u:object_r:var_run_t:s0 0 Sep  5 12:41 /var/run/apache.redmine.sock

@evgeni
Copy link
Member Author

evgeni commented Sep 6, 2023

type=AVC msg=audit(1693980504.181:4437): avc:  denied  { connectto } for  pid=62541 comm="httpd" path="/run/apache-redmine.sock" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:unconfined_service_t:s0 tclass=unix_stream_socket permissive=0

Too damn smart this thing is.

The socket is owned correctly:

# ls -alhZ /run/apache-redmine.sock 
srw-------. 1 apache apache system_u:object_r:httpd_var_run_t:s0 0 Sep  6 06:08 /run/apache-redmine.sock

But the service is running as unconfined_service_t and thus denied by SELinux:

[root@redmine ~]# ps auxZ |grep puma
system_u:system_r:unconfined_service_t:s0 redmine 62615 3.3  8.4 555808 170152 ? Ssl  06:10   0:02 puma 6.3.1 (unix:///run/apache-redmine.sock) [redmine]
system_u:system_r:unconfined_service_t:s0 redmine 62621 0.1  8.6 758724 173848 ? Sl   06:10   0:00 puma: cluster worker 0: 62615 [redmine]
system_u:system_r:unconfined_service_t:s0 redmine 62622 0.0  8.1 623492 162284 ? Sl   06:10   0:00 puma: cluster worker 1: 62615 [redmine]

@ekohl
Copy link
Member

ekohl commented Sep 6, 2023

I think that's what SELinuxContext= is for. Quoting man systemd.exec:

       SELinuxContext=
           Set the SELinux security context of the executed process. If set, this will override the automated domain transition. However, the policy still needs to authorize the
           transition. This directive is ignored if SELinux is disabled. If prefixed by "-", failing to set the SELinux security context will be ignored, but it's still possible
           that the subsequent execve() may fail if the policy doesn't allow the transition for the non-overridden context. This does not affect commands prefixed with "+". See
           setexeccon(3) for details.

The question is then: which domain would make sense.

@evgeni
Copy link
Member Author

evgeni commented Sep 6, 2023

The question is then: which domain would make sense.

Yeah, and this is something I'd prefer to think about another day ;)

@ekohl
Copy link
Member

ekohl commented Sep 6, 2023

I'd be good with an issue that summarizes the information about using a unix socket instead of TCP.

@evgeni
Copy link
Member Author

evgeni commented Sep 6, 2023

Opened #1885 and #1886 for the follow ups

@evgeni evgeni merged commit 5f7b714 into theforeman:master Sep 6, 2023
2 checks passed
@evgeni evgeni deleted the redmine-move branch September 6, 2023 11:35
@evgeni evgeni added this to the redmine migration milestone Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants