Merge branch 'ssh_authorized_key_group' of https://github.com/contradict/cdist
This commit is contained in:
		
				commit
				
					
						029dc4c387
					
				
			
		
					 2 changed files with 29 additions and 2 deletions
				
			
		
							
								
								
									
										15
									
								
								conf/type/__ssh_authorized_key/explorer/dstuser_group
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								conf/type/__ssh_authorized_key/explorer/dstuser_group
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | ||||||
|  | #!/bin/sh | ||||||
|  | 
 | ||||||
|  | # Get option dstuser if defined | ||||||
|  | if [ -f "$__object/parameter/dstuser" ]; then | ||||||
|  |    dstuser=`cat "$__object/parameter/dstuser"` | ||||||
|  | else | ||||||
|  |    dstuser="root" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | if id $dstuser >/dev/null 2>&1 ; then | ||||||
|  |     id -ng $dstuser | ||||||
|  | else | ||||||
|  |    echo "$__object_id: Destination user $dstuser does not exist" >&2 | ||||||
|  |    exit 1 | ||||||
|  | fi | ||||||
|  | @ -29,8 +29,13 @@ fi | ||||||
| # Get option dstuser if defined | # Get option dstuser if defined | ||||||
| if [ -f "$__object/parameter/dstuser" ]; then | if [ -f "$__object/parameter/dstuser" ]; then | ||||||
|    dstuser=`cat "$__object/parameter/dstuser"` |    dstuser=`cat "$__object/parameter/dstuser"` | ||||||
|  | else | ||||||
|  |    dstuser="root" | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
|  | # retrieve destination group | ||||||
|  | dstgroup=$(cat "$__object/explorer/dstuser_group") | ||||||
|  | 
 | ||||||
| # if a source user is defined, use it's public key | # if a source user is defined, use it's public key | ||||||
| if [ "$srcuser" ]; then | if [ "$srcuser" ]; then | ||||||
|    srcrsa="/home/${srcuser}/.ssh/id_rsa.pub" |    srcrsa="/home/${srcuser}/.ssh/id_rsa.pub" | ||||||
|  | @ -46,9 +51,16 @@ else | ||||||
|    sshpath="/root/.ssh" |    sshpath="/root/.ssh" | ||||||
| fi | fi | ||||||
| rsa=`cat $srcrsa` | rsa=`cat $srcrsa` | ||||||
| __directory $sshpath | __directory $sshpath \ | ||||||
|  |     --owner $dstuser \ | ||||||
|  |     --group $dstgroup \ | ||||||
|  |     --mode 700 | ||||||
| # the file authorized_keys depends on the .ssh folder | # the file authorized_keys depends on the .ssh folder | ||||||
| require="__directory${sshpath}" __file "$sshpath/authorized_keys" --mode 640 | require="__directory${sshpath}" \ | ||||||
|  |     __file "$sshpath/authorized_keys" \ | ||||||
|  |     --mode 640 \ | ||||||
|  |     --owner $dstuser \ | ||||||
|  |     --group $dstgroup | ||||||
| # the line added depends on authorized_keys existence | # the line added depends on authorized_keys existence | ||||||
| require="__file${sshpath}/authorized_keys" __addifnosuchline sshkey --file \ | require="__file${sshpath}/authorized_keys" __addifnosuchline sshkey --file \ | ||||||
|  "$sshpath/authorized_keys" --line "$rsa" |  "$sshpath/authorized_keys" --line "$rsa" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue