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

snapstate: do not allow classic mode for strict snaps #6039

Merged
merged 15 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions overlord/snapstate/check_snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func (e *SnapNeedsClassicSystemError) Error() string {
// determine whether the flags (and system overrides thereof) are
// compatible with the given *snap.Info
func validateFlagsForInfo(info *snap.Info, snapst *SnapState, flags Flags) error {
if flags.Classic && !info.NeedsClassic() {
return fmt.Errorf("classic confinment requested for a non classic confined snap")
Copy link
Contributor

Choose a reason for hiding this comment

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

confinement

}

switch c := info.Confinement; c {
case snap.StrictConfinement, "":
// strict is always fine
Expand Down
21 changes: 21 additions & 0 deletions overlord/snapstate/check_snap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,27 @@ confinement: classic
c.Assert(err, ErrorMatches, ".* requires classic confinement which is only available on classic systems")
}

func (s *checkSnapSuite) TestCheckSnapErrorClassicModeForStrictOrDevmode(c *C) {
const yaml = `name: hello
version: 1.10
confinement: strict
`
info, err := snap.InfoFromSnapYaml([]byte(yaml))
c.Assert(err, IsNil)

var openSnapFile = func(path string, si *snap.SideInfo) (*snap.Info, snap.Container, error) {
c.Check(path, Equals, "snap-path")
c.Check(si, IsNil)
return info, emptyContainer(c), nil
}
restore := snapstate.MockOpenSnapFile(openSnapFile)
defer restore()

err = snapstate.CheckSnap(s.st, "snap-path", "hello", nil, nil, snapstate.Flags{Classic: true})

c.Assert(err, ErrorMatches, "classic confinment requested for a non classic confined snap")
}

func (s *checkSnapSuite) TestCheckSnapKernelUpdate(c *C) {
reset := release.MockOnClassic(false)
defer reset()
Expand Down
7 changes: 7 additions & 0 deletions tests/main/install-errors/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ execute: |
exit 1
fi
MATCH 'characters that look like dashes but are not' < stderr.out

echo "Installing a strict snap in classic mode does not work"
if snap install --classic test-snapd-tools 2>stderr.out; then
echo "snap install ––classic test-snapd-tools should have failed but did not"
exit 1
fi
MATCH 'classic confinment requested for a non classic confined snap' < stderr.out