93 Commits

Author SHA1 Message Date
Ernest Lotter
92c818d86b sysconfig/cloudinit: check if disabled via kernel cmdline (#14034)
* sysconfig/cloudinit: Check if disabled via kernel commandline

As documented:

https://cloudinit.readthedocs.io/en/latest/howto/disable_cloud_init.html

Signed-off-by: Brett Holman <brett.holman@canonical.com>

* sysconfig: made kernel cmdline disable comment similar to that of disable file

---------

Signed-off-by: Brett Holman <brett.holman@canonical.com>
Co-authored-by: Brett Holman <brett.holman@canonical.com>
2024-06-03 14:42:31 +02:00
Valentin David
5cb08d998c sysconfig/cloudinint: accept exit status 2 as not an error 2024-04-26 17:35:02 +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
Alfonso Sánchez-Beato
b4f263bba8 many: replace exec.CombinedOutput when output is parsed
Some invocations to external programs used exec.CombinedOutput, that
combines stdout and strerr into a single byte array. This can be an
issue if this output is parsed, as many programs print debug output or
warnings to stderr and that data is unexpected by the parsers. This
patch changes to using osutil.RunSplitOutput or osutil.RunCmd (that
return separately stdout and stderr) when we need to parse stdout, and
also in some other cases when printing separately both streams could
be helpful. Fixes LP #1885597.
2023-10-05 14:14:28 +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
Michael Vogt
3cb01fa9d7 sysconfig: add missing osutil.MockMountInfo() 2023-03-08 12:11:00 +01:00
Alfonso Sánchez-Beato
dd69bf0df9 sysconfig: add TODO about _writable_defaults
as we do not want that eventually in classic.
2022-09-30 11:30:47 +01:00
Michael Vogt
b253550d24 tests: replace boot.InitramfsWritableDir with explicit string value
This was generated via:
```
$ git grep -l boot.InitramfsWritableDir | grep _test.go | xargs sed -i 's#boot.InitramfsWritableDir#filepath.Join(dirs.GlobalRootDir, "/run/mnt/data/system-data")#'
```
2022-09-22 14:54:00 +02:00
Michael Vogt
bf7ced964a boot: replace boot.InstallHostWritableDir with strings
This commit changes the tests to use the string
`/run/mnt/ubuntu-data/system-data` instead of using
`boot.InstallHostWritableDir`. There are two reasons for
this:
a) The tests are more explicit this way
b) A followup will change this string to a function and
   the tests should still validate that the string value
   has not changed

Fwiw, this change is auto-generated via:
```
$ git grep -l boot.InstallHostWritableDir | grep _test.go | xargs sed -i 's#boot.InstallHostWritableDir#filepath.Join(dirs.GlobalRootDir, "/run/mnt/ubuntu-data/system-data")#'
```
2022-09-22 12:08:31 +02:00
Michael Vogt
277eb06412 many: replace use of "sanity" with more inclusive naming
This commit replaces the use of "sanity" with more inclusive
naming.

When `sanity` is used in a more general sense either `validity`
or `quick` is used.
2022-03-14 18:22:34 +01:00
Michael Vogt
7e18504214 sysconfig: set TMPDIR in tests to avoid cluttering the real /tmp
The cloud-init filtering writes a bunch of files into /tmp that
are not removed. So avoid cluttering /tmp on the hosts when
unit tests are run this commit sets TMPDIR to the unit test
tmpdir so that it's properly cleaned up.
2021-09-22 12:08:17 +02:00
Ian Johnson
da14bdeacb sysconfig/cloudinit.go: fix comment
Thanks to Samuele for spotting this

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-09-16 18:56:06 -05:00
Ian Johnson
f3e10c3f14 sysconfig/cloudinit: fix datasource restriction file installation on dangerous
With grade dangerous we don't want to install the datasource restriction file,
so only install it if we installed files and if we are filtering those files.

