Merge lp:~javier.collado/utah/bug1068664 into lp:utah

Proposed by Javier Collado
Status: Rejected
Rejected by: Javier Collado
Proposed branch: lp:~javier.collado/utah/bug1068664
Merge into: lp:utah
Diff against target: 79 lines (+19/-5)
3 files modified
utah/config.py (+1/-0)
utah/provisioning/provisioning.py (+17/-4)
utah/run.py (+1/-1)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1068664
Reviewer Review Type Date Requested Status
Javier Collado (community) Disapprove
Joe Talbott (community) Needs Information
Review via email: mp+130601@code.launchpad.net

Description of the change

This branch changes the utah client command string to execute is as root as
it's required now.

Additional information:
- The way to use as root is to prepend "sudo -S".
- The -S tells sudo to read the password from stdin.
- SSHMixin.run takes care of writing the password to stdin when needed.
  (basically when the paramiko channel is still open after running the command).
- A new configuration variable (config.password) is used to store the password value.
- Support to overwrite the password in the preseed has been added so that the
  password in the preseed is in sync with the code.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

It seems to me that keeping the method name '_rewrite_passwd_username' is more descriptive since it's setting both the password and username.

Other than that looks good to me.

review: Needs Information
lp:~javier.collado/utah/bug1068664 updated
718. By Javier Collado

Renamed _rewrite_passwd as suggested by joetalbott

Final name is: _rewrite_username_and_passwd

719. By Javier Collado

Changed username and passwd lines changed if any of them exists

The username and password lines in the preseed were changed only
if 'passwd/username' was present. Now, all of them are changed
just if any of the following is available:
- 'passwd/username'
- 'passwd/user-password'
- 'passwd/user-password-again'

Revision history for this message
Max Brustkern (nuclearbob) wrote :

We also install ssh keys under the root user, so we can call the run method of the machine class with root=True to use root instead of using sudo. I think we'd just need to make that change in run.py on line 43. That would mean we wouldn't need to rewrite the password either, since we don't need the password for that. At some point I'd like to move to using an encypted password in the default or rewritten preseed, but I haven't worked on that in a while since it hasn't been high priority.

Revision history for this message
Javier Collado (javier.collado) wrote :

@Max

Looking at the alternative that you suggested.

Revision history for this message
Javier Collado (javier.collado) wrote :

I've created a new merge request with the one line change suggested by Max.

I'm rejecting this proposal, since all the complexity to write root password
to stdin so that sudo receives it isn't needed at all.

review: Disapprove

Unmerged revisions

719. By Javier Collado

Changed username and passwd lines changed if any of them exists

The username and password lines in the preseed were changed only
if 'passwd/username' was present. Now, all of them are changed
just if any of the following is available:
- 'passwd/username'
- 'passwd/user-password'
- 'passwd/user-password-again'

718. By Javier Collado

Renamed _rewrite_passwd as suggested by joetalbott

Final name is: _rewrite_username_and_passwd

717. By Javier Collado

Added password rewritting to the preseed

Given that the previous commit adds a new password field to the configuration
file, this commit adds support to use that value in the preseed as well.

716. By Javier Collado

Updated utah client command to use "sudo -S"

Additional information:
- This is needed because the client needs to be executed as root.
- The -S tells sudo to read the password from stdin.
- A new configuration variable `password` is used to get the password to be
  used.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'utah/config.py'
