[DOC] Add some hints to enable gitea on selinux/Ubuntu/Fedora #4788

Open
opened 2025-11-02 06:02:52 -06:00 by GiteaMirror · 13 comments
Owner

Originally created by @guillep2k on GitHub (Feb 4, 2020).

Users that attempt to install Gitea from binary on Fedora/Ubuntu/etc. may encounter several problems due to selinux. I'm not an expert on that, but I think we should add a couple of hints to the docs around this scenario.

Notes that might be useful:

(I might do this myself if I ever get time to investigate this setup).

Originally created by @guillep2k on GitHub (Feb 4, 2020). Users that attempt to install Gitea from binary on Fedora/Ubuntu/etc. may encounter several problems due to selinux. I'm not an expert on that, but I think we should add a couple of hints to the docs around this scenario. Notes that might be useful: - [`setcap cap_net_bind_service=+ep /path/to/binary/gitea`](http://manpages.ubuntu.com/manpages/bionic/man8/setcap.8.html) will allow the exact version of gitea's executable to [bind to privileged ports](http://man7.org/linux/man-pages/man7/capabilities.7.html); this permits Gitea to bind directly to 443 without running as root. Upgrading Gitea (i.e. replacing the executable) [will remove this capability](https://askubuntu.com/questions/92699/are-setcap-changes-permanent) and force the admin to run the command again. - There's a [number](https://unix.stackexchange.com/questions/447123/create-a-selinux-policy-for-a-custom-systemd-service) of [considerations](https://access.redhat.com/articles/2191331) for running the service from `systemd` if selinux is active; if we can't provide a full recipe for enabling Gitea, we may leave some pointers about these limitations. (I might do this myself if I ever get time to investigate this setup).
GiteaMirror added the issue/confirmedtype/docs labels 2025-11-02 06:02:52 -06:00
Author
Owner

@bagasme commented on GitHub (Feb 6, 2020):

Disabling selinux for now?

@bagasme commented on GitHub (Feb 6, 2020): Disabling selinux for now?
Author
Owner

@rmbleeker commented on GitHub (Feb 10, 2020):

I've having no issues running Gitea under its own user account on a host with selinux set to enforcing. To bind to ports 80 and 443 set CapabilityBoundingSet=CAP_NET_BIND_SERVICE and AmbientCapabilities=CAP_NET_BIND_SERVICE in the systemd unit file, they are commented out in the example unit file.
Other than that I'm running from a directory in /opt and haven't even looked at the selinux security contexts on the files in that directory.

@rmbleeker commented on GitHub (Feb 10, 2020): I've having no issues running Gitea under its own user account on a host with selinux set to enforcing. To bind to ports 80 and 443 set `CapabilityBoundingSet=CAP_NET_BIND_SERVICE` and `AmbientCapabilities=CAP_NET_BIND_SERVICE` in the systemd unit file, they are commented out in the [example unit file](../blob/master/contrib/systemd/gitea.service). Other than that I'm running from a directory in `/opt` and haven't even looked at the selinux security contexts on the files in that directory.
Author
Owner

@stale[bot] commented on GitHub (Apr 11, 2020):

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale[bot] commented on GitHub (Apr 11, 2020): This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.
Author
Owner

@stale[bot] commented on GitHub (Apr 25, 2020):

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale[bot] commented on GitHub (Apr 25, 2020): This issue has been automatically closed because of inactivity. You can re-open it if needed.
Author
Owner

@vwbusguy commented on GitHub (Jul 20, 2021):

I would really appreciate this. It's the worst game of whack a mole on CentOS 8.

@vwbusguy commented on GitHub (Jul 20, 2021): I would really appreciate this. It's the worst game of whack a mole on CentOS 8.
Author
Owner

@zeripath commented on GitHub (Jul 20, 2021):

The problem is someone needs to play that game of whackamole and write the documentation for us...

So if you have just done this - please consider documenting what you needed to do.

@zeripath commented on GitHub (Jul 20, 2021): The problem is someone needs to play that game of whackamole and write the documentation for us... So if you have just done this - please consider documenting what you needed to do.
Author
Owner

@vwbusguy commented on GitHub (Jul 20, 2021):

I would if setroubleshoot gave meaningful things and not touch /.autorelabel and ausearch -c 'gitea' --raw | audit2allow -M my-gitea && semodule -X 300 -i my-gitea.pp

I simply don't have the time to sort through all of that, sadly, especially if it's complicated enough that setroubleshoot isn't going to even give more meaningful hints.

I think that running restorecon on the binary and recursively on the gitea data path may have solved part of it.

@vwbusguy commented on GitHub (Jul 20, 2021): I would if setroubleshoot gave meaningful things and not `touch /.autorelabel` and `ausearch -c 'gitea' --raw | audit2allow -M my-gitea && semodule -X 300 -i my-gitea.pp` I simply don't have the time to sort through all of that, sadly, especially if it's complicated enough that setroubleshoot isn't going to even give more meaningful hints. I think that running `restorecon` on the binary and recursively on the gitea data path may have solved part of it.
Author
Owner

@rmbleeker commented on GitHub (Jul 21, 2021):

@vwbusguy can you perhaps elaborate a little more on what parts of Gitea are not working for you due to selinux? As I've stated before in this issue, I'm running Gitea on a RHEL7 host with selinux set to enforcing and have not run into any issues.

I have an Ansible role that I use for the installation and configuration of Gitea but it's also based around RHEL7 so I'm not sure if that would be of any help to you.

@rmbleeker commented on GitHub (Jul 21, 2021): @vwbusguy can you perhaps elaborate a little more on what parts of Gitea are not working for you due to selinux? As I've stated before in this issue, I'm running Gitea on a RHEL7 host with selinux set to `enforcing` and have not run into any issues. I have an Ansible role that I use for the installation and configuration of Gitea but it's also based around RHEL7 so I'm not sure if that would be of any help to you.
Author
Owner

@vwbusguy commented on GitHub (Jul 23, 2021):

It seems the biggest issue is proper labelling for the data directory/binary for file system writes. I doubt the SELInux policy would be any different between EL7 and EL8 for Gitea.

@vwbusguy commented on GitHub (Jul 23, 2021): It seems the biggest issue is proper labelling for the data directory/binary for file system writes. I doubt the SELInux policy would be any different between EL7 and EL8 for Gitea.
Author
Owner

@vwbusguy commented on GitHub (Sep 4, 2021):

I think I've figured out an SELinux policy that works, though it could be more granular. I suspect much of my problem may have been that I'm running the data directory in an alternative path where others are likely using /var/lib, etc.

But these two things fixed most (maybe all?) of the issues for me:

  • The executable binary should be labeled as "bin_t" (Ie: chcon -v -t bin_t gitea-1.15.2-linux-amd64)
  • The gitea data location should be labelled var_lib_t (In my case: chcon -Rv -t var_lib_t /local/gitea/)
@vwbusguy commented on GitHub (Sep 4, 2021): I *think* I've figured out an SELinux policy that works, though it could be more granular. I suspect much of my problem may have been that I'm running the data directory in an alternative path where others are likely using /var/lib, etc. But these two things fixed most (maybe all?) of the issues for me: - The executable binary should be labeled as "bin_t" (Ie: `chcon -v -t bin_t gitea-1.15.2-linux-amd64`) - The gitea data location should be labelled var_lib_t (In my case: `chcon -Rv -t var_lib_t /local/gitea/`)
Author
Owner

@sebeaumont commented on GitHub (Jan 30, 2025):

@vwbusguy Thank you indeed for that. Did it make it into any documentation?

@sebeaumont commented on GitHub (Jan 30, 2025): @vwbusguy Thank you indeed for that. Did it make it into any documentation?
Author
Owner

@lunny commented on GitHub (Jan 31, 2025):

Since the documentation has been relocated to https://gitea.com/gitea/docs , this issue should be moved there for further discussion or resolution. The file https://gitea.com/gitea/docs/src/branch/main/docs/installation/from-binary.md should be updated.

@lunny commented on GitHub (Jan 31, 2025): Since the documentation has been relocated to https://gitea.com/gitea/docs , this issue should be moved there for further discussion or resolution. The file https://gitea.com/gitea/docs/src/branch/main/docs/installation/from-binary.md should be updated.
Author
Owner

@Poikilos commented on GitHub (Apr 20, 2025):

Since the documentation has been relocated to https://gitea.com/gitea/docs , this issue should be moved there for further discussion or resolution. The file https://gitea.com/gitea/docs/src/branch/main/docs/installation/from-binary.md should be updated.

Ok, I created the issue selinux no longer allows setcap to let Gitea to run on privileged port such as 80 or 443 #211 on gitea.com/gitea/docs

  • I tried the syntax described at #8065
@Poikilos commented on GitHub (Apr 20, 2025): > Since the documentation has been relocated to https://gitea.com/gitea/docs , this issue should be moved there for further discussion or resolution. The file https://gitea.com/gitea/docs/src/branch/main/docs/installation/from-binary.md should be updated. Ok, I created the issue [selinux no longer allows setcap to let Gitea to run on privileged port such as 80 or 443 #211](https://gitea.com/gitea/docs/issues/211) on gitea.com/gitea/docs - I tried the syntax described at [#8065](https://github.com/go-gitea/gitea/issues/8065#issuecomment-719966331)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4788