Skip to content

Mask the Ceph key in KVM agent logs and errors - #14934

Open
bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:kvm-mask-rbd-key
Open

bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:kvm-mask-rbd-key

Conversation

@bhouse-nexthop

Copy link
Copy Markdown
Contributor

Description

When a qemu-img convert to or from an RBD pool fails, the KVM agent writes the cephx key to its log: the ERROR line from LibvirtStorageAdaptor.copyPhysicalDisk prints the rbd:...:key=<key>:... URI, and Script logs qemu-img's error output, which repeats the URI, at WARN. Script masked only an argument that starts with rbd:, so the key was also logged when the URI sits inside --image-opts or the comma-joined disk list passed to nasbackup.sh, and for the rbd du ... --key <key> command run on every RBD snapshot (DEBUG).

Now one helper, StringUtils.maskCephKey, replaces the key with ****** and is used:

  • in Script for the logged command line (it replaces the old rbd:-only sanitizer), the error and timeout output it logs and returns, and the DEBUG output of OutputLogger;
  • in QemuImgException, whose message becomes Answer details sent to the management server;
  • in the ERROR lines that print an RBD file name (LibvirtStorageAdaptor, LibvirtCreatePrivateTemplateFromVolumeCommandWrapper, LibvirtRestoreBackupCommandWrapper);
  • for the nasbackup.sh failure output that LibvirtTakeBackupCommandWrapper logs and returns.

The key stays on the qemu-img and rbd command lines themselves; this change is about logs and returned errors only.

Fixes: #14933

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

Before, a failed template copy to RBD (agent.log, key replaced here by <redacted>):

ERROR [kvm.storage.LibvirtStorageAdaptor] Failed to convert from /mnt/.../<template>.qcow2 to rbd:<pool>/<image>:mon_host=<mon>:auth_client_required=cephx:id=<user>:key=<redacted>:rbd_default_format=2:client_mount_timeout=30 the error was: ...

After:

ERROR [kvm.storage.LibvirtStorageAdaptor] Failed to convert from /mnt/.../<template>.qcow2 to rbd:<pool>/<image>:mon_host=<mon>:auth_client_required=cephx:id=<user>:key=******:rbd_default_format=2:client_mount_timeout=30 the error was: ...

How Has This Been Tested?

Unit tests for each path: StringUtilsTest, ScriptTest (command line with --image-opts, a joined disk list and rbd du --key; error output of execute and executeIgnoreExitValue), KVMStorageProcessorTest (template from an RBD volume, Answer details), LibvirtStorageAdaptorTest (NFS to RBD and RBD to RBD copies), LibvirtCreatePrivateTemplateFromVolumeCommandWrapperTest, LibvirtRestoreBackupCommandWrapperTest, LibvirtTakeBackupCommandWrapperTest.

Lab test results follow in a comment.

How did you try to break this feature and the system with this change?

The pattern only matches :key= after rbd: and --key in an rbd command, so other key= text such as OVS options:key=<id> or ovstunnel --key <id> is left as is (unit tested). Script.toString() is executed as a command by QemuImg.checkAndRepair; its file there is never an rbd: URI with a key, so the masking does not change what runs.

A failed qemu-img copy to or from RBD logged the image URI with its
cephx key at ERROR. Script masked only an argument that starts with
"rbd:", so the key was logged as is when the URI was inside
--image-opts or a comma-joined disk list, or passed to the rbd CLI
with --key. Command output that repeats the URI, such as the NAS
backup script's error, went into the agent log and into the error
returned to the management server.

Mask the key with one helper wherever a command line, its output, a
qemu-img error or an RBD file name is logged or returned.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@bhouse-nexthop

bhouse-nexthop commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Lab test, nested KVM lab with Ceph RBD primary storage, running a main (24.0.0-SNAPSHOT) build. The fix was tested by replacing the agents' cloud-utils and cloud-plugin-hypervisor-kvm jars with ones built from that build plus this commit (a revision from before the final version of this commit, which only widened the pattern to allow spaces in the URI and added an early return; unit tests cover both). The code it touches is the same on 4.22. Agent DEBUG was enabled for com.cloud.utils.script so the rbd du line is logged. Each check counts lines holding the pool's cephx key in agent.log on all three hosts, management-server.log, async_job.job_result and event.description, written after the step began.

  1. Failed template copy NFS -> RBD (VM deployed from a QCOW2 template with a corrupt L1 table):
    • before: 4 agent.log lines with the key: 2 ERROR from LibvirtStorageAdaptor ("Failed to convert from ... to rbd:...:key=..."), 2 WARN from Script ("encountered the error", qemu-img's output repeating the URI)
    • after: 0 lines with the key; the same ERROR line logged as ...:id=<user>:key=******:rbd_default_format=2...
  2. Snapshot of a running VM's ROOT volume on RBD:
    • before: 2 DEBUG lines with rbd du ... --key <key>
    • after: 0 lines with the key; logged as --key ******
  3. Management server log, job results, events: 0 lines with the key before and after (this path returns no URI to the server).

Not run in the lab: NAS backup/restore and template from an RBD volume (covered by the unit tests).

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.21739% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.36%. Comparing base (069ac79) to head (1850481).

Files with missing lines Patch % Lines
...s/src/main/java/com/cloud/utils/script/Script.java 42.85% 3 Missing and 1 partial ⚠️
...java/com/cloud/utils/script/OutputInterpreter.java 0.00% 1 Missing and 1 partial ⚠️
...ce/wrapper/LibvirtRestoreBackupCommandWrapper.java 0.00% 0 Missing and 1 partial ⚠️
.../hypervisor/kvm/storage/LibvirtStorageAdaptor.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14934      +/-   ##
============================================
+ Coverage     18.34%   18.36%   +0.02%     
- Complexity    16670    16687      +17     
============================================
  Files          5939     5939              
  Lines        537814   537808       -6     
  Branches      65937    65935       -2     
============================================
+ Hits          98637    98794     +157     
+ Misses       427953   427767     -186     
- Partials      11224    11247      +23     
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.46% <65.21%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@weizhouapache weizhouapache left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

@apache apache deleted a comment from kiranchavala Dec 2, 2026
@apache apache deleted a comment from kiranchavala Dec 2, 2026
@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 20264

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants