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

sandbox: Revert "sandbox/apparmor: do not skip ABI 4.0 from host parser (#14167)" #14223

Merged
merged 1 commit into from
Jul 23, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sandbox/apparmor/apparmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,15 @@ func AppArmorParser() (cmd *exec.Cmd, internal bool, err error) {
for _, dir := range filepath.SplitList(parserSearchPath) {
path := filepath.Join(dir, "apparmor_parser")
if _, err := os.Stat(path); err == nil {
// Detect but ignore apparmor 4.0 ABI support.
//
// At present this causes some bugs with mqueue mediation that can
// be avoided by pinning to 3.0 (which is also supported on
// apparmor 4). Once the mqueue issue is analyzed and fixed, this
// can be replaced with a --policy-features=hostAbi40File pin like
// we do below.
if fi, err := os.Lstat(hostAbi40File); err == nil && !fi.IsDir() {
return exec.Command(path, "--policy-features", hostAbi40File), false, nil
logger.Debugf("apparmor 4.0 ABI detected but ignored")
}

// Perhaps 3.0?
Expand Down
74 changes: 0 additions & 74 deletions sandbox/apparmor/apparmor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,80 +75,6 @@ func (*apparmorSuite) TestAppArmorParser(c *C) {
c.Check(err, Equals, nil)
}

func (*apparmorSuite) TestAppArmorHostAppArmorParserWithJustAbi3(c *C) {
fakeroot := c.MkDir()
dirs.SetRootDir(fakeroot)

mockParserCmd := testutil.MockCommand(c, "apparmor_parser", "")
defer mockParserCmd.Restore()

restore := apparmor.MockParserSearchPath(mockParserCmd.BinDir())
defer restore()

restore = apparmor.MockSnapdAppArmorSupportsReexec(func() bool { return false })
defer restore()

abiDir := filepath.Join(fakeroot, "etc", "apparmor.d", "abi")
c.Assert(os.MkdirAll(abiDir, 0755), IsNil)
c.Assert(os.WriteFile(filepath.Join(abiDir, "3.0"), nil, 0755), IsNil)

cmd, internal, err := apparmor.AppArmorParser()
c.Check(err, IsNil)
c.Check(cmd.Path, Equals, mockParserCmd.Exe())
c.Check(cmd.Args, DeepEquals, []string{mockParserCmd.Exe(), "--policy-features", filepath.Join(abiDir, "3.0")})
c.Check(internal, Equals, false)
}

func (*apparmorSuite) TestAppArmorHostAppArmorParserWithAbi3And4(c *C) {
fakeroot := c.MkDir()
dirs.SetRootDir(fakeroot)

mockParserCmd := testutil.MockCommand(c, "apparmor_parser", "")
defer mockParserCmd.Restore()

restore := apparmor.MockParserSearchPath(mockParserCmd.BinDir())
defer restore()

restore = apparmor.MockSnapdAppArmorSupportsReexec(func() bool { return false })
defer restore()

abiDir := filepath.Join(fakeroot, "etc", "apparmor.d", "abi")
c.Assert(os.MkdirAll(abiDir, 0755), IsNil)
c.Assert(os.WriteFile(filepath.Join(abiDir, "3.0"), nil, 0755), IsNil)
c.Assert(os.WriteFile(filepath.Join(abiDir, "4.0"), nil, 0755), IsNil)

cmd, internal, err := apparmor.AppArmorParser()
c.Check(err, IsNil)
c.Check(cmd.Path, Equals, mockParserCmd.Exe())
// When both are present, ABI 4 is preferred.
c.Check(cmd.Args, DeepEquals, []string{mockParserCmd.Exe(), "--policy-features", filepath.Join(abiDir, "4.0")})
c.Check(internal, Equals, false)
}

func (*apparmorSuite) TestAppArmorHostAppArmorParserWithJustAbi4(c *C) {
fakeroot := c.MkDir()
dirs.SetRootDir(fakeroot)

mockParserCmd := testutil.MockCommand(c, "apparmor_parser", "")
defer mockParserCmd.Restore()

restore := apparmor.MockParserSearchPath(mockParserCmd.BinDir())
defer restore()

restore = apparmor.MockSnapdAppArmorSupportsReexec(func() bool { return false })
defer restore()

abiDir := filepath.Join(fakeroot, "etc", "apparmor.d", "abi")
c.Assert(os.MkdirAll(abiDir, 0755), IsNil)
c.Assert(os.WriteFile(filepath.Join(abiDir, "4.0"), nil, 0755), IsNil)

cmd, internal, err := apparmor.AppArmorParser()
c.Check(err, IsNil)
c.Check(cmd.Path, Equals, mockParserCmd.Exe())
c.Check(cmd.Args, DeepEquals, []string{mockParserCmd.Exe(), "--policy-features", filepath.Join(abiDir, "4.0")})
c.Check(internal, Equals, false)
}

func (*apparmorSuite) TestAppArmorInternalAppArmorParserAbi3(c *C) {
fakeroot := c.MkDir()
dirs.SetRootDir(fakeroot)
Expand Down
Loading