--- utah/config.py 2012-10-16 10:46:10 +0000
+++ utah/config.py 2012-10-22 08:38:22 +0000
@@ -46,6 +46,7 @@
46 nfscommand=['sudo', os.path.join('/', 'etc', 'init.d', 'nfs-kernel-server'), 'reload'],46 nfscommand=['sudo', os.path.join('/', 'etc', 'init.d', 'nfs-kernel-server'), 'reload'],
47 nfsconfigfile=os.path.join('/', 'etc', 'exports'),47 nfsconfigfile=os.path.join('/', 'etc', 'exports'),
48 nfsoptions='*(ro,async,no_root_squash,no_subtree_check)',48 nfsoptions='*(ro,async,no_root_squash,no_subtree_check)',
49 password='!ubuntu123',
49 powertimeout=5,50 powertimeout=5,
50 preseed=None,51 preseed=None,
51 qemupath='qemu:///system',52 qemupath='qemu:///system',
5253
=== modified file 'utah/provisioning/provisioning.py'
--- utah/provisioning/provisioning.py 2012-10-16 10:46:10 +0000
+++ utah/provisioning/provisioning.py 2012-10-22 08:38:22 +0000
@@ -518,10 +518,14 @@
518 channel = self.ssh_client.get_transport().open_session()518 channel = self.ssh_client.get_transport().open_session()
519519
520 self.logger.info('Running command through SSH: ' + commandstring)520 self.logger.info('Running command through SSH: ' + commandstring)
521 stdin = channel.makefile('wb')
521 stdout = channel.makefile('rb')522 stdout = channel.makefile('rb')
522 stderr = channel.makefile_stderr('rb')523 stderr = channel.makefile_stderr('rb')
523 if timeout is None:524 if timeout is None:
524 channel.exec_command(commandstring)525 channel.exec_command(commandstring)
526 if not channel.closed:
527 stdin.write('{}\n'.format(config.password))
528 stdin.flush()
525 else:529 else:
526 utah.timeout.timeout(timeout, channel.exec_command, commandstring)530 utah.timeout.timeout(timeout, channel.exec_command, commandstring)
527 retval = channel.recv_exit_status()531 retval = channel.recv_exit_status()
@@ -820,8 +824,13 @@
820 self._rewrite_pkgsel_include(preseed)824 self._rewrite_pkgsel_include(preseed)
821 if 'netcfg/get_hostname' in preseed:825 if 'netcfg/get_hostname' in preseed:
822 self._rewrite_get_hostname(preseed)826 self._rewrite_get_hostname(preseed)
823 if 'passwd/username' in preseed:827
824 self._rewrite_passwd_username(preseed)828 username_and_passwd_qnames = ['passwd/username',
829 'passwd/user-password',
830 'passwd/user-password-again']
831 if any(qname in preseed
832 for qname in username_and_passwd_qnames):
833 self._rewrite_username_and_passwd(preseed)
825834
826 output_preseed_filename = os.path.join(tmpdir,835 output_preseed_filename = os.path.join(tmpdir,
827 'initrd.d', 'preseed.cfg')836 'initrd.d', 'preseed.cfg')
@@ -896,13 +905,17 @@
896 question = preseed['netcfg/get_hostname']905 question = preseed['netcfg/get_hostname']
897 question.value = self.name906 question.value = self.name
898907
899 def _rewrite_passwd_username(self, preseed):908 def _rewrite_username_and_passwd(self, preseed):
900 """909 """
901 Set password properly in the preseed910 Set username and password properly in the preseed
902 """911 """
903 self.logger.info('Rewriting username to ' + config.user)912 self.logger.info('Rewriting username to ' + config.user)
904 question = preseed['passwd/username']913 question = preseed['passwd/username']
905 question.value = config.user914 question.value = config.user
915 question = preseed['passwd/user-password']
916 question.value = config.password
917 question = preseed['passwd/user-password-again']
918 question.value = config.password
906919
907 def _preseedcasper(self, tmpdir=None):920 def _preseedcasper(self, tmpdir=None):
908 """921 """
909922
=== modified file 'utah/run.py'
--- utah/run.py 2012-10-16 10:46:10 +0000
+++ utah/run.py 2012-10-22 08:38:22 +0000
@@ -38,7 +38,7 @@
38 machine.uploadfiles([locallist], os.path.normpath('/tmp'))38 machine.uploadfiles([locallist], os.path.normpath('/tmp'))
3939
40 options = ' -r /tmp/' + os.path.basename(locallist)40 options = ' -r /tmp/' + os.path.basename(locallist)
41 utah_command = 'utah' + extraopts + options41 utah_command = 'sudo -S utah' + extraopts + options
42 try:42 try:
43 _returncode, stdout, _stderr = machine.run(utah_command)43 _returncode, stdout, _stderr = machine.run(utah_command)
44 # TODO: Decide which returncode means utah client failure44 # TODO: Decide which returncode means utah client failure

Subscribers

People subscribed via source and target branches