Skip to content

Commit 54cbed2

Browse files
committed
Fix ssh hostkeys export after merging #423
Without the workaround, we should use the ssh key type stored in the fact, as `ecdsa` isn't a valid key type. See https://www.puppet.com/docs/puppet/7/core_facts.html#ssh for valid names in the `ssh` fact
1 parent ac780d3 commit 54cbed2

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

manifests/hostkeys.pp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,23 @@
7878
@@sshkey { "${fqdn_real}_${key_type}":
7979
ensure => present,
8080
host_aliases => $host_aliases,
81-
type => $key_type,
81+
type => $facts['ssh'][$key_type]['type'],
8282
key => $facts['ssh'][$key_type]['key'],
8383
tag => $_tags,
8484
}
8585
} else {
86-
@@sshkey { "${fqdn_real}_${key_type}":
87-
ensure => absent,
88-
type => $key_type,
86+
if $key_type == 'ecdsa' {
87+
['ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521'].each |String[1] $kt| {
88+
@@sshkey { "${fqdn_real}_${kt}":
89+
ensure => absent,
90+
type => $kt,
91+
}
92+
}
93+
} else {
94+
@@sshkey { "${fqdn_real}_${key_type}":
95+
ensure => absent,
96+
type => $key_type,
97+
}
8998
}
9099
}
91100
}

spec/classes/hostkeys_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
expect(exported_resources).to contain_sshkey("foo.example.com_#{key_type}").
2020
with(
2121
ensure: 'present',
22-
type: %r{^#{key_type}},
22+
type: %r{^ssh-#{key_type}},
2323
tag: %w[group1 group2]
2424
)
2525
}
@@ -38,7 +38,7 @@
3838
expect(exported_resources).to contain_sshkey("foo.example.com_#{key_type}").
3939
with(
4040
ensure: 'present',
41-
type: %r{^#{key_type}},
41+
type: %r{^ssh-#{key_type}},
4242
tag: %w[hostkey_all hostkey_server_group]
4343
)
4444
}
@@ -58,7 +58,7 @@
5858
expect(exported_resources).to contain_sshkey("foo.example.com_#{key_type}").
5959
with(
6060
ensure: 'present',
61-
type: %r{^#{key_type}},
61+
type: %r{^ssh-#{key_type}},
6262
tag: %w[hostkey_all hostkey_server_group group1 group2]
6363
)
6464
}

0 commit comments

Comments
 (0)