interfaces,interfaces/dbus: add DBus security backend #767

Merged
merged 6 commits into from Mar 31, 2016

Conversation

Projects
None yet
3 participants
Contributor

zyga commented Mar 31, 2016

This branch adds the third security backend, DBus. Unlike other backends it is not used by any of our interfaces yet but we expect to make heavy use of it when implementing support for snaps like network-manager or bluez that use DBus extensively.

zyga added some commits Mar 18, 2016

interfaces/dbus: add security backend
This patch adds the third security backend - dbus. DBus differs from
earlier backends in that it is not yet used by any of the interfaces and
that by default (without any snippets) it doesn't generate any files.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: remove dbus securityHelper code
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/dbus/backend.go
+// Particular security snippets define whole <policy>...</policy> entires.
+//
+// NOTE: This interacts with systemd.
+// TODO: Explain how this works (security).
@jdstrand

jdstrand Mar 31, 2016

Contributor

Probably a link to this page is enough explanation: https://dbus.freedesktop.org/doc/dbus-daemon.1.html

@zyga

zyga Mar 31, 2016

Contributor

Thanks, I'll put this in

interfaces/dbus/backend.go
+
+// Configure creates dbus configuration files specific to a given snap.
+//
+// NOTE: DBus has no concept of a complain mode so developer mode is not supported.
@jdstrand

jdstrand Mar 31, 2016

Contributor

perhaps add: (ie, developerMode is ignored)

@niemeyer

niemeyer Mar 31, 2016

Contributor

Should it be ignored, or should dbus be unblocked altogether? That's what that mode does for the other security systems, right? Complain just ensures we're notifying about improper attempts.

@zyga

zyga Mar 31, 2016

Contributor

Done

interfaces/dbus/backend.go
+ // Get the snippets that apply to this snap
+ snippets, err := repo.SecuritySnippetsForSnap(snapInfo.Name, interfaces.SecurityDBus)
+ if err != nil {
+ return fmt.Errorf("cannot obtain security snippets for snap %q: %s", snapInfo.Name, err)
@jdstrand

jdstrand Mar 31, 2016

Contributor

I didn't notice this in previous reviews for other backends, but this error message seems too generic and should s/obtain security snippets/obtain dbus security snippets/ so that if there is a problem in a particular backend, we know which one. apparmor/backend.go and seccomp/backend.go need a corresponding change (can be done in a separate commit).

@zyga

zyga Mar 31, 2016

Contributor

Good point, I'll specialize this in all the backends.

@zyga

zyga Mar 31, 2016

Contributor

Done in dbus, I'll address seccomp and apparmor separately.

interfaces/dbus/backend.go
+ // Get the files that this snap should have
+ content, err := b.combineSnippets(snapInfo, developerMode, snippets)
+ if err != nil {
+ return fmt.Errorf("cannot obtain expected security files for snap %q: %s", snapInfo.Name, err)
@jdstrand

jdstrand Mar 31, 2016

Contributor

Ditto.

@zyga

zyga Mar 31, 2016

Contributor

Yep, I'll ensure this is not copy-pasted :)

interfaces/dbus/backend.go
+ glob := fmt.Sprintf("%s.conf", interfaces.SecurityTagGlob(snapInfo))
+ _, _, err = osutil.EnsureDirState(dirs.SnapBusPolicyDir, glob, content)
+ if err != nil {
+ return fmt.Errorf("cannot synchronize security files for snap %q: %s", snapInfo.Name, err)
@jdstrand

jdstrand Mar 31, 2016

Contributor

Perhaps ditto here too.

interfaces/dbus/backend.go
+ _, _, err = osutil.EnsureDirState(dirs.SnapBusPolicyDir, glob, content)
+ if err != nil {
+ return fmt.Errorf("cannot synchronize security files for snap %q: %s", snapInfo.Name, err)
+ }
@jdstrand

jdstrand Mar 31, 2016

Contributor

I'm not 100% sure that dbus daemon doesn't need to be force-reloaded. Looking at deb packaging for bluez, it has 'invoke-rc.d dbus force-reload'. On 15.04 I don't recall needing to do anything special about this, but it might've been because we were using Type=dbus and BusName=... in the systemd unit. Also, Tony didn't complain about the bus policy not taking effect immediately with his earlier 16.04 snap.... I looked at the dbus code and it has an inotify watch on configuration and service directories.

In all, I don't think there is anything to do here, but I wanted to add a comment here for future reference.

@zyga

zyga Mar 31, 2016

Contributor

Thanks for pointing this out

+var (
+ xmlHeader = []byte(`<!DOCTYPE busconfig PUBLIC\
+ "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
@jdstrand

jdstrand Mar 31, 2016

Contributor

In 15.04 we did:
<!--
This file is autogenerated by snappy
-->

I wonder if it should be in 16.04 as well. I don't have a strong opinion either way.

@zyga

zyga Mar 31, 2016

Contributor

Thanks, perhaps we should add that to all files we make?

@jdstrand

jdstrand Mar 31, 2016

Contributor

"Thanks, perhaps we should add that to all files we make?"

We could, but the difference here is that the file is in /etc as opposed to /var. I'm not opposed to adding it everywhere though.

@niemeyer

niemeyer Mar 31, 2016

Contributor

If adding it, let's please have just "This file is auto-generated." instead.

@zyga

zyga Mar 31, 2016

Contributor

Done in 06ae6d4

Contributor

jdstrand commented Mar 31, 2016

A few minor comment changes and one thing to note. LGTM

interfaces/dbus/backend.go
+// Each configuration is an XML file containing <busconfig>...</busconfig>.
+// Particular security snippets define whole <policy>...</policy> entires.
+//
+// NOTE: This interacts with systemd.
@niemeyer

niemeyer Mar 31, 2016

Contributor

The NOTE: prefix doesn't seem to be holding a consistent and useful meaning. These are comments. Everything in them are "notes". Would you mind to drop all such prefixes in this branch (there are many of them).

Contributor

niemeyer commented Mar 31, 2016

LGTM with trivials handled.

zyga added some commits Mar 31, 2016

interfaces/dbus: link to dbus documentation
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/dbus: tweak comment on Configure()
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/dbus: tweak error messages to clearly refer to DBus
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/dbus: add a generated-file comment to generated files
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

@zyga zyga merged commit 0c278b7 into snapcore:master Mar 31, 2016

2 of 4 checks passed

Integration tests No test results found.
Details
autopkgtest Triggered
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.07%) to 76.593%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment