Bug 1375369 - Onionservice are broken
Summary: Onionservice are broken
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: tor
Version: 24
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Nobody's working on this, feel free to take it
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 1301667 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-09-12 21:27 UTC by Michael S.
Modified: 2020-11-05 09:31 UTC (History)
9 users (show)

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
Clone Of:
Environment:
Last Closed: 2017-08-08 17:19:04 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Fix the issue on F24 and EPEL7 (761 bytes, patch)
2016-10-02 19:25 UTC, Michael S.
no flags Details | Diff

Description Michael S. 2016-09-12 21:27:12 UTC
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 S. 2016-09-12 22:40:59 UTC
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 S. 2016-09-12 23:03:25 UTC
So, i found that the cap missing is CAP_DAC_READ_SEARCH.

Comment 3 Hein-Pieter van Braam 2016-09-15 19:38:11 UTC
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 09:51:13 UTC
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 09:54:47 UTC
Downgrading to tor-0.2.7.6-4.el7 makes the service working again.

Comment 6 Gwyn Ciesla 2016-09-20 14:34:08 UTC
Seeing this on f24.

Comment 7 Michael S. 2016-09-30 07:42:54 UTC
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 S. 2016-10-02 19:25:58 UTC
Created attachment 1206673 [details]
Fix the issue on F24 and EPEL7

Comment 9 Hein-Pieter van Braam 2016-10-02 20:03:33 UTC
(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 20:29:10 UTC
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 S. 2016-10-02 21:43:35 UTC
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 22:22:39 UTC
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 06:48:58 UTC
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 07:19:57 UTC
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 07:22:38 UTC
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 18:49:50 UTC
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 13:13:11 UTC
Tor services still won't start.

Comment 18 Michael S. 2016-10-08 17:48:44 UTC
So you test with selinux on enforcing, or permissive ?

Comment 19 Fedora Update System 2016-10-09 18:51:17 UTC
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 14:24:56 UTC
Enforcing.

Comment 21 Fedora Update System 2016-10-13 02:53:45 UTC
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 19:50:35 UTC
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 15:52:07 UTC
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 11:02:51 UTC
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 S. 2016-11-05 20:08:55 UTC
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 13:57:34 UTC
Still not working on selinux-policy-targeted-3.13.1-225.6.fc25.noarch

Comment 27 Kyle Marek 2017-02-15 02:50:35 UTC
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 23:00:00 UTC
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 06:15:23 UTC
Applies to both Fedora 25 and 26. Please update version field accordingly.

Comment 30 Kyle Marek 2017-07-26 06:28:16 UTC
This is possibly a duplicate of: https://bugzilla.redhat.com/show_bug.cgi?id=1357395

Comment 31 Kyle Marek 2017-07-26 07:37:10 UTC
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 12:36:35 UTC
(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 07:43:29 UTC
(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 07:58:50 UTC
(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 17:19:04 UTC
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 18:57:49 UTC
it seems this issue was only pending another bug for an selinux update. So the original issue of this bug is actually resolved.

Comment 37 Marcel Haerry 2019-01-07 23:37:51 UTC
*** Bug 1301667 has been marked as a duplicate of this bug. ***


Note You need to log in before you can comment on or make changes to this bug.