62 Commits

Author SHA1 Message Date
Miguel Pires
8128ed20bb many: rename aspect/bundle to view/registry
This changes the naming of the aspects feature to be "registry" instead
of bundle (i.e., a configuration space backed with its own storage) and
"view" instead of aspect. Once this lands, anyone that has this enabled
needs to unset the experimental flag and rename the state entry before
refreshing snapd and then re-enable.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-06-17 17:16:57 +02:00
Oliver Calder
0ff642e82e many: include prompt prefix in apparmor rules (#13822)
* features,i/{apparmor,builtin}: include prompt prefix in home interface

If prompting is supported and enabled, include the prompt prefix in
AppArmor rules for the home interface, which will cause AppArmor to send
a prompt when accessing any file in $HOME.

In the future, if other interfaces include the ###PROMPT### prefix in
their rule snippets, this will also be handled accordingly.

At the moment, the status of prompting support is checked whenever the
AppArmor backend prepares profiles. This is okay, since AppArmor support
for prompting depends on kernel and parser features, which are only
probed once after snapd starts. However, to ensure that the same
supported value is used even if that were not the case, and in case we
wish to only use the prompt prefix for some snaps or interfaces, we may
wish to embed whether to use the prompt prefix in the AppArmor
Specification instead.

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

* features: adjust unsupported messages when checking apparmor features errors

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

* interfaces: add prompting status to system key

Include whether prompting is supported and enabled as a single field in
the system key. This way, if `(supported && enabled)` changes, security
profiles will be regenerated when snapd starts up.

Currently, prompting support only changes when the AppArmor kernel or
parser features change, and profile regeneration is the only other place
where it is checked whether AppArmor prompting is supported and enabled.
Thus, including whether prompting is supported and enabled in the system
key ensures that security profiles are regenerated when necessary during
snapd startup, and only when necessary (e.g. not if support changed but
prompting flag remained disabled nor if flag changed but prompting
remained unsupported).

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

* o/c/configcore: restart snapd when prompting value changes

When the prompting flag changes and the result entails that security
profiles should be regenerated, restart snapd to do so.

This is required iff prompting is supported and the experimental
apparmor-prompting flag changes -- if prompting is not supported,
prompting can't be used, so no need to regenerate profiles. Importantly,
prompting support is based entirely on the available AppArmor kernel and
parser features, and these are only probed once during snapd startup, so
prompting support cannot change (under the current implementation)
except when snapd restarts.

Since `(supported && enabled)` is part of the system key, and a restart
is only triggered if prompting is supported and the flag value changes
(which is equivalent to `(supported && enabled)`, since the supported
value cannot change while snapd is running), restarting after the flag
has changed causes the system key to be different, and thus to trigger a
security profile regeneration, as desired.

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

* interfaces,o/ifacestate: set prompting in apparmor spec

Rather than checking whether AppArmor prompting is supported and enabled
whenever the AppArmor backend is processing a snippet, instead include
that precomputed value in the Specification itself, and place it there
via `buildConfinementOptions`. This way, any spec created with the same
`confinementOptions` will make the same decision as to whether to
include prompt prefixes on relevant rules.

Currently, `buildConfinementOptions` simply checks whether prompting is
supported and enabled via the methods on `features.AppArmorPrompting`,
but ideally, this value would be looked up from either the system key
or by checking whether the prompting listener is running. It remains to
be seen how the value computed as part of the system key can be
guaranteed to be the same as that used elsewhere, either in
`buildConfinementOptions` or when deciding whether to start the
listener.

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

* o/c/configcore: request snapd restart whenever prompting flag changes

Previously, a snapd restart was only requested when the status of the
"apparmor-prompting" experimental feature flag changed and prompting was
supported. However, since prompting support is dependent on AppArmor
kernel and parser features which are probed only once during startup,
and systems which do not use vendored AppArmor may have had an update to
the system AppArmor package which newly supports AppArmor prompting, it
is safer to request a restart of snapd to re-check for prompting
support.

This way, if one is enabling prompting for the first time on a system
without prompting support, they can have snapd installed, update their
kernel or apparmor installation to support prompting, and then set the
prompting flag to enable prompting without needing to manually restart
snapd.

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

* interfaces: support optional trailing space after ###PROMPT###

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

i/apparmor: move promptReplacer definition to before its use

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

* tests: add test of restart behavior when setting experimental.apparmor-prompting

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

* tests: refactor prompting test to reset failed count and safely check for restarts

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

tests: add shellcheck exception for apparmor prompting flag restart test

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

* tests: check that snapd PID != 0 and use snap changes to wait for feature change to complete

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

* tests: check for start-limit-hit before calling reset-failed

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

* tests: add ubuntu core to apparmor prompting flag restart test

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

* tests: check apparmor-prompting value after setting it unchanged

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

* Revert "tests: check for start-limit-hit before calling reset-failed"

This reverts commit bea68516c3287fa44d6718f0794484746ae99ac5.

* tests: check systemd start-limit-hit when apparmor-prompting flag changed

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

* o/configstate/configcore: add unit tests for doExperimentalApparmorPromptingDaemonRestart

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

* i/builtin: add missing prompt prefix and adjust test

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

* i/apparmor: add test for prompt prefix substitution

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

* many: pass prompting value into system key functions

As such, we now precompute whether prompting is supported and enabled in
`InterfaceManager.StartUp()`, store it in the `InterfaceManager`
instance, and pass it into the call to `WriteSystemKey()`.

Additionally, we make `buildConfinementOptions` a method of
`InterfaceManager`, thus eliminating the need to check within the system
key functions whether prompting is supported and enabled.

However, there remains a problem that `snap run` calls
`SystemKeyMismatch()`, which previously invoked
`apparmor.ParserFeatures()` via `AppArmorPrompting.IsSupported()`, and
now calls `AppArmorPrompting.IsSupported()` directly and passes the
result into `SystemKeyMismatch()`. In either case, we really want this
to be avoided if at all possible, since `snap run` does not have access
to the cached value from the `InterfaceManager`, and thus must invoke
the `apparmor_parser` binary to check parser features whenever we want
to run any snap.

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

* many: don't probe parser features when checking system key mismatch

Since `snap run` calls `SystemKeyMismatch()`, we want to avoid needing
to call `AppArmorPrompting.IsSupported()` if at all possible, since this
calls `apparmor.ParserFeatures()`, which executes the `apparmor_parser`
binary. We can and should call `AppArmorPrompting.IsSupported()` when
writing the system key, but not when checking for a mismatch.

The system key written to disk should correctly hold the list of kernel
and parser features, the parser mtime, and whether or not prompting was
previously supported and enabled. We can check whether apparmor parser
features have changed by checking the parser mtime, without needing to
probe parser features -- this optimization is already used by
`SystemKeyMismatch()`. If we knew whether prompting was previously
supported (regardless of whether it was enabled), then so long as the
parser and kernel features are unchanged, we know that prompting support
is also unchanged.

Thus, if we add a second prompting-related field to the system key, this
one storing whether prompting is supported (ignoring enabled), we can
check if prompting support is unchanged without needing to call
`AppArmorPrompting.IsSupported()`.

Furthermore, `SystemKeyMismatch()` is the function in question, and if
there is any mismatch detected, it should return such as soon as
possible, regardless of what the mismatch is. Therefore, if we know that
either kernel or parser features have changed, then we can immediately
return that there is a mismatch, and we don't need to check whether
those feature changes affect prompting support.

Therefore, the new cases which we must worry about when checking for a
system key mismatch are the following, when all other system key fields
are unchanged (note that prompting must be supported in order to be
supported&&enabled):

1. supported: F, supported&&enabled: F, newFlag: F, mismatch: F
2. supported: F, supported&&enabled: F, newFlag: T, mismatch: F
3. supported: T, supported&&enabled: F, newFlag: F, mismatch: F
4. supported: T, supported&&enabled: F, newFlag: T, mismatch: T
5. supported: T, supported&&enabled: T, newFlag: F, mismatch: T
6. supported: T, supported&&enabled: T, newFlag: T, mismatch: F

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

* interfaces: fix test string formatting

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

* o/configstate/configcore: adjust prompting-related comments

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

* tests: increase prompting check_snapd_restarted timeout and add systemd show

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

* tests: reset start limit when checking if snapd restarted after prompting change

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

* many: add system key extra data to hold prompting enabled status

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

* many: only store one apparmor prompting value in system key

When checking for a system key mismatch, use the stored AppArmor
parser features from the system key on disk (along with the kernel
features from the newly-generated key) to check whether prompting is
supported, and AND that with the `AppArmorPrompting` value passed in
with the `SystemKeyExtraData`. If the kernel or parser features have
changed, the system key will be a mismatch anyway, so it is perfectly
safe to use the existing parser features to check for prompting support.

As such, the functions to check for prompting support have been moved
from `features` to `sandbox/apparmor`, and the support check has been
separated from the call to get `ParserFeatures()` and
`KernelFeatures()`, so that the values from the system key can be passed
in instead of invoking those functions.

Using the system key's stored parser and kernel features, there is no
need to save whether prompting is supported as part of the system key,
simplifying the key and the logic used to set the prompting value.

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

* tests: explicitly install jq in apparmor-prompting-flag-restart test

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

* many: consolidate checks for apparmor prompting support

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

* interfaces,s/apparmor: use features struct when checking prompting support

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

* tests: improve logging in apparmor-prompting-flag-restart test

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

* tests: fix prompting flag restart test on core18

For some reason, when snapd fails due to start-limit-hit on core18, the
snapd.failure.service starts and acquires the state lock, thus
preventing snapd from successfully becoming "active" again and leaving
it retrying at "activating". It is unclear why this happens on core18
and not elsewhere.

As a fix, when resetting the start limit, stop snapd.failure.service
manually to ensure that snapd can successfully start.

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

---------

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
2024-06-11 18:13:00 +01:00
Oliver Calder
a599d54722 features: add checks for prompt support in apparmor parser and kernel
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>

features: add tests for features supported callbacks

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

features: adjust prompting unsupported parser message

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
2024-04-26 09:38:12 -05:00
Oliver Calder
4714253f45 features: add function to return info about feature flags
Add `All()` function, which returns a map of feature names to
`FeatureInfo` structs. `FeatureInfo` contains boolean values for whether
the feature is supported and whether it is enabled.

A new map is defined from feature flags to callback functions which
return true if the feature is supported and false if it is unsupported.
Any feature for which no callback function is defined is assumed to be
supported.

Currently, callback functions are defined for `QuotaGroups` (check that
systemd version >= 230), `UserDaemons` (check that user units are
supported), and `AppArmorPrompting` (always return false, for now).

Since some components of prompting are not yet merged into snapd master,
the experimental "apparmor-prompting" feature is not yet supported. This
commit adds a callback for "apparmor-prompting" which returns false and
states that it requires a newer version of snapd.

Once the rest of the prompting system is ready, the callback for
AppArmorPrompting should be modified to instead check that the installed
AppArmor has kernel and parser support for prompting, and that the
notify socket for communicating with the kernel exists.

Any features which are set to values other than true or false are
omitted from the map returned by `All()`.

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

features: add unsupported reason when feature not supported

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

features: improved docstrings for `All()` and `FeatureInfo`

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

features: adjusted callback feature unsupported reasons

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

features: add supported callback for apparmor prompting

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
2024-03-14 08:39:09 +01:00
Oliver Calder
76b5ebd805 features: add experimental.apparmor-prompting feature stub
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
2024-03-13 09:32:25 +01:00
Miguel Pires
4439f6d25d features: add count checks to ensure features are tested (#13518)
* features: ensure features are tested

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* features: add quota group tests in features

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-01-26 09:29:36 +01:00
Miguel Pires
5204d36625 features: add experimental feature flag for aspects
Add the aspects-configuration experimental flag and use it to gate
functionality in the CLI and API.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-01-24 17:08:36 +00:00
Zeyad Gouda
5d39faeb9a features: add new feature (refresh-snap-awareness-ux)
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2024-01-16 14:16:53 +01:00
Miguel Pires
29c9752d66 many: s/ioutil.WriteFile/os.WriteFile (#13217)
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-09-26 11:38:46 +01:00
Philip Meulengracht
41f96ad50f many: move memory,cpu and thread quota out of experimental (#12529)
* many: repurpose quota-groups experimental feature instead of introducing a new feature flag

* cmd/snap: unhide quota commands

* cmd/snap: add missing help categories for quota commands

* features: remove feature flag from tests

* features,o/servicestate: review feedback

Clarify the docs for the quota-groups feature. Be more specific in regards to the experimental helper text. Simplify function that checks for feature flag
2023-02-01 15:53:50 +01:00
Philip Meulengracht
af1860b2fb features,overlord/servicestate: add support for per-quota requirements (#11962)
* features,overlord/servicestate: add support for per-quota requirements

* overlord/servicestate: add unit tests for the new per-quota requirements

* overlord/servicestate: fix doc

* tests/main/snap-logs-journal: set new experimental flag for this test

* o/servicestate: fix tests after rebase, add additional changes to spread tests after new tests have been introduced

* t/core/persistent-journal-namespace: enable experimental journal quotas

* o/servicestate: allow the old quota-groups option, remove the changes to tests as that is not needed for this PR

* o/servicestate: review feedback

spelling mistake, remove wrong return revealed by test. (but is not hit in this PR due to redundant quota checks)

* multiple: review feedback

fix unit test run

* t/m/snap-quota-journal: try again, couldn't figure out the whitespace
2023-01-26 15:59:47 +01:00
Michael Vogt
06df81c76e many: revert "features: disable refresh-app-awarness by default again"
This reverts commit db339ccd37.

The desktop team is very nervous about disabling
refresh-app-awareness, especially this close to the release of
22.04.1. The worry is that unknown bugs during a refresh may
cause firefox to crash. Given the really good progress we had
with the startup performance and other improvements this would
be very unfortunate. Fwiw, there are no refresh bugs known right
now but the risk is there. The desktop team feels that the
shortcoming in the UX are a better tradeoff than to risk crashes.

We fixed the known issues around refresh-app-awareness:
https://bugs.launchpad.net/snapd/+bug/1975714
https://bugs.launchpad.net/snapd/+bug/1978834
https://github.com/snapcore/snapd/pull/11834
https://github.com/snapcore/snapd/pull/11976
https://github.com/snapcore/snapd/pull/11855

so hopefully this does not hit the other side of this too
hard. Sorry to everyone for yet another flip-flop on this,
it's really hard to find the right trade-off here.

This reverts https://github.com/snapcore/snapd/pull/11912
2022-07-26 12:36:24 +02:00
Michael Vogt
db339ccd37 features: disable refresh-app-awarness by default again
* features: disable refresh-app-awarness by default again

We enabled the `experimental.refresh-app-awareness` option right
before the 22.04 release [1]. However in hindsight this move was
premature. The UX is not quite ready, the refresh is stopped
but the experience should be that once the app is closed the
update gets applied which is not implemented yet. There are
also design issues with e.g. LXD as outlined in LP:#1978005
the need time and design to resolve. Another reason was the
automatic ~/snap -> ~/Snap folder migration. But this is
done differently now.

For the above reasons this commit changes the default again
to `refresh-app-awarness=false` until there is time to
fix the UX and the LXD issues.

[1] https://github.com/snapcore/snapd/pull/11566

* hookstate: disable refresh-app-awareness in gateAutoRefreshHookSuite.SetUpTest() - not strictly needed but when we enable refresh-app-awareness again it will help
2022-07-05 18:02:50 +02:00
Miguel Pires
dd32173b78 o/snapstate: minor simplifications
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-06-13 09:34:20 +01:00
Miguel Pires
91bfc1efad features: add move snap home experimental feature
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-06-09 09:40:24 +01:00
Pawel Stolowski
5a9eb56825 features: enable refresh-app-awareness by default
* Enable refresh-app-awareness by default.

* Update tests.

* Fix comment.

* Pass --ignore-running in spread tests.

* Update hidden-snap-dir test with --ignore-running.

* Fix op-remove-retry test to kill test-snapd-tools.block process.

* Remove --ignore-running flag from hidden-snap-dir (not needed).

* Remove --ignore-running flag from refresh test (not needed).

* Add comment to the test

Co-authored-by: Maciej Borzecki <maciek.borzecki@gmail.com>

* Add comment to the test

Co-authored-by: Maciej Borzecki <maciek.borzecki@gmail.com>

* Add extra comments explaining --ignore-running use in the tests.

Co-authored-by: Maciej Borzecki <maciek.borzecki@gmail.com>
2022-04-21 09:00:05 +02:00
Miguel Pires
003247d4b7 cmd: use IsEnabled instead of Stat 2021-10-08 17:36:39 +01:00
Miguel Pires
a8f4b392ef many: s/SnapDataDir/SnapDataHomeDir/ 2021-10-04 15:10:55 +01:00
Miguel Pires
c734f653cb many: make naming more consistent 2021-09-29 12:33:20 +01:00
Miguel Pires
2c4d18eaf4 many: enable ~/.snap experimental feature 2021-09-23 23:51:36 +01:00
James Henstridge
88644518c5 Merge remote-tracking branch 'upstream/master' into enable-feature-dbus-activation 2021-05-27 13:33:45 +08:00
Michael Vogt
5603fbe09b features,servicestate: add experimental.quota-control flag
To allow us to still change he API we put resource groups
behind an experimental flag.
2021-04-29 20:35:46 +02:00
Paweł Stołowski
6d51527ddb Renamed refresh-control to gate-auto-refresh-hook. 2021-04-06 08:22:48 +00:00
Paweł Stołowski
bfc82b5fec Add refresh-control feature flag. 2021-04-06 08:22:48 +00:00
James Henstridge
926f7f7d67 features: enable dbus-activation feature by default 2021-03-18 19:12:25 +08:00