Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
interfaces/builtin: support time and date settings via 'org.freedesktop.timedate1 #1832
Merged
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c6c5858
Added timedate_control interface file
stolowski 2785097
Fixes
stolowski 235656a
Added a test
stolowski 6c0a554
Fix policy
stolowski 8f62b27
Renamed to timedate-control
stolowski c5a7eda
Added doc
stolowski 1e1cb3d
Tweaks to the apparmor policy
stolowski dc157a5
Merge branch 'master' into timedate-interface
stolowski ce54c15
Fix expected values in the test
stolowski 1e1d4c3
Merge branch 'master' into timedate-interface
stolowski 0c0e5e2
Merge branch 'master' into timedate-interface
stolowski 6b33141
Addressed review comments
stolowski 4ae0883
Fix test
stolowski 97159df
Check that seccomp snippet is not empty in timezone and timeserver co…
stolowski e9f9084
Comments
stolowski 6171153
Removed the test for unused security systems
stolowski b4892d0
Merge branch 'master' into timedate-interface
stolowski b5e2d73
Renamed to time-control, doc updates according to review comments
stolowski c0d9f8c
Renamed to time-control, doc updates according to review comments
stolowski 0b080c6
Fix name of the variable
stolowski 46c5752
Fix naming in the tests
stolowski
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,84 @@ | ||
| +// -*- Mode: Go; indent-tabs-mode: t -*- | ||
| + | ||
| +/* | ||
| + * Copyright (C) 2016 Canonical Ltd | ||
| + * | ||
| + * This program is free software: you can redistribute it and/or modify | ||
| + * it under the terms of the GNU General Public License version 3 as | ||
| + * published by the Free Software Foundation. | ||
| + * | ||
| + * This program is distributed in the hope that it will be useful, | ||
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + * GNU General Public License for more details. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| + * | ||
| + */ | ||
| + | ||
| +package builtin | ||
| + | ||
| +import "github.com/snapcore/snapd/interfaces" | ||
| + | ||
| +const timeControlConnectedPlugAppArmor = ` | ||
| +# Description: Can set time and date via systemd' timedated D-Bus interface. | ||
| +# Can read all properties of /org/freedesktop/timedate1 D-Bus object; see | ||
| +# https://www.freedesktop.org/wiki/Software/systemd/timedated/ | ||
| +# Usage: reserved | ||
| + | ||
| +#include <abstractions/dbus-strict> | ||
| + | ||
| +# Introspection of org.freedesktop.timedate1 | ||
| +dbus (send) | ||
| + bus=system | ||
| + path=/org/freedesktop/timedate1 | ||
| + interface=org.freedesktop.DBus.Introspectable | ||
| + member=Introspect | ||
| + peer=(label=unconfined), | ||
| + | ||
| +dbus (send) | ||
| + bus=system | ||
| + path=/org/freedesktop/timedate1 | ||
| + interface=org.freedesktop.timedate1 | ||
| + member="Set{Time,LocalRTC}" | ||
| + peer=(label=unconfined), | ||
| + | ||
| +# Read all properties from timedate1 | ||
| +dbus (send) | ||
| + bus=system | ||
| + path=/org/freedesktop/timedate1 | ||
| + interface=org.freedesktop.DBus.Properties | ||
| + member=Get{,All} | ||
| + peer=(label=unconfined), | ||
| + | ||
| +# Receive timedate1 property changed events | ||
| +dbus (receive) | ||
| + bus=system | ||
| + path=/org/freedesktop/timedate1 | ||
| + interface=org.freedesktop.DBus.Properties | ||
| + member=PropertiesChanged | ||
| + peer=(label=unconfined), | ||
| +` | ||
| +const timeControlConnectedPlugSecComp = ` | ||
| +# dbus | ||
| +connect | ||
| +getsockname | ||
| +recvmsg | ||
| +recvfrom | ||
| +send | ||
| +sendto | ||
| +sendmsg | ||
| +socket | ||
| +` | ||
| + | ||
| +// NewTimeDateControlInterface returns a new "time-control" interface. | ||
| +func NewTimeControlInterface() interfaces.Interface { | ||
| + return &commonInterface{ | ||
| + name: "time-control", | ||
| + connectedPlugAppArmor: timeControlConnectedPlugAppArmor, | ||
| + connectedPlugSecComp: timeControlConnectedPlugSecComp, | ||
| + reservedForOS: true, | ||
| + autoConnect: false, | ||
| + } | ||
| +} |
| @@ -0,0 +1,94 @@ | ||
| +// -*- Mode: Go; indent-tabs-mode: t -*- | ||
| + | ||
| +/* | ||
| + * Copyright (C) 2016 Canonical Ltd | ||
| + * | ||
| + * This program is free software: you can redistribute it and/or modify | ||
| + * it under the terms of the GNU General Public License version 3 as | ||
| + * published by the Free Software Foundation. | ||
| + * | ||
| + * This program is distributed in the hope that it will be useful, | ||
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + * GNU General Public License for more details. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| + * | ||
| + */ | ||
| + | ||
| +package builtin_test | ||
| + | ||
| +import ( | ||
| + . "gopkg.in/check.v1" | ||
| + | ||
| + "github.com/snapcore/snapd/interfaces" | ||
| + "github.com/snapcore/snapd/interfaces/builtin" | ||
| + "github.com/snapcore/snapd/snap" | ||
| +) | ||
| + | ||
| +type TimeControlTestInterfaceSuite struct { | ||
| + iface interfaces.Interface | ||
| + slot *interfaces.Slot | ||
| + plug *interfaces.Plug | ||
| +} | ||
| + | ||
| +var _ = Suite(&TimeControlTestInterfaceSuite{ | ||
| + iface: builtin.NewTimeControlInterface(), | ||
| + slot: &interfaces.Slot{ | ||
| + SlotInfo: &snap.SlotInfo{ | ||
| + Snap: &snap.Info{SuggestedName: "ubuntu-core", Type: snap.TypeOS}, | ||
| + Name: "time-control", | ||
| + Interface: "time-control", | ||
| + }, | ||
| + }, | ||
| + plug: &interfaces.Plug{ | ||
| + PlugInfo: &snap.PlugInfo{ | ||
| + Snap: &snap.Info{SuggestedName: "other"}, | ||
| + Name: "time-control", | ||
| + Interface: "time-control", | ||
| + }, | ||
| + }, | ||
| +}) | ||
| + | ||
| +func (s *TimeControlTestInterfaceSuite) TestName(c *C) { | ||
| + c.Assert(s.iface.Name(), Equals, "time-control") | ||
| +} | ||
| + | ||
| +func (s *TimeControlTestInterfaceSuite) TestSanitizeSlot(c *C) { | ||
| + err := s.iface.SanitizeSlot(s.slot) | ||
| + c.Assert(err, IsNil) | ||
| + err = s.iface.SanitizeSlot(&interfaces.Slot{SlotInfo: &snap.SlotInfo{ | ||
| + Snap: &snap.Info{SuggestedName: "some-snap"}, | ||
| + Name: "time-control", | ||
| + Interface: "time-control", | ||
| + }}) | ||
| + c.Assert(err, ErrorMatches, "time-control slots are reserved for the operating system snap") | ||
| +} | ||
| + | ||
| +func (s *TimeControlTestInterfaceSuite) TestSanitizePlug(c *C) { | ||
| + err := s.iface.SanitizePlug(s.plug) | ||
| + c.Assert(err, IsNil) | ||
| +} | ||
| + | ||
| +func (s *TimeControlTestInterfaceSuite) TestSanitizeIncorrectInterface(c *C) { | ||
| + c.Assert(func() { s.iface.SanitizeSlot(&interfaces.Slot{SlotInfo: &snap.SlotInfo{Interface: "other"}}) }, | ||
| + PanicMatches, `slot is not of interface "time-control"`) | ||
| + c.Assert(func() { s.iface.SanitizePlug(&interfaces.Plug{PlugInfo: &snap.PlugInfo{Interface: "other"}}) }, | ||
| + PanicMatches, `plug is not of interface "time-control"`) | ||
| +} | ||
| + | ||
| +func (s *TimeControlTestInterfaceSuite) TestUsedSecuritySystems(c *C) { | ||
| + // connected plugs have a non-nil security snippet for apparmor | ||
| + snippet, err := s.iface.ConnectedPlugSnippet(s.plug, s.slot, interfaces.SecurityAppArmor) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, Not(IsNil)) | ||
| + // connected plugs have a non-nil security snippet for seccomp | ||
| + snippet, err = s.iface.ConnectedPlugSnippet(s.plug, s.slot, interfaces.SecuritySecComp) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, Not(IsNil)) | ||
| +} | ||
| + | ||
| +func (s *TimeControlTestInterfaceSuite) TestAutoConnect(c *C) { | ||
| + c.Check(s.iface.AutoConnect(), Equals, false) | ||
| +} |