Merge ~kirkland/ssh-import-id:master into ssh-import-id:master

Proposed by Dustin Kirkland 
Status: Needs review
Proposed branch: ~kirkland/ssh-import-id:master
Merge into: ssh-import-id:master
Diff against target: 246 lines (+71/-21)
11 files modified
README.md (+3/-2)
debian/changelog (+9/-0)
debian/control (+3/-3)
debian/copyright (+1/-1)
debian/links (+1/-0)
debian/rules (+3/-7)
dev/null (+0/-5)
setup.py (+2/-1)
ssh_import_id/__init__.py (+21/-1)
usr/bin/ssh-import-id-gl (+24/-0)
usr/share/man/man1/ssh-import-id.1 (+4/-1)
Reviewer Review Type Date Requested Status
Robie Basak Pending
Review via email: mp+445392@code.launchpad.net

Commit message

Added support for Gitlab

Description of the change

Added support for Gitlab

To post a comment you must log in.

Unmerged commits

17a4c7d... by Dustin Kirkland 

added Gitlab support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/README.md b/README.md
index e839b64..5bea7d5 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Oh. You have to ask them to cat their public SSH key, paste it into IRC (wait, n
88
9That's where ssh-import-id comes in. With ssh-import-id, you can add the public SSH keys from a known, trusted online identity to grant SSH access.9That's where ssh-import-id comes in. With ssh-import-id, you can add the public SSH keys from a known, trusted online identity to grant SSH access.
1010
11Currently supported identities include Github and Launchpad.11Currently supported identities include Github, Gitlab, and Launchpad.
1212
13Usage13Usage
14-----14-----
@@ -16,6 +16,7 @@ Usage
16ssh-import-id uses short prefix to indicate the location of the online identity. For now, these are:16ssh-import-id uses short prefix to indicate the location of the online identity. For now, these are:
1717
18 'gh:' for Github18 'gh:' for Github
19 'gl:' for Gitlab
19 'lp:' for Launchpad20 'lp:' for Launchpad
2021
21Command line help:22Command line help:
@@ -41,7 +42,7 @@ If you wanted me to be able to ssh into your server, as the desired user on that
4142
42You can also import multiple users on the same line, even from different key services, like so:43You can also import multiple users on the same line, even from different key services, like so:
4344
44 $ ssh-import-id gh:cmars lp:kirkland45 $ ssh-import-id gh:cmars lp:kirkland gl:speeves
4546
46Used with care, it's a great collaboration tool!47Used with care, it's a great collaboration tool!
4748
diff --git a/debian/changelog b/debian/changelog
index 32ed111..13e6200 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
1ssh-import-id (5.12) unreleased; urgency=medium
2
3 [ Dustin Kirkland, Shannon Eric Peevey, Gabriel Mazetto ]
4 * debian/control, debian/copyright, debian/links, README.md, setup.py,
5 ssh_import_id/__init__.py, usr/share/man/man1/ssh-import-id.1:
6 - adding support for Gitlab.com
7
8 -- Dustin Kirkland <kirkland@ubuntu.com> Mon, 26 Jun 2023 19:50:29 -0500
9
1ssh-import-id (5.11-0ubuntu1) hirsute; urgency=medium10ssh-import-id (5.11-0ubuntu1) hirsute; urgency=medium
211
3 * Upstream Release 5.1112 * Upstream Release 5.11
diff --git a/debian/changelog.trunk b/debian/changelog.trunk
4deleted file mode 10064413deleted file mode 100644
index 39d90e2..0000000
--- a/debian/changelog.trunk
+++ /dev/null
@@ -1,5 +0,0 @@
1ssh-import-id (UPSTREAM_VER-0~upstream0) UNRELEASED; urgency=medium
2
3 * UNRELEASED
4
5 -- Dustin Kirkland <kirkland@ubuntu.com> Tue, 11 Jul 2017 15:51:44 -0500
diff --git a/debian/control b/debian/control
index 99c5b75..e24998e 100644
--- a/debian/control
+++ b/debian/control
@@ -24,6 +24,6 @@ Depends: ca-certificates,
24Recommends: openssh-server24Recommends: openssh-server
25Description: securely retrieve an SSH public key and install it locally25Description: securely retrieve an SSH public key and install it locally
26 This utility will securely contact a public keyserver (Launchpad.net by26 This utility will securely contact a public keyserver (Launchpad.net by
27 default, but Github.com is also supported), retrieve one or more user's27 default, but Github.com and Gitlab.com are also supported), retrieve one
28 public keys, and append these to the current user's ~/.ssh/authorized_keys28 or more user's public keys, and append these to the current user's
29 file.29 ~/.ssh/authorized_keys file.
diff --git a/debian/copyright b/debian/copyright
index bb8e48a..ffedd84 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -6,7 +6,7 @@ Upstream-Contact: Dustin Kirkland <kirkland@ubuntu.com>
6Files: *6Files: *
7Copyright: 2010, Canonical Ltd.7Copyright: 2010, Canonical Ltd.
8 2013, Casey Marshall <casey.marshall@gmail.com>8 2013, Casey Marshall <casey.marshall@gmail.com>
9 2013, Dustin Kirkland <dustin.kirkland@gmail.com>9 2013-2023, Dustin Kirkland <dustin.kirkland@gmail.com>
10License: GPL-310License: GPL-3
11 This program is free software: you can redistribute it and/or modify11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by12 it under the terms of the GNU General Public License as published by
diff --git a/debian/links b/debian/links
index 1ad132a..39d8ac8 100644
--- a/debian/links
+++ b/debian/links
@@ -1,2 +1,3 @@
1usr/share/man/man1/ssh-import-id.1 usr/share/man/man1/ssh-import-id-lp.11usr/share/man/man1/ssh-import-id.1 usr/share/man/man1/ssh-import-id-lp.1
2usr/share/man/man1/ssh-import-id.1 usr/share/man/man1/ssh-import-id-gh.12usr/share/man/man1/ssh-import-id.1 usr/share/man/man1/ssh-import-id-gh.1
3usr/share/man/man1/ssh-import-id.1 usr/share/man/man1/ssh-import-id-gl.1
diff --git a/debian/rules b/debian/rules
index 75bb1da..f66f72d 100755
--- a/debian/rules
+++ b/debian/rules
@@ -3,13 +3,9 @@
3# Uncomment this to turn on verbose mode.3# Uncomment this to turn on verbose mode.
4#export DH_VERBOSE=14#export DH_VERBOSE=1
55
6DEB_VERSION := $(shell dpkg-parsechangelog --show-field=Version)
7
8%:6%:
9 dh $@ --with python3 --buildsystem=pybuild7 dh $@ --with python3 --buildsystem=pybuild
108
11override_dh_auto_install:9override_dh_clean:
12 dh_auto_install10 rm -rf *.egg-info/
13 # upstream provides a way to patch in the distro11 dh_clean
14 # version by replacing @@PACKAGED_VERSION@@ in version.py
15 for f in $$(find $(CURDIR)/debian/ -type f -name version.py); do [ -f "$$f" ] || continue; sed -i 's,@@PACKAGED_VERSION@@,$(DEB_VERSION),' "$$f"; done
diff --git a/setup.py b/setup.py
index f00afa6..45b5629 100755
--- a/setup.py
+++ b/setup.py
@@ -2,6 +2,7 @@
2#2#
3# ssh-import-id - Authorize SSH public keys from trusted online identities.3# ssh-import-id - Authorize SSH public keys from trusted online identities.
4# Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>4# Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>
5# Copyright (c) 2023 Dustin Kirkland <dustin.kirkland@gmail.com>
5#6#
6# ssh-import-id is free software: you can redistribute it and/or modify7# ssh-import-id is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by8# it under the terms of the GNU General Public License as published by
@@ -50,7 +51,7 @@ setup(
50 url='https://launchpad.net/ssh-import-id',51 url='https://launchpad.net/ssh-import-id',
51 platforms=['any'],52 platforms=['any'],
52 packages=['ssh_import_id'],53 packages=['ssh_import_id'],
53 scripts=['usr/bin/ssh-import-id-gh', 'usr/bin/ssh-import-id-lp'],54 scripts=['usr/bin/ssh-import-id-gh', 'usr/bin/ssh-import-id-lp', 'usr/bin/ssh-import-id-gl'],
54 install_requires=["distro"],55 install_requires=["distro"],
55 entry_points={56 entry_points={
56 'console_scripts': [57 'console_scripts': [
diff --git a/ssh_import_id/__init__.py b/ssh_import_id/__init__.py
index 034adda..b8a05a9 100644
--- a/ssh_import_id/__init__.py
+++ b/ssh_import_id/__init__.py
@@ -3,7 +3,7 @@
3# ssh-import-id - Authorize SSH public keys from trusted online identities3# ssh-import-id - Authorize SSH public keys from trusted online identities
4#4#
5# Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>5# Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>
6# Copyright (c) 2013 Dustin Kirkland <dustin.kirkland@gmail.com>6# Copyright (c) 2013-2023 Dustin Kirkland <dustin.kirkland@gmail.com>
7#7#
8# ssh-import-id is free software: you can redistribute it and/or modify8# ssh-import-id is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by9# it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@ except ImportError:
26 JSONDecodeError = ValueError26 JSONDecodeError = ValueError
27import logging27import logging
28import os28import os
29import requests
29import subprocess30import subprocess
30import sys31import sys
31import tempfile32import tempfile
@@ -224,6 +225,8 @@ def fetch_keys(proto, username, useragent):
224 return fetch_keys_lp(username, useragent)225 return fetch_keys_lp(username, useragent)
225 if proto == "gh":226 if proto == "gh":
226 return fetch_keys_gh(username, useragent)227 return fetch_keys_gh(username, useragent)
228 if proto == "gl":
229 return fetch_keys_gl(username, useragent)
227230
228 die("ssh-import-id protocol handler %s: not found or cannot execute" %231 die("ssh-import-id protocol handler %s: not found or cannot execute" %
229 (proto))232 (proto))
@@ -355,6 +358,23 @@ def fetch_keys_gh(ghid, useragent):
355 die(str(e))358 die(str(e))
356 return keys359 return keys
357360
361def fetch_keys_gl(glid, useragent):
362 try:
363 url = os.getenv("URL", None)
364 if url is not None:
365 url = url % (quote_plus(glid))
366 # Finally, fall back to gitlab.com
367 if url is None:
368 url = "https://gitlab.com/%s.keys" % (quote_plus(glid))
369 headers = {'User-Agent': user_agent(useragent)}
370 text = requests.get(url, verify=True, headers=headers).text
371 keys = str(text)
372 except (Exception,):
373 e = sys.exc_info()[1]
374 sys.stderr.write("ERROR: %s\n" % (str(e)))
375 os._exit(1)
376 return keys
377
358378
359def main():379def main():
360 errors = []380 errors = []
diff --git a/usr/bin/ssh-import-id-gl b/usr/bin/ssh-import-id-gl
361new file mode 100644381new file mode 100644
index 0000000..5aa5fa7
--- /dev/null
+++ b/usr/bin/ssh-import-id-gl
@@ -0,0 +1,24 @@
1#!/bin/sh
2#
3# ssh-import-id-gl - Authorize SSH public keys from trusted online identities.
4#
5# Copyright (c) 2016-2023 Dustin Kirkland <dustin.kirkland@gmail.com>
6# Copyright (c) 2022 Shannon Eric Peevey <shannonpeevey@gmail.com>
7#
8# ssh-import-id is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, version 3.
11#
12# ssh-import-id is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with ssh-import-id. If not, see <http://www.gnu.org/licenses/>.
19
20set -e
21
22for i in $@; do
23 ssh-import-id gl:$i
24done
diff --git a/usr/share/man/man1/ssh-import-id.1 b/usr/share/man/man1/ssh-import-id.1
index 6d26fa7..fa52bb5 100644
--- a/usr/share/man/man1/ssh-import-id.1
+++ b/usr/share/man/man1/ssh-import-id.1
@@ -9,12 +9,14 @@
99
10.BI "ssh\-import\-id\-gh USER_ID_1 [USER_ID_2] ... [USER_ID_n]10.BI "ssh\-import\-id\-gh USER_ID_1 [USER_ID_2] ... [USER_ID_n]
1111
12.BI "ssh\-import\-id\-gl USER_ID_1 [USER_ID_2] ... [USER_ID_n]
13
12.SH OPTIONS14.SH OPTIONS
13 \-h | \-\-help usage15 \-h | \-\-help usage
14 \-o | \-\-output F write output to file 'F' (default ~/.ssh/authorized_keys, use "\-" for standard out)16 \-o | \-\-output F write output to file 'F' (default ~/.ssh/authorized_keys, use "\-" for standard out)
15 \-r | \-\-remove remove keys from authorized keys file 'F'17 \-r | \-\-remove remove keys from authorized keys file 'F'
16 \-u | \-\-useragent U append U to the user agent string18 \-u | \-\-useragent U append U to the user agent string
17 PROTO:USER_ID Protocol can be 'lp' for Launchpad.net, or 'gh' for Github.com19 PROTO:USER_ID Protocol can be 'lp' for Launchpad.net, 'gh' for Github.com, or 'gl' for Gitlab.com
1820
19.SH DESCRIPTION21.SH DESCRIPTION
20This utility will securely contact a public keyserver and retrieve one or more user's public keys, and append these to the current user's \fI~/.ssh/authorized_keys\fP file, standard output or any other specified output file.22This utility will securely contact a public keyserver and retrieve one or more user's public keys, and append these to the current user's \fI~/.ssh/authorized_keys\fP file, standard output or any other specified output file.
@@ -23,6 +25,7 @@ User IDs can be prepended by a protocol:
2325
24 - \fBlp:\fP to use \fIhttps://launchpad.net/~%s/+sshkeys\fP26 - \fBlp:\fP to use \fIhttps://launchpad.net/~%s/+sshkeys\fP
25 - \fBgh:\fP to use \fIhttps://api.github.com/users/%s/keys\fP27 - \fBgh:\fP to use \fIhttps://api.github.com/users/%s/keys\fP
28 - \fBgl:\fP to use \fIhttps://gitlab.com/%s.keys\fP
2629
27If the protocol is not explicitly specified, then \fBssh-import-id\fP will read a URL variable string from \fI/etc/ssh/ssh_import_id\fP as installed by your package manager and configured by your system administrator. You can override this locally by exporting the string you want in a URL environment variable. If all of these are empty, then the protocol is assumed to be "lp:", which was the original target implementation of this tool.30If the protocol is not explicitly specified, then \fBssh-import-id\fP will read a URL variable string from \fI/etc/ssh/ssh_import_id\fP as installed by your package manager and configured by your system administrator. You can override this locally by exporting the string you want in a URL environment variable. If all of these are empty, then the protocol is assumed to be "lp:", which was the original target implementation of this tool.
2831

Subscribers

People subscribed via source and target branches