76 Commits

Author SHA1 Message Date
Andrew Phelps
6abc1a3e6a a/snapasserts, o/assertstate: implement validate-component task handler (#13964)
* a/snapasserts: add helpers for checking validity of component against assertions

* a/snapasserts, o/assertstate: implement validate-component task handler

* o/assertstate: test validate-component handler with provenance
2024-06-03 17:29:13 +02:00
Andrew Phelps
3a7d30b271 a/snapasserts: add ValidationSets.SnapConstrained method (#13457) 2024-01-09 22:49:18 -05:00
Andrew Phelps
154d46b46c many: take into account validation sets during remodel (#13243)
This PR makes remodels take into account revision constraints from validation sets on the new model. Additionally, snaps that are marked as invalid in validation sets are checked for in the model.

* a/snapasserts: add methods for extracting more information out of ValidationSets type

* o/assertstate: add ValidationSetsFromModel function for extracting a snapasserts.ValidationSets from an asserts.Model

* o/snapstate: prevent installing/updating a snap from a local file that does not match requested revision

* o/devicestate: consider validation sets during remodeling

* tests/nested/manual: add remodel test that downgrades a snap because of a validation set

* tests/nested/manual: add remodel test that fails to remodel because of an invalid snap in a validation set

* tests/nested/manual: extend offline remodel test to also include a validation set

* tests/lib/assertions: fix timestamps on assertions

* asserts: add Key method to ValidationSet and ModelValidationSet

* o/devicestate: use new Key methods

* o/devicestate: maybe enforce validation sets during doSetModel

* o/devicestate: add test for enforcing validation sets in doSetModel

* a/snapasserts: simplify TestCanBePresent with loop

* tests/lib/assertions: add bluez snap to offline remodel test

* o/devicestate: remove done TODO

* o/snapstate: if remodeling, do not install prereq if link-snap task is present

* tests/nested/manual/remodel-offline: extend test to verify that validation sets are accounted for

* Revert "o/snapstate: if remodeling, do not install prereq if link-snap task is present"

This reverts commit 57c7725a2513df51be7ac1c06c492aaed07a6e3b.

This change is independent and will be included in another PR.

* a/snapasserts: add methods for extracting more information out of ValidationSets type

* o/assertstate: add ValidationSetsFromModel function for extracting a snapasserts.ValidationSets from an asserts.Model

* o/devicestate: add test for ValidationSetsConflictError.Is

* a/snapasserts: move methods after New function

* a/snapasserts: add test for ValidationSets.Revisions to verify ValidationSetsConflictError is returned

* o/assertstate: change ValidationSetsFromModel to take in a DeviceContext, rather than a StoreService

* o/assertstate: rename ValidationSetsModelFlags to ValidationSetsModelOptions

* o/devicestate: add type to export_test to make testing simpler

* tests: add details to new spread tests

* asserts: rename ModelValidationSet.Key and ValidationSet.Key to .SequenceName and add unit tests for them

* o/snapstate: update snap revision mismatch error message to be more clear

* o/devicestate: introduce helper for setting ValidationSets on snapstate.RevisionOptions if Revision is set

* o/devicestate: verify the parameters that fakeSequenceStore receives

* o/devicestate: fix revisions not being respected for essential snaps (and add a test for it)

* o/devicestate: extend TestRemodelUC20EssentialSnapsAlreadyInstalledAndLocal to also exercise case where a validation set requires a revision but the currently installed version is unasserted

* s/seedtest: update retrieveSeq to handle unconstrained sequence forming assertions

* a/snapasserts: add ValidationSets.Sets method

* o/assertstate: add deviceContext to ForgetValidationSet function so that change can happen during remodel

* o/devicestate: attempt to handle rollback of validation sets during failed remodel

* overlord: test for replacing conflicting validation sets during remodel

* o/assertstate: update ForgetValidationSet to take in a DeviceContext and to allow for forcing removal even if the validation set is in use by the model

* o/devicestate: roll back validation set changes on remodel failure

* o/devicestate: make sure that validation sets unrelated to the model survive a remodel

* o/devicestate: rename param in installedSnapRevisionChanged

* o/devicestate: rename field newSnapRevision to newRequiredRevision in modelSnapsForRemodel

* o/devicestate: simplify loops in checkForInvalidSnapsInModel

* o/devicestate: compare validation sets using SequenceName methods

* o/devicestate: fail remodel if we attempt to use an unasserted snap as a specific revision

* tests/nested/manual/remodel-offline: fix test to actually use validation set

* o/devicestate: create helper for creating snapstate.RevisionOptions during remodel

* o/devicestate: name param literals for clarity

* o/devicestate: invert logic to eliminate double negative

* o/devicestate: fix missed inversion of logic

* o/assertstate: update comment on ForgetValidationSetOpts.ForceForget

* overlord, o/devicestate: update remodel test to change models that contain the same validation set

* o/assertstate: test ForceForget functionality in ForgetValidationSet

* o/devicestate: rename function newRevisionOptionsForRemodel to revisionOptionsForRemodel

* o/assertstate, o/devicestate, daemon: remove unneeded DeviceContext param from ForgetValidationSet

* o/devicestate: remove println

* o/devicestate: clarify comment in rollback of adding validation sets

* o/devicestate: rename variable in enforceValidationSetsForRemodel

* o/snapstate: clarify error when attempting to install/refresh local snap with different revision than requested

* o/devicestate: naming consistency

* o/devicestate: simplify error when model is missing snap that is required in validation set

* asserts, overlord, o/devicestate: rename SequenceName to SequenceKey and prefix the series to the string that is returned
2023-12-12 10:00:48 +01:00
Andrew Phelps
38a74ecb3f a/snapasserts, o/assertstate: add functions to help during remodel (#13345) 2023-11-28 15:54:39 -05: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
Zeyad Yasser
54c6a1d8c3 refactor: replace IsNotFound usages for errors.Is(err, &NotFoundError{}) 2023-02-09 16:02:40 +00:00
Miguel Pires
1bc20a8391 daemon: change summary message + minor changes
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-28 10:28:31 +01:00
Miguel Pires
af2750d0a4 o/assertstate: add all used sets to ValidationSetsValidationError
Include all validation sets used to check in the validation error
instead of wrapping error with additional information.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-27 17:10:18 +01:00
Miguel Pires
73484a1523 asserts: wrap validation error with new sets data
Wrap the error returned by CheckInstalledSnaps with the new sets
that are not currently tracked. The previous approach required
marking those sets as "extra" in the validation set but was out
of place since this is only required for callers of "TryEnforce" to
resolve constraints that led to the validation error

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-26 17:17:46 +01:00
Miguel Pires
65e5c0271b asserts: add unit test for SetExtraSets method
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-26 14:46:23 +01:00
Miguel Pires
3cf8a0828b asserts: rename SexExtra method
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-26 14:46:09 +01:00
Miguel Pires
5c42708c8c daemon: support validation set refresh+enforce in API
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-23 15:43:31 +01:00
Miguel Pires
de9e6b210a asserts: pass assertion by ref instead of value
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-15 10:59:05 +01:00
Miguel Pires
7cb5386ebb store: use typed valset key in store action
Take a typed ValidationSetKey in the store package instead of a
[][]string, to help prevent wrong keys from being passed. To the same
end, also renames the field from ValidationSet to ValidationSetKey.
Also adds a Components() helper to split the key into its primary key
components.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-13 10:57:43 +01:00
Miguel Pires
5bcc0a98be asserts/snapasserts: use typed valset key in CheckPresenceInvalid
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-12 10:50:48 +01:00
Miguel Pires
621ff727c1 asserts/snapasserts: move and test ValidationSetKey helpers
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-12 10:50:48 +01:00
Miguel Pires
1bd6e476ce asserts/snapasserts: add ValidationSetKey type for RevisionOptions
Add ValidationSetKey type to prevent incorrect keys from being used.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-09-08 18:30:51 +01:00
Michael Vogt
e53a826e18 Merge pull request #11911 from stolowski/validation-sets/try-enforce-validation-sets
o/assertstate, snapasserts: implementation of assertstate.TryEnforceValidationSets function
2022-08-16 18:30:58 +02:00
Michael Vogt
42dc5efb05 Merge remote-tracking branch 'upstream/master' into validation-sets/try-enforce-validation-sets 2022-08-16 12:59:08 +02:00
Michael Vogt
9512a42ae5 Merge pull request #11988 from pedronis/crisper-check-provenance-api
many: change name and input of CheckProvenance to clarify usage
2022-08-16 12:51:04 +02:00
Samuele Pedroni
cbddde69ff a/snapasserts: add a test about DeriveSideInfo* ambiguity limitations 2022-07-22 18:25:10 +02:00
Samuele Pedroni
14a5f258e1 many: change name and input of CheckProvenance to clarify usage 2022-07-22 13:20:16 +02:00
Samuele Pedroni
21e2207e9e many: support non-default provenance snap-revisions in DeriveSideInfo*
snapsserts.DeriveSideInfo* cannot deal with snap-revisions with the
same hash but different provenance in the local system assertion
database, this should be an acceptable limitation for a while

the seedwriter code now assumes that the input can be trusted, this is
reasonable

systems.go uses already installed snaps, so it's fine but probably
would still be good to address the TODO in it for efficiency/clarity
as the code in seedwriter DeriveSideInfo is even more clunky now for
this use case, we should be able to find an applicable snap-revision
by other means
2022-07-22 11:30:28 +02:00
Samuele Pedroni
1ca77ad4e2 image,a/snapasserts: doc comment improvements/formatting
from comments on the previous PR and this, thanks @mardy, @MiguelPires
2022-07-21 09:17:14 +02:00
Samuele Pedroni
a58b5b6640 many: snap revision fetching and cross-checking for delegation
snap revision fetching and cross-checking should take provenance into
account and also verify device scope constraints for revision
authority delegation

provenance is taken as a hint from the store, but then matching
assertions must be found and then provenance is double checked

a failure of the latter check is likely a sign of a bug or
error as an attacker that can submit or forge/sign a blob could
as well do one with the expected provenance

provenance goals are tracing and avoiding the risk of polluting
the snap-revision namespace

this leaves alone the DeriveSideInfo* functions mainly used for
asserted local installs, this means they might fail to find a
snap-revision sometimes, they will be updated in a different branch.
2022-07-20 11:03:20 +02:00