cloud-init
cloud-init copied to clipboard
Traceback when running `cloud-init collect-logs` as non-root
While it is correct behavior to disallow access to root read-only files, we should emit a helpful error message rather than an ugly traceback.
nonroot@me:/tmp$ cloud-init collect-logs
version: /usr/bin/cloud-init 24.1.2
Traceback (most recent call last):
File "/usr/bin/cloud-init", line 33, in <module>
sys.exit(load_entry_point('cloud-init==24.1', 'console_scripts', 'cloud-init')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 1138, in main
retval = util.log_time(
^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2828, in log_time
ret = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/cmd/devel/logs.py", line 296, in handle_collect_logs_args
return collect_logs(args.tarfile, args.userdata, args.verbosity)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/cmd/devel/logs.py", line 255, in collect_logs
_collect_file(log, log_dir, verbosity)
File "/usr/lib/python3/dist-packages/cloudinit/cmd/devel/logs.py", line 185, in _collect_file
copy(path, out_dir)
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2094, in copy
shutil.copy(src, dest)
File "/usr/lib/python3.12/shutil.py", line 435, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/lib/python3.12/shutil.py", line 260, in copyfile
with open(src, 'rb') as fsrc:
^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/var/log/cloud-init.log'
nonroot@me:/tmp$