summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorPablo Carranza <pcarranza@gmail.com>2016-03-08 17:49:22 +0000
committerPablo Carranza <pcarranza@gmail.com>2016-03-24 20:48:27 +0000
commitc9fac154cd99233c9a6f1cbb88316a476fffc3ad (patch)
tree6d7c6ea65e4c0204ca9596adc3da7e9e29caa51c /bin
parent1f2bef765d8aa03b76f991178cfa7513833b4c3b (diff)
downloadgitlab-shell-c9fac154cd99233c9a6f1cbb88316a476fffc3ad.tar.gz
Add authorized keys bin script to find keys by fingerprint
Diffstat (limited to 'bin')
-rwxr-xr-xbin/authorized_keys25
1 files changed, 25 insertions, 0 deletions
diff --git a/bin/authorized_keys b/bin/authorized_keys
new file mode 100755
index 0000000..6f9880c
--- /dev/null
+++ b/bin/authorized_keys
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+#
+# GitLab shell authorized_keys. Query gitlab API to get the authorized command for a given ssh key fingerprint
+#
+# Ex.
+# /bin/authorized_keys e6:17:f2:f3:b7
+#
+# Returns
+# command="/bin/gitlab-shell key-#",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQA...
+#
+
+fingerprint = ARGV[0]
+abort "# No fingerprint provided" if fingerprint.nil?
+
+require_relative "../lib/gitlab_init"
+require_relative "../lib/gitlab_net"
+require_relative "../lib/gitlab_keys"
+
+authorized_key = GitlabNet.new.authorized_key(fingerprint)
+unless authorized_key.nil?
+ puts GitlabKey.new.key_line(authorized_key["id"], authorized_key["key"])
+else
+ puts "# No key was found with fingerprint #{fingerprint}"
+end