cloud-init query traceback on root read-only etc/cloud/cloud.cfg.d/ files

Bug #1953430 reported by Chad Smith
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
High
Unassigned

Bug Description

If any files are root read-only in /etc/cloud/cloud.cfg.d cloud-init query tracebacks for non-root user
cloud-init version: 21.4

Reproducible on Jammy Desktop installer images

csmith@csmith-Standard-PC-i440FX-PIIX-1996:~$ cloud-init query --all
Traceback (most recent call last):
  File "/usr/bin/cloud-init", line 33, in <module>
    sys.exit(load_entry_point('cloud-init==21.4', 'console_scripts', 'cloud-init')())
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 927, in main
    retval = util.log_time(
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2472, in log_time
    ret = func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/query.py", line 109, in handle_args
    paths = read_cfg_paths()
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/devel/__init__.py", line 22, in read_cfg_paths
    init.read_cfg()
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 229, in read_cfg
    self._cfg = self._read_cfg(extra_fns)
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 237, in _read_cfg
    base_cfg=fetch_base_config())
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 1049, in fetch_base_config
    util.read_conf_with_confd(CLOUD_CONFIG),
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 950, in read_conf_with_confd
    confd_cfg = read_conf_d(confd)
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 925, in read_conf_d
    cfgs.append(read_conf(os.path.join(confd, fn)))
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 271, in read_conf
    return load_yaml(load_file(fname), default={})
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1361, in load_file
    with open(fname, 'rb') as ifh:
PermissionError: [Errno 13] Permission denied: '/etc/cloud/cloud.cfg.d/99-installer.cfg'

