diff options
author | Chad Smith <chad.smith@canonical.com> | 2018-10-26 03:49:57 +0000 |
---|---|---|
committer | Server Team CI Bot <josh.powers+server-team-bot@canonical.com> | 2018-10-26 03:49:57 +0000 |
commit | dc0be9c56f78537f1808934d26f5aa0868ae7842 (patch) | |
tree | 53caf37637bf79f5c93683bfe87ec85008b9bc1b /cloudinit/cmd/query.py | |
parent | 532ff0f0a4f12225d5785bc98d7a4528e0c779d6 (diff) | |
download | vyos-cloud-init-dc0be9c56f78537f1808934d26f5aa0868ae7842.tar.gz vyos-cloud-init-dc0be9c56f78537f1808934d26f5aa0868ae7842.zip |
instance-data: fallback to instance-data.json if sensitive is absent.
On cloud-init upgrade path from 18.3 to 18.4 cloud-init changed how
instance-data is written. Cloud-init changes instance-data.json from root
read-only to redacted world-readable content, and provided a separate
unredacted instance-data-sensitive.json which is read-only root.
Since instance-data is only rewritten from cache on
reboot, the query and render tools needed fallback to use the 'old'
instance-data.json if the new sensitive file isn't yet present.
This avoids error messages from tools about an absebt
/run/instance-data-sensitive.json file.
LP: #1798189
Diffstat (limited to 'cloudinit/cmd/query.py')
-rw-r--r-- | cloudinit/cmd/query.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/cloudinit/cmd/query.py b/cloudinit/cmd/query.py index 7d2d4fe4..ff03de94 100644 --- a/cloudinit/cmd/query.py +++ b/cloudinit/cmd/query.py @@ -79,22 +79,30 @@ def handle_args(name, args): uid = os.getuid() if not all([args.instance_data, args.user_data, args.vendor_data]): paths = read_cfg_paths() - if not args.instance_data: + if args.instance_data: + instance_data_fn = args.instance_data + else: + redacted_data_fn = os.path.join(paths.run_dir, INSTANCE_JSON_FILE) if uid == 0: - default_json_fn = INSTANCE_JSON_SENSITIVE_FILE + sensitive_data_fn = os.path.join( + paths.run_dir, INSTANCE_JSON_SENSITIVE_FILE) + if os.path.exists(sensitive_data_fn): + instance_data_fn = sensitive_data_fn + else: + LOG.warning( + 'Missing root-readable %s. Using redacted %s instead.', + sensitive_data_fn, redacted_data_fn) + instance_data_fn = redacted_data_fn else: - default_json_fn = INSTANCE_JSON_FILE # World readable - instance_data_fn = os.path.join(paths.run_dir, default_json_fn) + instance_data_fn = redacted_data_fn + if args.user_data: + user_data_fn = args.user_data else: - instance_data_fn = args.instance_data - if not args.user_data: user_data_fn = os.path.join(paths.instance_link, 'user-data.txt') + if args.vendor_data: + vendor_data_fn = args.vendor_data else: - user_data_fn = args.user_data - if not args.vendor_data: vendor_data_fn = os.path.join(paths.instance_link, 'vendor-data.txt') - else: - vendor_data_fn = args.vendor_data try: instance_json = util.load_file(instance_data_fn) |