Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interfaces/desktop-launch: support confined snaps launching other snaps #8699

Merged
merged 130 commits into from
May 31, 2021
Merged

interfaces/desktop-launch: support confined snaps launching other snaps #8699

merged 130 commits into from
May 31, 2021

Conversation

AlanGriffiths
Copy link
Contributor

@AlanGriffiths AlanGriffiths commented May 19, 2020

Add a new interface desktop-launch that allows shells to read .desktop files from /var/lib/snapd/desktop/applications/ and call io.snapcraft.PrivilegedDesktopLauncher.OpenDesktopEntry.

Add io.snapcraft.PrivilegedDesktopLauncher.OpenDesktopEntry support to userd that implements support for this on Classic systems.

The result is that a confined desktop shell can identify other snaps and launch them with (for example) the WAYLAND_DESKTOP environment variable needed for the client to connect to the correct desktop.

Follows on from:

> * tests/lib/snaps/test-snapd-policy-app-consumer/meta/snap.yaml
@jhenstridge
Copy link
Contributor

Once the changes from https://github.com/MirServer/snapd/pull/6 are merged into this PR, I think it would probably be ready for another review. I've tried to close off all the threads that appear to have been addressed, but the number of comments on the PR has become a bit unmanageable.

bors bot added a commit to canonical/mir that referenced this pull request Mar 25, 2021
1968: Update the snapcraft launch object path r=wmww a=AlanGriffiths

To reflect recent changes to canonical/snapd#8699

Co-authored-by: Alan Griffiths <alan@octopull.co.uk>
Copy link
Contributor

@jhenstridge jhenstridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@anonymouse64 anonymouse64 self-requested a review March 29, 2021 19:41
@pedronis pedronis self-requested a review April 1, 2021 08:06
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, did an almost final pass

// Iterate through the potential subdirectories formed by the first i elements of the desktop file ID.
// Maybe this is overkill: At the time of writing, the only use is in desktopFileIDToFilename() and there
// we're only checking dirs.SnapDesktopFilesDir (not all entries in $XDG_DATA_DIRS) and we know that snapd
// does not create subdirectories in that location.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't sound valid anymore as the new approach seems to be to find the file as anything else would, and then double check that is from a place that is supported

// /var/lib/snapd/desktop/applications and these desktop files are written by snapd and
// considered safe for userd to process. If other directories are added in the future,
// verifyDesktopFileLocation() and parseExecCommand() may need to be updated.
return fmt.Errorf("internal error: only launching snap applications from %s is supported", dirs.SnapDesktopFilesDir)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the new approach to search this is not an internal error anymore, the prefix should be stripped


package builtin

const desktopLaunchSummary = `allows snaps to identify and launch other snaps`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be now:

allows to identify and launch desktop applications in(or from) other snaps

?


const desktopLaunchSummary = `allows snaps to identify and launch other snaps`

