blob: eab5d7aac8937e3182992f22e704c879363d359b [file] [log] [blame]
Thomas Vachuska12bf4452015-06-26 09:15:38 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Enables secure access to ONOS console by removing default users & keys.
4# -----------------------------------------------------------------------------
5
Thomas Vachuskabef07502016-03-01 14:12:59 -08006# Remove the "unsecure" shell client which uses karaf "client" which is used
7# by default; we will install the "secure" client that just uses raw ssh later.
Thomas Vachuska12bf4452015-06-26 09:15:38 -07008rm -f $(dirname $0)/onos
9
10set -e
11
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070012# Scan arguments for user/password or other options...
Thomas Vachuskaeff0e4e2015-08-11 00:26:24 -070013while getopts u:p: o; do
14 case "$o" in
15 u) user=$OPTARG;;
16 p) password=$OPTARG;;
17 esac
18done
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070019password=${password:-$user} # password defaults to the user if not specified
Thomas Vachuskaeff0e4e2015-08-11 00:26:24 -070020let OPC=$OPTIND-1
21shift $OPC
22
Thomas Vachuska12bf4452015-06-26 09:15:38 -070023cd $(dirname $0)/../apache-karaf-*/etc
24USERS=users.properties
25KEYS=keys.properties
26
27# Remove the built-in users and keys to secure the access implicitly.
28egrep -v "^(karaf|onos)[ ]*=" $USERS > $USERS.new && mv $USERS.new $USERS
29egrep -v "^(#karaf|onos)[ ]*=" $KEYS > $KEYS.new && mv $KEYS.new $KEYS
30
31# Remove any previous known keys for the local host.
32ssh-keygen -f "$HOME/.ssh/known_hosts" -R [localhost]:8101
33
Thomas Vachuskaeff0e4e2015-08-11 00:26:24 -070034# Swap the onos client to use the SSH variant.
Thomas Vachuska12bf4452015-06-26 09:15:38 -070035ln -s $(dirname $0)/onos-ssh $(dirname $0)/onos
Thomas Vachuskaeff0e4e2015-08-11 00:26:24 -070036
37# If user and password options were given, setup the user/password.
38if [ -n "$user" -a -n "$password" ]; then
39 echo "$user = $password,_g_:admingroup" >> $USERS
40fi