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

cmd/snap-confine: switch to dynamic SNAP_MOUNT_DIR #14074

Merged

Conversation

zyga
Copy link
Contributor

@zyga zyga commented Jun 12, 2024

This is based on #14068 which contains the first patch in this series (snap-dir.[ch] and snap-dir-test.c). Please disregard that when reviewing.

Bulk of the changes are related to testing sc-invocation. I can break that out if it helps. The rest is fairly straigtforward replacement of SNAP_MOUNT_DIR with sc_snap_mount_dir(NULL) except when it was used as a compile time string concatenation (only in tests) where a sligthly more verbose construct is in use.

The apparmor profile has two changes: one to allow it to probe (stat,readlink) /proc/1/root/snap. This change is contained in the patch "cmd/snap-confine: probe SNAP_MOUNT_DIR on startup". The second change is to remove @SNAP_MOUNT_DIR@ - sed text replacement - from snap-confie.apparmor.in and replace it with @{SNAP_MOUNT_DIR_LIST} - an apparmor parser variable - so that the same loaded profile allows probing and interacting with either of the locations (canonical and alternate).

This works for me locally. I'm opening a draft PR to run tests more widely.

Autoconf still needs AC_SUBST on SNAP_MOUNT_DIR as we have a number of places that still hard-code the location at compile time - most notably shell scripts (snap-mgmt.sh, snap-mgmt-selinux.sh) and the snad-generator. This will be left as-is until another pass.

Jira: SNAPDENG-22336
Spec: SD-179

@zyga zyga changed the title Feature/probe and use snap mount dir snapdeng 22335 cmd/snap-confine: switch to dynamic SNAP_MOUNT_DIR Jun 12, 2024
@pedronis pedronis added the Needs security review Can only be merged once security gave a :+1: label Jun 14, 2024
@zyga zyga force-pushed the feature/probe-and-use-snap-mount-dir-SNAPDENG-22335 branch 2 times, most recently from ce41f3d to bc56b12 Compare June 18, 2024 13:13
@zyga zyga marked this pull request as ready for review June 18, 2024 17:23
@zyga zyga requested review from alexmurray and bboozzoo June 18, 2024 17:24
@zyga zyga marked this pull request as draft June 18, 2024 21:48
@zyga
Copy link
Contributor Author

zyga commented Jun 18, 2024

There are some denials that look like missing bits in the security profile. I will investigate tomorrow.

Copy link
Contributor

@alexmurray alexmurray left a comment

Choose a reason for hiding this comment

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

LGTM in general but I think that SNAP_MOUNT_DIR_LIST in snap-confine.apparmor.in needs a minor update from what I can see.

cmd/snap-confine/snap-confine.apparmor.in Outdated Show resolved Hide resolved
@zyga zyga force-pushed the feature/probe-and-use-snap-mount-dir-SNAPDENG-22335 branch from bc56b12 to 7b3089a Compare June 19, 2024 12:13
@zyga zyga requested a review from alexmurray June 19, 2024 12:13
Copy link
Contributor

@alexmurray alexmurray left a comment

Choose a reason for hiding this comment

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

LGTM!

@alexmurray alexmurray removed the Needs security review Can only be merged once security gave a :+1: label Jun 20, 2024
@zyga zyga marked this pull request as ready for review June 20, 2024 07:25
@zyga zyga force-pushed the feature/probe-and-use-snap-mount-dir-SNAPDENG-22335 branch 3 times, most recently from fe2de96 to 87bca11 Compare June 24, 2024 12:08
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

@@ -32,6 +32,10 @@

static const char *_snap_mount_dir = NULL;

// Function is exported only for tests.
void sc_set_snap_mount_dir(const char *dir);
Copy link
Contributor

Choose a reason for hiding this comment

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

this forward declaration doesn't do anything useful

Suggested change
void sc_set_snap_mount_dir(const char *dir);

Copy link
Contributor

Choose a reason for hiding this comment

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

turns out it's needed after all, we use -Wmissing-prototypes

Copy link
Contributor

@MiguelPires MiguelPires left a comment

Choose a reason for hiding this comment

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

lgtm

zyga added 9 commits June 27, 2024 12:41
Call the probe early in snap-confine's startup logic and display the discovered
value. This triggers all the extra LSM permissions necessary to read through
/proc/1/root.

Signed-off-by: Zygmunt Krynicki <[email protected]>
Instead of a pre-processed apparmor profile, with a statically compiled /snap
or /var/lib/snapd/snap, use an apparmor parser variable that expands to both
locations.

The sed replacement of @SNAP_MOUNT_DIR@ is now pointless.

Signed-off-by: Zygmunt Krynicki <[email protected]>
zyga added 2 commits June 27, 2024 12:41
The profile is full of "slave" as in MS_SLAVE, which is a kernel interface.

Signed-off-by: Zygmunt Krynicki <[email protected]>
@zyga zyga force-pushed the feature/probe-and-use-snap-mount-dir-SNAPDENG-22335 branch from 87bca11 to 39919ba Compare June 27, 2024 10:54
The symlink /snap -> /var/lib/snapd/snap may be alternatively encoded as /snap
-> var/lib/snapd/snap in order to stay compatible with symlink packaging rules.

Adjusts tests to handle both variatns and tweak naming to match the non-test code.

Signed-off-by: Zygmunt Krynicki <[email protected]>
@zyga zyga merged commit e899ee3 into canonical:master Jun 28, 2024
48 of 51 checks passed
@zyga zyga deleted the feature/probe-and-use-snap-mount-dir-SNAPDENG-22335 branch June 28, 2024 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants