diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-12-19 16:02:13 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-12-19 16:02:13 +0000 |
commit | f8f314890758983e9d167529cb3a332a01262d5c (patch) | |
tree | 41909b1b8957495435ecdb4a368ca75fd0dfd305 /bin/gitlab-shell-authorized-keys-check | |
parent | 5cad42aadaa1bea02f3edb3bfffc95cb0799c259 (diff) | |
parent | d40383fef6feaf282eed03f38e71e522494c1282 (diff) | |
download | gitlab-shell-f8f314890758983e9d167529cb3a332a01262d5c.tar.gz |
Merge branch '118-database-authorized-keys' into 'master'v5.11.0
Introduce a more-complete implementation of bin/authorized_keys
Closes #118
See merge request gitlab-org/gitlab-shell!178
Diffstat (limited to 'bin/gitlab-shell-authorized-keys-check')
-rwxr-xr-x | bin/gitlab-shell-authorized-keys-check | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/bin/gitlab-shell-authorized-keys-check b/bin/gitlab-shell-authorized-keys-check new file mode 100755 index 0000000..2ea1a74 --- /dev/null +++ b/bin/gitlab-shell-authorized-keys-check @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby + +# +# GitLab shell authorized_keys helper. Query GitLab API to get the authorized +# command for a given ssh key fingerprint +# +# Ex. +# bin/gitlab-shell-authorized-keys-check <username> <public-key> +# +# Returns +# command="/bin/gitlab-shell key-#",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAA... +# +# Expects to be called by the SSH daemon, via configuration like: +# AuthorizedKeysCommandUser git +# AuthorizedKeysCommand /bin/gitlab-shell-authorized-keys-check git %u %k + +abort "# Wrong number of arguments. #{ARGV.size}. Usage: +# gitlab-shell-authorized-keys-check <expected-username> <actual-username> <key>" unless ARGV.size == 3 + +expected_username = ARGV[0] +abort '# No username provided' if expected_username.nil? || expected_username == '' + +actual_username = ARGV[1] +abort '# No username provided' if actual_username.nil? || actual_username == '' + +# Only check access if the requested username matches the configured username. +# Normally, these would both be 'git', but it can be configured by the user +exit 0 unless expected_username == actual_username + +key = ARGV[2] +abort "# No key provided" if key.nil? || key == '' + +require_relative '../lib/gitlab_init' +require_relative '../lib/gitlab_net' +require_relative '../lib/gitlab_keys' + +authorized_key = GitlabNet.new.authorized_key(key) +if authorized_key.nil? + puts "# No key was found for #{key}" +else + puts GitlabKeys.key_line("key-#{authorized_key['id']}", authorized_key['key']) +end |