From 4d244e9ea2ff10521a9216166bacf53598f02d20 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 Apr 2011 22:30:06 +0200 Subject: [PATCH] =?UTF-8?q?import=20=5F=5Fssh=5Fauthorized=5Fkey=20from=20?= =?UTF-8?q?Aur=C3=A9lien's=20tree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nico Schottelius --- conf/type/__ssh_authorized_key/man.text | 46 ++++++++++++++++ conf/type/__ssh_authorized_key/manifest | 55 +++++++++++++++++++ .../__ssh_authorized_key/parameter/optional | 2 + 3 files changed, 103 insertions(+) create mode 100644 conf/type/__ssh_authorized_key/man.text create mode 100755 conf/type/__ssh_authorized_key/manifest create mode 100644 conf/type/__ssh_authorized_key/parameter/optional diff --git a/conf/type/__ssh_authorized_key/man.text b/conf/type/__ssh_authorized_key/man.text new file mode 100644 index 00000000..af0c2017 --- /dev/null +++ b/conf/type/__ssh_authorized_key/man.text @@ -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). diff --git a/conf/type/__ssh_authorized_key/manifest b/conf/type/__ssh_authorized_key/manifest new file mode 100755 index 00000000..efadc3f6 --- /dev/null +++ b/conf/type/__ssh_authorized_key/manifest @@ -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 . +# +# +# 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" + diff --git a/conf/type/__ssh_authorized_key/parameter/optional b/conf/type/__ssh_authorized_key/parameter/optional new file mode 100644 index 00000000..4903f5be --- /dev/null +++ b/conf/type/__ssh_authorized_key/parameter/optional @@ -0,0 +1,2 @@ +srcuser +dstuser