import __ssh_authorized_key from Aurélien's tree

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-04-19 22:30:06 +02:00
parent 0e5cb9b11f
commit 4d244e9ea2
3 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,46 @@
cdist-type__ssh_authorized_key(7)
=================================
Aurélien Bondis - aurelien.bondis AT gmail DOT com
NAME
----
cdist-type__ssh_authorized_key - Sends a user's public key to another user's authorized_keys
DESCRIPTION
-----------
This type sends a rsa key. By default uses root's key and sends it to root's authorized_keys
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
srcuser:: the user to take the rsa public key from
dstuser:: the user to give the rsa public key to
EXAMPLES
--------
--------------------------------------------------------------------------------
#deploy root's public key
__ssh_authorized_key admin
#deploy bob's public key to alice's authorized_keys
__ssh_authorized_key --srcuser bob --dstuser alice
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -0,0 +1,55 @@
#!/bin/sh
#
# 2011 Aurélien Bondis aurelien.bondis AT gmail DOT com
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# This type allows to send a public ssh key from a user to the
# authorized_keys of another
#
#require="__package openssh-server --state installed"
# Get option srcuser if defined
if [ -f "$__object/parameter/srcuser" ]; then
srcuser=`cat "$__object/parameter/srcuser"`
fi
# Get option dstuser if defined
if [ -f "$__object/parameter/dstuser" ]; then
dstuser=`cat "$__object/parameter/dstuser"`
fi
# if a source user is defined, use it's public key
if [ "$srcuser" ]; then
srcrsa="/home/${srcuser}/.ssh/id_rsa.pub"
# if no source user is defined we use root's public key
else
srcrsa="/root/.ssh/id_rsa.pub"
fi
# if a destination user is defined, insert in it's authorized_keys
if [ "$dstuser" ]; then
sshpath="/home/$dstuser/.ssh"
# if no destination user is defined we use root's home
else
sshpath="/root/.ssh"
fi
rsa=`cat $srcrsa`
__directory $sshpath
# the file authorized_keys depends on the .ssh folder
require="__directory${sshpath}" __file "$sshpath/authorized_keys" --mode 640
# the line added depends on authorized_keys existence
require="__file${sshpath}/authorized_keys" __addifnosuchline sshkey --file \
"$sshpath/authorized_keys" --line "$rsa"

View File

@ -0,0 +1,2 @@
srcuser
dstuser