58 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
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
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
Ian Johnson
c24d190778 o/devicestate, sysconfig: refactor cloud-init config permission handling
Move more responsibility of handling cloud-init config permission handling to
sysconfig instead of devicestate since we now have access to the model in
ConfigureTargetSystem which we can use to get the model grade.

This also means we can refactor the functions which install cloud-init config
to be more straight forward and readable.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-15 19:58:08 -05:00
Ian Johnson
ed91b8712c sysconfig/cloudinit.go: move function call into if
As requested by Michael

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-06-17 13:47:56 -05:00
Ian Johnson
a0a6ea53be sysconfig/cloudinit.go: make ubuntu-seed c-i files always have 90_ prefix
Then it's easier to reason about the order in which they will be run/processed.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-06-16 11:00:51 -05:00
Ian Johnson
c3f851eee3 sysconfig/cloudinit.go: make seed c-i files take precedence over gadget files
Also fix an out-dated comment in installCloudInitCfgDir which referenced a
non-existent function.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-06-15 11:54:46 -05:00
Ian Johnson
2f0a6e2d22 sysconfig/cloudinit.go: allow installing both gadget + ubuntu-seed config
We have use cases for doing this that pertain to our testing system, so enable
this use case now.

Fixes: https://bugs.launchpad.net/snapd/+bug/1918299
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-06-08 16:50:35 -05:00
Maciej Borzecki
fad2fc689e sysconfig: tweaks, log when cloud init is not present
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-01-19 11:04:17 +01:00
Maciej Borzecki
46bb93156b sysconfig: restrict can deal with missing cloud-init binary
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-01-18 13:49:22 +01:00