Skip to content

Commit 188e6af

Browse files
authored
Make ntpsec use a compatible Apparmor configuration (sous-chefs#257) (sous-chefs#258)
* Make ntpsec use a compatible Apparmor configuration (sous-chefs#257) * Use ntpsec paths when ntpsec is installed * Fix ntp.conf's path on Debian and Ubuntu * Make Ubuntu use ntpsec, starting release 23.10.
1 parent d585ee8 commit 188e6af

File tree

4 files changed

+113
-3
lines changed

4 files changed

+113
-3
lines changed

attributes/default.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
default['ntp']['conf_owner'] = 'root'
4545
default['ntp']['conf_group'] = 'root'
4646

47-
if platform?('debian') && node['platform_version'].to_i >= 12
47+
if (platform?('debian') && node['platform_version'].to_i >= 12) || (platform?('ubuntu') && node['platform_version'].gsub('.', '').to_i >= 2310)
4848
default['ntp']['var_owner'] = 'ntpsec'
4949
default['ntp']['var_group'] = 'ntpsec'
50+
default['ntp']['conffile'] = '/etc/ntpsec/ntp.conf'
51+
default['ntp']['statsdir'] = '/var/log/ntpsec/'
5052
else
5153
default['ntp']['var_owner'] = 'ntp'
5254
default['ntp']['var_group'] = 'ntp'

files/usr.sbin.ntpsec.apparmor

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# vim:syntax=apparmor
2+
#
3+
# Maintained by Chef
4+
#
5+
# Updated for Ubuntu by: Jamie Strandboge <[email protected]>
6+
# ------------------------------------------------------------------
7+
#
8+
# Copyright (C) 2002-2005 Novell/SUSE
9+
# Copyright (C) 2009-2012 Canonical Ltd.
10+
#
11+
# This program is free software; you can redistribute it and/or
12+
# modify it under the terms of version 2 of the GNU General Public
13+
# License published by the Free Software Foundation.
14+
#
15+
# ------------------------------------------------------------------
16+
17+
#include <tunables/global>
18+
#include <tunables/ntpd>
19+
/usr/sbin/ntpd flags=(attach_disconnected) {
20+
#include <abstractions/base>
21+
#include <abstractions/nameservice>
22+
#include <abstractions/openssl>
23+
#include <abstractions/user-tmp>
24+
25+
capability ipc_lock,
26+
capability net_admin,
27+
capability net_bind_service,
28+
capability setgid,
29+
capability setuid,
30+
capability sys_chroot,
31+
capability sys_resource,
32+
capability sys_time,
33+
capability sys_nice,
34+
35+
# ntp uses AF_INET, AF_INET6 and AF_UNSPEC
36+
network dgram,
37+
network stream,
38+
39+
@{PROC}/net/if_inet6 r,
40+
@{PROC}/*/net/if_inet6 r,
41+
@{NTPD_DEVICE} rw,
42+
# pps devices are almost exclusively used with NTP
43+
/dev/pps[0-9]* rw,
44+
45+
/{,s}bin/ r,
46+
/usr/{,s}bin/ r,
47+
/usr/local/{,s}bin/ r,
48+
/usr/sbin/ntpd rmix,
49+
50+
/etc/ntpsec/ntp.conf r,
51+
/etc/ntpsec/ntp.d/ r,
52+
/etc/ntpsec/ntp.d/*.conf r,
53+
/run/ntpsec/ntp.conf.dhcp r,
54+
55+
/etc/ntpsec/cert-chain.pem r,
56+
/etc/ntpsec/key.pem r,
57+
/etc/ntpsec/ntp.keys r,
58+
59+
/var/lib/ntpsec/ntp.drift rw,
60+
/var/lib/ntpsec/ntp.drift-tmp rw,
61+
/var/lib/ntpsec/nts-keys rw,
62+
/usr/share/zoneinfo/leap-seconds.list rw,
63+
64+
/var/log/ntp w,
65+
/var/log/ntp.log w,
66+
/var/log/ntpd w,
67+
/var/log/ntpsec/clockstats* rwl,
68+
/var/log/ntpsec/loopstats* rwl,
69+
/var/log/ntpsec/peerstats* rwl,
70+
/var/log/ntpsec/protostats* rwl,
71+
/var/log/ntpsec/rawstats* rwl,
72+
/var/log/ntpsec/sysstats* rwl,
73+
74+
/{,var/}run/ntpd.pid w,
75+
76+
# to be able to check for running ntpdate
77+
/run/lock/ntpsec-ntpdate wk,
78+
79+
# To sign replies to MS-SNTP clients by the smbd daemon /var/lib/samba
80+
/var/lib/samba/ntp_signd/socket rw,
81+
82+
# For use with clocks that report via shared memory (e.g. gpsd),
83+
# you may need to give ntpd access to all of shared memory, though
84+
# this can be considered dangerous. See https://launchpad.net/bugs/722815
85+
# for details. To enable, add this to local/usr.sbin.ntpd:
86+
# capability ipc_owner,
87+
88+
# Site-specific additions and overrides. See local/README for details.
89+
#include <local/usr.sbin.ntpd>
90+
}

recipes/apparmor.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@
2121
action :nothing
2222
end
2323

24+
apparmor_source = if node['ntp']['var_owner'] == 'ntpsec'
25+
'usr.sbin.ntpsec.apparmor'
26+
else
27+
'usr.sbin.ntpd.apparmor'
28+
end
29+
2430
cookbook_file '/etc/apparmor.d/usr.sbin.ntpd' do
25-
source 'usr.sbin.ntpd.apparmor'
31+
source apparmor_source
2632
owner 'root'
2733
group 'root'
2834
mode '0644'

test/integration/default/default_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,22 @@
2323
describe file '/usr/share/zoneinfo/leapseconds' do
2424
it { should be_file }
2525
end
26-
elsif os.family == 'debian'
26+
elsif os.name == 'debian' && os.release.to_i <= 11
2727
describe file '/etc/ntp.conf' do
2828
it { should be_file }
2929
end
30+
elsif os.name == 'debian' && os.release.to_i >= 12
31+
describe file '/etc/ntpsec/ntp.conf' do
32+
it { should be_file }
33+
end
34+
elsif os.name == 'ubuntu' && os.release.gsub('.', '').to_i < 2310
35+
describe file '/etc/ntp.conf' do
36+
it { should be_file }
37+
end
38+
elsif os.name == 'ubuntu' && os.release.gsub('.', '').to_i >= 23.10
39+
describe file '/etc/ntpsec/ntp.conf' do
40+
it { should be_file }
41+
end
3042

3143
describe ntp_conf do
3244
its('tos') { should eq 'maxdist 1' }

0 commit comments

Comments
 (0)