In the case where we are filtering files but there are no files to install, we
will already not create the file, but if we are filtering and we try to install
some files but they all get filtered out, then we will not install a datasource
restriction file because nothing untrusted from ubuntu-seed was installed, only
files from the gadget which are never filtered but are trusted.

Also remove a redundant test case now that it is reflected in the bigger test
case table.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-09-16 18:56:03 -05:00
Ian Johnson
824c502ebe sysconfig/cloudinit: fix 99_snapd_datasource.yaml -> .cfg
Thanks to Samuele for spotting this.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-09-16 18:55:59 -05:00
Ian Johnson
8d6680d620 sysconfig/cloudinit: filter ubuntu-seed c-i config for grade: signed images
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-09-15 11:13:38 -05:00
Ian Johnson
1f5908b2d3 sysconfig/cloudinit.go: only consider .cfg files in cloudDatasourcesInUseForDir
Cloud-init itself only considers .cfg files in the cloud-init.cfg.d directory,
so we should only consider files with .cfg file extension in the ubuntu-seed
directory.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-09-14 19:26:52 -05:00
Ian Johnson
21761a11ab sysconfig/cloudinit.go: adjust doc-comment for cloudDatasourcesInUseForDir
Also fix a typo.

Thanks to Alberto for the recommendations.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-09-08 12:36:33 -05:00
Ian Johnson
1356c9536b sysconfig/export_test.go: fix returned type from mocked function
This actually works in Go to return an unexported type and be able to use it's
exported fields, but wasn't the intention at all since we do actually export a
type alias for testing of the unexported type.

Thanks to Samuele for spotting this.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-09-08 12:14:54 -05:00
Ian Johnson
95d9bea5d2 sysconfig/cloudinit: add cloudDatasourcesInUseForDir
This function is the directory analogue of cloudDatasourcesInUse, and takes
into account the fact that a collection of config files coming from the same
dir will be processed by cloud-init "together" with lexically later files
overwriting settings of lexically earlier files.

This is necessary for full MAAS support with cloud-init on grade signed
systems.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-09-03 11:12:15 -05:00
Ian Johnson
b93ff437c3 sysconfig/cloudinit: don't run switch statement on error case
For the error case we should only concern ourselves with checking if the output
is "status: error", anything else should not be handled with the switch case,
as that could obscure the non-zero exit status with returning an otherwise
valid status. In other words, if cloud-init status returns "status: enabled"
but exits with non-zero exit code, we still want to return CloudInitErrored.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-08-26 09:42:57 -05:00
Ian Johnson
87887b3398 sysconfig/cloudinit.go: handle cloud-init status error properly
When cloud-init is actually in error condition, it will exit with a non-zero
status code. We previously had been assuming that this condition would have a
zero exit code, so the code would end up returning a non-nil err which in
devicestate would lead to devicestate never attempting to restrict cloud-init
and never disabling it either, thus effectively leaving the entire machinery
around force disabling cloud-init after 3 minutes if it was in error never to
be executed.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-08-24 14:27:47 -05:00
Ian Johnson
2208c89daf sysconfig/cloudinit.go: add functions for filtering cloud-init config
This will filter out the config we allow on ubuntu-seed to a subset of
cloud-init configuration.

Currently, this just allows configuration as required by MAAS to setup a device
with cloud-init, but this could be expanded in the future.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-08-12 18:37:57 -05:00
Ian Johnson
f547d16463 sysconfig/cloudinit: handle duplicated datasource names in datasource_list
We previously would just create a list with the duplicated names in it, which
didn't break anything but may be confusing for some other bits of code later
on. Instead trim out duplicates using a map instead of appending directly into
the resultant list.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-08-04 17:14:29 -05:00
Ian Johnson
020a1f9b76 sysconfig/cloudinit.go: measure (but don't use) gadget cloud-init datasource
In a future commit, we will use the result of measuring the datasource settings
for the cloud-init config from the gadget, but for now just introduce the
machinery to read it.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-08-03 10:56:19 -05:00
Maciej Borzecki
5125816d8f sysconfig: typo fix
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-07-19 10:49:43 +02:00