Skip to content

Provide the RBD keeyring to QEMU #1709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/server/device/device_utils_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,21 @@ func DiskParseRBDFormat(rbd string) (string, string, map[string]string, error) {

// DiskGetRBDFormat returns a rbd formatted string with the given values.
func DiskGetRBDFormat(clusterName string, userName string, poolName string, volumeName string) string {
// Resolve any symlinks to config path.
confPath := fmt.Sprintf("/etc/ceph/%s.conf", clusterName)
target, err := filepath.EvalSymlinks(confPath)
if err == nil {
confPath = target
}

// Configuration values containing :, @, or = can be escaped with a leading \ character.
// According to https://docs.ceph.com/docs/hammer/rbd/qemu-rbd/#usage
optEscaper := strings.NewReplacer(":", `\:`, "@", `\@`, "=", `\=`)
opts := []string{
fmt.Sprintf("id=%s", optEscaper.Replace(userName)),
fmt.Sprintf("pool=%s", optEscaper.Replace(poolName)),
fmt.Sprintf("cluster=%s", optEscaper.Replace(clusterName)),
fmt.Sprintf("conf=%s", optEscaper.Replace(confPath)),
}

return fmt.Sprintf("%s%s%s/%s%s%s", RBDFormatPrefix, RBDFormatSeparator, optEscaper.Replace(poolName), optEscaper.Replace(volumeName), RBDFormatSeparator, strings.Join(opts, ":"))
Expand Down
12 changes: 12 additions & 0 deletions internal/server/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4226,17 +4226,29 @@ func (d *qemu) addDriveConfig(qemuDev map[string]any, bootIndexes map[string]int
rbdImageName := storageDrivers.CephGetRBDImageName(vol, "", false)

// Scan & pass through options.
clusterName := storageDrivers.CephDefaultCluster
userName := storageDrivers.CephDefaultUser

blockDev["pool"] = poolName
blockDev["image"] = rbdImageName
for key, val := range opts {
// We use 'id' where qemu uses 'user'.
if key == "id" {
blockDev["user"] = val
userName = val
} else if key == "cluster" {
clusterName = val
} else {
blockDev[key] = val
}
}

// Parse the secret (QEMU runs unprivileged and can't read the keyring directly).
rbdSecret, err = storageDrivers.CephKeyring(clusterName, userName)
if err != nil {
return nil, err
}

// The aio option isn't available when using the rbd driver.
delete(blockDev, "aio")
}
Expand Down