Skip to content

Commit

Permalink
Use the interface name instead of the plug name
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-costas committed May 6, 2024
1 parent 0d9de14 commit 0ffa8a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 9 additions & 3 deletions interfaces/builtin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,18 @@ func aareExclusivePatterns(orig string) []string {
// in the dir, causing excessive noise. (LP: #1868051)
func getDesktopFileRules(snapInstanceName string, spec *apparmor.Specification) []string {
// desktop-launch allows to read all .desktop files; but "deny" rules overrule any "allow"
// rule, so we must not add these rules if this snap uses the desktop-launch interface
// rule, so we must not add these rules if this snap uses the desktop-launch interface.
// Also, for security reasons, all these rules are removed if the desktop-launch interface
// is listed, thus only if it is really connected will the snap have any kind of access to
// these folders/files.
if spec != nil {
if _, ok := spec.SnapAppSet().Info().Plugs["desktop-launch"]; ok {
return nil
for _, plug := range spec.SnapAppSet().Info().Plugs {
if plug.Interface == "desktop-launch" {
return nil
}
}
}

baseDir := dirs.SnapDesktopFilesDir

rules := []string{
Expand Down
8 changes: 6 additions & 2 deletions interfaces/builtin/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,15 @@ func (s *utilsSuite) TestGetDesktopFileRulesWithDesktopLaunchPlug(c *C) {
// fake apparmor.Specification
info := snap.Info{}
snapSet := interfaces.NewSnapAppSet(&info)
// although usually the name is equal to the interface, this is not
// guaranteed, so to test it right we must try with a name that is
// different than the interface.
plugInfo := snap.PlugInfo{
Name: "desktop-launch",
Name: "desktop-launch-iface",
Interface: "desktop-launch",
}
snapSet.Info().Plugs = make(map[string]*snap.PlugInfo)
snapSet.Info().Plugs["desktop-launch"] = &plugInfo
snapSet.Info().Plugs["desktop-launch-iface"] = &plugInfo
spec := apparmor.NewSpecification(snapSet)

res := builtin.GetDesktopFileRules("foo-bar", spec)
Expand Down

0 comments on commit 0ffa8a6

Please sign in to comment.