const desktopLaunchBaseDeclarationPlugs = `
Copy link
Collaborator

@pedronis pedronis Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the base declaration looks right, it follow the same pattern as snapd-control of a superprivileged interface

err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot)
c.Assert(err, IsNil)
c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.other.app"})
c.Assert(apparmorSpec.SnippetForTag("snap.other.app"), testutil.Contains, `Can identify and launch other snaps.`)
Copy link
Collaborator

@pedronis pedronis Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want to check as well at least for:

member=OpenDesktopEntry
peer=(label=unconfined),

@@ -48,7 +48,7 @@ dbus (send)
bus=session
path=/io/snapcraft/PrivilegedDesktopLauncher
interface=io.snapcraft.PrivilegedDesktopLauncher
member=OpenDesktopEntry
peer=(label=unconfined),member=OpenDesktopEntry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. The comma separates AppArmor rules, so this breaks a rule in half.

Rather than changing the AppArmor snippet, @pedronis was suggesting that an extra assertion be added to the test verifying that the snippet contained this part of the rule.

Copy link
Contributor

@anonymouse64 anonymouse64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a conflict here, but +1 from me to merge this as-is, I left some comments about followups but this is looking very good thank you for the iteration on this

conn *dbus.Conn
}

// Name returns the name of the interface this object implements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, but we typically like to end doc-comments with ".", but this should be done in a followup

// desktopFileIDToFilename determines the path associated with a desktop file ID.
func desktopFileIDToFilename(desktopFileID string) (string, error) {
if !isValidDesktopFileID(desktopFileID) {
return "", fmt.Errorf("cannot find desktop file for %q", desktopFileID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this error message indicate that the desktop file ID is invalid insofar as it doesn't match the expected regex? something like

Suggested change
return "", fmt.Errorf("cannot find desktop file for %q", desktopFileID)
return "", fmt.Errorf("cannot find desktop file for %q: desktop file ID is malformed", desktopFileID)

also fine for followup if we want it


args := make([]string, 0, len(origArgs))
for _, arg := range origArgs {
// We want to keep literal '%' (expressed as '%%') but filter our exec variables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We want to keep literal '%' (expressed as '%%') but filter our exec variables
// We want to keep literal '%' (expressed as '%%') but filter out exec variables

{"/snap/bin/foo -f %U %%bar", []string{"/snap/bin/foo", "-f", "%bar"}},
{"/snap/bin/foo -f %U %i %%bar", []string{"/snap/bin/foo", "-f", "--icon", "/snap/chromium/1193/chromium.png", "%bar"}},
{"/snap/bin/foo -f %U %%bar %i", []string{"/snap/bin/foo", "-f", "%bar", "--icon", "/snap/chromium/1193/chromium.png"}},
{"/snap/bin/foo -f %%bar %U %i", []string{"/snap/bin/foo", "-f", "%bar", "--icon", "/snap/chromium/1193/chromium.png"}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is okay to do as a followup

})
}

func (s *privilegedDesktopLauncherSuite) TestDesktopFileLookup(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding this test

c.Assert(err, ErrorMatches, `desktop file ".*" has an unsupported 'Exec' value: ""`)
}

func (s *privilegedDesktopLauncherInternalSuite) TestReadExecCOmmandFromDesktopFileMultipleDesktopEntrySections(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this test too

The desktop-launch interface allows a snap to launch other snaps via
the desktop files they provide to the host system.

systems: [-ubuntu-core-*]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a comment that userd does not yet work properly enough on ubuntu core to be able to run this test there (fine for followup)?

snap connections test-launcher | MATCH "desktop-launch +test-launcher:desktop-launch +:desktop-launch +manual"

echo "The launcher snap can launch other snaps via userd"
tests.session -u test exec test-launcher \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be exec? I assume this is somehow related to user sessions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should we be checking the output of this command with MATCH, since we are using --print-reply?

@pedronis pedronis closed this May 28, 2021
@pedronis pedronis reopened this May 28, 2021
@anonymouse64 anonymouse64 added this to the 2.52 milestone May 28, 2021
@pedronis
Copy link
Collaborator

@AlanGriffiths @jhenstridge the last run of tests got stuck, anyway it seems something changed in master before the last master merge and now the spread test is failing and need adjusting/fixing, this probably needs again a master merge and fixes, sorry

Copy link
Contributor

@anonymouse64 anonymouse64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've commented with the spread test changes necessary

tests/main/interfaces-desktop-launch/task.yaml Outdated Show resolved Hide resolved
tests/main/interfaces-desktop-launch/task.yaml Outdated Show resolved Hide resolved
AlanGriffiths and others added 2 commits May 28, 2021 23:46
Co-authored-by: Ian Johnson <person.uwsome@gmail.com>
Co-authored-by: Ian Johnson <person.uwsome@gmail.com>
@pedronis pedronis merged commit 856a839 into canonical:master May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Samuele review Needs a review from Samuele before it can land
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants