26 Commits

Author SHA1 Message Date
Maciej Borzecki
c816218fe3 snapdtool: proceed with trying reexec when SNAP_REEXEC=1 is set on an unsupported distro
Snapd normally stops trying to reexec when the current host distribution is not
in the list of supported ones. However, allow reexec to be attempt if
SNAP_REEXEC is explicitly set to a truthy value in the environment. This enables
testing of the reexec functionality on a wider range of distributions.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-06-27 12:35:31 +02:00
Maciej Borzecki
d45fdbfe7a snapdtool: simplify check
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-06-27 08:29:36 +02:00
Maciej Borzecki
ca1b67d8b1 snapdtool: fix unit tests on distros with /usr/libexec
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-06-27 08:29:36 +02:00
Maciej Borzecki
1ff4dd9ddf snapdtool: extract a helper for determining process binary and root
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-06-27 08:29:36 +02:00
Maciej Borzecki
4a5b76fe54 snapdtool: tweak name of env variable passed to indicate FIPS bootstrap
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-06-27 08:29:36 +02:00
Maciej Borzecki
d5027fe4ea snapdtool: add missing copyright information header
Add missing copyright info header.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-06-27 08:29:36 +02:00
Maciej Borzecki
6fdd0457c7 snapdtool: add helpers for setting up FIPS environment
Add helpers for setting up environment for running in FIPS mode when reexecd
from the snapd snap.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-06-27 08:29:36 +02:00
Valentin David
8de525b470 snapdtool/cmdutil.go: do not override dynamic linker for snapd snap
Executable files from snapd snap do not need anymore to have
the dynamic linker and library paths to be overridden. But
the ones from core snap still need it.
2024-05-29 14:13:55 +02:00
Maciej Borzecki
3c35660e1c snapdtool: simplify check for reexec being enabled
Simplify the check for reexec being enabled in the system.

Thanks to @alfonsosanchezbeato.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-05-28 10:37:35 +02:00
Maciej Borzecki
ef3a5ab927 snapdtool: export helper for asserting whether reexec is enabled for a given distro
Expose another helper for asserting whether reexec is enabled for a given
distribution we're running on.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-05-24 15:48:46 +02:00
Maciej Borzecki
76037d4081 snapdtools: export a helper for asserting whether reexec is enabled
Export a helper for checking whether reexec is enabled (or otherwise not
disabled).

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-05-24 15:48:46 +02:00
Maciej Borzecki
080ff53f5f snapdtool: fix unit tests when running on distro using /usr/libexec/snapd (#13818)
Distros like openSUSE Tumbleweed or Fedora use /usr/libexec/snapd. Update the
test to account for the correct path.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-04-12 10:29:51 +02:00
Miguel Pires
79c5ac14b2 many: remove usages of deprecated io/ioutil package (#13768)
* many: remove usages of deprecated io/ioutil package

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

* .golangci.yml: remove errcheck ignore rule for io/ioutil

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

* run-checks: prevent new usages of io/ioutil

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

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-04-03 23:23:24 +02:00
Michael Vogt
1f621a9dee snapdtool: check for binary existence in InternalToolPath() (#13227)
* snapdtool: check for binary existance in InternalToolPath()

The current version of `InternalToolPath()` does not actually
checks in all cases if the binary is actually there. Historically
this was not a problem but with recent snapd releases we have
the internal tool `apparmor_parser` that is only available in
the `snapd` snap but not in the `core` snap. This means that
on systems that have the snapd deb and only core `InternalToolPath`
may return `/snap/core/123/usr/lib/snapd/apparmor_parser` even
if this tool in not available inside the core snap.

This commit fixes this by checking if the actual executable
is available.

* snapdtool: add test for non-executable internal tool path

* snapdtool: simplify InternalToolPath() (thanks to Samuele)
2023-10-24 08:54:31 +02: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
Dimitri John Ledkov
d55f3123d4 go: go fix with 1.18
Apply `go fix ./...` to the whole code base using go-1.18 to remove
old build tags.
2023-09-25 13:22:14 +02:00
Samuele Pedroni
b3003bc7a5 snap,snapdtool: introduce SnapdAssertionMaxFormatsFromSnapFile
this will be useful to determine supported assertion max formats for snapd/core
and kernel snaps that are used to build an image

to do this we split out snapdtool.ParseInfoFile
2023-02-14 14:26:27 +01:00
Michael Vogt
eae07969f5 snapdtool: run go fmt 2022-03-29 10:53:32 +02:00
Ian Johnson
6f903940b5 snapdtool: rename to use "system snap" terminology over "core snap"
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-03-25 16:29:44 -05:00
Miguel Pires
13209fc52c many: fix formatting w/ latest go version
Fix formatting when running the latest version (1.17) of gofmt.
2021-12-08 13:59:56 +00:00
Ian Johnson
8a2ab9f794 snapdtool/info_file.go: update doc-comment
Thanks to Samuele for pointing this out

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-12-03 10:03:51 -06:00
Ian Johnson
7ad3c6b3e8 snapdtool, cmd/snap-preseed: adjust SnapdVersionFromInfoFile to take a dir
The info file is essentially always implicit here, so we can just provide the
dir. Thanks to Samuele for pointing this out.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-12-02 12:04:52 -06:00
Ian Johnson
c5f3197518 snapdtool, many: support additional key/value flags in info file
Also set a new key, SNAPD_APPARMOR_REEXEC, to 0 for now, since this key will be
used shortly with the new apparmor vendoring inside the snapd snap.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-12-01 16:08:28 -06:00
Maciej Borzecki
3dc1ca5ad3 snapdtool: helper to check whether the current binary is reexeced from a snap
Add a helper for checking whether the current binary is running from a snap.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-06-22 11:55:56 +02:00
Samuele Pedroni
d3fce20df6 many: merge cmd/cmdutil into snapdtool 2020-06-12 17:50:50 +02:00