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

Move nginx config to /etc/nginx/dokku.d #3443

Open
josegonzalez opened this issue Feb 14, 2019 · 6 comments
Open

Move nginx config to /etc/nginx/dokku.d #3443

josegonzalez opened this issue Feb 14, 2019 · 6 comments

Comments

@josegonzalez
Copy link
Member

josegonzalez commented Feb 14, 2019

When SELinux is in use, nginx cannot read nginx.conf files in /home/dokku/*/dokku.conf. This causes routing issues, resulting in a terrible experience for our users.

We should:

  • On install, update the /etc/nginx/conf.d/dokku.conf file to add include /etc/nginx/dokku.d/*.conf and include /etc/nginx/dokku.d/*/*.conf.
  • On nginx config build, delete the path at /home/dokku/APP/nginx.conf and create the new file in /etc/nginx/dokku.d/APP.conf.
  • Modify the generated nginx.conf to include /etc/nginx/dokku.d/APP/*.conf.
  • Update the dokku-letsencrypt and dokku-redirect to handle both cases.
  • Provide a helper method for presenting where the current nginx config file is.
  • Add an nginx:show-conf APP command that shows the current app config.

Marking as a bug as compatibility with SELinux systems is completely broken without this.

@josegonzalez
Copy link
Member Author

Note: this is a some-what BC incompatible change, due to where files get included from. We'll include both paths but warn users to move their files to the new path during a deploy.

@rbclark
Copy link

rbclark commented Feb 19, 2020

In addition to the nginx config, the location of the TLS certificates also seems to be an issue with SELinux. I ended up having to install letsencrypt and run audit2allow -a -M dokku and then semodule -i dokku.pp.

I believe the relevant policies are:

#!!!! This avc is allowed in the current policy
allow httpd_t user_home_dir_t:dir read;

#!!!! This avc can be allowed using the boolean 'httpd_read_user_content'
allow httpd_t user_home_t:dir read;

#!!!! This avc can be allowed using the boolean 'httpd_read_user_content'
allow httpd_t user_home_t:file { open read };

@josegonzalez
Copy link
Member Author

josegonzalez commented Feb 19, 2020

Is there a way to ship that with Dokku somehow? If so, that would resolve our SELinux issues and be an alternative to moving files into the correct place...

@rbclark
Copy link

rbclark commented Feb 19, 2020

Yeah that should be possible, it would be best to avoid providing full access to the whole home directory though, I have found 2 commands that seem to setup permissions correctly where nginx can still read them.

/usr/sbin/semanage fcontext -a -t httpd_sys_content_t "/home/dokku(/[^\.].*)?"
/sbin/restorecon -R /home/dokku

Based on the information provided at https://fedoraproject.org/wiki/PackagingDrafts/SELinux#File_contexts the easiest way to do this following in the RPM spec:

Requires(post): policycoreutils-python
Requires(postun): policycoreutils-python

...

%post
semanage fcontext -a -t httpd_sys_content_t "/home/dokku(/[^\.].*)?" 2>/dev/null || :
restorecon -R /home/dokku || :

%postun
if [ $1 -eq 0 ] ; then  # final removal
semanage fcontext -d -t httpd_sys_content_t "/home/dokku(/[^\.].*)?" 2>/dev/null || :
fi

The only disadvantage to this is it adds a dependency on policycoreutils-python which isn't necessary for people who are not using SELinux.

@josegonzalez
Copy link
Member Author

Thats annoying, and might be OS-specific. May as well fix the underlying issue in that case...

@josegonzalez josegonzalez added this to the v1.0.0 milestone Jun 17, 2020
@josegonzalez josegonzalez added this to Scheduled for future release in Release Board Dec 2, 2020
@josegonzalez josegonzalez moved this from Scheduled for future release to Backlog in Release Board Dec 2, 2020
@josegonzalez
Copy link
Member Author

Updating this to be an enhancement, as we never purported to work with SELinux (though you can now with an alternative proxy implementation like openresty).

@josegonzalez josegonzalez modified the milestones: v1.0.0, v0.34.0 Oct 16, 2023
@josegonzalez josegonzalez added the estimate: 8h Estimated time: 8 hours label Jan 30, 2024
@josegonzalez josegonzalez modified the milestones: v0.34.0, v0.35.0 Mar 13, 2024
@josegonzalez josegonzalez modified the milestones: v0.35.0, v0.36.0 Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants