Skip to content

Commit

Permalink
Merge pull request #483 from bastelfreak/empty
Browse files Browse the repository at this point in the history
usermanagement: prohibit empty ssh keys
  • Loading branch information
bastelfreak authored May 7, 2024
2 parents 927c433 + 9fab5e9 commit 883ba88
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ Default value: `'0600'`

##### <a name="-accounts--user--sshkeys"></a>`sshkeys`

Data type: `Array[String]`
Data type: `Array[String[1]]`

An array of SSH public keys associated with the user. These should be
complete public key strings that include the type, content and name of the
Expand Down Expand Up @@ -559,7 +559,7 @@ The returned options element can by an empty string.
accounts_ssh_authorized_keys_line_parser_string('options ssh-rsa AAAA... comment)
```

#### `accounts_ssh_authorized_keys_line_parser(String $str)`
#### `accounts_ssh_authorized_keys_line_parser(String[1] $str)`

Parse an ssh authorized_keys line string into an array using its expected
pattern by using a combination of regex matching and extracting the substring
Expand All @@ -580,7 +580,7 @@ accounts_ssh_authorized_keys_line_parser_string('options ssh-rsa AAAA... comment

##### `str`

Data type: `String`
Data type: `String[1]`

ssh authorized_keys line string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# @example Calling the function
# accounts_ssh_authorized_keys_line_parser_string('options ssh-rsa AAAA... comment)
dispatch :accounts_ssh_authorized_keys_line_parser_string do
param 'String', :str
param 'String[1]', :str
end

def accounts_ssh_authorized_keys_line_parser_string(str)
Expand Down
4 changes: 2 additions & 2 deletions manifests/key_management.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
Accounts::User::Name $sshkey_group = $group,
Accounts::User::Name $sshkey_owner = $user,
Variant[Integer[0],String] $sshkey_mode = '0600',
Array[String] $sshkeys = [],
Array[String[1]] $sshkeys = [],
Optional[Stdlib::Unixpath] $user_home = undef,
) {
if $user_home {
Expand Down Expand Up @@ -98,7 +98,7 @@
}

if $sshkeys != [] {
$sshkeys.each |$sshkey| {
$sshkeys.each |String[1] $sshkey| {
accounts::manage_keys { "${sshkey} for ${user}":
ensure => $ensure,
keyspec => $sshkey,
Expand Down
2 changes: 1 addition & 1 deletion manifests/manage_keys.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
define accounts::manage_keys (
Stdlib::Unixpath $key_file,
String $keyspec,
String[1] $keyspec,
Accounts::User::Name $user,
Enum['absent','present'] $ensure = 'present',
Accounts::User::Name $key_owner = $user,
Expand Down
2 changes: 1 addition & 1 deletion manifests/user.pp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
Optional[Accounts::User::Name] $sshkey_group = $group,
Optional[Accounts::User::Name] $sshkey_owner = $name,
Variant[Integer[0],String] $sshkey_mode = '0600',
Array[String] $sshkeys = [],
Array[String[1]] $sshkeys = [],
Boolean $system = false,
Optional[Accounts::User::Uid] $uid = undef,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

it {
expect(subject).to run.with_params('').and_raise_error(ArgumentError, %r{Wrong Keyline format!})
expect(subject).to run.with_params('').and_raise_error(ArgumentError, %r{'accounts_ssh_authorized_keys_line_parser' parameter 'str' expects a String\[1\] value, got String})
}

it {
Expand Down

0 comments on commit 883ba88

Please sign in to comment.