Bug 1585749 - Security Key Pair creation is not allowed with "underscore" character from the Launch Instance menu on Horizon.
Summary: Security Key Pair creation is not allowed with "underscore" character from th...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat OpenStack
Classification: Red Hat
Component: python-django-horizon
Version: 10.0 (Newton)
Hardware: Unspecified
OS: Unspecified
low
low
Target Milestone: beta
: 14.0 (Rocky)
Assignee: RHOS Maint
QA Contact: Beth White
URL:
Whiteboard:
Depends On:
Blocks: 1621357 1665084
TreeView+ depends on / blocked
 
Reported: 2018-06-04 15:32 UTC by David Hill
Modified: 2019-01-11 11:50 UTC (History)
8 users (show)

Fixed In Version: python-django-horizon-14.0.0-0.20180725221532.74d75da.el7ost
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1621357 1665084 (view as bug list)
Environment:
Last Closed: 2019-01-11 11:50:06 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Launchpad 1775030 0 None None None 2018-06-04 15:34:00 UTC
OpenStack gerrit 572141 0 None None None 2018-06-04 15:34:42 UTC
Red Hat Product Errata RHEA-2019:0045 0 None None None 2019-01-11 11:50:31 UTC

Description David Hill 2018-06-04 15:32:56 UTC
Description of problem:
Using Horizon to instantiate VM:
Instances -> Launch Instance -> Key Pair -> Create Key Pair 
Trying to create Key Pair name with underscore character, getting "name contains bad characters" error - see attached screenshot.
If you are trying to create Security Key Pair prior to VM instantiation using Access & Security -> Create Key Pair, "underscore" character is accepted.
"Underscore" character shall be accepted in Security Key Pair name also in Instances -> Launch Instance -> Key Pair -> Create Key Pair menu.



Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. 
2.
3.

Actual results:


Expected results:


Additional info:

Comment 10 Udi Kalifon 2018-11-26 08:02:42 UTC
The underscore is now allowed from the launch instance wizard, but not allowed from the key pairs page. This seems to be to opposite situation from what the bug describes.

Comment 11 David Hill 2018-12-31 14:13:45 UTC
The code we changed here isn't used by that form ... are you able to revert that patch and confirm it doesn't change the behavior of the create_key form ?

Comment 12 David Hill 2018-12-31 14:22:37 UTC
That part of the form regex is handled by this chunk of code:

***
NEW_LINES = re.compile(r"\r|\n")

KEYPAIR_NAME_REGEX = re.compile(r"^\w+(?:[- ]\w+)*$", re.UNICODE)
KEYPAIR_ERROR_MESSAGES = {
    'invalid': _('Key pair name may only contain letters, '
                 'numbers, underscores, spaces, and hyphens '
                 'and may not be white space.')}


class CreateKeypair(forms.SelfHandlingForm):
    name = forms.RegexField(max_length=255,
                            label=_("Key Pair Name"),
                            regex=KEYPAIR_NAME_REGEX,
                            error_messages=KEYPAIR_ERROR_MESSAGES)
***

Out of curiosity, I tested this and it worked:

###
import re

KEYPAIR_NAME_REGEX = re.compile(r"^\w+(?:[- ]\w+)*$", re.UNICODE)
string="test_test"

pattern = KEYPAIR_NAME_REGEX.match(string)
if pattern:
  print("matched")
else:
  print("not matched")
###

[dhill@knox openstack_dashboard]$ python regex_test.py
matched

Comment 13 David Hill 2018-12-31 16:29:51 UTC
Well that is strange I was just able to reproduce this issue too.

Comment 14 David Hill 2018-12-31 16:50:45 UTC
And stranger is that I was able to reproduce this issue too up until now.    Now I'm no longer able to reproduce this issue with the patch on and no changes at all.  Could it be a browser cache issue and QA procedure ? 

What I did is something like this:

1) Applied the patch
2) Restarted httpd
3) Tried creating a Key Pair from the Access & Security tab
4) Didn't work for ANY Key Pairs (not just containing an underscore, all of them would just fail)

then :

1) Reverted the patch
2) Restarted httpd
3) Tried creating a Key Pair from the Access & Security tab
4) Started working back again

then :
1) Applied the patch
2) Restarted httpd
3) Tried creating a Key Pair from the Access & Security tab
4) Failed back again for all Key Pairs

and well, then I tried lots of things like moving the undercore elsewhere in the regex, for instance "[_A-Za-z0-9 -]" , restarted httpd, retried and it failed back again.  

Finally, all of a sudden, it started working for some reasons .  I'm wondering if there's a temp file in horizon or the browser that could have generated this situation ?

Comment 15 David Hill 2018-12-31 17:05:36 UTC
It looks like you have to restart httpd twice when changing the files in /usr/share/openstack-dashboard/openstack_dashboard because the first time you restart it, it copies the change to /usr/share/openstack-dashboard/static and I'm not able to create any key pairs .   Then, if I restart httpd, it starts working.   What happens if you change the existing files in /usr/share/openstack-dashboard/static before restarting httpd ?  Does it help ?  Are you able to solve the problem by restarting httpd a second time ?

Comment 16 David Hill 2018-12-31 17:15:16 UTC
I can confirm that each time I modify the file located in /usr/share/openstack-dashboard/openstack_dashboard, I need to restart httpd twice or Key Pair creation isn't working at all in that section.   I'd suggest you try it too to confirm it solves it for you too.

Comment 18 errata-xmlrpc 2019-01-11 11:50:06 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2019:0045


Note You need to log in before you can comment on or make changes to this bug.