Skip to content

Commit dc49d7e

Browse files
authored
Merge pull request #31 from Dorin-Pleava/MODULES-10671/New_ssh_keys_types_open_ssh_8.2
(MODULES-10671) New SSH key types for OpenSSH 8.2
2 parents 9b2d2aa + 210f2e1 commit dc49d7e

File tree

5 files changed

+65
-10
lines changed

5 files changed

+65
-10
lines changed

lib/puppet/type/ssh_authorized_key.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ module Puppet
6262
newproperty(:type) do
6363
desc 'The encryption type used.'
6464

65-
newvalues :'ssh-dss', :'ssh-rsa', :'ecdsa-sha2-nistp256', :'ecdsa-sha2-nistp384', :'ecdsa-sha2-nistp521', :'ssh-ed25519'
65+
newvalues :'ssh-dss', :'ssh-rsa', :'ecdsa-sha2-nistp256', :'ecdsa-sha2-nistp384', :'ecdsa-sha2-nistp521', :'ssh-ed25519',
66+
:'sk-ecdsa-sha2-nistp256@openssh.com', :'sk-ssh-ed25519@openssh.com'
6667

6768
aliasvalue(:dsa, :'ssh-dss')
6869
aliasvalue(:ed25519, :'ssh-ed25519')
6970
aliasvalue(:rsa, :'ssh-rsa')
71+
aliasvalue(:'ecdsa-sk', :'sk-ecdsa-sha2-nistp256@openssh.com')
72+
aliasvalue(:'ed25519-sk', :'sk-ssh-ed25519@openssh.com')
7073
end
7174

7275
newproperty(:key) do
@@ -159,7 +162,9 @@ def insync?(is)
159162
end
160163

161164
# regular expression suitable for use by a ParsedFile based provider
162-
REGEX = %r{^(?:(.+)\s+)?(ssh-dss|ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521)\s+([^ ]+)\s*(.*)$}
165+
REGEX = %r{^(?:(.+)\s+)?(ssh-dss|ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp256|
166+
ecdsa-sha2-nistp384|ecdsa-sha2-nistp521|ecdsa-sk|ed25519-sk|
167+
sk-ecdsa-sha2-nistp256@openssh.com|sk-ssh-ed25519@openssh.com)\s+([^ ]+)\s*(.*)$}x
163168
def self.keyline_regex
164169
REGEX
165170
end

lib/puppet/type/sshkey.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def name
1515
def self.title_patterns
1616
[
1717
[
18-
%r{^(.*)@(.*)$},
18+
%r{^(.*?)@(.*)$},
1919
[
2020
[:name],
2121
[:type],
@@ -35,11 +35,14 @@ def self.title_patterns
3535

3636
isnamevar
3737

38-
newvalues :'ssh-dss', :'ssh-ed25519', :'ssh-rsa', :'ecdsa-sha2-nistp256', :'ecdsa-sha2-nistp384', :'ecdsa-sha2-nistp521'
38+
newvalues :'ssh-dss', :'ssh-ed25519', :'ssh-rsa', :'ecdsa-sha2-nistp256', :'ecdsa-sha2-nistp384', :'ecdsa-sha2-nistp521',
39+
:'sk-ecdsa-sha2-nistp256@openssh.com', :'sk-ssh-ed25519@openssh.com'
3940

4041
aliasvalue(:dsa, :'ssh-dss')
4142
aliasvalue(:ed25519, :'ssh-ed25519')
4243
aliasvalue(:rsa, :'ssh-rsa')
44+
aliasvalue(:'ecdsa-sk', :'sk-ecdsa-sha2-nistp256@openssh.com')
45+
aliasvalue(:'ed25519-sk', :'sk-ssh-ed25519@openssh.com')
4346
end
4447

4548
newproperty(:key) do

spec/integration/provider/sshkey_spec.rb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,44 @@
9191
expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=})
9292
end
9393

94+
it 'prioritizes the specified type instead of type in the name' do
95+
manifest = "#{type_under_test} { '#{super_unique}@rsa':
96+
ensure => 'present',
97+
type => 'dsa',
98+
key => 'mykey',
99+
target => '#{sshkey_file}' }"
100+
apply_with_error_check(manifest)
101+
expect(File.read(sshkey_file)).to match(%r{#{super_unique} ssh-dss.*mykey})
102+
end
103+
104+
it 'can parse SSH key type that contains @openssh.com in name' do
105+
manifest = "#{type_under_test} { '#{super_unique}@sk-ssh-ed25519@openssh.com':
106+
ensure => 'present',
107+
key => 'mykey',
108+
target => '#{sshkey_file}' }"
109+
apply_with_error_check(manifest)
110+
expect(File.read(sshkey_file)).to match(%r{#{super_unique} sk-ssh-ed25519@openssh.com.*mykey})
111+
end
112+
94113
# test all key types
95114
types = [
96115
'ssh-dss', 'dsa',
97116
'ssh-ed25519', 'ed25519',
98117
'ssh-rsa', 'rsa',
99118
'ecdsa-sha2-nistp256',
100119
'ecdsa-sha2-nistp384',
101-
'ecdsa-sha2-nistp521'
120+
'ecdsa-sha2-nistp521',
121+
'ecdsa-sk', 'sk-ecdsa-sha2-nistp256@openssh.com',
122+
'ed25519-sk', 'sk-ssh-ed25519@openssh.com'
102123
]
103124
# these types are treated as aliases for sshkey <ahem> type
104125
# so they are populated as the *values* below
105126
aliases = {
106-
'dsa' => 'ssh-dss',
107-
'ed25519' => 'ssh-ed25519',
108-
'rsa' => 'ssh-rsa',
127+
'dsa' => 'ssh-dss',
128+
'ed25519' => 'ssh-ed25519',
129+
'rsa' => 'ssh-rsa',
130+
'ecdsa-sk' => 'sk-ecdsa-sha2-nistp256@openssh.com',
131+
'ed25519-sk' => 'sk-ssh-ed25519@openssh.com',
109132
}
110133
types.each do |type|
111134
it "should update an entry with #{type} type" do

spec/unit/type/ssh_authorized_key_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@
8585
:'ecdsa-sha2-nistp256',
8686
:'ecdsa-sha2-nistp384',
8787
:'ecdsa-sha2-nistp521',
88-
:ed25519, :'ssh-ed25519'
88+
:ed25519, :'ssh-ed25519',
89+
:'ecdsa-sk', :'sk-ecdsa-sha2-nistp256@openssh.com',
90+
:'ed25519-sk', :'sk-ssh-ed25519@openssh.com'
8991
].each do |keytype|
9092
it "supports #{keytype}" do
9193
described_class.new(name: 'whev', type: keytype, user: 'nobody')
@@ -102,6 +104,16 @@
102104
expect(key.should(:type)).to eq :'ssh-dss'
103105
end
104106

107+
it 'aliases :ecdsa-sk to :sk-ecdsa-sha2-nistp256@openssh.com' do
108+
key = described_class.new(name: 'whev', type: :'ecdsa-sk', user: 'nobody')
109+
expect(key.should(:type)).to eq :'sk-ecdsa-sha2-nistp256@openssh.com'
110+
end
111+
112+
it 'aliases :ed25519-sk to :sk-ssh-ed25519@openssh.com' do
113+
key = described_class.new(name: 'whev', type: :'ed25519-sk', user: 'nobody')
114+
expect(key.should(:type)).to eq :'sk-ssh-ed25519@openssh.com'
115+
end
116+
105117
it "doesn't support values other than ssh-dss, ssh-rsa, dsa, rsa" do
106118
expect { described_class.new(name: 'whev', type: :something) }.to raise_error(Puppet::Error, %r{Invalid value})
107119
end

spec/unit/type/sshkey_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
:'ecdsa-sha2-nistp256',
2828
:'ecdsa-sha2-nistp384',
2929
:'ecdsa-sha2-nistp521',
30-
:'ssh-ed25519', :ed25519
30+
:'ssh-ed25519', :ed25519,
31+
:'ecdsa-sk', :'sk-ecdsa-sha2-nistp256@openssh.com',
32+
:'ed25519-sk', :'sk-ssh-ed25519@openssh.com'
3133
].each do |keytype|
3234
it "supports #{keytype} as a type value" do
3335
described_class.new(name: 'foo', type: keytype)
@@ -44,6 +46,16 @@
4446
expect(key.parameter(:type).value).to eq :'ssh-dss'
4547
end
4648

49+
it 'aliases :ecdsa-sk to :sk-ecdsa-sha2-nistp256@openssh.com' do
50+
key = described_class.new(name: 'foo', type: :'ecdsa-sk')
51+
expect(key.parameter(:type).value).to eq :'sk-ecdsa-sha2-nistp256@openssh.com'
52+
end
53+
54+
it 'aliases :ed25519-sk to :ssh-dss' do
55+
key = described_class.new(name: 'foo', type: :'ed25519-sk')
56+
expect(key.parameter(:type).value).to eq :'sk-ssh-ed25519@openssh.com'
57+
end
58+
4759
it "doesn't support values other than ssh-dss, ssh-rsa, dsa, rsa for type" do
4860
expect {
4961
described_class.new(name: 'whev', type: :'ssh-dsa')

0 commit comments

Comments
 (0)