Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Enables secure access to ONOS console by removing default users & keys. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
Thomas Vachuska | bef0750 | 2016-03-01 14:12:59 -0800 | [diff] [blame] | 6 | # 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 Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 8 | rm -f $(dirname $0)/onos |
| 9 | |
| 10 | set -e |
| 11 | |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 12 | # Scan arguments for user/password or other options... |
Thomas Vachuska | eff0e4e | 2015-08-11 00:26:24 -0700 | [diff] [blame] | 13 | while getopts u:p: o; do |
| 14 | case "$o" in |
| 15 | u) user=$OPTARG;; |
| 16 | p) password=$OPTARG;; |
| 17 | esac |
| 18 | done |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 19 | password=${password:-$user} # password defaults to the user if not specified |
Thomas Vachuska | eff0e4e | 2015-08-11 00:26:24 -0700 | [diff] [blame] | 20 | let OPC=$OPTIND-1 |
| 21 | shift $OPC |
| 22 | |
Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 23 | cd $(dirname $0)/../apache-karaf-*/etc |
| 24 | USERS=users.properties |
| 25 | KEYS=keys.properties |
| 26 | |
| 27 | # Remove the built-in users and keys to secure the access implicitly. |
| 28 | egrep -v "^(karaf|onos)[ ]*=" $USERS > $USERS.new && mv $USERS.new $USERS |
| 29 | egrep -v "^(#karaf|onos)[ ]*=" $KEYS > $KEYS.new && mv $KEYS.new $KEYS |
| 30 | |
| 31 | # Remove any previous known keys for the local host. |
| 32 | ssh-keygen -f "$HOME/.ssh/known_hosts" -R [localhost]:8101 |
| 33 | |
Thomas Vachuska | eff0e4e | 2015-08-11 00:26:24 -0700 | [diff] [blame] | 34 | # Swap the onos client to use the SSH variant. |
Thomas Vachuska | 12bf445 | 2015-06-26 09:15:38 -0700 | [diff] [blame] | 35 | ln -s $(dirname $0)/onos-ssh $(dirname $0)/onos |
Thomas Vachuska | eff0e4e | 2015-08-11 00:26:24 -0700 | [diff] [blame] | 36 | |
| 37 | # If user and password options were given, setup the user/password. |
| 38 | if [ -n "$user" -a -n "$password" ]; then |
| 39 | echo "$user = $password,_g_:admingroup" >> $USERS |
| 40 | fi |