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,interfaces/udev: add udev security backend #768
Merged
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
da65c74
interfaces/udev: add udev security backend
zyga a3157d0
interfaces: remove all remains of secuirtyHelpers
zyga 7848ea6
interfaces: remove now-unused naming functions
zyga 71242a2
interfaces: remove unused xmanager module
zyga f39027b
interfaces/udev: simplify combineSnippets
zyga 281390a
interfaces/udev: react to rule changes even on failure
zyga e18657a
interfaces/udev: simplify command mocking
zyga 2a2cb4a
interfaces/udev: s/mockCmd/udevadmCmd/g
zyga 59289a5
interfaces/udev: s/profile/fname/g
zyga e3ee5a3
interfaces/udev: unify error handling
zyga 1ef118b
interfaces/udev: add local ensureDirState which handles changes
zyga eff523f
Merge branch 'master' of github.com:ubuntu-core/snappy into security-…
zyga 4393395
interfaces/udev: simplify ensureDirState error handling
zyga 414d7de
interfaces/udev: fix typo
zyga af7879f
interfaces/udev: don't repeat error message
zyga c0309d1
interfaces/udev: tweak auto-generated comment
zyga
Jump to file or symbol
Failed to load files and symbols.
| @@ -1,33 +0,0 @@ | ||
| -// -*- 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 interfaces | ||
| - | ||
| -import ( | ||
| - "github.com/ubuntu-core/snappy/testutil" | ||
| -) | ||
| - | ||
| -// MockActiveSnapMetaData replaces the function used to determine version and origin of a given snap. | ||
| -func MockActiveSnapMetaData(test *testutil.BaseTest, fn func(string) (string, string, []string, error)) { | ||
| - orig := ActiveSnapMetaData | ||
| - ActiveSnapMetaData = fn | ||
| - test.AddCleanup(func() { | ||
| - ActiveSnapMetaData = orig | ||
| - }) | ||
| -} |
| @@ -1,68 +0,0 @@ | ||
| -// -*- 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 interfaces | ||
| - | ||
| -import ( | ||
| - "fmt" | ||
| -) | ||
| - | ||
| -// securityHelper is an interface for common aspects of generating security files. | ||
| -type securityHelper interface { | ||
| - securitySystem() SecuritySystem | ||
| - pathForApp(snapName, snapVersion, snapOrigin, appName string) string | ||
| - headerForApp(snapName, snapVersion, snapOrigin, appName string) []byte | ||
| - footerForApp(snapName, snapVersion, snapOrigin, appName string) []byte | ||
| -} | ||
| - | ||
| -// uDev is a security subsystem that writes additional udev rules (one per snap). | ||
| -// | ||
| -// Each rule looks like this: | ||
| -// | ||
| -// KERNEL=="hiddev0", TAG:="snappy-assign", ENV{SNAPPY_APP}:="http.GET.snap" | ||
| -// | ||
| -// NOTE: This interacts with ubuntu-core-launcher. | ||
| -// | ||
| -// This tag is picked up by /lib/udev/rules.d/80-snappy-assign.rules which in | ||
| -// turn runs /lib/udev/snappy-app-dev script, which re-configures the device | ||
| -// cgroup at /sys/fs/cgroup/devices/snappy.$SNAPPY_APP for the acl | ||
| -// "c $major:$minor rwm" for character devices and "b $major:$minor rwm" for | ||
| -// block devices. | ||
| -// | ||
| -// $SNAPPY_APP is always computed with SecurityTagForApp() | ||
| -// | ||
| -// The control group is created by ubuntu-app-launcher. | ||
| -type uDev struct{} | ||
| - | ||
| -func (udev *uDev) securitySystem() SecuritySystem { | ||
| - return SecurityUDev | ||
| -} | ||
| - | ||
| -func (udev *uDev) pathForApp(snapName, snapVersion, snapOrigin, appName string) string { | ||
| - // NOTE: we ignore appName so effectively udev rules apply to entire snap. | ||
| - return fmt.Sprintf("/etc/udev/rules.d/70-%s.rules", SecurityTagForApp(snapName, appName)) | ||
| -} | ||
| - | ||
| -func (udev *uDev) headerForApp(snapName, snapVersion, snapOrigin, appName string) []byte { | ||
| - return nil // udev doesn't require a header | ||
| -} | ||
| - | ||
| -func (udev *uDev) footerForApp(snapName, snapVersion, snapOrigin, appName string) []byte { | ||
| - return nil // udev doesn't require a footer | ||
| -} |
| @@ -1,120 +0,0 @@ | ||
| -// -*- Mote: 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 interfaces_test | ||
| - | ||
| -import ( | ||
| - . "gopkg.in/check.v1" | ||
| - | ||
| - . "github.com/ubuntu-core/snappy/interfaces" | ||
| - "github.com/ubuntu-core/snappy/snap" | ||
| - "github.com/ubuntu-core/snappy/testutil" | ||
| -) | ||
| - | ||
| -type SecuritySuite struct { | ||
| - testutil.BaseTest | ||
| - repo *Repository | ||
| - plug *Plug | ||
| - slot *Slot | ||
| -} | ||
| - | ||
| -var _ = Suite(&SecuritySuite{}) | ||
| - | ||
| -func (s *SecuritySuite) SetUpTest(c *C) { | ||
| - s.BaseTest.SetUpTest(c) | ||
| - s.repo = NewRepository() | ||
| - // NOTE: the names producer/consumer are confusing. They will be fixed shortly. | ||
| - producer, err := snap.InfoFromSnapYaml([]byte(` | ||
| -name: producer | ||
| -apps: | ||
| - hook: | ||
| -plugs: | ||
| - plug: interface | ||
| -`)) | ||
| - c.Assert(err, IsNil) | ||
| - consumer, err := snap.InfoFromSnapYaml([]byte(` | ||
| -name: consumer | ||
| -apps: | ||
| - app: | ||
| -slots: | ||
| - slot: | ||
| - interface: interface | ||
| - label: label | ||
| - attr: value | ||
| -`)) | ||
| - c.Assert(err, IsNil) | ||
| - s.plug = &Plug{PlugInfo: producer.Plugs["plug"]} | ||
| - s.slot = &Slot{SlotInfo: consumer.Slots["slot"]} | ||
| - // TODO: make this obsolete thanks to unified and rich snap.Info | ||
| - MockActiveSnapMetaData(&s.BaseTest, func(snapName string) (string, string, []string, error) { | ||
| - switch snapName { | ||
| - case "producer": | ||
| - return "version", "origin", []string{"hook"}, nil | ||
| - case "consumer": | ||
| - return "version", "origin", []string{"app"}, nil | ||
| - default: | ||
| - panic("unexpected snap name") | ||
| - } | ||
| - }) | ||
| -} | ||
| - | ||
| -func (s *SecuritySuite) prepareFixtureWithInterface(c *C, i Interface) { | ||
| - err := s.repo.AddInterface(i) | ||
| - c.Assert(err, IsNil) | ||
| - err = s.repo.AddPlug(s.plug) | ||
| - c.Assert(err, IsNil) | ||
| - err = s.repo.AddSlot(s.slot) | ||
| - c.Assert(err, IsNil) | ||
| - err = s.repo.Connect(s.plug.Snap.Name, s.plug.Name, s.slot.Snap.Name, s.slot.Name) | ||
| - c.Assert(err, IsNil) | ||
| -} | ||
| - | ||
| -// Tests for uDev | ||
| - | ||
| -func (s *SecuritySuite) TestUdevPlugPermissions(c *C) { | ||
| - s.prepareFixtureWithInterface(c, &TestInterface{ | ||
| - InterfaceName: "interface", | ||
| - PlugSnippetCallback: func(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error) { | ||
| - if securitySystem == SecurityUDev { | ||
| - return []byte("...\n"), nil | ||
| - } | ||
| - return nil, nil | ||
| - }, | ||
| - }) | ||
| - // Ensure that plug-side security profile looks correct. | ||
| - blobs, err := s.repo.SecurityFilesForSnap(s.plug.Snap.Name) | ||
| - c.Assert(err, IsNil) | ||
| - c.Check(blobs["/etc/udev/rules.d/70-producer.hook.snap.rules"], DeepEquals, []byte("...\n")) | ||
| -} | ||
| - | ||
| -func (s *SecuritySuite) TestUdevSlotPermissions(c *C) { | ||
| - s.prepareFixtureWithInterface(c, &TestInterface{ | ||
| - InterfaceName: "interface", | ||
| - SlotSnippetCallback: func(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error) { | ||
| - if securitySystem == SecurityUDev { | ||
| - return []byte("...\n"), nil | ||
| - } | ||
| - return nil, nil | ||
| - }, | ||
| - }) | ||
| - // Ensure that slot-side security profile looks correct. | ||
| - blobs, err := s.repo.SecurityFilesForSnap(s.slot.Snap.Name) | ||
| - c.Assert(err, IsNil) | ||
| - c.Check(blobs["/etc/udev/rules.d/70-consumer.app.snap.rules"], DeepEquals, []byte("...\n")) | ||
| -} |
Oops, something went wrong.