Skip to content

Commit 2e89e52

Browse files
Merge pull request #172 from lubomir-kacalek/master
Authorized keys custom path
2 parents eaf6c11 + 71b4f50 commit 2e89e52

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ override['ssh-hardening']['ssh']['server']['listen_to'] = node['ipaddress']
7676
* `['ssh-hardening']['ssh']['server']['sftp']['enable']` - `false`. Set to `true` to enable the SFTP feature of OpenSSH daemon
7777
* `['ssh-hardening']['ssh']['server']['sftp']['group']` - `sftponly`. Sets the `Match Group` option of SFTP to allow SFTP only for dedicated users
7878
* `['ssh-hardening']['ssh']['server']['sftp']['chroot']` - `/home/%u`. Sets the directory where the SFTP user should be chrooted
79-
79+
* `['ssh-hardening']['ssh']['server']['authorized_keys_path']` - `nil`. If not nil, full path to an authorized keys folder is expected
8080
* `['ssh-hardening']['ssh']['server']['extras']` - `{}`. Add extra configuration options, see [below](#extra-configuration-options) for details
8181

82-
8382
## Usage
8483

8584
Add the recipes to the run_list:

attributes/default.rb

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
server['password_authentication'] = false
106106
server['log_level'] = 'verbose'
107107
server['accept_env'] = ['LANG', 'LC_*', 'LANGUAGE']
108+
server['authorized_keys_path'] = nil # if not nil, full path to an authorized keys folder is expected
108109

109110
# extra server configuration options
110111
server['extras'] = {}

spec/recipes/server_spec.rb

+26
Original file line numberDiff line numberDiff line change
@@ -663,4 +663,30 @@
663663
with_content(/AcceptEnv some environment variables/)
664664
end
665665
end
666+
667+
describe 'customized AuthorizedKeysFile option' do
668+
context 'without customized AuthorizedKeysFile' do
669+
cached(:chef_run) do
670+
ChefSpec::ServerRunner.new.converge(described_recipe)
671+
end
672+
673+
it 'does not have AuthorizedKeysFile configured' do
674+
expect(chef_run).not_to render_file('/etc/ssh/sshd_config').
675+
with_content('AuthorizedKeysFile')
676+
end
677+
end
678+
679+
context 'with customized AuthorizedKeysFile' do
680+
cached(:chef_run) do
681+
ChefSpec::ServerRunner.new do |node|
682+
node.normal['ssh-hardening']['ssh']['server']['authorized_keys_path'] = '/some/authorizedkeysfile'
683+
end.converge(described_recipe)
684+
end
685+
686+
it 'has AuthorizedKeysFile configured' do
687+
expect(chef_run).to render_file('/etc/ssh/sshd_config').
688+
with_content('AuthorizedKeysFile /some/authorizedkeysfile')
689+
end
690+
end
691+
end
666692
end

templates/default/opensshd.conf.erb

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ MaxStartups 10:30:100
9696
# Enable public key authentication
9797
PubkeyAuthentication yes
9898

99+
<% if @node['ssh-hardening']['ssh']['server']['authorized_keys_path'] %>
100+
# Customized authorized keys path
101+
AuthorizedKeysFile <%= @node['ssh-hardening']['ssh']['server']['authorized_keys_path'] %>
102+
<% end %>
103+
99104
# Never use host-based authentication. It can be exploited.
100105
IgnoreRhosts yes
101106
IgnoreUserKnownHosts yes

0 commit comments

Comments
 (0)