Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.

Bug 1375369

Summary: Onionservice are broken
Product: [Fedora] Fedora Reporter: Michael Scherer <misc>
Component: torAssignee: Jamie Nguyen <jamielinux>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 24CC: fedora, hp, jamielinux, lewk, limburgher, peter.meier, psppsn96, pwouters, s
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: tor-0.2.8.8-1.fc24 tor-0.2.8.8-1.fc25 tor-0.2.8.8-1.fc23 tor-0.2.8.8-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-08 13:19:04 EDT Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Attachments:
Description Flags
Fix the issue on F24 and EPEL7 none

Description Michael Scherer 2016-09-12 17:27:12 EDT
Description of problem:

after updating to tor-0.2.8.7-1.fc24.x86_64, I found out that tor refuse to start if I have a HiddenService defined:

Sep 12 23:18:30.884 [notice] Tor v0.2.8.7 running on Linux with Libevent 2.0.21-stable, OpenSSL 1.0.2h-fips and Zlib 1.2.8.
Sep 12 23:18:30.884 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Sep 12 23:18:30.884 [notice] Read configuration file "/usr/share/tor/defaults-torrc".
Sep 12 23:18:30.885 [notice] Read configuration file "/etc/tor/torrc".
Sep 12 23:18:30.889 [warn] Directory /var/lib/tor/ssh_service/ cannot be read: Permission denied
Sep 12 23:18:30.889 [warn] Failed to parse/validate config: Failed to configure rendezvous options. See logs for details.
Sep 12 23:18:30.889 [err] Reading config failed--see warnings above.
tor.service: Control process exited, code=exited status=1

The relelvent part of the config is 

HiddenServiceDir /var/lib/tor/hidden_service_ssh
HiddenServicePort 22 127.0.0.1:22

At first, i supposed this was a local issue, but I can reproduce on another computer. I put selinux in permissive and that's not the issue.
Starting tor manually work, and config is seen as ok.

So I suspect something in the service file.
Comment 1 Michael Scherer 2016-09-12 18:40:59 EDT
So, after searching, the issue is caused by "CapabilityBoundingSet=CAP_SETUID CAP_SETGID CAP_NET_BIND_SERVICE".

I guess one caps is missing, not sure which one.
Comment 2 Michael Scherer 2016-09-12 19:03:25 EDT
So, i found that the cap missing is CAP_DAC_READ_SEARCH.
Comment 3 Hein-Pieter van Braam 2016-09-15 15:38:11 EDT
This does not appear to be the only cap missing, if I add the following drop-in file it still does not work:

# cat /etc/systemd/system/tor.conf.d/fix-caps.conf
[Service]
CapabilityBoundingSet=CAP_SETUID CAP_SETGID CAP_NET_BIND_SERVICE CAP_DAC_READ_SEARCH

I have now copied the entire service and just commented out the CapbilityBoundingSet and now tor is starting again.

The problem is at least definitely the capabilities but I do not know which one(s)
Comment 4 Peter Meier 2016-09-16 05:51:13 EDT
So it works on the first start of the daemon and the onionservice directories are getting created, as well as the onionservices.

However as soon as you try to restart a service with a previously present onionservice, the service will fail to start.

To make it work you have to:

* disable SELinux
* cp the entire service and just commented out the CapbilityBoundingSet as Hein-Pieter mentioned.

It's not possible to restart it with SELinux enabled nor the right capabilities.

