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
create mir interface #1299
Merged
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
e24369e
create mir interface
kgunn 9cee697
update manual integration tests for mir interface
kgunn 6813119
ran go fmt on modified files
kgunn e4483dd
remove /tmp/mir reference artifacts
kgunn 22c67fe
remove ptrace
kgunn fb10b7d
remove old template paths
kgunn c7aad8d
remove more unnecessary syscalls
kgunn b8109d6
clean up seccomp
kgunn 51dd518
cleaned up AA
kgunn 20e2869
removed commented out AA
kgunn 55ddacc
Merge remote-tracking branch 'upstream/master'
kgunn e1742e3
clean up interface defs and checks
kgunn 28a8d73
autoconnect true
kgunn 8adc9f7
note on input access
kgunn c988814
remove cruft from test
kgunn d7c7f64
clean up test code
kgunn c0a5d6a
resolve conflict
kgunn d002a64
merge upstream
kgunn 71ec402
resolve conflict and merge upstream
kgunn d407a2d
Merge remote-tracking branch 'upstream/master'
kgunn 4b03b2b
Merge remote-tracking branch 'upstream/master'
kgunn 1118d65
Merge remote-tracking branch 'upstream/master'
kgunn a84b3d4
merge upstream
kgunn a88a213
update for the new security trait securitymount
kgunn 0becd9e
Merge remote-tracking branch 'upstream/master'
kgunn e6b8f9b
Merge remote-tracking branch 'upstream/master'
kgunn bf47bb2
Merge remote-tracking branch 'upstream/master'
kgunn 0c56d70
merge upstream
kgunn d55862a
update with snippets for client substitution
kgunn 4d367b8
Merge remote-tracking branch 'upstream/master'
kgunn 399d40c
correct permanent slot result
kgunn 5fe1f1b
Merge remote-tracking branch 'upstream/master'
kgunn c655d9b
add client path
kgunn 2225606
Merge remote-tracking branch 'upstream/master'
kgunn f6d59f8
correct/revert an errant change to dependencies.tsv
kgunn e85cbe8
small clean up to policy defs
kgunn 8406688
Merge remote-tracking branch 'upstream/master'
kgunn 9d8bd03
make all.go alphabetical in mir listing
kgunn 3971b16
clean up snippet
kgunn aaadb75
address some clean up and code review feedback
kgunn 38d77f0
bit more clean up of whitespace
kgunn 285d12b
final mir-client confinement and clean up
kgunn 2e3ae6f
remove experiment
kgunn a8819e2
more profile tuning
kgunn 6310f93
remove some unnecessary syscalls from connected plug
kgunn b8faee0
remove unix snd rcv line and clean up common for usages
kgunn 26660f6
update to rely on opengl interface for relevant slot and plug activity
kgunn f57b8fd
resolve conflict with upstream
kgunn 119d0f2
go fmt files and update test instructions
kgunn f2968dd
correct mir_test
kgunn e0abb50
typo
kgunn a4211f6
one more typo
kgunn 016b16f
add isnot on assertion
kgunn b891933
adjest implicit interface numbers
kgunn 01dffe5
remove mir from implicit and reduce scope on dev/tty
kgunn 2471773
add missing * to dev/tty
kgunn
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,158 @@ | ||
| +// -*- 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 dtails. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. | ||
| + * | ||
| + */ | ||
| + | ||
| +package builtin | ||
| + | ||
| +import ( | ||
| + "bytes" | ||
| + "github.com/snapcore/snapd/interfaces" | ||
| +) | ||
| + | ||
| +var mirPermanentSlotAppArmor = []byte(` | ||
| +# Description: Allow operating as the Mir server. Reserved because this | ||
| +# gives privileged access to the system. | ||
| +# Usage: reserved | ||
| +# needed since Mir is the display server, to configure tty devices | ||
| +capability sys_tty_config, | ||
| +/dev/shm/\#* rw, | ||
| +/dev/tty[0-9]* rw, | ||
| +network netlink raw, | ||
| +/run/mir_socket rw, | ||
| +#NOTE: this allows reading and inserting all input events | ||
| +/dev/input/* rw, | ||
| +`) | ||
| + | ||
| +var mirPermanentSlotSecComp = []byte(` | ||
| +# Description: Allow operating as the mir server. Reserved because this | ||
| +# gives privileged access to the system. | ||
| +# Needed for server launch | ||
| +bind | ||
| +listen | ||
| +setsockopt | ||
| +getsockname | ||
| +# Needed by server upon client connect | ||
| +sendto | ||
| +accept | ||
| +shmctl | ||
| +open | ||
| +getsockopt | ||
| +recvmsg | ||
| +sendmsg | ||
| +`) | ||
| + | ||
| +var mirConnectedSlotAppArmor = []byte(` | ||
| +# Description: Permit clients to use Mir | ||
| +# Usage: reserved | ||
| +unix (receive, send) type=seqpacket addr=none peer=(label=###PLUG_SECURITY_TAGS###), | ||
| +`) | ||
| + | ||
| +var mirConnectedPlugAppArmor = []byte(` | ||
| +# Description: Permit clients to use Mir | ||
| +# Usage: common | ||
| +unix (receive, send) type=seqpacket addr=none peer=(label=###SLOT_SECURITY_TAGS###), | ||
| +/run/mir_socket rw, | ||
| +/run/user/[0-9]*/mir_socket rw, | ||
| +`) | ||
| + | ||
| +var mirConnectedPlugSecComp = []byte(` | ||
| +# Description: Permit clients to use Mir | ||
| +# Usage: common | ||
| +recvmsg | ||
| +sendmsg | ||
| +sendto | ||
| +`) | ||
| + | ||
| +type MirInterface struct{} | ||
| + | ||
| +func (iface *MirInterface) Name() string { | ||
| + return "mir" | ||
| +} | ||
| + | ||
| +func (iface *MirInterface) PermanentPlugSnippet( | ||
|
|
||
| + plug *interfaces.Plug, | ||
| + securitySystem interfaces.SecuritySystem) ([]byte, error) { | ||
| + switch securitySystem { | ||
| + case interfaces.SecurityAppArmor, interfaces.SecuritySecComp, | ||
| + interfaces.SecurityUDev, interfaces.SecurityDBus, | ||
| + interfaces.SecurityMount: | ||
| + return nil, nil | ||
| + default: | ||
| + return nil, interfaces.ErrUnknownSecurity | ||
| + } | ||
| +} | ||
| + | ||
| +func (iface *MirInterface) ConnectedPlugSnippet( | ||
| + plug *interfaces.Plug, | ||
| + slot *interfaces.Slot, | ||
| + securitySystem interfaces.SecuritySystem) ([]byte, error) { | ||
| + switch securitySystem { | ||
| + case interfaces.SecurityAppArmor: | ||
| + old := []byte("###SLOT_SECURITY_TAGS###") | ||
| + new := slotAppLabelExpr(slot) | ||
| + snippet := bytes.Replace(mirConnectedPlugAppArmor, old, new, -1) | ||
| + return snippet, nil | ||
| + case interfaces.SecuritySecComp: | ||
| + return mirConnectedPlugSecComp, nil | ||
| + case interfaces.SecurityUDev, interfaces.SecurityDBus, interfaces.SecurityMount: | ||
| + return nil, nil | ||
| + default: | ||
| + return nil, interfaces.ErrUnknownSecurity | ||
| + } | ||
| +} | ||
| + | ||
| +func (iface *MirInterface) PermanentSlotSnippet( | ||
|
|
||
| + slot *interfaces.Slot, | ||
| + securitySystem interfaces.SecuritySystem) ([]byte, error) { | ||
| + switch securitySystem { | ||
| + case interfaces.SecurityAppArmor: | ||
| + return mirPermanentSlotAppArmor, nil | ||
| + case interfaces.SecuritySecComp: | ||
| + return mirPermanentSlotSecComp, nil | ||
| + case interfaces.SecurityUDev, interfaces.SecurityDBus, interfaces.SecurityMount: | ||
| + return nil, nil | ||
| + default: | ||
| + return nil, interfaces.ErrUnknownSecurity | ||
| + } | ||
| +} | ||
| + | ||
| +func (iface *MirInterface) ConnectedSlotSnippet(plug *interfaces.Plug, slot *interfaces.Slot, securitySystem interfaces.SecuritySystem) ([]byte, error) { | ||
| + switch securitySystem { | ||
| + case interfaces.SecurityAppArmor: | ||
| + old := []byte("###PLUG_SECURITY_TAGS###") | ||
| + new := plugAppLabelExpr(plug) | ||
| + snippet := bytes.Replace(mirConnectedSlotAppArmor, old, new, -1) | ||
| + return snippet, nil | ||
| + case interfaces.SecuritySecComp, interfaces.SecurityUDev, interfaces.SecurityDBus, interfaces.SecurityMount: | ||
| + return nil, nil | ||
| + default: | ||
| + return nil, interfaces.ErrUnknownSecurity | ||
| + } | ||
| +} | ||
| + | ||
| +func (iface *MirInterface) SanitizePlug(plug *interfaces.Plug) error { | ||
| + return nil | ||
| +} | ||
| + | ||
| +func (iface *MirInterface) SanitizeSlot(slot *interfaces.Slot) error { | ||
| + return nil | ||
| +} | ||
| + | ||
| +func (iface *MirInterface) AutoConnect() bool { | ||
jdstrand
Contributor
|
||
| + return true | ||
| +} | ||
| @@ -0,0 +1,117 @@ | ||
| +// -*- Mode: Go; indent-tabs-mode: t -*- | ||
| + | ||
kgunnfront
|
||
| +/* | ||
| + * 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 MirInterfaceSuite struct { | ||
| + iface interfaces.Interface | ||
| + slot *interfaces.Slot | ||
| + plug *interfaces.Plug | ||
| +} | ||
| + | ||
| +var _ = Suite(&MirInterfaceSuite{ | ||
| + iface: &builtin.MirInterface{}, | ||
| + slot: &interfaces.Slot{ | ||
| + SlotInfo: &snap.SlotInfo{ | ||
| + Snap: &snap.Info{SuggestedName: "mir-server", Type: snap.TypeOS}, | ||
| + Name: "mir-server", | ||
| + Interface: "mir", | ||
| + }, | ||
| + }, | ||
| + plug: &interfaces.Plug{ | ||
| + PlugInfo: &snap.PlugInfo{ | ||
| + Snap: &snap.Info{SuggestedName: "other"}, | ||
| + Name: "mir-client", | ||
| + Interface: "mir", | ||
| + }, | ||
| + }, | ||
| +}) | ||
| + | ||
| +func (s *MirInterfaceSuite) TestName(c *C) { | ||
| + c.Assert(s.iface.Name(), Equals, "mir") | ||
| +} | ||
| + | ||
| +func (s *MirInterfaceSuite) TestUnusedSecuritySystems(c *C) { | ||
| + systems := [...]interfaces.SecuritySystem{interfaces.SecurityAppArmor, | ||
| + interfaces.SecuritySecComp, interfaces.SecurityDBus, | ||
| + interfaces.SecurityUDev} | ||
| + for _, system := range systems { | ||
| + snippet, err := s.iface.PermanentPlugSnippet(s.plug, system) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, IsNil) | ||
| + if system != interfaces.SecurityAppArmor { | ||
| + snippet, err := s.iface.ConnectedSlotSnippet(s.plug, s.slot, system) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, IsNil) | ||
| + } | ||
| + if system != interfaces.SecurityAppArmor && system != interfaces.SecuritySecComp { | ||
| + snippet, err := s.iface.PermanentSlotSnippet(s.slot, system) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, IsNil) | ||
| + snippet, err = s.iface.ConnectedPlugSnippet(s.plug, s.slot, system) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, IsNil) | ||
| + } | ||
| + } | ||
| +} | ||
| + | ||
| +func (s *MirInterfaceSuite) TestUsedSecuritySystems(c *C) { | ||
| + systems := [...]interfaces.SecuritySystem{interfaces.SecurityAppArmor, | ||
| + interfaces.SecuritySecComp} | ||
| + for _, system := range systems { | ||
| + snippet, err := s.iface.PermanentSlotSnippet(s.slot, system) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, Not(IsNil)) | ||
| + snippet, err = s.iface.ConnectedPlugSnippet(s.plug, s.slot, system) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, Not(IsNil)) | ||
| + if system != interfaces.SecuritySecComp { | ||
| + snippet, err := s.iface.ConnectedSlotSnippet(s.plug, s.slot, system) | ||
| + c.Assert(err, IsNil) | ||
| + c.Assert(snippet, Not(IsNil)) | ||
| + } | ||
| + } | ||
| +} | ||
| + | ||
| +func (s *MirInterfaceSuite) TestUnexpectedSecuritySystems(c *C) { | ||
| + snippet, err := s.iface.PermanentPlugSnippet(s.plug, "foo") | ||
| + c.Assert(err, Equals, interfaces.ErrUnknownSecurity) | ||
| + c.Assert(snippet, IsNil) | ||
| + snippet, err = s.iface.ConnectedPlugSnippet(s.plug, s.slot, "foo") | ||
| + c.Assert(err, Equals, interfaces.ErrUnknownSecurity) | ||
| + c.Assert(snippet, IsNil) | ||
| + snippet, err = s.iface.PermanentSlotSnippet(s.slot, "foo") | ||
| + c.Assert(err, Equals, interfaces.ErrUnknownSecurity) | ||
| + c.Assert(snippet, IsNil) | ||
| + snippet, err = s.iface.ConnectedSlotSnippet(s.plug, s.slot, "foo") | ||
| + c.Assert(err, Equals, interfaces.ErrUnknownSecurity) | ||
| + c.Assert(snippet, IsNil) | ||
| +} | ||
jdstrand
Contributor
|
||
| + | ||
| +func (s MirInterfaceSuite) TestAutoConnect(c *C) { | ||
| + c.Check(s.iface.AutoConnect(), Equals, true) | ||
| +} | ||
Please run
go fmton this file.