Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

$handle_nsswitch = false,
$handle_sshd_config = false,
$handle_sudo_config = false,
$sudoers_name = undef,
) {

validate_string($user)
Expand Down Expand Up @@ -77,4 +79,41 @@
}
}

if $handle_sudo_config {
if $sudoers_name {
validate_string($sudoers_name)

augeas {'sudo pam with stns':
context => '/files/etc/pam.d/sudo',
changes => [
'ins "01" after #comment',
'set 01/type auth',
'set 01/control sufficient',
'set 01/module libpam_stns.so',
'set 01/argument[1] sudo',
"set 01/argument[2] ${sudoers_name}",
],
onlyif => [
"values *[type = 'auth']/module not_include libpam_stns.so",
"match *[module = 'libpam_stns.so']/argument size < 2",
"match *[module = 'libpam_stns.so']/argument != ['sudo', ${sudoers_name}]",
],
}
} else {
augeas {'sudo pam with stns':
context => '/files/etc/pam.d/sudo',
changes => [
'ins "01" after #comment',
'set 01/type auth',
'set 01/control sufficient',
'set 01/module libpam_stns.so',
],
onlyif => [
"values *[type = 'auth']/module not_include libpam_stns.so",
"match *[module = 'libpam_stns.so']/argument size == 0",
],
}
}
}

}
14 changes: 10 additions & 4 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
# stns::server is to install and configure stns.

class stns::server (
$port = 1104,
$user = undef,
$password = undef,
$package_ensure = present,
$port = 1104,
$user = undef,
$password = undef,
$package_ensure = present,
$sudoers_name = undef,
$sudoers_password = undef,
$sudoers_hash_type = 'sha256',
) {

validate_integer($port)
validate_string($user)
validate_string($password)
validate_string($package_ensure)
validate_string($sudoers_name)
validate_string($sudoers_password)
validate_re($sudoers_hash_type, '\Asha(256|512)\z', 'sudoers_hash_type supports sha256 or sha512.')

require stns::repo

Expand Down
21 changes: 16 additions & 5 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

class stns::server::config {

$port = $stns::server::port
$user = $stns::server::user
$password = $stns::server::password
$users = $stns::server::users
$groups = $stns::server::groups
$port = $stns::server::port
$user = $stns::server::user
$password = $stns::server::password
$users = $stns::server::users
$groups = $stns::server::groups
$sudoers_name = $stns::server::sudoers_name
$sudoers_password = $stns::server::sudoers_password
$sudoers_hash_type = $stns::server::sudoers_hash_type

concat { '/etc/stns/stns.conf':
ensure => present,
Expand Down Expand Up @@ -41,4 +44,12 @@
order => '60';
}

if $sudoers_name != undef {
concat::fragment { 'sudoers_config_in_stns':
target => '/etc/stns/stns.conf',
content => template('stns/sudoers.conf.erb'),
order => '25',
}
}

}
5 changes: 5 additions & 0 deletions spec/acceptance/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class { '::stns::client':
http_proxy => 'http://proxy.example.com:1104',
handle_nsswitch => true,
handle_sshd_config => true,
handle_sudo_config => true,
}
EOS
end
Expand Down Expand Up @@ -76,4 +77,8 @@ class { '::stns::client':
its(:content) { should match %r{^\s*AuthorizedKeysCommand\s+/usr/local/bin/stns-key-wrapper$} }
its(:content) { should match /^\s*AuthorizedKeysCommand(User|RunAs)\s+root$/ }
end

describe file('/etc/pam.d/sudo') do
its(:content) { should match /^#%PAM-1.0\nauth\s+sufficient\s+libpam_stns.so$/ }
end
end
12 changes: 9 additions & 3 deletions spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
let(:manifest) do
<<-EOS
class { '::stns::server':
port => 1104,
user => 'sample',
password => 's@mp1e',
port => 1104,
user => 'sample',
password => 's@mp1e',
sudoers_name => 'sandbox',
sudoers_password => 'b7ad567477c83756aab9a542b2be04f77dbae25115d85f22070d74d8cc4779dc',
}

::stns::server::users { 'sandbox':
Expand Down Expand Up @@ -62,6 +64,10 @@ class { '::stns::server':
its(:content) { should match /^\[groups.sandbox\]$/ }
its(:content) { should match /^id = 1001$/ }
its(:content) { should match /^users = \["sandbox"\]$/ }

its(:content) { should match /^\[sudoers.sandbox\]$/ }
its(:content) { should match /^password = "[a-z0-9]{64}"$/ }
its(:content) { should match /^hash_type = "sha256"$/ }
end

describe service('stns') do
Expand Down
4 changes: 4 additions & 0 deletions templates/sudoers.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[sudoers.<%= @sudoers_name %>]
password = "<%= @sudoers_password %>"
hash_type = "<%= @sudoers_hash_type || 'sha256' %>"