ssh-import-id gh:$missing-user does not flush stdout properly

Bug #1770302 reported by Michael Hudson-Doyle on 2018-05-10
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ssh-import-id
Medium
Michael Hudson-Doyle
ssh-import-id (Ubuntu)
Medium
Unassigned
Bionic
Undecided
Unassigned

Bug Description

[Impact]
Invoking ssh-import-id gh:$missing_user in a non-interactive context produces no output.

I want to change subiquity to invoke ssh-import-id directly and helpful error messages are important in giving useful feedback to the user.

[Test case]
"ssh-import-id gh:mwhudso 2>&1 | cat" should output "no such user" or some similar helpful messsage, not nothing at all.

[Regression potential]
The upload to bionic unapproved is an untested combination of patches so needs careful testing. Fortunately each patch is small and mostly independent so testing each affected area of code should not be too onerous.

[Original Description]
mwhudson@ringil:~/src/ssh-import-id$ ssh-import-id gh:mwhudso
Username "mwhudso" not found at GitHub API
mwhudson@ringil:~/src/ssh-import-id$ ssh-import-id gh:mwhudso | cat
mwhudson@ringil:~/src/ssh-import-id$

What happened? The offending code looks like

  if resp.status_code == 404:
   print('Username "%s" not found at GitHub API' % ghid)
   os._exit(1)

print does not flush by default. When stdout is a terminal you get an implicit flush on newline but when it's a pipe you do not and calling _exit(1) exits the process without flushing the buffers either. Two fixes suggest themselves: 1) add flush=True to the print() calls 2) exiting more conventionally by e.g. calling sys.exit()

Scott Moser (smoser) on 2018-05-11
Changed in ssh-import-id:
assignee: nobody → Michael Hudson-Doyle (mwhudson)
importance: Undecided → Medium
status: New → Fix Committed
Scott Moser (smoser) on 2018-05-11
Changed in ssh-import-id (Ubuntu):
status: New → Confirmed
importance: Undecided → Medium
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ssh-import-id - 5.7-24-g4001a38e-0ubuntu1

---------------
ssh-import-id (5.7-24-g4001a38e-0ubuntu1) cosmic; urgency=medium

  * New upstream snapshot.
    - debian/postinst: Correctly check old version.
    - debian/: Adjust packaging to include debian's changes and fix
      lintian warnings.
    - Migrate upstream to git.
    - Add running of pycodestyle and pylint via tox and fix warnings.
    - Convert tabs to spaces for indentation globally.
    - Get path to user's authorized_keys even if HOME is not set.
      (LP: #1570997)
    - Exit with sys.exit() rather than os._exit.
      [Michael Hudson-Doyle] (LP: #1770302)
    - Launchpad: check status code of response when fetching ssh keys.
      [Michael Hudson-Doyle] (LP: #1770305)
    - Fix NameError on unknown service/proto. [Michael Hudson-Doyle]
    - debian/rules: no longer run pep8 in debian build.
    - Use setup.py's console_scripts to write ssh-import-id to /usr/bin.

 -- Scott Moser <email address hidden> Fri, 11 May 2018 14:56:46 -0400

Changed in ssh-import-id (Ubuntu):
status: Confirmed → Fix Released
description: updated
description: updated

Hello Michael, or anyone else affected,

Accepted ssh-import-id into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ssh-import-id/5.7-0ubuntu1.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed.Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in ssh-import-id (Ubuntu Bionic):
status: New → Fix Committed
tags: added: verification-needed verification-needed-bionic
Michael Hudson-Doyle (mwhudson) wrote :

Verification done on bionic.

$ dpkg-query -W ssh-import-id
ssh-import-id 5.7-0ubuntu1.1
$ ssh-import-id gh:mwhudso 2>&1 | cat
2018-05-20 22:47:00,209 ERROR Username "mwhudso" not found at GitHub API
$ ssh-import-id gh:mwhudson 2>&1 | cat
2018-05-20 22:47:03,645 INFO Already authorized ['1024', 'SHA256:Dl9JYCMT9yklbtkp8cedYOJmKaeRYzrAezJdKumCdq0', 'mwhudson@github/681882', '(RSA)']
2018-05-20 22:47:03,646 INFO [1] SSH keys [Authorized]
[disable networking]
$ ssh-import-id gh:mwhudson 2>&1 | cat
2018-05-20 22:48:54,549 ERROR HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /users/mwhudson/keys (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fedaf2c50b8>: Failed to establish a new connection: [Errno -2] Name or service not known',))

All working as hoped for.

tags: added: verification-done-bionic
removed: verification-needed verification-needed-bionic
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ssh-import-id - 5.7-0ubuntu1.1

---------------
ssh-import-id (5.7-0ubuntu1.1) bionic; urgency=medium

  * Convert source foramt to "3.0 (quilt)", implicitly removing
    ssh_import_id.egg-info presumably included in last upload by
    mistake.
  * Backport some fixes from cosmic:
    - d/patches/0001-lp-1770302-output-flushing.patch: Ensure error
      messages in fetch_keys_gh get flushed by replacing calls to print
      with calls to die and calls to os._exit() with calls to sys.exit.
      (LP: #1770302)
    - d/patches/0002-lp-1770503-launchpad-error-checking.patch: Check
      status code of response when fetching ssh keys from Launchpad.
      (LP: #1770305)
    - d/patches/0003-lp-1570997-find-keys-no-HOME.patch: Get path to
      user's authorized_keys even if HOME is not set. (LP: #1570997)

 -- Michael Hudson-Doyle <email address hidden> Thu, 17 May 2018 11:40:43 +1200

Changed in ssh-import-id (Ubuntu Bionic):
status: Fix Committed → Fix Released

The verification of the Stable Release Update for ssh-import-id has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers