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

snap/validate.go: disallow snap layouts with new top-level directories #8985

Conversation

anonymouse64
Copy link
Contributor

@anonymouse64 anonymouse64 commented Jul 6, 2020

We previously wouldn't fail on verification for snaps that used new top-level directories, and would fail at runtime, which produces a very unhelpful message.

Also adjust some test yamls in interfaces/mount tests, which are not valid as they are for new top-level directories in /.

Finally, add an additional unit test for the test case with LP #1831010 that is already covered by spread tests, but not yet by unit tests.

See https://forum.snapcraft.io/t/snap-application-works-in-classic-mode-fails-in-dev-mode-and-strict/18562/7 for an example of such a confusion.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
@anonymouse64 anonymouse64 requested a review from zyga July 6, 2020 20:37
@anonymouse64 anonymouse64 force-pushed the bugfix/check-new-top-level-dirs-layouts branch from 9ff2d2c to ef9ba38 Compare July 6, 2020 22:37
We previously wouldn't fail on verification for snaps that used new top-level
directories, and would fail at runtime, which produces a very unhelpful message.

Also adjust some test yamls in interfaces/mount tests, which are not valid as
they are for new top-level directories in /.

Finally, add an additional unit test for the test case with LP #1831010 that is
already covered by spread tests, but not yet by unit tests.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
@anonymouse64 anonymouse64 force-pushed the bugfix/check-new-top-level-dirs-layouts branch from ef9ba38 to 7ae57af Compare July 7, 2020 03:36
zyga
zyga previously approved these changes Jul 7, 2020
Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@zyga
Copy link
Contributor

zyga commented Jul 7, 2020

@anonymouse64 my review was hasty, the validator needs to expand variables or it will lead to failures in supported cases like this:

2020-07-07T04:26:45.0448863Z error: cannot pack "test-snapd-layout": cannot validate snap "test-snapd-layout": layout "$SNAP/d" is a relative filename

snap/validate.go Outdated
@@ -400,6 +400,38 @@ func ValidateLayoutAll(info *Info) error {
}
sort.Strings(paths)

// Validate that each source path is not a new top-level directory
for pathSrc := range info.Layout {
cleanPathSrc := info.ExpandSnapVariables(filepath.Clean(pathSrc))
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 puzzling. Having expanded the variables it still is confused. Looking at the rest of the code we seem to use Layout.PathJ

In actual usages outside of the unit tests, we will use the layout.Path
element so use that instead.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
@anonymouse64 anonymouse64 requested a review from zyga July 7, 2020 14:36
@anonymouse64 anonymouse64 dismissed zyga’s stale review July 7, 2020 14:36

changed since review

Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

LGTM

// this list was produced by taking all of the top level
// directories in the core snap and removing the explicitly
// denied top-level directories
case "bin", "etc", "lib", "lib64", "meta", "mnt", "opt", "root", "sbin", "snap", "srv", "usr", "var", "writable":
Copy link
Contributor

Choose a reason for hiding this comment

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

Orthogonal to the PR, but shouldn't /writable be denied too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mmm not sure, since the directory is there and since 2.4X we don't mount /writable inside the snap's mount namespace anyways I don't see why we should disallow /writable, @zyga what do you think ?

@anonymouse64 anonymouse64 merged commit 5e8670d into canonical:master Jul 8, 2020
@anonymouse64 anonymouse64 deleted the bugfix/check-new-top-level-dirs-layouts branch July 8, 2020 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants