blob: cd9f12c3641b2130859c0f310c416cec1c139a15 [file] [log] [blame]
Thomas Vachuska12bf4452015-06-26 09:15:38 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Secures the ONOS console for all instances in the cell ONOS cluster.
4# -----------------------------------------------------------------------------
5
6[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7. $ONOS_ROOT/tools/build/envDefaults
8
Thomas Vachuska35349332016-04-04 14:06:46 -07009# Scan arguments for user/password or other options...
10while getopts u:p: o; do
11 case "$o" in
12 u) user=$OPTARG;;
13 p) password=$OPTARG;;
14 esac
15done
16password=${password:-$user} # password defaults to the user if not specified
17let OPC=$OPTIND-1
18shift $OPC
19
Claudine Chiu45312d02016-06-15 13:17:12 +000020nodes=${1:-$(env | sort | egrep "^OC[0-9]+" | cut -d= -f2)}
Thomas Vachuska12bf4452015-06-26 09:15:38 -070021
Yuta HIGUCHI04107122017-01-13 18:51:12 -080022# ensure known_hosts file exist
23(umask 077; touch "$HOME/.ssh/known_hosts")
24
Thomas Vachuska12bf4452015-06-26 09:15:38 -070025for node in $nodes; do
Thomas Vachuska12bf4452015-06-26 09:15:38 -070026 # Prune the node entry from the known hosts file since server key changes
Yuta HIGUCHI04107122017-01-13 18:51:12 -080027 ssh-keygen -f "$HOME/.ssh/known_hosts" -R [$node]:8101 ||
Brian O'Connorc5876fd2015-10-29 23:07:55 -070028 ( echo "Failed to remove key from known_hosts" >&2 && exit 1 )
Thomas Vachuska12bf4452015-06-26 09:15:38 -070029
30 # Setup passwordless login for the local user on the remote node
31 ssh $ONOS_USER@$node "
32 [ ! -f ~/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' -q
33 $ONOS_INSTALL_DIR/bin/onos-user-key \$(id -un) \$(cut -d\\ -f2 ~/.ssh/id_rsa.pub)
Thomas Vachuska5af2e4f2016-12-16 12:07:33 -080034 $ONOS_INSTALL_DIR/bin/onos-user-password $user $password
Thomas Vachuska12bf4452015-06-26 09:15:38 -070035
36 # Implicitly accept the new server key in dev/test environments
37 while ! ssh -p 8101 -o StrictHostKeyChecking=no localhost list 2>/dev/null; do
38 echo Waiting for connection...
39 sleep 1
40 done
41 "
Charles Chan2497dbe2015-10-14 17:08:56 -070042
43 # Setup passwordless login for the remote user on the local bench host
44 # For now, we let the local public key override the remote one
45 # TODO: fix username collision between workbench and the remote hosts
46 onos-user-key $node
Thomas Vachuska12bf4452015-06-26 09:15:38 -070047done