Restrict access in Puppet - part 1
by
- create <user> creates a new user with the given username.
- clientkey <user> [filename] installs the key for a given user, optionally set a filename. I already have some keys
- serverkey <user> [login_as] installs the key into the authorized_keys allowing users to login to this server. Defaults to logging in as the same user as the key 'owner' if the. I also need to use my key to login as another user, the git and svn users for example.
# wget http://projects.reductivelabs.com/attachments/download/935/auth.pp -O ./modules/user/manifests/auth.pp
modules/user/manifests/keystore.pp
class user::keystore {
include ssh::auth::keymaster
}
manifests/nodes.pp
node build {
include sudo, user, ssh::auth, user::keystore
}
/var/lib/keys
# puppet -v --modulepath=/etc/puppet/modules /etc/puppet/manifests/site.pp
# rm modules/user/manifests/virtual.pp
# rm modules/user/manifests/unixadmins.pp
modules/users/manifests/init.pp
import "*"
class user {
define create {
@user { "$title":
ensure => "present",
gid => "$title",
home => "/home/$title",
shell => "/bin/bash",
managehome => true,
require => [Group["$title"]],
}
@file { "/home/$title":
ensure => "directory",
mode => 700,
owner => "$title",
group => "$title",
}
@file { "/home/$title/.ssh":
ensure => "directory",
mode => 600,
owner => "$title",
group => "$title",
}
@group { "$title":
ensure => "present",
}
realize User[$title]
realize Group[$title]
realize File["/home/$title"]
realize File["/home/$title/.ssh"]
ssh::auth::key{"$title":}
}
define client_key ($ensure = "", $filename = "") {
ssh::auth::client{"$title": ensure=>$ensure, filename=>$filename}
}
define server_key ($ensure = "", $user = "") {
ssh::auth::server{"$title": ensure=>$ensure, user=>$user}
}
}
manifests/nodes.pp
node my-server {
include sudo, ssh::auth, ssh::auth::keymaster, user
user::create{"andrewmccall":}
user::client_key{"andrewmccall":}
user::server_key{"andrewmccall":}
}
Subscribe via RSS