summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2021-09-07ssh_utils.py: ignore when sshd_config options are not key/value pairs (#1007)Emanuele Giuseppe Esposito
As specified in #LP 1845552, In cloudinit/ssh_util.py, in parse_ssh_config_lines(), we attempt to parse each line of sshd_config. This function expects each line to be one of the following forms: \# comment key value key=value However, options like DenyGroups and DenyUsers are specified to *optionally* accepts values in sshd_config. Cloud-init should comply to this and skip the option if a value is not provided. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
2021-09-03Set Azure to only update metadata on BOOT_NEW_INSTANCE (#1006)James Falcon
In #834, we refactored the handling of events for fetching new metadata. Previously, in Azure's __init__, the BOOT event was added to the update_events, so it was assumed that Azure required the standard BOOT behavior, which is to apply metadata twice every boot: once during local-init, then again during standard init phase. https://github.com/canonical/cloud-init/blob/21.2/cloudinit/sources/DataSourceAzure.py#L356 However, this line was effectively meaningless. After the metadata was fetched in local-init, it was then pickled out to disk. Because "update_events" was a class variable, the EventType.BOOT was not persisted into the pickle. When the pickle was then unpickled in the init phase, metadata did not get re-fetched because EventType.BOOT was not present, so Azure is effectely only BOOT_NEW_INSTANCE. Fetching metadata twice during boot causes some issue for pre-provisioning on Azure because updating metadata during re-provisioning will cause cloud-init to poll for reprovisiondata again in DataSourceAzure, which will infinitely return 404(reprovisiondata is deleted from IMDS after health signal was sent by cloud-init during init-local). This makes cloud-init stuck in 'init'
2021-09-02cc_update_etc_hosts: Use the distribution-defined path for the hosts file (#983)Andy Fiddaman
The distribution class has a field that specifies the location of the system hosts file and this can be overridden in subclasses. While the field is correctly used in distro.update_etc_hosts(), the update_etc_hosts module does not use it and just assumes '/etc/hosts' This fixes the module to use the distribution-specific variable.
2021-09-01Add CloudLinux OS support (#1003)Alexandr Kravchenko
https://www.cloudlinux.com/
2021-09-01puppet config: add the start_agent option (#1002)Andrew Bogott
The current code starts the puppet agent and also sets autostart in all cases. This conflicts with a common pattern where puppet itself manages the agent and autostart state. For example, in my deploy puppet disables the puppet agent and replaces it with a cron. This causes various races both within this cloud-init unit and within puppet itself while cloud-init and puppet fight over whether or not to enable the service.
2021-09-01Fix `make style-check` errors (#1000)Shreenidhi Shedi
Using flake8 inplace of pyflakes Renamed run-pyflakes -> run-flake8 Changed target name to flake8 in Makefile With pyflakes we can't suppress warnings/errors in few required places. flake8 is flexible in that regard. Hence using flake8 seems to be a better choice here. flake8 does the job of pep8 anyway. So, removed pep8 target from Makefile along with tools/run-pep8 script. Included setup.py in flake8 checks
2021-08-31Make cloud-id copyright year (#991)Andrii Podanenko
2021-08-30Add support to accept-ra in networkd renderer (#999)Shreenidhi Shedi
Also fix search path in networkd
2021-08-24Update ds-identify to pass shellcheck (#979)Andrew Kutz
This patch updates the ds-identify file to pass the popular shell linter, shellcheck. Updates include: * Global ignore for error code 3043, the warning about the "local" keyword not being POSIX compliant. This keyword is used everywhere and cannot be easily removed. * Point-of-use ignore for error code 3013, the warning about the "-nt" comparator not being POSIX compliant. There's no POSIX compliant way to compare timestamps on two files without forking a new process, so this comparator remains. * Several point-of-use ignores for error code 2254, the warning about quoting parameters. These warnings are ignored for the *_matches functions where wildcard tokens are expected to be used. Quoting the parameters would prevent the desired globbing and cause calls to these functions with wildcards to fail. * A point-of-use ignore for error code 2086 for the same reason as the above ignore -- allowing globbing to take place for matching. * Quoted parameters in the remainder of the locations where it was safe to do so and did not break the tests.
2021-08-24Azure: Retry dhcp on timeouts when polling reprovisiondata (#998)aswinrajamannar
In the nic attach path, we skip doing dhcp since we already did it when bringing the interface up. However when polling for reprovisiondata, it is possible for the request to timeout due to platform issues. In those cases we still need to do dhcp and try again since we tear down the context. We can only skip the first dhcp attempt.
2021-08-23testing: Fix ssh keys integration test (#992)James Falcon
Home directory permissions changed in hirsute. The integration test assumed permissions from earlier releases. Test was fixed to take both permissions into account
2021-08-23Release 21.3 (#993)James Falcon
Bump the version in cloudinit/version.py to 21.3 and update ChangeLog. LP: #1940839
2021-08-20Azure: During primary nic detection, check interface status continuously ↵aswinrajamannar
before rebinding again (#990) Add 10 second polling loop in wait_for_link_up after performing an unbind and re-bind of primary NIC in hv_netvsc driver. Also reduce cloud-init logging levels to debug for these operations.
2021-08-20Fix home permissions modified by ssh module (SC-338) (#984)James Falcon
Fix home permissions modified by ssh module In #956, we updated the file and directory permissions for keys not in the user's home directory. We also unintentionally modified the permissions within the home directory as well. These should not change, and this commit changes that back. LP: #1940233
2021-08-20Add integration test for sensitive jinja substitution (#986)James Falcon
Ensure jinja templates work for both instance-data.json and instance-data-sensitive.json. Test for LP: #1931392 Also removed test_runcmd.py as it's made redundant by this change.
2021-08-19Ignore hotplug socket when collecting logs (#985)James Falcon
Update "cloud-init collect-logs" to ignore /run/cloud-init/hook-hotplug-cmd as this will raise the error "/run/cloud-init/hook-hotplug-cmd` is a named pipe" if included. Also updated logs.py to continue writing the tarball if it fails collecting a file rather than let the exception bubble up. LP: #1940235
2021-08-19testing: Add missing mocks to test_vmware.py (#982)James Falcon
2021-08-16add Zadara Edge Cloud Platform to the supported clouds list (#963)sarahwzadara
2021-08-13testing: skip upgrade tests on LXD VMs (#980)James Falcon
The issues we see on Bionic VMs don't appear anywhere else, including when invoking kvm directly. It likely has to do with the extra LXD agent setup happening on bionic. Given that we still have Bionic covered on all other platforms, the risk of skipping bionic for LXD VM tests seems low.
2021-08-13Only invoke hotplug socket when functionality is enabled (#952)James Falcon
Alters hotplug hook to have a query mechanism checking if the functionality is enabled. This allows us to avoid using the hotplug socket and service when hotplug is disabled.
2021-08-13Revert unnecesary lcase in ds-identify (#978)Andrew Kutz
This patch reverts an unnecessary lcase optimization in the ds-identify script. SystemD documents the values produced by the systemd-detect-virt command are lower case, and the mapping table used by the FreeBSD check is also lower-case. The optimization added two new forked processes, needlessly causing overhead.
2021-08-12cc_resolv_conf: fix typos (#969)Shreenidhi Shedi
Add tests for cc_resolv_conf handler
2021-08-12Replace broken httpretty tests with mock (SC-324) (#973)James Falcon
* Replace broken httpretty tests with mock Certain versions of python/httpretty don't work correctly using https URIs. #960 recently added httpretty tests using https. This commit replaces the httpretty tests that were failing on https with mocks of readurl instead.
2021-08-12Azure: Check if interface is up after sleep when trying to bring it up (#972)aswinrajamannar
When bringing interface up by unbinding and then binding hv_netvsc driver, it might take a short delay after binding for the link to be up. So before trying unbind/bind again after sleep, check if the link is up. This is a corner case when a preprovisioned VM is reused and the NICs are hot-attached.
2021-08-12Update dscheck_VMware's rpctool check (#970)Shreenidhi Shedi
This patch updates the dscheck_VMware function's use of "vmware-rpctool". When checking to see if a "guestinfo" property is set. Because a successful exit code can occur even if there is an empty string returned, it is possible that the VMware datasource will be loaded as a false-positive. This patch ensures that in addition to validating the exit code, the emitted output is also examined to ensure a non-empty value is returned by rpctool before returning "${DS_FOUND}" from "dscheck_VMware()".
2021-08-12Azure: Logging the detected interfaces (#968)Moustafa Moustafa
2021-08-10Change netifaces dependency to 0.10.4 (#965)Andrew Kutz
Change netifaces dependency to 0.10.4 Currently versions Ubuntu <=20.10 use netifaces 0.10.4 By requiring netifaces 0.10.9, the VMware datasource omitted itself from cloud-init on Ubuntu <=20.10. This patch changes the netifaces dependency to 0.10.4. While it is true there are patches to netifaces post 0.10.4 that are desirable, testing against the most common network configuration was performed to verify the VMware datasource will still function with netifaces 0.10.4.
2021-08-10Azure: Limit polling network metadata on connection errors (#961)aswinrajamannar
2021-08-10Update inconsistent indentation (#962)Andrew Kutz
This patch updates some indentation in a comment that prevented an attempt to run the Black formatter (https://github.com/psf/black) against the cloud-init codebase: $ find cloudinit -name '*.py' -type f | xargs black -l 79 --check ... Oh no! 💥 💔 💥 262 files would be reformatted, 19 files would be left unchanged, 1 file would fail to reformat. The one file that fails to format is cloudinit/net/__init__.py. With this fix in place, the black command can successfully parse the file into AST and back again: $ black -l 79 --check cloudinit/net/__init__.py would reformat cloudinit/net/__init__.py Oh no! 💥 💔 💥 1 file would be reformatted. Normally this patch would be part of such an overall effort, but since this is the only location that interrupted running the black command, this author felt it was worth addressing this discrepancy sooner than later in the case there is subsequent desire to use a standard format tool such as black.
2021-08-10cc_puppet: support AIO installations and more (#960)Gabriel Nagy
- update the puppet module to support AIO installations by setting `install_type` to `aio` - make the install collection configurable through the `collection` parameter; by default the rolling `puppet` collection will be used, which installs the latest version) - when `install_type` is `aio`, puppetlabs repos will be purged after installation; set `cleanup` to `False` to prevent this - AIO installations are performed by downloading and executing a shell script; the URL for this script can be overridden using the `aio_install_url` parameter - make it possible to run puppet agent after installation/configuration via the `exec` key - by default, puppet agent will run with the `--test` argument; this can be overridden via the `exec_args` key
2021-08-10Add Puppet contributors to CLA signers (#964)Noah Fontes
2021-08-09Datasource for VMware (#953)Andrew Kutz
This patch finally introduces the Cloud-Init Datasource for VMware GuestInfo as a part of cloud-init proper. This datasource has existed since 2018, and rapidly became the de facto datasource for developers working with Packer, Terraform, for projects like kube-image-builder, and the de jure datasource for Photon OS. The major change to the datasource from its previous incarnation is the name. Now named DatasourceVMware, this new version of the datasource will allow multiple transport types in addition to GuestInfo keys. This datasource includes several unique features developed to address real-world situations: * Support for reading any key (metadata, userdata, vendordata) both from the guestinfo table when running on a VM in vSphere as well as from an environment variable when running inside of a container, useful for rapid dev/test. * Allows booting with DHCP while still providing full participation in Cloud-Init instance data and Jinja queries. The netifaces library provides the ability to inspect the network after it is online, and the runtime network configuration is then merged into the existing metadata and persisted to disk. * Advertises the local_ipv4 and local_ipv6 addresses via guestinfo as well. This is useful as Guest Tools is not always able to identify what would be considered the local address. The primary author and current steward of this datasource spoke at Cloud-Init Con 2020 where there was interest in contributing this datasource to the Cloud-Init codebase. The datasource currently lives in its own GitHub repository at https://github.com/vmware/cloud-init-vmware-guestinfo. Once the datasource is merged into Cloud-Init, the old repository will be deprecated.
2021-08-09photon: refactor hostname handling and add networkd activator (#958)sshedi
2021-08-09Stop copying ssh system keys and check folder permissions (#956)Emanuele Giuseppe Esposito
In /etc/ssh/sshd_config, it is possible to define a custom authorized_keys file that will contain the keys allowed to access the machine via the AuthorizedKeysFile option. Cloudinit is able to add user-specific keys to the existing ones, but we need to be careful on which of the authorized_keys files listed to pick. Chosing a file that is shared by all user will cause security issues, because the owner of that key can then access also other users. We therefore pick an authorized_keys file only if it satisfies the following conditions: 1. it is not a "global" file, ie it must be defined in AuthorizedKeysFile with %u, %h or be in /home/<user>. This avoids security issues. 2. it must comply with ssh permission requirements, otherwise the ssh agent won't use that file. If it doesn't meet either of those conditions, write to ~/.ssh/authorized_keys We also need to consider the case when the chosen authorized_keys file does not exist. In this case, the existing behavior of cloud-init is to create the new file. We therefore need to be sure that the file complies with ssh permissions too, by setting: - the actual file to permission 600, and owned by the user - the directories in the path that do not exist must be root owned and with permission 755.
2021-08-06testing: port remaining cloud tests to integration testing framework ↵James Falcon
(SC-191) (#955) This should enable us to remove the cloud-tests entirely.
2021-08-05generate contents for ovf-env.xml when provisioning via IMDS (#959)Anh Vo
Azure Linux Agent (WaLinuxAgent) waits for the ovf-env.xml file to be written by cloud-init when cloud-init provisions the VM. This file is written whenever cloud-init reads its contents from the provisioning ISO. With this change, when there is no provisioning ISO, DataSourceAzure will generate the ovf-env.xml file based on the metadata obtained from Azure IMDS.
2021-08-05Add support for EuroLinux 7 && EuroLinux 8 (#957)Aleksander Baranowski
2021-08-03Implementing device_aliases as described in docs (#945)Mal Graty
Implement missing device_aliases feature The device_aliases key has been documented as part of disk_setup for years, however the feature was never implemented. This implements the feature as documented allowing usercfg (rather than dsconfig) to create a mapping of device names. This is not to be confused with disk_aliases, a very similar map but existing solely for use by datasources. LP: #1867532
2021-07-29testing: fix test_ssh_import_id.py (#954)James Falcon
test_ssh_import_id.py occassionally fails because cloud-init finishes before the keys have been fully imported. A retry has been added to the test.
2021-07-23Add ability to manage fallback network config on PhotonOS (#941)sshedi
Currently cloud-init generates fallback network config on various scenarios. For example: 1. When no DS found 2. There is no 'network' info given in DS metadata. 3. If a DS gives a network config once and upon reboot if DS doesn't give any network info, previously set network data will be overridden. A newly introduced key in cloud.cfg.tmpl can be used to control this behavior on PhotonOS. Also, if OS comes with a set of default network files(configs), like in PhotonOS, cloud-init should not overwrite them by default. This change also includes some nitpicking changes of reorganizing few config variables. Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
2021-07-21Add VZLinux support (#951)eb3095
Virtuozzo Linux is a distro based off of CentOS 8, similar to Alma Linux and Rocky Linux.
2021-07-20VMware: add network-config support in ovf-env.xml (#947)PengpengSun
Details: 1. Support guest set network config through guestinfo.ovfEnv using OVF 2. 'network-config' Property is optional 3. 'network-config' Property's value has to be base64 encoded Added unittests and updated ovf-env.xml example
2021-07-20Update pylint to v2.9.3 and fix the new issues it spots (#946)Paride Legovini
In CI run against pylint 2.9.3 and fix occurrences of: - W0237 (arguments-renamed) - W0402 (deprecated-module) The W0402 deprecated-module was about module `imp`: cloudinit/patcher.py:9: [W0402(deprecated-module), ] Uses of a deprecated module 'imp' The imp module is deprecated and replaced by importlib, which according to the documentation has no replacement for acquire_lock() and release_lock(), which are the only reason why `imp` is imported. Nothing about the code using this lock that actually requires it. Let's remove the locking code and the import altogether. Dropping the locking makes patcher.patch() an empty wrapper around _patch_logging(). Rename _patch_logging() to patch_logging() and call it directly instead. Drop patch().
2021-07-19Azure: mount default provisioning iso before try device listing (#870)Anh Vo
With a few exceptions, Azure VM deployments receive provisioning metadata through the provisioning iso presented as a cdrom device (/dev/sr0). The existing code attempts to find this device by calling blkid to find all devices that have either type iso9660 or udf. This can be very expensive if the VM has a lot of disks. This commit will attempt to mount the default iso location first and only tries to use blkid to locate the iso location if the default mounting location fails
2021-07-19Document known hotplug limitations (#950)James Falcon
2021-07-19Initial hotplug support (#936)James Falcon
Adds a udev script which will invoke a hotplug hook script on all net add events. The script will write some udev arguments to a systemd FIFO socket (to ensure we have only instance of cloud-init running at a time), which is then read by a new service that calls a new 'cloud-init devel hotplug-hook' command to handle the new event. This hotplug-hook command will: - Fetch the pickled datsource - Verify that the hotplug event is supported/enabled - Update the metadata for the datasource - Ensure the hotplugged device exists within the datasource - Apply the config change on the datasource metadata - Bring up the new interface (or apply global network configuration) - Save the updated metadata back to the pickle cache Also scattered in some unrelated typing where helpful
2021-07-15Fix MIME policy failure on python version upgrade (#934)James Falcon
Python 3.6 added a new `policy` attribute to `MIMEMultipart`. MIMEMultipart may be part of the cached object pickle of a datasource. Upgrading from an old version of python to 3.6+ will cause the datasource to be invalid after pickle load. This commit uses the upgrade framework to attempt to access the mime message and fail early (thus discarding the cache) if we cannot. Commit 78e89b03 should fix this issue more generally.
2021-07-13run-container: fixup the centos repos baseurls when using http_proxy (#944)Paride Legovini
The EPEL repo file used to have download.fedoraproject.org as its baseurl. That has now been replaced by `download.example`, which we need to replace with dl.fedoraproject.org, the actual mirror we want to download from. We can't use download.fedoraproject.org or the mirrorlist (which is the default way for finding mirrors) because of our internal proxy rules. This change only applies if http_proxy is set, otherwise the mirrors are reached in the default way.
2021-07-12tools: add support for building rpms on rocky linux (#940)Chad Smith
2021-07-12ssh-util: allow cloudinit to merge all ssh keys into a custom user file, ↵Emanuele Giuseppe Esposito
defined in AuthorizedKeysFile (#937) This patch aims to fix LP1911680, by analyzing the files provided in sshd_config and merge all keys into an user-specific file. Also introduces additional tests to cover this specific case. The file is picked by analyzing the path given in AuthorizedKeysFile. If it points inside the current user folder (path is /home/user/*), it means it is an user-specific file, so we can copy all user-keys there. If it contains a %u or %h, it means that there will be a specific authorized_keys file for each user, so we can copy all user-keys there. If no path points to an user-specific file, for example when only /etc/ssh/authorized_keys is given, default to ~/.ssh/authorized_keys. Note that if there are more than a single user-specific file, the last one will be picked. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Co-authored-by: James Falcon <therealfalcon@gmail.com> LP: #1911680 RHBZ:1862967