summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2018-08-01 12:16:42 +1000
committerAsh McKenzie <amckenzie@gitlab.com>2018-08-01 12:47:30 +1000
commit2bdf08e732ad5d959bfebd222e58a7cd4a4971eb (patch)
tree1676c34376205ace5088b34c4a124c86ca7f8d9e /bin
parenta686b9a0ee4c180b272b26e45c9a2c6cb84c742c (diff)
parente3fead94b6f71d3501d586cbb2295ea0d1da2b31 (diff)
downloadgitlab-shell-2bdf08e732ad5d959bfebd222e58a7cd4a4971eb.tar.gz
Merge remote-tracking branch 'origin/master' into ash.mckenzie/srp-refactor
Diffstat (limited to 'bin')
-rwxr-xr-xbin/gitlab-shell6
-rwxr-xr-xbin/gitlab-shell-authorized-principals-check36
2 files changed, 39 insertions, 3 deletions
diff --git a/bin/gitlab-shell b/bin/gitlab-shell
index 818a328..1016570 100755
--- a/bin/gitlab-shell
+++ b/bin/gitlab-shell
@@ -5,19 +5,19 @@ unless ENV['SSH_CONNECTION']
exit
end
-key_str = /key-[0-9]+/.match(ARGV.join).to_s
original_cmd = ENV.delete('SSH_ORIGINAL_COMMAND')
require_relative '../lib/gitlab_init'
#
#
-# GitLab shell, invoked from ~/.ssh/authorized_keys
+# GitLab shell, invoked from ~/.ssh/authorized_keys or from an
+# AuthorizedPrincipalsCommand in the key-less SSH CERT mode.
#
#
require File.join(ROOT_PATH, 'lib', 'gitlab_shell')
-if GitlabShell.new(key_str).exec(original_cmd)
+if GitlabShell.new(ARGV.join).exec(original_cmd)
exit 0
else
exit 1
diff --git a/bin/gitlab-shell-authorized-principals-check b/bin/gitlab-shell-authorized-principals-check
new file mode 100755
index 0000000..25ee612
--- /dev/null
+++ b/bin/gitlab-shell-authorized-principals-check
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+
+#
+# GitLab shell authorized principals helper. Emits the same sort of
+# command="..." line as gitlab-shell-authorized-principals-check, with
+# the right options.
+#
+# Ex.
+# bin/gitlab-shell-authorized-keys-check <key-id> <principal1> [<principal2>...]
+#
+# Returns one line per principal passed in, e.g.:
+# command="/bin/gitlab-shell username-{KEY_ID}",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty {PRINCIPAL}
+# [command="/bin/gitlab-shell username-{KEY_ID}",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty {PRINCIPAL2}]
+#
+# Expects to be called by the SSH daemon, via configuration like:
+# AuthorizedPrincipalsCommandUser root
+# AuthorizedPrincipalsCommand /bin/gitlab-shell-authorized-principals-check git %i sshUsers
+
+abort "# Wrong number of arguments. #{ARGV.size}. Usage:
+# gitlab-shell-authorized-principals-check <key-id> <principal1> [<principal2>...]" unless ARGV.size >= 2
+
+key_id = ARGV[0]
+abort '# No key_id provided' if key_id.nil? || key_id == ''
+
+principals = ARGV[1..-1]
+principals.each { |principal|
+ abort '# An invalid principal was provided' if principal.nil? || principal == ''
+}
+
+require_relative '../lib/gitlab_init'
+require_relative '../lib/gitlab_net'
+require_relative '../lib/gitlab_keys'
+
+principals.each { |principal|
+ puts GitlabKeys.principal_line("username-#{key_id}", principal.dup)
+}