This is on EL7 with tor v0.2.8.7
Comment 5 Peter Meier 2016-09-16 05:54:47 EDT
Downgrading to tor-0.2.7.6-4.el7 makes the service working again.
Comment 6 Gwyn Ciesla 2016-09-20 10:34:08 EDT
Seeing this on f24.
Comment 7 Michael Scherer 2016-09-30 03:42:54 EDT
There is also some generic selinux issue,(likely the one seen by #4), tracked https://bugzilla.redhat.com/show_bug.cgi?id=1357395

On my side, I do have this:

# cat fix_rh_1375369.conf 
[Service]
CapabilityBoundingSet=CAP_DAC_READ_SEARCH

In the case of #3, it seems that the file name is wrong, it should be /etc/systemd/system/tor.service.d/fix-caps.conf , not tor.conf.d
Comment 8 Michael Scherer 2016-10-02 15:25 EDT
Created attachment 1206673 [details]
Fix the issue on F24 and EPEL7
Comment 9 Hein-Pieter van Braam 2016-10-02 16:03:33 EDT
(In reply to Michael Scherer from comment #7)
> There is also some generic selinux issue,(likely the one seen by #4),
> tracked https://bugzilla.redhat.com/show_bug.cgi?id=1357395
> 
> On my side, I do have this:
> 
> # cat fix_rh_1375369.conf 
> [Service]
> CapabilityBoundingSet=CAP_DAC_READ_SEARCH
> 
> In the case of #3, it seems that the file name is wrong, it should be
> /etc/systemd/system/tor.service.d/fix-caps.conf , not tor.conf.d

Do'h! Thanks! That was... stupid of me.
Comment 10 Jamie Nguyen 2016-10-02 16:29:10 EDT
Tor shouldn't need CAP_DAC_READ_SEARCH, or at least I thought some patches I sent upstream last year removed the need for it (and apparently things have been working without it until recently). I'll have to take a closer look, but for now I'll add CAP_DAC_READ_SEARCH back into the bounding set. Builds in progress, updates to follow. Sorry for the delay.
Comment 11 Michael Scherer 2016-10-02 17:43:35 EDT
So, that's only for hidden services, not for regular tor. The code is running as root before the configuration is parsed, and so root need to be able to open the directory, who has restricted permissions (and so need CAP_DAC_READ_SEARCH is needed for that use case)

I guess having the directory could be owned by the root group with g+rx as a alternative ?
Comment 12 Fedora Update System 2016-10-02 18:22:39 EDT
tor-0.2.8.8-1.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-881d78edf2
Comment 13 Fedora Update System 2016-10-03 02:48:58 EDT
tor-0.2.8.8-1.el7 has been pushed to the Fedora EPEL 7 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-69f1c1433b
Comment 14 Fedora Update System 2016-10-03 03:19:57 EDT
tor-0.2.8.8-1.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-877b55bdd7
Comment 15 Fedora Update System 2016-10-03 03:22:38 EDT
tor-0.2.8.8-1.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-1fce1e0993
Comment 16 Fedora Update System 2016-10-04 14:49:50 EDT
tor-0.2.8.8-1.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.
Comment 17 Gwyn Ciesla 2016-10-05 09:13:11 EDT
Tor services still won't start.
Comment 18 Michael Scherer 2016-10-08 13:48:44 EDT
So you test with selinux on enforcing, or permissive ?
Comment 19 Fedora Update System 2016-10-09 14:51:17 EDT
tor-0.2.8.8-1.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.
Comment 20 Gwyn Ciesla 2016-10-12 10:24:56 EDT
Enforcing.
Comment 21 Fedora Update System 2016-10-12 22:53:45 EDT
tor-0.2.8.8-1.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.
Comment 22 Peter Meier 2016-10-14 15:50:35 EDT
I can confirm that with 0.2.8.8-1 onion services still do not work with SELinux in enforcing mode. They work now with SELinux disabled.

The missing parts in the tor policy are:

# grep tor /var/log/audit/audit.log | audit2allow -m tor_dac

module tor_dac 1.0;

require {
	type tor_t;
	class capability { dac_read_search dac_override };
}

#============= tor_t ==============
allow tor_t self:capability { dac_read_search dac_override };

loading this module makes tor and onionservices working with selinux in enforcing mode.
Comment 23 Fedora Update System 2016-10-21 11:52:07 EDT
tor-0.2.8.8-1.el7 has been pushed to the Fedora EPEL 7 stable repository. If problems still persist, please make note of it in this bug report.
Comment 24 Peter Meier 2016-11-04 07:02:51 EDT
Unfortunately, the selinux policy still needs to be added to get onion services running:

An initial starting with an onionservice configured works and it gets created. However, once an onionservice was created and the tor daemon gets restarted it's not able to read from the onionservice directory.

The problem is that tor requires onionservice directories to be owned very clearly by the daemon user, but still requiring access at the moment when it runs as root.

Nov 04 10:39:38 foo tor[28961]: Nov 04 10:39:38.459 [notice] Tor v0.2.8.9 running on Linux with Libevent 2.0.21-stable, 
Nov 04 10:39:38 foo tor[28961]: Nov 04 10:39:38.459 [notice] Tor can't help you if you use it wrong! Learn how to be saf
Nov 04 10:39:38 foo tor[28961]: Nov 04 10:39:38.459 [notice] Read configuration file "/usr/share/tor/defaults-torrc".
Nov 04 10:39:38 foo tor[28961]: Nov 04 10:39:38.459 [notice] Read configuration file "/etc/tor/torrc".
Nov 04 10:39:38 foo tor[28961]: Nov 04 10:39:38.463 [warn] Directory /var/lib/tor/smtp cannot be read: Permission denied
Nov 04 10:39:38 foo tor[28961]: Nov 04 10:39:38.463 [warn] Failed to parse/validate config: Failed to configure rendezvo
Nov 04 10:39:38 foo tor[28961]: Nov 04 10:39:38.463 [err] Reading config failed--see warnings above.


# rpm -qi tor
Name        : tor
Version     : 0.2.8.9
Release     : 1.el7
Architecture: x86_64
Install Date: Fri 04 Nov 2016 10:39:17 AM CET
Group       : System Environment/Daemons
Size        : 10756994
License     : BSD
Signature   : RSA/SHA256, Fri 21 Oct 2016 09:24:38 PM CEST, Key ID 6a2faea2352c64e5
Source RPM  : tor-0.2.8.9-1.el7.src.rpm
Build Date  : Wed 19 Oct 2016 08:48:19 AM CEST
Build Host  : buildvm-08.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://www.torproject.org
Summary     : Anonymizing overlay network for TCP
erver on the
Tor network, or as a client to connect to the Tor network.


# grep tor /var/log/audit/audit.log | audit2allow -m tor_dac

module tor_dac 1.0;

require {
	type tor_t;
	class capability { dac_read_search dac_override };
}

#============= tor_t ==============
allow tor_t self:capability { dac_read_search dac_override };
Comment 25 Michael Scherer 2016-11-05 16:08:55 EDT
I confirm. 

So I opened another bug for that :
https://bugzilla.redhat.com/show_bug.cgi?id=1392187
Comment 26 Gwyn Ciesla 2017-01-25 08:57:34 EST
Still not working on selinux-policy-targeted-3.13.1-225.6.fc25.noarch
Comment 27 Kyle Marek 2017-02-14 21:50:35 EST
I am experiencing the exact issue as described in comment 24 (https://bugzilla.redhat.com/show_bug.cgi?id=1375369#c24) but on Fedora 25 with all packages up to date.

The same solution of allowing dac_read_search and dac_override makes it work on a fresh (enforcing) minimal installation of Fedora 25.

However, I almost want to blame systemd. Commenting the user line in /usr/share/tor/defaults-torrc and adding User=toranon under the Service section of /usr/lib/systemd/system/tor.service (or a drop-in file) also makes it work, which seems to imply that systemd is denying the root user access to the directories. Access to a hidden service directory is also granted when manually running the ExecStart command as root outside of the systemd service. I am not familiar enough with SELinux workings to know if there's a difference in applied policies depending on how I execute the tor binary.
Comment 28 Fedora End Of Life 2017-07-25 19:00:00 EDT
This message is a reminder that Fedora 24 is nearing its end of life.
Approximately 2 (two) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 24. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '24'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 24 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.
Comment 29 Kyle Marek 2017-07-26 02:15:23 EDT
Applies to both Fedora 25 and 26. Please update version field accordingly.
Comment 30 Kyle Marek 2017-07-26 02:28:16 EDT
This is possibly a duplicate of: https://bugzilla.redhat.com/show_bug.cgi?id=1357395
Comment 31 Kyle Marek 2017-07-26 03:37:10 EDT
Whoops, misjudged the situation with both Fedora 25 and 26. A boolean has been added to enable hidden service-supporting policies:

sudo setsebool -P tor_can_onion_services on


See:
$ sudo ausearch -c tor --raw | audit2allow


#============= tor_t ==============

#!!!! This avc can be allowed using the boolean 'tor_can_onion_services'
allow tor_t self:capability { dac_override dac_read_search };
Comment 32 Gwyn Ciesla 2017-07-26 08:36:35 EDT
(In reply to Kyle Marek from comment #31)
> Whoops, misjudged the situation with both Fedora 25 and 26. A boolean has
> been added to enable hidden service-supporting policies:
> 
> sudo setsebool -P tor_can_onion_services on
> 
> 
> See:
> $ sudo ausearch -c tor --raw | audit2allow
> 
> 
> #============= tor_t ==============
> 
> #!!!! This avc can be allowed using the boolean 'tor_can_onion_services'
> allow tor_t self:capability { dac_override dac_read_search };

This resolves the issue for me on f26, thank you!
Comment 33 Christian Stadelmann 2017-07-30 03:43:29 EDT
(In reply to Kyle Marek from comment #30)
> This is possibly a duplicate of:
> https://bugzilla.redhat.com/show_bug.cgi?id=1357395

I'd rather say https://bugzilla.redhat.com/show_bug.cgi?id=1471477.
Comment 34 Kyle Marek 2017-07-30 03:58:50 EDT
(In reply to Christian Stadelmann from comment #33)
> (In reply to Kyle Marek from comment #30)
> > This is possibly a duplicate of:
> > https://bugzilla.redhat.com/show_bug.cgi?id=1357395
> 
> I'd rather say https://bugzilla.redhat.com/show_bug.cgi?id=1471477.

Bug ID 1471477 > 1357395.
Comment 35 Fedora End Of Life 2017-08-08 13:19:04 EDT
Fedora 24 changed to end-of-life (EOL) status on 2017-08-08. Fedora 24 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.
Comment 36 Paul Wouters 2017-08-08 14:57:49 EDT
it seems this issue was only pending another bug for an selinux update. So the original issue of this bug is actually resolved.