Bug 1306046

Summary: chrony systemd service unit is missing "ConditionCapability=CAP_SYS_TIME"
Product: Red Hat Enterprise Linux 7 Reporter: Elias Probst <mail>
Component: chronyAssignee: Miroslav Lichvar <mlichvar>
Status: CLOSED ERRATA QA Contact: Karel Volný <kvolny>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.2CC: jprokes, kvolny
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: chrony-3.1-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 16:20:39 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Elias Probst 2016-02-09 23:20:12 UTC
Description of problem:
Starting RHEL7/CentOS7 in a systemd-nspawn container results in chronyd failing to start, because adjtimex() can't be called from an unprivileged container.

The systemd service unit for chrony needs to have the following line in the [Unit] section to prevent it from being started in container environments:

ConditionVirtualization=!container

Comment 2 Miroslav Lichvar 2016-02-12 13:39:48 UTC
What if someone wants to run chronyd in a privileged container? It's probably not very common, or even an advisable thing to do, but I'm not sure if the default unit file should be preventing it.

The chronyd service is disabled by default, so I'm wondering what has enabled in the container.

Comment 3 Elias Probst 2016-02-12 16:39:45 UTC
(In reply to Miroslav Lichvar from comment #2)
> What if someone wants to run chronyd in a privileged container? It's
> probably not very common, or even an advisable thing to do, but I'm not sure
> if the default unit file should be preventing it.

I think the default units should always be built under the assumption of a most common scenario. Special scenarios like running chronyd from within a privileged container can be easily achieved through a drop-in 2-line configuration like:

/etc/systemd/system/chronyd.service.d/privileged-container.conf:
[Unit]
ConditionVirtualization=!container


> The chronyd service is disabled by default, so I'm wondering what has
> enabled in the container.

To me it looks like it is enabled by default (at least on CentOS 7.2), but I can't find a corresponding .preset file.
This is possibly a side-effect of chronyd being registered as ntp-unit in /usr/lib/systemd/ntp-units.d/50-chronyd.list

Comment 5 Miroslav Lichvar 2017-01-17 08:38:52 UTC
I noticed that the chrony unit file in Debian is now using ConditionCapability=CAP_SYS_TIME. If I understand it correctly, this prevents starting of chronyd when it doesn't have privileges to call adjtimex(), i.e. the issue that was reported in this bug. To me it looks like a cleaner solution than the ConditionalVirtualization directive.

Comment 6 Elias Probst 2017-01-17 10:16:49 UTC
(In reply to Miroslav Lichvar from comment #5)
> I noticed that the chrony unit file in Debian is now using
> ConditionCapability=CAP_SYS_TIME. If I understand it correctly, this
> prevents starting of chronyd when it doesn't have privileges to call
> adjtimex(), i.e. the issue that was reported in this bug. To me it looks
> like a cleaner solution than the ConditionalVirtualization directive.

I agree - this is a better solution of which I didn't think when writing the initial report.

Comment 9 errata-xmlrpc 2017-08-01 16:20:39 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:1908