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

i/builtin: prohibit trailing '@' in common-files filepaths #14696

Conversation

olivercalder
Copy link
Member

For the common-files interface and those which use commonFilesInterface (such as system-files and personal-files), these append a trailing {,/,/**} to the end of each path.

The @ character is allowed in filepaths specified in these plugs, since filepaths like /dev/foo@bar may be required. However, if an @ character occurs at the end of the filepath (e.g. /foo/bar@), then the resulting filepath in the rule is /foo/bar@{,/,/**}. AppArmor treats @{FOO} as a variable, so having @{,/,/**} in the final rule snippet is problematic.

This commit adds a check to common_files.go to ensure that filepaths do not have a trailing @.

This addresses #14651 (comment)

For the `common-files` interface and those which use
`commonFilesInterface` (such as `system-files` and `personal-files`),
these append a trailing `{,/,/**}` to the end of each path.

The `@` character is allowed in filepaths specified in these plugs,
since filepaths like `/dev/foo@bar` may be required. However, if an `@`
character occurs at the end of the filepath (e.g. `/foo/bar@`), then the
resulting filepath in the rule is `/foo/bar@{,/,/**}`. AppArmor treats
`@{FOO}` as a variable, so having `@{,/,/**}` in the final rule snippet
is problematic.

This commit adds a check to `common_files.go` to ensure that filepaths
do not have a trailing `@`.

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.96%. Comparing base (96ea7b0) to head (0b55ae4).
Report is 29 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14696      +/-   ##
==========================================
+ Coverage   78.95%   78.96%   +0.01%     
==========================================
  Files        1084     1085       +1     
  Lines      146638   147112     +474     
==========================================
+ Hits       115773   116169     +396     
- Misses      23667    23719      +52     
- Partials     7198     7224      +26     
Flag Coverage Δ
unittests 78.96% <100.00%> (+0.01%) ⬆️

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.

@olivercalder olivercalder added the Simple 😃 A small PR which can be reviewed quickly label Nov 6, 2024
@bboozzoo bboozzoo requested a review from alexmurray November 7, 2024 07:15
@bboozzoo bboozzoo added the Needs security review Can only be merged once security gave a :+1: label Nov 7, 2024
@@ -104,6 +104,9 @@ func (iface *commonFilesInterface) validateSinglePath(np string) error {
if strings.HasSuffix(np, "/") {
return fmt.Errorf(`%q cannot end with "/"`, np)
}
if strings.HasSuffix(np, "@") {
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs a comment that in order to prevent emitting of dubious rules that look like @{,/,/**} and could be confusing to the parser we disallow trailing @. We prob. need to consult with the store to see if there are snaps using such path with system-files or personal-files interfaces.

Copy link
Member Author

@olivercalder olivercalder Nov 7, 2024

Choose a reason for hiding this comment

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

By parser do you mean the person reading this code later, or the AppArmor Parser itself?

I'll add a comment explaining though

Copy link
Contributor

Choose a reason for hiding this comment

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

both 'entities' could be equally confused without some context :)

…ith @

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
@olivercalder olivercalder requested a review from bboozzoo November 7, 2024 15:05
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

@olivercalder
Copy link
Member Author

The store team is checking whether there are any current users of system-files or personal-files which have been approved to use a path pattern ending in @. This is tracked internally by https://warthogs.atlassian.net/browse/SN-3859

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 but I also wonder if we should reject explicit use of @{ within the paths too?

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.

Copy link
Contributor

@ZeyadYasser ZeyadYasser left a comment

Choose a reason for hiding this comment

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

Great catch, Thank you!

@Meulengracht Meulengracht merged commit e323241 into canonical:master Nov 12, 2024
42 of 56 checks passed
@olivercalder
Copy link
Member Author

We need to follow up with https://warthogs.atlassian.net/browse/SN-3859 before the next release to ensure that this won't cause regressions, as it's possible (though unlikely) some snaps have registered paths with trailing @. My intention was to wait to merge this PR until that was confirmed.

@olivercalder
Copy link
Member Author

Ahh nevermind, I see there was an update posted to https://warthogs.atlassian.net/browse/SN-3859 yesterday, and it's all clear. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs security review Can only be merged once security gave a :+1: Simple 😃 A small PR which can be reviewed quickly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants