Skip to content

Commit

Permalink
Parameterize the sshd port
Browse files Browse the repository at this point in the history
  • Loading branch information
daaang committed Aug 13, 2024
1 parent 5bcba49 commit ac969e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions manifests/profile/networking/sshd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class nebula::profile::networking::sshd (
Array[String] $whitelist,
String $addon_directives = '',
Integer $port = 22,
) {

# This will do nothing if the keytab doesn't exist
Expand Down
15 changes: 15 additions & 0 deletions spec/classes/profile/networking/sshd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def contain_sshd
end

[
%r{^#Port 22$},
%r{^PermitRootLogin (prohibit|without)-password$},
%r{^PubkeyAuthentication no$},
%r{^PasswordAuthentication no$},
Expand Down Expand Up @@ -97,6 +98,20 @@ class { 'nebula::profile::networking::keytab':
.with_target('/etc/pam.d/sshd')
.with_content(%r{@include sshd-defaults})
end

context 'with port set to 44' do
let(:params) { { port: 44 } }

it { is_expected.not_to contain_sshd.with_content(%r{^#Port 22$}) }
it { is_expected.to contain_sshd.with_content(%r{^Port 44$}) }
end

context 'with port set to 333' do
let(:params) { { port: 333 } }

it { is_expected.not_to contain_sshd.with_content(%r{^#Port 22$}) }
it { is_expected.to contain_sshd.with_content(%r{^Port 333$}) }
end
end
end
end
4 changes: 4 additions & 0 deletions templates/profile/networking/sshd_config.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
# possible, but leave them commented. Uncommented options override the
# default value.

<% if @port == 22 -%>
#Port 22
<% else -%>
Port <%= @port %>
<% end -%>
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
Expand Down

0 comments on commit ac969e6

Please sign in to comment.