Skip to content
Snippets Groups Projects

Allow configuration of the authorized_keys file location used by gitlab-shell

Merged DJ Mountney requested to merge config-shell-auth-file into master
7 unresolved threads

Also added an alternative search location for authorized_keys to our docker sshd_config

We wil make use of this in the OpenShift template in order to get around root_squash issues with the git user's home directory.

cc\ @jacobvosmaer-gitlab @marin

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
23 23 gitlab_shell_var_dir = "/var/opt/gitlab/gitlab-shell"
24 24 git_data_directories = node['gitlab']['gitlab-shell']['git_data_directories']
25 25 repositories_storages = node['gitlab']['gitlab-rails']['repositories_storages']
26 ssh_dir = File.join(node['gitlab']['user']['home'], ".ssh")
27 authorized_keys = File.join(ssh_dir, "authorized_keys")
26 authorized_keys = node['gitlab']['gitlab-shell']['auth_file']
27 ssh_dir = File.dirname(authorized_keys)
  • 11 11 PrintMotd no
    12 12 PrintLastLog no
    13 13 PubkeyAuthentication yes
    14 AuthorizedKeysFile %h/.ssh/authorized_keys /gitlab-data/%u/authorized_keys
  • 173 173 generate_secrets(node_name)
    174 174 GitlabWorkhorse.parse_variables
    175 175 GitlabRails.parse_variables
    176 GitlabShell.parse_variables
    • I would also put this one line above. At the moment it doesn't make a difference but it might be good to split parse_git_data_dirs from GitlabRails to make the separation clearer.

    • Please register or sign in to reply
  • DJ Mountney Added 1 commit:

    Added 1 commit:

    • 59788d3c - Allow configuration of the authorized_keys file location used by gitlab-shell
  • Author Contributor

    @jacobvosmaer-gitlab @marin feedback has been implemented

  • Author Contributor

    The current way I have it here doesn't handle selinux rules for the auth file. In order to get it working you have to run something like:

    semanage fcontext -a -t sshd_key_t '/gitlab-data/authorized_keys'
    restorecon -v '/gitlab-data/authorized_keys'

    I'm thinking I should add that in to the recipe as well? Thoughts?

  • mentioned in issue #1305 (closed)

  • 24 24 git_data_directories = node['gitlab']['gitlab-shell']['git_data_directories']
    25 25 repositories_storages = node['gitlab']['gitlab-rails']['repositories_storages']
    26 26 ssh_dir = File.join(node['gitlab']['user']['home'], ".ssh")
    27 authorized_keys = File.join(ssh_dir, "authorized_keys")
    27 authorized_keys = node['gitlab']['gitlab-shell']['auth_file']
  • Now that we have https://gitlab.com/gitlab-org/gitlab-shell/merge_requests/79 we can catch authorized_keys permissions issues, even if the file is not in ~git/.ssh, with:

    command '/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions' do
      user 'git'
      group 'git'
    end
  • If we depend on policycoreutils then we can probably do the semanage stuff. Good that you thought of that @twk3 .

    @marin I believe this is an old topic. Where are we on the idea of the (EL) packages depending on policycoreutils?

  • @jacobvosmaer-gitlab We didn't make a decision on that. The only thing that was clear in discussions about policycoreutils was that we are not bundling that, but maybe that changed in the meantime (highly doubt it). If we are to introduce another runtime dependency we need to make sure that not only CentOS 6/7 support it but that it is also supported on RedHat/Oracle/Scientific Linux . So we will have to do an analysis whether that is worth it.

  • DJ Mountney Added 1 commit:

    Added 1 commit:

    • d1d1a7ac - Run the gitlab-shell keys permission check during the shell recipe
  • Author Contributor

    @jacobvosmaer-gitlab @marin should I just add a chcon exec then for the file for now? To avoid the policycoreutils and to match what we are doing for the ssh home directory.

  • @twk3 Yes. Could you also create an issue about policycoreutils so we can investigate further what the cost of introducing it is?

  • DJ Mountney Added 1 commit:

    Added 1 commit:

    • 19ce4c42 - Use gitlab-shell bin/keys to create the authorized_keys file if it doesn't already exist
  • Author Contributor

    Updated with the chcon changes, I also brought back the auth_file creation, otherwise the chcon and the check permissions were failing. I am using the gitlab-shell keys clear command for it though.

    A new issue for policycoreutils has been created: https://gitlab.com/gitlab-org/omnibus-gitlab/issues/1485

  • @twk3 you can also use the new gitlab-keys check-permissions command. That will create the file if missing and it does not clear it.

  • Author Contributor

    @jacobvosmaer-gitlab I don't think check-permissions creates the file, it also complains if it doesn't exist

  • DJ Mountney Added 52 commits:

    Added 52 commits:

    • 19ce4c42...06b2dddf - 49 commits from branch master
    • 8df5fe1c - Allow configuration of the authorized_keys file location used by gitlab-shell
    • 69866a1e - Run the gitlab-shell keys permission check during the shell recipe
    • 14f61764 - Use gitlab-shell bin/keys to create the authorized_keys file if it doesn't already exist
  • @twk3 yes you are right. I think the current combination is good. Although 'clear unless exists' does have a race condition.

  • We could also change check-permissions so that it creates the file. That might be better than having a race condition.

  • diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
    index dc654fd..e10af83 100644
    --- a/lib/gitlab_keys.rb
    +++ b/lib/gitlab_keys.rb
    @@ -101,7 +101,7 @@ class GitlabKeys
       end
     
       def check_permissions
    -    open_auth_file('r+') { true }
    +    open_auth_file(File::RDWR | File::CREAT) { true }
       rescue => ex
         puts "error: could not open #{auth_file}: #{ex}"
         if File.exist?(auth_file)

    Would do it in gitlab-shell. Plus a test case that asserts file creation.

  • DJ Mountney Added 1 commit:

    Added 1 commit:

    • f1c0b038 - Drop use of keys clear, and use the new check-permissions command for the key file creation
  • Author Contributor

    Updated with the latest changes, uses check-permissions to create the file.

  • DJ Mountney Added 27 commits:

    Added 27 commits:

    • f1c0b038...2bb3e43f - 22 commits from branch master
    • 18a90aa9 - Allow configuration of the authorized_keys file location used by gitlab-shell
    • 4d976f23 - Run the gitlab-shell keys permission check during the shell recipe
    • f7865775 - Use gitlab-shell bin/keys to create the authorized_keys file if it doesn't already exist
    • efb9beaa - Drop use of keys clear, and use the new check-permissions command for the key file creation
    • 21c54b87 - Added chefspec tests for the authorized_keys config change
  • Author Contributor

    Added chefspec tests

    Anything else? @jacobvosmaer-gitlab @marin

  • Looks good from my end @twk3 !

  • 11 11 PrintMotd no
    12 12 PrintLastLog no
    13 13 PubkeyAuthentication yes
    14 AuthorizedKeysFile %h/.ssh/authorized_keys /gitlab-data/authorized_keys
    • Just thinking for a moment about security angles about this. What do we know about the permissions on /gitlab-data/ ? Do we know anything?

      I am thinking about the pathological scenario where gitlab-keys check-permissions successfully creates the file and sets its mode to 0600, yet the directory permissions allow some other user to remove the file and put a different one there. It might be better to create a subdirectory for this, with mode 0755 and owner git:git.

    • Author Contributor

      yeah, the directory, in the case I am trying to address with openshift, will be 0777 and owned by nobody:nogroup

      If I want to use a subdirectory, it will have to be created during reconfigure, or during the docker command execution

    • @twk3 sounds like we definitely want to use a subdirectory then.

    • Please register or sign in to reply
  • 1 require 'chef_helper'
    2
    3 describe 'gitlab_shell' do
    4 let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }
    5
    6 before { allow(Gitlab).to receive(:[]).and_call_original }
    7
    8 # def stub_gitlab_rb(config)
    9 # config.each do |key, value|
    10 # value = Mash.from_hash(value) if value.is_a?(Hash)
    11 # allow(Gitlab).to receive(:[]).with(key.to_s).and_return(value)
    12 # end
    13 # end
  • @twk3 I've picked 46f123b2 into one of my branches and merged to master in order to reuse some of the things you already wrote. You will need to rebase from master.

  • DJ Mountney Added 22 commits:

    Added 22 commits:

    • 21c54b87...07d58533 - 17 commits from branch master
    • 923fd761 - Allow configuration of the authorized_keys file location used by gitlab-shell
    • 5e20e585 - Run the gitlab-shell keys permission check during the shell recipe
    • e751a044 - Use gitlab-shell bin/keys to create the authorized_keys file if it doesn't already exist
    • de05e405 - Drop use of keys clear, and use the new check-permissions command for the key file creation
    • 459e5d8a - Add in some of the missing tests from the rebase for the authorized_keys changes
  • Author Contributor

    rebased for the test changes

  • DJ Mountney Added 1 commit:

    Added 1 commit:

    • 18bb09a1 - Update the gitlab-shell recipe to make sure it create the directory for the auth…
  • DJ Mountney Added 1 commit:

    Added 1 commit:

    • 58de5cba - Add gitlab-shell recipe test for alternate auth_files directory permissions
  • Author Contributor

    @jacobvosmaer-gitlab I've updated the alternate authorized_keys location, and have made sure the omnibus willcreate and assign the correct privileges

  • 45 46 end
    46 47 end
    47 48
    48 directory ssh_dir do
    49 owner git_user
    50 group git_group
    51 mode "0700"
    52 recursive true
    49 [
    50 ssh_dir,
    51 File.dirname(authorized_keys)
    52 ].uniq.each do |dir|
    53 directory dir do
  • Reassigned to @marin

  • Marin Jankovski Status changed to merged

    Status changed to merged

  • Marin Jankovski mentioned in commit 82269203

    mentioned in commit 82269203

  • Please register or sign in to reply
    Loading