Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OHAI-402] Fixes ssh keypairs on EL systems #131

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/ohai/plugins/ssh_host_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def is_dsa_or_rsa?(file)
end
end
end
else
end

# Fall back to looking at files directly if sshd_config yields no valid keys.
if keys[:ssh].empty?
if keys[:ssh][:host_dsa_public].nil? && File.exists?("/etc/ssh/ssh_host_dsa_key.pub")
keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1]
end
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/plugins/ssh_host_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,18 @@

it_behaves_like "loads keys"
end

context "when an sshd_config is found but does not contain valid keys" do
before do
sshd_config_file_without_keys =<<EOS
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
EOS
File.stub(:open).with("/etc/ssh/sshd_config").and_yield(sshd_config_file_without_keys)
File.stub(:exists?).and_return(true)
end

it_behaves_like "loads keys"
end
end