57540 Commits

Author SHA1 Message Date
Michael Vogt
ad865412fa releasing package snapd version 2.58.2 (#12522) 2.58.2 2023-01-25 21:37:27 +01:00
Miguel Pires
3000bf458c bootloader: fix test w/ auto-generated copyright year
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-01-25 20:50:19 +01:00
Michael Vogt
7f1d30a9a1 bootloader: hardcode copyright year
The copyright of the auto-generated grub_{recovery,}_cfg_assets.go
file is generated from the current date. This leads to a dirty build
when the year changes. This commit hardcodes the copyright year
to 2022.

Once there is a better go build system (or we use something like
meson) we can re-introduce this because then the generated files
will be no longer in git.
2023-01-25 15:38:32 +01:00
Michael Vogt
4ce9e7475e release: 2.58.1 (#12510) 2.58.1 2023-01-23 18:25:04 +01:00
James Henstridge
6f0be3b846 ci: update golangci-lint to v1.50.1
The stable Go snap was updated to 1.19.4, which golangci-lint 1.45.2 is
incompatible with. So switch to the latest version.
2023-01-23 17:56:05 +01:00
Michael Vogt
573d8a9816 secboot: detect lockout mode in CheckTPMKeySealingSupported (#12418)
This commit fixes the issue that the detection of TPM key sealing
does not take into account if the system is already has the lockout
auth attribute set. If this is the case an install will not be
successful but currently this is detected very late.

Note that lockoutAuthSet() is exactly the same 5 lines of code like
https://github.com/snapcore/secboot/pull/220/files
Once we can use secboot master this can be removed and
`secboot.LockoutAuthSet()` can be used instead.

* devicestate: take tpm provision mode into account when checking for encryption

* devicestate: tweak MockSecbootCheckTPMKeySealingSupported() usage and tests

* secboot: improve test coverage for CheckTPMKeySealingSupported()

* secboot: use LockoutAuthSet from secboot

* devicestate: more mode->tpmMode
2023-01-23 17:56:05 +01:00
Alberto Mardegan
75497d295f tests: update mount-ns test for new tmpdir handling
With commit a9812c4675 we changed the
location of the private tmp directory in snaps. Update the mount-ns test
accordingly.
2023-01-23 15:58:11 +01:00
Alfonso Sánchez-Beato
dec6110368 tests/fde-on-classic: add case of aborted refresh
Check that an aborted kernel refresh leaves the system in a clean
state.
2023-01-23 15:53:14 +01:00
Alfonso Sánchez-Beato
f1d17aaf52 boot: remove leftovers on kernel installation abort
When we were aborting a kernel installation before a reboot happened,
a proper clean-up of left-overs was not happening. To fix that, make
sure that current kernels in modeenv is always set appropriately and
also make sure that the try-kernel.efi symbolic link used by the grub
bootloader is removed.
2023-01-23 15:53:04 +01:00
Alfonso Sánchez-Beato
56d0ac59d0 tests: add test to check layouts are removed properly
As in some corner cases this was not the case and the applications
could not even start.
2023-01-23 15:49:42 +01:00
Alfonso Sánchez-Beato
3fbc941e3f cmd/snap-update-ns: prevent keeping unneeded mountpoints
In some cases we were keeping mounts from removed layouts, because we
were not identifying properly the mounts that we wanted to keep, as we
used mountpoint as key for the reuse map used in neededChanges, while
there are corner cases when we mount more that once on a given
mountpoint. This can happen when, say, we have a layout for /dir/sd1
and another one for /dir/sd2/sd3, being the case that /dir/sd1 and
/dir/sd2/sd3 do not exist (but their parent dirs do exist) - /dir/sd2
will be one of the bind mounted directories of the tmpfs that is
created in /dir to have a layout on /dir/sd1, while at the same time a
tmpfs will be mounted in /dir/sd2 so we can have a layout in
/dir/sd2/sd3. So /dir/sd2 is used twice with different filesystem
types (none and tmpfs).

To prevent this, use as key in the reuse map dir+fstype. As we make
sure that mimics are created only once per directory, we should only
have one entry per dir+fstype, being fstype either none or tmpfs.

In the future we should clean-up mountpoints before performing
changes, but that is a bigger change and anyway this fix is needed for
mount namespaces already created by older snapd versions.
2023-01-23 15:49:42 +01:00
Philip Meulengracht
d38710f236 o/snapstate: do not infinitely retry when an update fails during seeding (#12490)
* o/snapstate: During seeding, UpdateWithDeviceContext will fail with a conflict error describing that it is too early to update snaps, as we have not been seeded. Handle this and log that it was not possible, but do not return an error as this will break seeding, also do not return a state.Retry in this case as this will result in an infinite loop which will halt seeding.

* o/snapstate: review feedback

Check on ChangeKind instead

* o/snapstate: review feedback

improve error messages.

* o/snapstate: check for entire error string
2023-01-23 15:48:12 +01:00
Valentin David
323a0d75b2 tests/main/lxd-mount-units: fix a check
snap.mount is not generated by snapd-generator if / is shared.
2023-01-23 15:47:36 +01:00
Valentin David
c227954a01 tests/main/lxd: fix a check
snap.mount is not generated by snapd-generator if / is shared.
2023-01-23 15:47:23 +01:00
Alfonso Sánchez-Beato
df2e1ccbcf interfaces/modem-manager: add permissions for NETLINK_ROUTE
NETLINK_ROUTE netlink sockets are being used since modem-manager 1.18
for some modems.
2023-01-20 11:49:13 +01:00
Valentin David
68ef69d9d0 systemd/emulation.go: use systemctl --root to enable/disable 2023-01-20 10:30:50 +01:00
Michael Vogt
3ec4381aa2 snap: provide more error context in NotSnapError (#12474)
When a NotSnapError is returned right now there is no context
provided what went wrong. This makes debugging issues difficult
when the user just reports:
```
2022-11-23T14:47:57Z ERROR "/var/lib/snapd/snaps/.local-install-130452292" is not a snap or snapdir
```

This commit creates a constructor `snap.NewNotSnapErrorWithContext()`
that provides some context like:
```
cannot process snap or snapdir: open non-existing-file: no such file or directory
cannot process snap or snapdir: directory "empty-dir" is empty
cannot process snap or snapdir: directory "invalid-dir" is invalid
cannot process snap or snapdir: file "not-snap" is invalid header [110 111 116 45 97 45 115 110 97 112])
```
2023-01-19 16:45:17 +01:00
Peter Sabaini
1989906e64 Fix dm-crypt: add read access to /run for cryptsetup
When running `cryptsetup luksFormat` cryptsetup attempts to open /run
but fails due to a missing apparmor rule

Fixes: https://bugs.launchpad.net/snapd/+bug/1999683

Signed-off-by: Peter Sabaini <peter.sabaini@canonical.com>
2023-01-03 16:56:03 +01:00
alfonsosanchezbeato
b9597bbf3e boot: avoid reboot loop if there is a bad try kernel (#12425)
In case a bad try kernel was in the disk (i.e. by just a simple
dangling symlink try-kernel.efi), we entered a boot loop. Avoid that.

* tests: add test that checks that there is no boot loop

when we have a dangling try-kernel.efi symlink.

* boot: return status when asking for kernel revisions

Return status when asking for kernel revisions even if there is no try
kernel. It will still be useful. Also, add some clarifying comments to
genericInitramfsSelectSnap.

* boot: clarify comments and traces

* boot: add test for bad try status with no try kernel

* cmd/snap-bootstrap: adapt error string in tests

Due to changes in bootstate.
2022-12-15 11:38:33 +01:00
Michael Vogt
cb028ca53f devicestate: retry serial acquire on time based certificate errors (#12403)
This commit adds code to deal with the issue that the time may
we widely off when snapd tries to register the serial. For devices
without a RTC the date maybe so much in the past that the SSL
certificats are not valid yet. To fix this the following changes are
made:

* httputil: add `CertExpiredOrNotValidYet()` helper

This helper can be used to check if the error is that the
certificate is expired or not yet not valid. This is useful
to detect situations like when the time has not yet been
syncronized from a NTP sources.

* devicestate: retry serial acquire on time based certificate errors

When the serial assertion cannot be acquired because the certificate
of the remote system is expired or not yet valid then the most
likely reason for this is that the system clock is off. This case
is now treated in the similar to no network errors, i.e. snapd
will retry to acquire the serial and will only go into the a slow backoff
mode. This helps with the issue that on systems without a RTC
when the device comes up and the NTP sync is slow the serial
is (re)tried 3 times and then it goes into a very long backoff
(as defined in DeviceManager.ensureOperationalShouldBackoff()).

A gradual backoff is still used to not overwhelm the servers and
it is only tried for a bit more than 2048s because that is the maxium
time it takes for timesyncd to wait before trying a NTP sync.
2022-12-15 11:22:34 +01:00
Alex Lewontin
de2f9b81b6 o/devicestate: run systemctl daemon-reload after install-device hook (#12404)
Run systemctl daemon-reload before rebooting from install mode to run
mode in cases where the gadget snap has an install-device hook, so as to
account for any potential side-effects of that install-device hook.

Signed-off-by: Alex Lewontin <alex.lewontin@canonical.com>

* devicestate: move daemon-reload earlier (thanks to Samuele)

* devicestate: tweak tests

* devicestate: surface error if InstallDeviceHook cannot be obtained

* devicestate: drop error prefix in doRestartSystemToRunMode()

Signed-off-by: Alex Lewontin <alex.lewontin@canonical.com>
Co-authored-by: Michael Vogt <mvo@ubuntu.com>
2022-12-15 09:23:25 +01:00
Miguel Pires
0458bb1d82 cmd/snap,daemon: add 'held' to notes in 'snap list'
Adds a 'held' note to a snap's notes in the 'snap list' output. It only
displays the note if the hold is placed by the user (not a gating snap)
on that specific snap (not an all-snaps hold) and it hasn't expired yet.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-12-14 22:24:05 +01:00
Miguel Pires
c7b678cb12 .shellcheckrc: ignore all unreachable code warnings
Shellcheck's unreachable code warnings are a bit over-zealous in that
they log a warning for each unreachable line instead of block. We also
sometimes leave unreachable code that is meant to be re-enabled later.
Finally, we can't disable this for specific spread tests (because
shellcheck file-wide disables must be the next non-empty line after a #!
directive), so we'd have to add a disable for each line. Therefore,
disabling for the whole project seems reasonable given the constraints
and that we sometimes leave code to be re-enabled after an exit 0.

This also removes an exit in tools/boot-state which was harmless but
unnecessary because the function invoked before always exits.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-12-14 17:31:54 +01:00
Miguel Pires
0b9170dc2e tests: double quote bash vars to prevent string splitting and globbing
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-12-14 17:31:54 +01:00
Miguel Pires
3e6c544e1e tests: fix broken snap-run-symlink-error test
The return code being captured was that of the "echo" and not the
command being tested. This wasn't noticed because although the
error code check echoed an error message, it didn't fail the test.
This was presumably because the command's output would also fail if
the error code was wrong but that wasn't the case because the code was
taken from the wrong command.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2022-12-14 17:31:54 +01:00