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

o/c/configcore,o/ifacestate: check for presence of handler-service on startup #14843

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

olivercalder
Copy link
Member

@olivercalder olivercalder commented Dec 11, 2024

During snapd startup, if the "apparmor-prompting" flag is enabled but there is no snap with an interfaces-requests-control connection and an app app declared as a "handler-service", then record a warning that prompts will be auto-denied until a prompting client is installed.

Such a situation could arise if the user uninstalled the prompting client snap without disabling the "apparmor-prompting" feature flag, or if they disconnected the plug for the interfaces-requests-control interface.

There is a check for the presence of a handler-service client when one attempts to enable the "apparmor-prompting" feature flag in the first place: when enabling the flag, if there is no handler-service app present, or it cannot be successfully started, then the flag is left disabled. Before this commit, however, there were no subsequent checks for the presence of a handler-service, so the user would have no indication of why snaps may be blocking on syscalls or having syscalls denied. Now, we make this check again at snapd startup, but rather than disabling prompting, we instead simply record a warning to the user.

In a previous iteration of this PR, if no handler-service was connected during snapd startup, then prompting was treated as inactive until snapd was restarted. The implementation of that approach can be found here: dabea71

This work is tracked internally by https://warthogs.atlassian.net/browse/SNAPDENG-34245

@olivercalder olivercalder added the Needs Samuele review Needs a review from Samuele before it can land label Dec 11, 2024
@olivercalder olivercalder added this to the 2.68 milestone Dec 11, 2024
@github-actions github-actions bot added the Needs Documentation -auto- Label automatically added which indicates the change needs documentation label Dec 11, 2024
@olivercalder
Copy link
Member Author

The tests for interfacesRequestsControlHandlerServicePresent etc. need to be migrated from overlord/configstate/configcore, but there's some complexity around mocking. I'll take a look at this again tomorrow.

@olivercalder olivercalder force-pushed the prompting-check-for-handler-service-on-startup branch from ef5eac5 to dabea71 Compare December 11, 2024 14:57
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 67.39130% with 15 lines in your changes missing coverage. Please review.

Project coverage is 78.29%. Comparing base (24a0034) to head (4761cfb).
Report is 71 commits behind head on master.

Files with missing lines Patch % Lines
overlord/ifacestate/ifacestate.go 58.62% 8 Missing and 4 partials ⚠️
overlord/ifacestate/ifacemgr.go 81.25% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14843      +/-   ##
==========================================
+ Coverage   78.20%   78.29%   +0.08%     
==========================================
  Files        1151     1154       +3     
  Lines      151396   152638    +1242     
==========================================
+ Hits       118402   119508    +1106     
- Misses      25662    25758      +96     
- Partials     7332     7372      +40     
Flag Coverage Δ
unittests 78.29% <67.39%> (+0.08%) ⬆️

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
Copy link
Member Author

We don't want to treat prompting as inactive if there's no client, instead check for the presence of a client and record a warning if there's not one. So I need to rework this PR.

… startup

During snapd startup, if the "apparmor-prompting" flag is enabled but
there is no snap with an interfaces-requests-control connection and an
app app declared as a "handler-service", then record a warning that
prompts will be auto-denied until a prompting client is installed.

Such a situation could arise if the user uninstalled the prompting
client snap without disabling the "apparmor-prompting" feature flag, or
if they disconnected the plug for the interfaces-requests-control
interface.

There is a check for the presence of a handler-service client when one
attempts to enable the "apparmor-prompting" feature flag in the first
place: when enabling the flag, if there is no handler-service app
present, or it cannot be successfully started, then the flag is left
disabled. Before this commit, however, there were no subsequent checks
for the presence of a handler-service, so the user would have no
indication of why snaps may be blocking on syscalls or having syscalls
denied. Now, we make this check again at snapd startup, but rather than
disabling prompting, we instead simply record a warning to the user.

Signed-off-by: Oliver Calder <[email protected]>
@olivercalder olivercalder force-pushed the prompting-check-for-handler-service-on-startup branch from dabea71 to 404acaa Compare December 16, 2024 22:36
@olivercalder
Copy link
Member Author

This PR has been reworked to record a notice rather than marking prompting as disabled, if there is no handler service connected during snapd StartUp.

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, thank you

overlord/ifacestate/ifacestate.go Outdated Show resolved Hide resolved
Comment on lines 577 to 581
func (m *InterfaceManager) interfacesRequestsControlHandlerServicePresent() (bool, error) {
return interfacesRequestsControlHandlerServicePresentImpl(m)
}

var interfacesRequestsControlHandlerServicePresentImpl = func(m *InterfaceManager) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a nitpick but why not call this directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

I want the function to be a method but I want to be able to mock the implementation as a function which can take a minimal InterfaceManager wrapper around a custom state. But in retrospect, I think I was trying to have it both ways: either the method itself should be mockable or the implementation should simply take a state.State instead of an InterfaceManager. Would you prefer the former?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Documentation -auto- Label automatically added which indicates the change needs documentation Needs Samuele review Needs a review from Samuele before it can land
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants