83 Commits

Author SHA1 Message Date
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
Ian Johnson
ffddf26f0e sysconfig: enforce only uc20 style models with ConfigureTargetSystem
Thanks to Samuele for pointing this out, the function has always only been used
with UC20 devices/systems so make that explicit via checking the model we now
have as the argument to the function.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-07-16 16:15:03 -05: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
Samuele Pedroni
3cb049a2f6 sysconfig: clarify s/devinceInfo/configedDevice/ and its RunMode
the functions using configedDevice are not used from run mode

(thanks @mvo)
2021-06-24 13:22:14 +02:00
Samuele Pedroni
5df525aa61 many: start configcore taking model/device information
introduce sysconfig.Device (similar to boot.Device)

have sysconfig.ApplyFilesystemOnlyDefaults and
sysconfig.ConfigureTargetSystem take the model and pass down a
sysconfig.Device

for these two we assume that mode is not run
2021-06-23 18:24:17 +02: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
243cef7e52 Merge branch 'master' into bugfix/lp-1918299
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-06-16 11:01:08 -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
Samuele Pedroni
54e84fb8db many: fix imports order (according to gci)
had to make the comment in wrappers/services_test.go a one-liner
otherwise half of it is lost

last set of files needing changing (as per current master)
2021-06-16 09:54:31 +02: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