# works fine for root user
csmith@csmith-Standard-PC-i440FX-PIIX-1996:~$ sudo cloud-init query --all
[sudo] password for csmith:
{
 "_beta_keys": [
  "subplatform"
 ],
 "availability_zone": null,
 "base64_encoded_keys": [],
 "cloud_name": "none",
 "distro": "ubuntu",
 "distro_release": "jammy",
 "distro_version": "22.04",
 "ds": {
  "_doc": "EXPERIMENTAL: The structure and format of content scoped under the 'ds' key may change in subsequent releases of cloud-init.",
  "meta_data": {
   "instance_id": "fd598361-12e8-41e0-a7eb-7c9f2d7d3b41"
  }
 },
 "instance_id": "iid-datasource-none",
 "kernel_release": "5.13.0-19-generic",
 "local_hostname": "csmith-Standard-PC-i440FX-PIIX-1996",
 "machine": "x86_64",
 "merged_cfg": {
  "_doc": "Merged cloud-init system config from /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d/",
  "_log": [
   "[loggers]\nkeys=root,cloudinit\n\n[handlers]\nkeys=consoleHandler,cloudLogHandler\n\n[formatters]\nkeys=simpleFormatter,arg0Formatter\n\n[logger_root]\nlevel=DEBUG\nhandlers=consoleHandler,cloudLogHandler\n\n[logger_cloudinit]\nlevel=DEBUG\nqualname=cloudinit\nhandlers=\npropagate=1\n\n[handler_consoleHandler]\nclass=StreamHandler\nlevel=WARNING\nformatter=arg0Formatter\nargs=(sys.stderr,)\n\n[formatter_arg0Formatter]\nformat=%(asctime)s - %(filename)s[%(levelname)s]: %(message)s\n\n[formatter_simpleFormatter]\nformat=[CLOUDINIT] %(filename)s[%(levelname)s]: %(message)s\n",
   "[handler_cloudLogHandler]\nclass=FileHandler\nlevel=DEBUG\nformatter=arg0Formatter\nargs=('/var/log/cloud-init.log', 'a', 'UTF-8')\n",
   "[handler_cloudLogHandler]\nclass=handlers.SysLogHandler\nlevel=DEBUG\nformatter=simpleFormatter\nargs=(\"/dev/log\", handlers.SysLogHandler.LOG_USER)\n"
  ],
  "apt": {
   "preserve_sources_list": true
  },
  "cloud_config_modules": [
   "emit_upstart",
   "snap",
   "ssh-import-id",
   "locale",
   "set-passwords",
   "grub-dpkg",
   "apt-pipelining",
   "apt-configure",
   "ubuntu-advantage",
   "ntp",
   "timezone",
   "disable-ec2-metadata",
   "runcmd",
   "byobu"
  ],
  "cloud_final_modules": [
   "package-update-upgrade-install",
   "fan",
   "landscape",
   "lxd",
   "ubuntu-drivers",
   "write-files-deferred",
   "puppet",
   "chef",
   "mcollective",
   "salt-minion",
   "reset_rmc",
   "refresh_rmc_and_interface",
   "rightscale_userdata",
   "scripts-vendor",
   "scripts-per-once",
   "scripts-per-boot",
   "scripts-per-instance",
   "scripts-user",
   "ssh-authkey-fingerprints",
   "keys-to-console",
   "install-hotplug",
   "phone-home",
   "final-message",
   "power-state-change"
  ],
  "cloud_init_modules": [
   "migrator",
   "seed_random",
   "bootcmd",
   "write-files",
   "growpart",
   "resizefs",
   "disk_setup",
   "mounts",
   "set_hostname",
   "update_hostname",
   "update_etc_hosts",
   "ca-certs",
   "rsyslog",
   "users-groups",
   "ssh"
  ],
  "datasource": {
   "None": {
    "metadata": {
     "instance_id": "fd598361-12e8-41e0-a7eb-7c9f2d7d3b41"
    },
    "userdata_raw": "#cloud-config\ngrowpart:\n mode: 'off'\nlocale: en_US.UTF-8\npreserve_hostname: true\nresize_rootfs: false\ntimezone: America/Denver\nusers:\n- gecos: csmith\n groups: !!set\n adm: null\n cdrom: null\n dip: null\n lpadmin: null\n lxd: null\n plugdev: null\n sudo: null\n lock_passwd: false\n name: csmith\n passwd: $6$64oWiK3gfM8OoPHu$VeKnP.4Gji4T1IonINOARKTnQt3p6fQ4yY2N9u7DMve9goqCOrUluGX0qjU176w6a39w6RsjAtRUBGCJR3Qgh.\n shell: /bin/bash\n"
   }
  },
  "datasource_list": [
   "None"
  ],
  "def_log_file": "/var/log/cloud-init.log",
  "disable_root": true,
  "log_cfgs": [
   [
    "[loggers]\nkeys=root,cloudinit\n\n[handlers]\nkeys=consoleHandler,cloudLogHandler\n\n[formatters]\nkeys=simpleFormatter,arg0Formatter\n\n[logger_root]\nlevel=DEBUG\nhandlers=consoleHandler,cloudLogHandler\n\n[logger_cloudinit]\nlevel=DEBUG\nqualname=cloudinit\nhandlers=\npropagate=1\n\n[handler_consoleHandler]\nclass=StreamHandler\nlevel=WARNING\nformatter=arg0Formatter\nargs=(sys.stderr,)\n\n[formatter_arg0Formatter]\nformat=%(asctime)s - %(filename)s[%(levelname)s]: %(message)s\n\n[formatter_simpleFormatter]\nformat=[CLOUDINIT] %(filename)s[%(levelname)s]: %(message)s\n",
    "[handler_cloudLogHandler]\nclass=FileHandler\nlevel=DEBUG\nformatter=arg0Formatter\nargs=('/var/log/cloud-init.log', 'a', 'UTF-8')\n"
   ]
  ],
  "network": {
   "config": "disabled"
  },
  "output": {
   "all": "| tee -a /var/log/cloud-init-output.log"
  },
  "preserve_hostname": false,
  "syslog_fix_perms": [
   "syslog:adm",
   "root:adm",
   "root:wheel",
   "root:root"
  ],
  "users": [
   "default"
  ],
  "vendor_data": {
   "enabled": true,
   "prefix": []
  },
  "vendor_data2": {
   "enabled": true,
   "prefix": []
  }
 },
 "platform": "none",
 "public_ssh_keys": [],
 "python_version": "3.9.9",
 "region": null,
 "sensitive_keys": [
  "merged_cfg"
 ],
 "subplatform": "config",
 "sys_info": {
  "dist": [
   "ubuntu",
   "22.04",
   "jammy"
  ],
  "platform": "Linux-5.13.0-19-generic-x86_64-with-glibc2.34",
  "python": "3.9.9",
  "release": "5.13.0-19-generic",
  "system": "Linux",
  "uname": [
   "Linux",
   "csmith-Standard-PC-i440FX-PIIX-1996",
   "5.13.0-19-generic",
   "#19-Ubuntu SMP Thu Oct 7 21:58:00 UTC 2021",
   "x86_64",
   "x86_64"
  ],
  "variant": "ubuntu"
 },
 "system_platform": "Linux-5.13.0-19-generic-x86_64-with-glibc2.34",
 "userdata": "#cloud-config\ngrowpart:\n mode: 'off'\nlocale: en_US.UTF-8\npreserve_hostname: true\nresize_rootfs: false\ntimezone: America/Denver\nusers:\n- gecos: csmith\n groups: !!set\n adm: null\n cdrom: null\n dip: null\n lpadmin: null\n lxd: null\n plugdev: null\n sudo: null\n lock_passwd: false\n name: csmith\n passwd: $6$6.....\n shell: /bin/bash\n",
 "v1": {
  "_beta_keys": [
   "subplatform"
  ],
  "availability_zone": null,
  "cloud_name": "none",
  "distro": "ubuntu",
  "distro_release": "jammy",
  "distro_version": "22.04",
  "instance_id": "iid-datasource-none",
  "kernel_release": "5.13.0-19-generic",
  "local_hostname": "csmith-Standard-PC-i440FX-PIIX-1996",
  "machine": "x86_64",
  "platform": "none",
  "public_ssh_keys": [],
  "python_version": "3.9.9",
  "region": null,
  "subplatform": "config",
  "system_platform": "Linux-5.13.0-19-generic-x86_64-with-glibc2.34",
  "variant": "ubuntu"
 },
 "variant": "ubuntu",
 "vendordata": ""
}

Chad Smith (chad.smith)
description: updated
James Falcon (falcojr)
Changed in cloud-init:
status: New → Triaged
importance: Undecided → High
Revision history for this message
Brett Holman (holmanb) wrote : Fixed in cloud-init version 22.2.

This bug is believed to be fixed in cloud-init in version 22.2. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in cloud-init:
status: Triaged → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.