summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorChuck Short <chuck.short@canonical.com>2012-03-08 15:09:38 -0500
committerBrian Waldon <bcwaldon@gmail.com>2012-03-09 17:27:00 -0800
commit6f67c9d043ebd104e07a59f0cd2e9eaca003a4c1 (patch)
tree584f223f11b4dc5b3cb2d74ab07f7a6b7846baa4 /nova/api
parentbd2d89dd567dc8544201042487ac23c2096a4b8d (diff)
downloadnova-6f67c9d043ebd104e07a59f0cd2e9eaca003a4c1.tar.gz
nova-6f67c9d043ebd104e07a59f0cd2e9eaca003a4c1.tar.xz
nova-6f67c9d043ebd104e07a59f0cd2e9eaca003a4c1.zip
EC2 KeyName validation.
According to EC2 API Documentation, the keyname is acccetable as a alphanumeric characters, spaces, dashes, and underscores. As well as make sure that the keyname doesnt exceed 255 characters. Make sure that the key that is being created is valid. Fixes bug 947750. Change-Id: I083af7f2cbc417150fadb79b307083bb3ba229d6 Signed-off-by: Chuck Short <chuck.short@canonical.com>
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/ec2/cloud.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index 25d6c1c81..f4886551d 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -369,6 +369,17 @@ class CloudController(object):
return {'keySet': result}
def create_key_pair(self, context, key_name, **kwargs):
+ if not re.match('^[a-zA-Z0-9_\- ]+$', str(key_name)):
+ err = _("Value (%s) for KeyName is invalid."
+ " Content limited to Alphanumeric character, "
+ "spaces, dashes, and underscore.") % key_name
+ raise exception.EC2APIError(err)
+
+ if len(str(key_name)) > 255:
+ err = _("Value (%s) for Keyname is invalid."
+ " Length exceeds maximum of 255.") % key_name
+ raise exception.EC2APIError(err)
+
LOG.audit(_("Create key pair %s"), key_name, context=context)
data = _gen_key(context, context.user_id, key_name)
return {'keyName': key_name,