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

osutil: add mount/libmount package with option validator #14814

Conversation

zyga
Copy link
Contributor

@zyga zyga commented Dec 6, 2024

We need to recognize and validate libmount-style mount options, such as those that one can use with the mount(1) utility on command line for possible conflicts. This is so that the apparmor parser, which does similar validation, does not fail "late" in the interface setup process, when given incorrect data by the mount-control interface.

This patch adds the skeleton of the validator, along with read-only and read-write mount options.

Jira: https://warthogs.atlassian.net/browse/SNAPDENG-32984

NOTE: this is a draft, I need to hook it up to interfaces logic as well.
I have considered asking apparmor for this information but given that we cannot even discover the full set of known mount options and the interrogation is inefficient (compile and see if it gets ignored), I chose to just bake in the table. There are only 32 bits possible so we are not up an unbound problem anyway.

I've only added one pair of conflicting options as this is a draft solicitng review

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.26%. Comparing base (24a0034) to head (c789f68).
Report is 29 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14814      +/-   ##
==========================================
+ Coverage   78.20%   78.26%   +0.05%     
==========================================
  Files        1151     1152       +1     
  Lines      151396   152065     +669     
==========================================
+ Hits       118402   119015     +613     
- Misses      25662    25693      +31     
- Partials     7332     7357      +25     
Flag Coverage Δ
unittests 78.26% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zyga zyga force-pushed the fix/mount-control-option-validation-SNAPDENG-32984 branch 5 times, most recently from a45e563 to f5aaf1d Compare December 10, 2024 14:27
@zyga zyga marked this pull request as ready for review December 10, 2024 14:28
zyga added 4 commits December 11, 2024 09:54
We need to recognize and validate libmount-style mount options, such as those
that one can use with the mount(1) utility on command line for possible
conflicts.  This is so that the apparmor parser, which does similar validation,
does not fail "late" in the interface setup process, when given incorrect data
by the mount-control interface.

Note that the Darwin implementation of the function is a stub.

Jira: https://warthogs.atlassian.net/browse/SNAPDENG-32984

Signed-off-by: Zygmunt Krynicki <[email protected]>
Mount APIs use event propagation terminology with the words mater and slave
that are hard to change. Add the two files to the exception list.

Signed-off-by: Zygmunt Krynicki <[email protected]>
The mount-control interface used to allow requesting contradicting mount
options, such as nodev and dev and would silently pass this down to
apparmor_parser. The parser would detect this and cause the failure of the
security setup.

With this code we now detect this much earlier, at interface validation stage.

Fixes: https://warthogs.atlassian.net/browse/SNAPDENG-32984

Signed-off-by: Zygmunt Krynicki <[email protected]>
@zyga zyga force-pushed the fix/mount-control-option-validation-SNAPDENG-32984 branch from f5aaf1d to c789f68 Compare December 11, 2024 08:54
@zyga
Copy link
Contributor Author

zyga commented Dec 11, 2024

I've made the code compatible with Go 1.18

Copy link
Member

@Meulengracht Meulengracht left a comment

Choose a reason for hiding this comment

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

To me this looks super clean and nice. Thank you!


// ValidateMountOptions is a stub.
func ValidateMountOptions(opts ...string) error {
// This is not implemented for Darwin. We could implement it by baking all
Copy link
Member

Choose a reason for hiding this comment

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

Until the need arrives for this to be on darwin I think this is fine. I'd rather move things around when we need to than try to predict.

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

@Meulengracht Meulengracht merged commit 5dfc211 into canonical:master Dec 11, 2024
55 of 59 checks passed
@zyga zyga deleted the fix/mount-control-option-validation-SNAPDENG-32984 branch December 12, 2024 17:12
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.

3 participants