mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-30 16:35:24 +00:00
domain: parse XML for iscsi authorization credentials
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
adba070122
commit
6dca6d84ed
@ -1768,12 +1768,12 @@
|
|||||||
holds the actual password or other credentials (the domain XML
|
holds the actual password or other credentials (the domain XML
|
||||||
intentionally does not expose the password, only the reference
|
intentionally does not expose the password, only the reference
|
||||||
to the object that does manage the password). For now, the
|
to the object that does manage the password). For now, the
|
||||||
only known secret <code>type</code> is "ceph", for Ceph RBD
|
known secret <code>type</code>s are "ceph", for Ceph RBD
|
||||||
network sources, and requires either an
|
network sources, and "iscsi", for CHAP authentication of iSCSI
|
||||||
attribute <code>uuid</code> with the UUID of the Ceph secret
|
targets. Both require either a <code>uuid</code> attribute
|
||||||
object, or an attribute <code>usage</code> with the name
|
with the UUID of the secret object, or a <code>usage</code>
|
||||||
associated with the Ceph secret
|
attribute matching the key that was specified in the
|
||||||
object. <span class="since">libvirt 0.9.7</span>
|
secret object. <span class="since">libvirt 0.9.7</span>
|
||||||
</dd>
|
</dd>
|
||||||
<dt><code>geometry</code></dt>
|
<dt><code>geometry</code></dt>
|
||||||
<dd>The optional <code>geometry</code> element provides the
|
<dd>The optional <code>geometry</code> element provides the
|
||||||
|
@ -3642,6 +3642,7 @@
|
|||||||
<attribute name='type'>
|
<attribute name='type'>
|
||||||
<choice>
|
<choice>
|
||||||
<value>ceph</value>
|
<value>ceph</value>
|
||||||
|
<value>iscsi</value>
|
||||||
</choice>
|
</choice>
|
||||||
</attribute>
|
</attribute>
|
||||||
<choice>
|
<choice>
|
||||||
|
@ -3992,6 +3992,8 @@ virDomainDiskDefParseXML(virCapsPtr caps,
|
|||||||
char *wwn = NULL;
|
char *wwn = NULL;
|
||||||
char *vendor = NULL;
|
char *vendor = NULL;
|
||||||
char *product = NULL;
|
char *product = NULL;
|
||||||
|
int expected_secret_usage = -1;
|
||||||
|
int auth_secret_usage = -1;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0) {
|
if (VIR_ALLOC(def) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
@ -4029,7 +4031,6 @@ virDomainDiskDefParseXML(virCapsPtr caps,
|
|||||||
if (cur->type == XML_ELEMENT_NODE) {
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
if (!source && !hosts &&
|
if (!source && !hosts &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
||||||
|
|
||||||
sourceNode = cur;
|
sourceNode = cur;
|
||||||
|
|
||||||
switch (def->type) {
|
switch (def->type) {
|
||||||
@ -4057,6 +4058,11 @@ virDomainDiskDefParseXML(virCapsPtr caps,
|
|||||||
protocol);
|
protocol);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
if (def->protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI) {
|
||||||
|
expected_secret_usage = VIR_SECRET_USAGE_TYPE_ISCSI;
|
||||||
|
} else if (def->protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) {
|
||||||
|
expected_secret_usage = VIR_SECRET_USAGE_TYPE_CEPH;
|
||||||
|
}
|
||||||
if (!(source = virXMLPropString(cur, "name")) &&
|
if (!(source = virXMLPropString(cur, "name")) &&
|
||||||
def->protocol != VIR_DOMAIN_DISK_PROTOCOL_NBD) {
|
def->protocol != VIR_DOMAIN_DISK_PROTOCOL_NBD) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -4242,8 +4248,9 @@ virDomainDiskDefParseXML(virCapsPtr caps,
|
|||||||
_("missing type for secret"));
|
_("missing type for secret"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virSecretUsageTypeTypeFromString(usageType) !=
|
auth_secret_usage =
|
||||||
VIR_SECRET_USAGE_TYPE_CEPH) {
|
virSecretUsageTypeTypeFromString(usageType);
|
||||||
|
if (auth_secret_usage < 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("invalid secret type %s"),
|
_("invalid secret type %s"),
|
||||||
usageType);
|
usageType);
|
||||||
@ -4393,6 +4400,13 @@ virDomainDiskDefParseXML(virCapsPtr caps,
|
|||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auth_secret_usage != -1 && auth_secret_usage != expected_secret_usage) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("invalid secret type '%s'"),
|
||||||
|
virSecretUsageTypeTypeToString(auth_secret_usage));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
device = virXMLPropString(node, "device");
|
device = virXMLPropString(node, "device");
|
||||||
if (device) {
|
if (device) {
|
||||||
if ((def->device = virDomainDiskDeviceTypeFromString(device)) < 0) {
|
if ((def->device = virDomainDiskDeviceTypeFromString(device)) < 0) {
|
||||||
@ -12787,15 +12801,18 @@ virDomainDiskDefFormat(virBufferPtr buf,
|
|||||||
if (def->auth.username) {
|
if (def->auth.username) {
|
||||||
virBufferEscapeString(buf, " <auth username='%s'>\n",
|
virBufferEscapeString(buf, " <auth username='%s'>\n",
|
||||||
def->auth.username);
|
def->auth.username);
|
||||||
|
if (def->protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI) {
|
||||||
|
virBufferAsprintf(buf, " <secret type='iscsi'");
|
||||||
|
} else if (def->protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) {
|
||||||
|
virBufferAsprintf(buf, " <secret type='ceph'");
|
||||||
|
}
|
||||||
|
|
||||||
if (def->auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_UUID) {
|
if (def->auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_UUID) {
|
||||||
virUUIDFormat(def->auth.secret.uuid, uuidstr);
|
virUUIDFormat(def->auth.secret.uuid, uuidstr);
|
||||||
virBufferAsprintf(buf,
|
virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr);
|
||||||
" <secret type='ceph' uuid='%s'/>\n",
|
|
||||||
uuidstr);
|
|
||||||
}
|
}
|
||||||
if (def->auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_USAGE) {
|
if (def->auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_USAGE) {
|
||||||
virBufferEscapeString(buf,
|
virBufferEscapeString(buf, " usage='%s'/>\n",
|
||||||
" <secret type='ceph' usage='%s'/>\n",
|
|
||||||
def->auth.secret.usage);
|
def->auth.secret.usage);
|
||||||
}
|
}
|
||||||
virBufferAddLit(buf, " </auth>\n");
|
virBufferAddLit(buf, " </auth>\n");
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
<domain type='qemu'>
|
||||||
|
<name>QEMUGuest1</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory unit='KiB'>219136</memory>
|
||||||
|
<currentMemory unit='KiB'>219136</currentMemory>
|
||||||
|
<vcpu placement='static'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='i686' machine='pc'>hvm</type>
|
||||||
|
<boot dev='hd'/>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/bin/qemu</emulator>
|
||||||
|
<disk type='network' device='disk'>
|
||||||
|
<driver name='qemu' type='raw'/>
|
||||||
|
<auth username='myname'>
|
||||||
|
<secret type='iscsi' usage='mycluster_myname'/>
|
||||||
|
</auth>
|
||||||
|
<source protocol='iscsi' name='iqn.1992-01.com.example'>
|
||||||
|
<host name='example.org'/>
|
||||||
|
</source>
|
||||||
|
<target dev='vda' bus='virtio'/>
|
||||||
|
</disk>
|
||||||
|
<controller type='usb' index='0'/>
|
||||||
|
<controller type='ide' index='0'/>
|
||||||
|
<memballoon model='virtio'/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -175,6 +175,7 @@ mymain(void)
|
|||||||
DO_TEST("disk-drive-network-nbd-ipv6-export");
|
DO_TEST("disk-drive-network-nbd-ipv6-export");
|
||||||
DO_TEST("disk-drive-network-nbd-unix");
|
DO_TEST("disk-drive-network-nbd-unix");
|
||||||
DO_TEST("disk-drive-network-iscsi");
|
DO_TEST("disk-drive-network-iscsi");
|
||||||
|
DO_TEST("disk-drive-network-iscsi-auth");
|
||||||
DO_TEST("disk-scsi-device");
|
DO_TEST("disk-scsi-device");
|
||||||
DO_TEST("disk-scsi-vscsi");
|
DO_TEST("disk-scsi-vscsi");
|
||||||
DO_TEST("disk-scsi-virtio-scsi");
|
DO_TEST("disk-scsi-virtio-scsi");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user