Skip to content

Commit f2e0818

Browse files
author
Pradeep Kilambi
committed
Allow secure user password update.
This patch allows the ability for user password to be updated via a command prompt so the password doesnt show up in the bash history. The prompted password is asked twice to verify the match. If user cntl-D's the prompt a message appears suggesting user to use either of the options to update the password. Fixes: bug#938315 Change-Id: I4271ae569b922f33c34f9b015a7ee6f760414e39
1 parent 1130dd7 commit f2e0818

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

keystoneclient/utils.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import uuid
1+
import getpass
22
import hashlib
3+
import sys
4+
import uuid
35

46
import prettytable
57

@@ -128,3 +130,22 @@ def hash_signed_token(signed_text):
128130
hash_ = hashlib.md5()
129131
hash_.update(signed_text)
130132
return hash_.hexdigest()
133+
134+
135+
def prompt_for_password():
136+
"""
137+
Prompt user for password if not provided so the password
138+
doesn't show up in the bash history.
139+
"""
140+
if not (hasattr(sys.stdin, 'isatty') and sys.stdin.isatty()):
141+
# nothing to do
142+
return
143+
144+
while True:
145+
try:
146+
new_passwd = getpass.getpass('New Password: ')
147+
rep_passwd = getpass.getpass('Repeat New Password: ')
148+
if new_passwd == rep_passwd:
149+
return new_passwd
150+
except EOFError:
151+
return

keystoneclient/v2_0/shell.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import argparse
1919
import getpass
20+
import sys
2021

2122
from keystoneclient.v2_0 import client
2223
from keystoneclient import utils
@@ -103,14 +104,19 @@ def do_user_update(kc, args):
103104
print 'Unable to update user: %s' % e
104105

105106

106-
@utils.arg('--pass', metavar='<password>', dest='passwd', required=True,
107+
@utils.arg('--pass', metavar='<password>', dest='passwd', required=False,
107108
help='Desired new password')
108109
@utils.arg('user', metavar='<user>',
109110
help='Name or ID of user to update password')
110111
def do_user_password_update(kc, args):
111112
"""Update user password"""
112113
user = utils.find_resource(kc.users, args.user)
113-
kc.users.update_password(user, args.passwd)
114+
new_passwd = args.passwd or utils.prompt_for_password()
115+
if new_passwd is None:
116+
msg = ("\nPlease specify password using the --pass option "
117+
"or using the prompt")
118+
sys.exit(msg)
119+
kc.users.update_password(user, new_passwd)
114120

115121

116122
@utils.arg('--current-password', metavar='<current-password>',

0 commit comments

Comments
 (0)