Skip to content

Commit cb98f40

Browse files
committed
Fixes #38567 - Support setting the DHCP key algorithm
1 parent 6315c34 commit cb98f40

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

manifests/init.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@
165165
#
166166
# $dhcp_key_secret:: DHCP password
167167
#
168+
# $dhcp_key_algorithm:: DHCP key algorithm
169+
#
168170
# $dhcp_omapi_port:: DHCP server OMAPI port
169171
#
170172
# $dhcp_node_type:: DHCP node type
@@ -365,6 +367,7 @@
365367
Stdlib::Absolutepath $dhcp_leases = $foreman_proxy::params::dhcp_leases,
366368
Optional[String] $dhcp_key_name = undef,
367369
Optional[String] $dhcp_key_secret = undef,
370+
Optional[String] $dhcp_key_algorithm = undef,
368371
Stdlib::Port $dhcp_omapi_port = 7911,
369372
Optional[String] $dhcp_peer_address = undef,
370373
Enum['standalone', 'primary', 'secondary'] $dhcp_node_type = 'standalone',

manifests/proxydhcp.pp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@
6363
}
6464

6565
class { 'dhcp':
66-
dnsdomain => $foreman_proxy::dhcp_option_domain,
67-
nameservers => $nameservers,
68-
interfaces => [$foreman_proxy::dhcp_interface] + $foreman_proxy::dhcp_additional_interfaces,
69-
pxeserver => $ip,
70-
pxefilename => $foreman_proxy::dhcp_pxefilename,
71-
ipxe_filename => $_dhcp_ipxefilename,
72-
omapi_name => $foreman_proxy::dhcp_key_name,
73-
omapi_key => $foreman_proxy::dhcp_key_secret,
74-
conf_dir_mode => $conf_dir_mode,
66+
dnsdomain => $foreman_proxy::dhcp_option_domain,
67+
nameservers => $nameservers,
68+
interfaces => [$foreman_proxy::dhcp_interface] + $foreman_proxy::dhcp_additional_interfaces,
69+
pxeserver => $ip,
70+
pxefilename => $foreman_proxy::dhcp_pxefilename,
71+
ipxe_filename => $_dhcp_ipxefilename,
72+
omapi_name => $foreman_proxy::dhcp_key_name,
73+
omapi_key => $foreman_proxy::dhcp_key_secret,
74+
omapi_algorithm => $foreman_proxy::dhcp_key_algorithm,
75+
conf_dir_mode => $conf_dir_mode,
7576
}
7677

7778
dhcp::pool { $facts['networking']['domain']:

spec/classes/foreman_proxy__proxydhcp__spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
}
2020
end
2121

22+
let(:etc_dir) do
23+
case facts[:os]['family']
24+
when 'FreeBSD', 'DragonFly'
25+
'/usr/local/etc'
26+
else
27+
'/etc'
28+
end
29+
end
30+
2231
context "on physical interface" do
2332
let :facts do
2433
override_facts(super(), networking: {
@@ -145,6 +154,46 @@
145154
.with_address('192.0.2.10')
146155
end
147156
end
157+
158+
context 'with TSIG' do
159+
let(:params) do
160+
super().merge(
161+
dhcp_key_name: 'my_key',
162+
dhcp_key_secret: 'dontlook',
163+
)
164+
end
165+
166+
it { should compile.with_all_deps }
167+
it do
168+
is_expected.to contain_file("#{etc_dir}/foreman-proxy/settings.d/dhcp_isc.yml")
169+
.with_content(/^:key_name: my_key$/)
170+
.with_content(/^:key_secret: dontlook$/)
171+
.without_content(/^:key_algorithm:/)
172+
end
173+
it do
174+
is_expected.to contain_class('dhcp')
175+
.with_omapi_name('my_key')
176+
.with_omapi_key('dontlook')
177+
end
178+
179+
context 'with key algorithm specified' do
180+
let(:params) { super().merge(dhcp_key_algorithm: 'HMAC-SHA512') }
181+
182+
it { should compile.with_all_deps }
183+
it do
184+
is_expected.to contain_file("#{etc_dir}/foreman-proxy/settings.d/dhcp_isc.yml")
185+
.with_content(/^:key_name: my_key$/)
186+
.with_content(/^:key_secret: dontlook$/)
187+
.with_content(/^:key_algorithm: HMAC-SHA512/)
188+
end
189+
it do
190+
is_expected.to contain_class('dhcp')
191+
.with_omapi_name('my_key')
192+
.with_omapi_key('dontlook')
193+
.with_omapi_algorithm('HMAC-SHA512')
194+
end
195+
end
196+
end
148197
end
149198

150199
context "on vlan interface" do

templates/dhcp_isc.yml.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
[nil, :undefined, :undef, ''].include?(scope.lookupvar("foreman_proxy::dhcp_key_secret")) -%>
2121
:key_name: <%= scope.lookupvar("foreman_proxy::dhcp_key_name") %>
2222
:key_secret: <%= scope.lookupvar("foreman_proxy::dhcp_key_secret") %>
23+
<% unless [nil, :undefined, :undef, ''].include?(scope.lookupvar("foreman_proxy::dhcp_key_algorithm")) -%>
24+
:key_algorithm: <%= scope.lookupvar("foreman_proxy::dhcp_key_algorithm") %>
25+
<% else -%>
26+
#:key_algorithm: HMAC-MD5
27+
<% end -%>
2328
<% else -%>
2429
#:key_name: secret_key_name
2530
#:key_secret: secret_key
31+
#:key_algorithm: HMAC-MD5
2632
<% end -%>
2733

2834
:omapi_port: <%= scope.lookupvar("foreman_proxy::dhcp_omapi_port") %>

0 commit comments

Comments
 (0)