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: clean system apparmor cache on core device (2.29) #4084

Merged
merged 4 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions interfaces/apparmor/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ func (b *Backend) Setup(snapInfo *snap.Info, opts interfaces.ConfinementOptions,
logger.Noticef("cannot create host snap-confine apparmor configuration: %s", err)
}
}
// core on core devices is also special, the apparmor cache gets
// confused too easy, especially at rollbacks, so we delete the cache.
// See LP:#1460152 and
// https://forum.snapcraft.io/t/core-snap-revert-issues-on-core-devices/
if snapName == "core" && !release.OnClassic {
if li, err := filepath.Glob(filepath.Join(dirs.SystemApparmorCacheDir, "*")); err == nil {
for _, p := range li {
if st, err := os.Stat(p); err == nil && st.Mode().IsRegular() {
if err := os.Remove(p); err != nil {
logger.Noticef("cannot remove %q: %s", p, err)
}
}
}
}
}

// Get the files that this snap should have
content, err := b.deriveContent(spec.(*Specification), snapInfo, opts)
Expand Down
28 changes: 28 additions & 0 deletions interfaces/apparmor/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,31 @@ func (s *backendSuite) TestSetupHostSnapConfineApparmorForReexecWritesNew(c *C)
c.Check(err, IsNil)

}

func (s *backendSuite) TestCoreOnCoreCleansApparmorCache(c *C) {
restorer := release.MockOnClassic(false)
defer restorer()

err := os.MkdirAll(dirs.SystemApparmorCacheDir, 0755)
c.Assert(err, IsNil)
// the canary file in the cache will be removed
canaryPath := filepath.Join(dirs.SystemApparmorCacheDir, "meep")
err = ioutil.WriteFile(canaryPath, nil, 0644)
c.Assert(err, IsNil)
// but non-regular entries in the cache dir are kept
dirsAreKept := filepath.Join(dirs.SystemApparmorCacheDir, "dir")
err = os.MkdirAll(dirsAreKept, 0755)
c.Assert(err, IsNil)
symlinksAreKept := filepath.Join(dirs.SystemApparmorCacheDir, "symlink")
err = os.Symlink("some-sylink-target", symlinksAreKept)
c.Assert(err, IsNil)

// install the new core snap on classic triggers a new snap-confine
// for this snap-confine on core
s.InstallSnap(c, interfaces.ConfinementOptions{}, coreYaml, 111)

l, err := filepath.Glob(filepath.Join(dirs.SystemApparmorCacheDir, "*"))
c.Assert(err, IsNil)
// canary is gone, extra stuff is kept
c.Check(l, DeepEquals, []string{dirsAreKept, symlinksAreKept})
}