[PATCH 0/3] Fix backend VM, POOL, NETWORK naming validation

This patchset fixes the backend JSON name checkings when user creates a new VM, POOL or NETWORK. Rodrigo Trujillo (3): Prohibits slashes '/' in VM name Move slash checking in storagepool name from UI to backend Fix Network create name checking in backend (slashes and quotes) src/kimchi/API.json | 4 ++++ src/kimchi/i18n.py | 6 +++--- src/kimchi/model/utils.py | 3 ++- ui/js/src/kimchi.storagepool_add_main.js | 5 ----- ui/pages/i18n.json.tmpl | 1 - 5 files changed, 9 insertions(+), 10 deletions(-) -- 2.1.0

This patch adds a pattern to checks if vm name has slashes. It also replace slashes from template name by dashes, case user does not give any name to the new VM. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/API.json | 2 ++ src/kimchi/i18n.py | 2 +- src/kimchi/model/utils.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/kimchi/API.json b/src/kimchi/API.json index f507251..2455745 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -228,6 +228,7 @@ "name": { "description": "The name of the new VM", "type": "string", + "pattern": "^[^/]*$", "error": "KCHVM0011E" }, "template": { @@ -252,6 +253,7 @@ "name": { "description": "New name of VM", "type": "string", + "pattern": "^[^/]*$", "minLength": 1, "error": "KCHVM0011E" }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index e4e1a89..7c11016 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -83,7 +83,7 @@ messages = { "KCHVM0008E": _("Unable to update virtual machine %(name)s. Details: %(err)s"), "KCHVM0009E": _("Unable to retrieve virtual machine %(name)s. Details: %(err)s"), "KCHVM0010E": _("Unable to connect to powered off virtual machine %(name)s."), - "KCHVM0011E": _("Virtual machine name must be a string"), + "KCHVM0011E": _("Virtual machine name must be a string without slashes (/)"), "KCHVM0012E": _("Invalid template URI %(value)s specified for virtual machine"), "KCHVM0013E": _("Invalid storage pool URI %(value)s specified for virtual machine"), "KCHVM0014E": _("Supported virtual machine graphics are Spice or VNC"), diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py index 9896289..80e7da0 100644 --- a/src/kimchi/model/utils.py +++ b/src/kimchi/model/utils.py @@ -34,7 +34,8 @@ def get_vm_name(vm_name, t_name, name_list): if vm_name: return vm_name for i in xrange(1, 1000): - vm_name = "%s-vm-%i" % (t_name, i) + # VM will have templace name, but without slashes + vm_name = "%s-vm-%i" % (t_name.replace('/', '-'), i) if vm_name not in name_list: return vm_name raise OperationFailed("KCHUTILS0003E") -- 2.1.0

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 24/03/2015 13:46, Rodrigo Trujillo wrote:
This patch adds a pattern to checks if vm name has slashes. It also replace slashes from template name by dashes, case user does not give any name to the new VM.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/API.json | 2 ++ src/kimchi/i18n.py | 2 +- src/kimchi/model/utils.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/API.json b/src/kimchi/API.json index f507251..2455745 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -228,6 +228,7 @@ "name": { "description": "The name of the new VM", "type": "string", + "pattern": "^[^/]*$", "error": "KCHVM0011E" }, "template": { @@ -252,6 +253,7 @@ "name": { "description": "New name of VM", "type": "string", + "pattern": "^[^/]*$", "minLength": 1, "error": "KCHVM0011E" }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index e4e1a89..7c11016 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -83,7 +83,7 @@ messages = { "KCHVM0008E": _("Unable to update virtual machine %(name)s. Details: %(err)s"), "KCHVM0009E": _("Unable to retrieve virtual machine %(name)s. Details: %(err)s"), "KCHVM0010E": _("Unable to connect to powered off virtual machine %(name)s."), - "KCHVM0011E": _("Virtual machine name must be a string"), + "KCHVM0011E": _("Virtual machine name must be a string without slashes (/)"), "KCHVM0012E": _("Invalid template URI %(value)s specified for virtual machine"), "KCHVM0013E": _("Invalid storage pool URI %(value)s specified for virtual machine"), "KCHVM0014E": _("Supported virtual machine graphics are Spice or VNC"), diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py index 9896289..80e7da0 100644 --- a/src/kimchi/model/utils.py +++ b/src/kimchi/model/utils.py @@ -34,7 +34,8 @@ def get_vm_name(vm_name, t_name, name_list): if vm_name: return vm_name for i in xrange(1, 1000): - vm_name = "%s-vm-%i" % (t_name, i) + # VM will have templace name, but without slashes + vm_name = "%s-vm-%i" % (t_name.replace('/', '-'), i) if vm_name not in name_list: return vm_name raise OperationFailed("KCHUTILS0003E")

Backend was not validating storagepool names. It was possible to send a request to Kimchi API to create a pool with slashes in the name using CURL calls, for instance. The UI was doing the checking, but for better compatibility, this was moved to JSON validation phase. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/API.json | 1 + src/kimchi/i18n.py | 2 +- ui/js/src/kimchi.storagepool_add_main.js | 5 ----- ui/pages/i18n.json.tmpl | 1 - 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 2455745..9d54665 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -91,6 +91,7 @@ "description": "The name of the Storage Pool", "type": "string", "minLength": 1, + "pattern": "^[^/]*$", "required": true, "error": "KCHPOOL0016E" }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 7c11016..0a2a59d 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -166,7 +166,7 @@ messages = { "KCHPOOL0013E": _("Unable to create NFS Pool as export path %(path)s mount failed"), "KCHPOOL0014E": _("Unsupported storage pool type: %(type)s"), "KCHPOOL0015E": _("Error while retrieving storage pool XML to %(pool)s"), - "KCHPOOL0016E": _("Storage pool name must be a string"), + "KCHPOOL0016E": _("Storage pool name must be a string without slashes (/)"), "KCHPOOL0017E": _("Supported storage pool types are dir, netfs, logical, iscsi, isci and kimchi-iso"), "KCHPOOL0018E": _("Storage pool path must be a string"), "KCHPOOL0019E": _("Storage pool host must be a IP or hostname"), diff --git a/ui/js/src/kimchi.storagepool_add_main.js b/ui/js/src/kimchi.storagepool_add_main.js index 5ef84af..aaf2496 100644 --- a/ui/js/src/kimchi.storagepool_add_main.js +++ b/ui/js/src/kimchi.storagepool_add_main.js @@ -282,12 +282,7 @@ kimchi.inputsNotBlank = function() { }; kimchi.validateForm = function() { - var name = $('#poolId').val(); var poolType = $("#poolTypeInputId").val(); - if (name.indexOf("/")!=-1) { - kimchi.message.error.code('KCHPOOL6004E'); - return false; - } if (poolType === "dir") { return kimchi.validateDirForm(); } else if (poolType === "netfs") { diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index 8e45b51..6ad9872 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -166,7 +166,6 @@ "KCHPOOL6001E": "$_("The storage pool name can not be blank.")", "KCHPOOL6002E": "$_("The storage pool path can not be blank.")", "KCHPOOL6003E": "$_("NFS server mount path can not be blank.")", - "KCHPOOL6004E": "$_("Invalid storage pool name. It should not contain '/'.")", "KCHPOOL6005E": "$_("Invalid NFS mount path.")", "KCHPOOL6006E": "$_("No logical device selected.")", "KCHPOOL6007E": "$_("The iSCSI target can not be blank.")", -- 2.1.0

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 24/03/2015 13:46, Rodrigo Trujillo wrote:
Backend was not validating storagepool names. It was possible to send a request to Kimchi API to create a pool with slashes in the name using CURL calls, for instance. The UI was doing the checking, but for better compatibility, this was moved to JSON validation phase.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/API.json | 1 + src/kimchi/i18n.py | 2 +- ui/js/src/kimchi.storagepool_add_main.js | 5 ----- ui/pages/i18n.json.tmpl | 1 - 4 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 2455745..9d54665 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -91,6 +91,7 @@ "description": "The name of the Storage Pool", "type": "string", "minLength": 1, + "pattern": "^[^/]*$", "required": true, "error": "KCHPOOL0016E" }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 7c11016..0a2a59d 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -166,7 +166,7 @@ messages = { "KCHPOOL0013E": _("Unable to create NFS Pool as export path %(path)s mount failed"), "KCHPOOL0014E": _("Unsupported storage pool type: %(type)s"), "KCHPOOL0015E": _("Error while retrieving storage pool XML to %(pool)s"), - "KCHPOOL0016E": _("Storage pool name must be a string"), + "KCHPOOL0016E": _("Storage pool name must be a string without slashes (/)"), "KCHPOOL0017E": _("Supported storage pool types are dir, netfs, logical, iscsi, isci and kimchi-iso"), "KCHPOOL0018E": _("Storage pool path must be a string"), "KCHPOOL0019E": _("Storage pool host must be a IP or hostname"), diff --git a/ui/js/src/kimchi.storagepool_add_main.js b/ui/js/src/kimchi.storagepool_add_main.js index 5ef84af..aaf2496 100644 --- a/ui/js/src/kimchi.storagepool_add_main.js +++ b/ui/js/src/kimchi.storagepool_add_main.js @@ -282,12 +282,7 @@ kimchi.inputsNotBlank = function() { };
kimchi.validateForm = function() { - var name = $('#poolId').val(); var poolType = $("#poolTypeInputId").val(); - if (name.indexOf("/")!=-1) { - kimchi.message.error.code('KCHPOOL6004E'); - return false; - } if (poolType === "dir") { return kimchi.validateDirForm(); } else if (poolType === "netfs") { diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index 8e45b51..6ad9872 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -166,7 +166,6 @@ "KCHPOOL6001E": "$_("The storage pool name can not be blank.")", "KCHPOOL6002E": "$_("The storage pool path can not be blank.")", "KCHPOOL6003E": "$_("NFS server mount path can not be blank.")", - "KCHPOOL6004E": "$_("Invalid storage pool name. It should not contain '/'.")", "KCHPOOL6005E": "$_("Invalid NFS mount path.")", "KCHPOOL6006E": "$_("No logical device selected.")", "KCHPOOL6007E": "$_("The iSCSI target can not be blank.")",

This patch adds the JSON checking for Network name, when user tries to create a new network using the API directly. Slashes are not allowed by default, but quotes should also be avoided due to an error raised in /sbin/dnsmasq. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/API.json | 1 + src/kimchi/i18n.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 9d54665..fa18e84 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -319,6 +319,7 @@ "description": "The name of the new network", "type": "string", "minLength": 1, + "pattern": "^[^/\"]*$", "required": true, "error": "KCHNET0011E" }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 0a2a59d..34137f1 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -224,7 +224,7 @@ messages = { "KCHNET0008E": _("Unable to create network %(name)s. Details: %(err)s"), "KCHNET0009E": _("Unable to find a free IP address for network '%(name)s'"), "KCHNET0010E": _("The interface %(iface)s already exists."), - "KCHNET0011E": _("Network name must be a string"), + "KCHNET0011E": _("Network name must be a string without slashes (/) or quotes (\")"), "KCHNET0012E": _("Supported network types are isolated, NAT and bridge"), "KCHNET0013E": _("Network subnet must be a string with IP address and prefix or netmask"), "KCHNET0014E": _("Network interface must be a string"), -- 2.1.0

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 24/03/2015 13:46, Rodrigo Trujillo wrote:
This patch adds the JSON checking for Network name, when user tries to create a new network using the API directly. Slashes are not allowed by default, but quotes should also be avoided due to an error raised in /sbin/dnsmasq.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/API.json | 1 + src/kimchi/i18n.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 9d54665..fa18e84 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -319,6 +319,7 @@ "description": "The name of the new network", "type": "string", "minLength": 1, + "pattern": "^[^/\"]*$", "required": true, "error": "KCHNET0011E" }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 0a2a59d..34137f1 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -224,7 +224,7 @@ messages = { "KCHNET0008E": _("Unable to create network %(name)s. Details: %(err)s"), "KCHNET0009E": _("Unable to find a free IP address for network '%(name)s'"), "KCHNET0010E": _("The interface %(iface)s already exists."), - "KCHNET0011E": _("Network name must be a string"), + "KCHNET0011E": _("Network name must be a string without slashes (/) or quotes (\")"), "KCHNET0012E": _("Supported network types are isolated, NAT and bridge"), "KCHNET0013E": _("Network subnet must be a string with IP address and prefix or netmask"), "KCHNET0014E": _("Network interface must be a string"),
participants (2)
-
Aline Manera
-
Rodrigo Trujillo