Allow configuration of the authorized_keys file location used by gitlab-shell
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.
Merge request reports
Activity
mentioned in merge request !899 (merged)
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) I'm with @jacobvosmaer-gitlab on this one,
auth_file
could be on a completely separate location than the ssh_dir
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 @jacobvosmaer-gitlab @marin feedback has been implemented
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
@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.@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?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.@jacobvosmaer-gitlab I don't think check-permissions creates the file, it also complains if it doesn't exist
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
Toggle commit list- 19ce4c42...06b2dddf - 49 commits from branch
@twk3 yes you are right. I think the current combination is good. Although 'clear unless exists' does have 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.
Added a MR for shell: https://gitlab.com/gitlab-org/gitlab-shell/merge_requests/83
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
Toggle commit list- f1c0b038...2bb3e43f - 22 commits from branch
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.@twk3 sounds like we definitely want to use a subdirectory then.
- spec/chef/gitlab_shell_spec.rb 0 → 100644
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 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
Toggle commit list- 21c54b87...07d58533 - 17 commits from branch
Added 1 commit:
- 18bb09a1 - Update the gitlab-shell recipe to make sure it create the directory for the auth…
Added 1 commit:
- 58de5cba - Add gitlab-shell recipe test for alternate auth_files directory permissions
@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 @twk3 will this work with root_squash on NFS?
Reassigned to @marin
mentioned in commit 82269203