Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Instrumental | 7a1817b | 2018-11-05 11:11:15 -0600 | [diff] [blame] | 2 | ######### |
| 3 | # ============LICENSE_START==================================================== |
| 4 | # org.onap.aaf |
| 5 | # =========================================================================== |
| 6 | # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. |
| 7 | # =========================================================================== |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # ============LICENSE_END==================================================== |
| 20 | # |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 21 | # This script is run when starting client Container. |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 22 | # It needs to cover the cases where the initial data doesn't exist, and when it has already been configured (don't overwrite) |
| 23 | # |
| 24 | JAVA=/usr/bin/java |
| 25 | AAF_INTERFACE_VERSION=2.1 |
| 26 | |
| 27 | # Extract Name, Domain and NS from FQI |
| 28 | FQIA=($(echo ${APP_FQI} | tr '@' '\n')) |
| 29 | FQI_SHORT=${FQIA[0]} |
| 30 | FQI_DOMAIN=${FQIA[1]} |
| 31 | # Reverse DOMAIN for NS |
| 32 | FQIA_E=($(echo ${FQI_DOMAIN} | tr '.' '\n')) |
| 33 | for (( i=( ${#FQIA_E[@]} -1 ); i>0; i-- )); do |
| 34 | NS=${NS}${FQIA_E[i]}'.' |
| 35 | done |
| 36 | NS=${NS}${FQIA_E[0]} |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 37 | CONFIG="/opt/app/aaf_config" |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 38 | OSAAF="/opt/app/osaaf" |
| 39 | LOCAL="$OSAAF/local" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 40 | DOT_AAF="$HOME/.aaf" |
| 41 | SSO="$DOT_AAF/sso.props" |
| 42 | |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 43 | JAVA_CADI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.CmdLine" |
| 44 | JAVA_AGENT="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$SSO org.onap.aaf.cadi.configure.Agent" |
| 45 | JAVA_AGENT_SELF="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/${NS}.props org.onap.aaf.cadi.configure.Agent" |
| 46 | JAVA_AAFCLI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.auth.cmd.AAFcli" |
| 47 | |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 48 | # Check for local dir |
| 49 | if [ ! -d $LOCAL ]; then |
| 50 | mkdir -p $LOCAL |
| 51 | for D in bin logs; do |
Instrumental | 12414fe | 2019-01-22 10:27:32 -0600 | [diff] [blame] | 52 | mkdir -p $OSAAF/$D |
Instrumental | 7f1e2c0 | 2019-02-18 10:06:21 -0600 | [diff] [blame] | 53 | cp $CONFIG/$D/* $OSAAF/$D |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 54 | done |
| 55 | fi |
| 56 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 57 | # Setup Bash, first time only |
Instrumental | 628b710 | 2019-02-15 19:40:04 -0600 | [diff] [blame] | 58 | if [ ! -e "$HOME/.bashrc" ] || [ -z "$(grep cadi $HOME/.bashrc)" ]; then |
| 59 | echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bashrc |
| 60 | echo "alias agent='$CONFIG/bin/agent.sh agent \$*'" >>$HOME/.bashrc |
| 61 | echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bashrc |
| 62 | chmod a+x $CONFIG/bin/agent.sh |
| 63 | . $HOME/.bashrc |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 64 | fi |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 65 | |
| 66 | # Setup SSO info for Deploy ID |
| 67 | function sso_encrypt() { |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 68 | $JAVA_CADI digest ${1} $DOT_AAF/keyfile |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 71 | |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 72 | # Create Deployer Info, located at /root/.aaf |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 73 | if [ ! -e "$DOT_AAF/keyfile" ]; then |
| 74 | mkdir -p $DOT_AAF |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 75 | $JAVA_CADI keygen $DOT_AAF/keyfile |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 76 | chmod 400 $DOT_AAF/keyfile |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 77 | echo cadi_latitude=${LATITUDE} > ${SSO} |
| 78 | echo cadi_longitude=${LONGITUDE} >> ${SSO} |
| 79 | echo aaf_id=${DEPLOY_FQI} >> ${SSO} |
| 80 | if [ ! "${DEPLOY_PASSWORD}" = "" ]; then |
| 81 | echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO} |
| 82 | fi |
| 83 | echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO} |
| 84 | echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO} |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 85 | |
| 86 | base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks |
| 87 | echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO} |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 88 | echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO} |
Instrumental | 284ad0a | 2018-10-24 07:01:09 -0500 | [diff] [blame] | 89 | echo "Caller Properties Initialized" |
| 90 | INITIALIZED="true" |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 91 | fi |
| 92 | |
| 93 | # Only initialize once, automatically... |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 94 | if [ ! -e $LOCAL/${NS}.props ]; then |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 95 | echo "#### Create Configuration files " |
| 96 | $JAVA_AGENT config $APP_FQI \ |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 97 | aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \ |
| 98 | cadi_etc_dir=$LOCAL |
| 99 | cat $LOCAL/$NS.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 100 | |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 101 | echo |
| 102 | echo "#### Certificate Authorization Artifact" |
| 103 | TMP=$(mktemp) |
| 104 | $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} \ |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 105 | cadi_prop_files=${SSO} \ |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 106 | cadi_etc_dir=$LOCAL > $TMP |
| 107 | cat $TMP |
| 108 | echo |
| 109 | if [ -n "$(grep 'Namespace:' $TMP)" ]; then |
| 110 | echo "#### Place Certificates (by deployer)" |
| 111 | $JAVA_AGENT place ${APP_FQI} ${APP_FQDN} \ |
| 112 | cadi_prop_files=${SSO} \ |
| 113 | cadi_etc_dir=$LOCAL |
| 114 | |
| 115 | echo "#### Validate Configuration and Certificate with live call" |
| 116 | $JAVA_AGENT_SELF validate |
Instrumental | 284ad0a | 2018-10-24 07:01:09 -0500 | [diff] [blame] | 117 | echo "Obtained Certificates" |
| 118 | INITIALIZED="true" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 119 | else |
| 120 | echo "#### Certificate Authorization Artifact must be valid to continue" |
| 121 | fi |
| 122 | rm $TMP |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 123 | fi |
| 124 | |
| 125 | # Now run a command |
| 126 | CMD=$2 |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 127 | if [ -z "$CMD" ]; then |
Instrumental | 284ad0a | 2018-10-24 07:01:09 -0500 | [diff] [blame] | 128 | if [ -n "$INITIALIZED" ]; then |
| 129 | echo "Initialization complete" |
| 130 | else |
| 131 | $JAVA_AGENT |
| 132 | fi |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 133 | else |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 134 | shift |
| 135 | shift |
| 136 | case "$CMD" in |
| 137 | ls) |
| 138 | echo ls requested |
| 139 | find /opt/app/osaaf -depth |
| 140 | ;; |
| 141 | cat) |
| 142 | if [ "$1" = "" ]; then |
| 143 | echo "usage: cat <file... ONLY files ending in .props>" |
| 144 | else |
| 145 | if [[ $1 == *.props ]]; then |
| 146 | echo |
| 147 | echo "## CONTENTS OF $3" |
| 148 | echo |
| 149 | cat "$1" |
| 150 | else |
| 151 | echo "### ERROR ####" |
| 152 | echo " \"cat\" may only be used with files ending with \".props\"" |
| 153 | fi |
| 154 | fi |
| 155 | ;; |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 156 | showpass) |
| 157 | echo "## Show Passwords" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 158 | $JAVA_AGENT showpass ${APP_FQI} ${APP_FQDN} |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 159 | ;; |
| 160 | check) |
Instrumental | bf3d307 | 2019-02-18 14:01:07 -0600 | [diff] [blame] | 161 | echo "## Check Certificate" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 162 | $JAVA_AGENT check ${APP_FQI} ${APP_FQDN} |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 163 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 164 | validate) |
| 165 | echo "## validate requested" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 166 | $JAVA_AGENT_SELF validate |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 167 | ;; |
Instrumental | bf3d307 | 2019-02-18 14:01:07 -0600 | [diff] [blame] | 168 | renew) |
| 169 | echo "## Renew Certificate" |
| 170 | $JAVA_AGENT place ${APP_FQI} ${APP_FQDN} |
| 171 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 172 | bash) |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 173 | shift |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 174 | cd $LOCAL || exit |
Instrumental | 12414fe | 2019-01-22 10:27:32 -0600 | [diff] [blame] | 175 | exec bash "$@" |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 176 | ;; |
| 177 | setProp) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 178 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 179 | FILES=$(grep -l "$1" ./*.props) |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 180 | if [ -z "$FILES" ]; then |
| 181 | if [ -z "$3" ]; then |
| 182 | FILES=${NS}.props |
| 183 | else |
| 184 | FILES="$3" |
| 185 | fi |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 186 | ADD=Y |
| 187 | fi |
| 188 | for F in $FILES; do |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 189 | if [ "$ADD" = "Y" ]; then |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 190 | echo "Changing $1 to $F" |
| 191 | echo "$1=$2" >> $F |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 192 | else |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 193 | echo "Changing $1 in $F" |
Instrumental | 6095e29 | 2018-09-06 13:27:15 -0500 | [diff] [blame] | 194 | sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 195 | fi |
| 196 | cat $F |
| 197 | done |
| 198 | ;; |
| 199 | encrypt) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 200 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 201 | echo $1 |
| 202 | FILES=$(grep -l "$1" ./*.props) |
| 203 | if [ "$FILES" = "" ]; then |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 204 | FILES=$LOCAL/${NS}.cred.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 205 | ADD=Y |
| 206 | fi |
| 207 | for F in $FILES; do |
| 208 | echo "Changing $1 in $F" |
| 209 | if [ "$2" = "" ]; then |
| 210 | read -r -p "Password (leave blank to cancel): " -s ORIG_PW |
| 211 | echo " " |
| 212 | if [ "$ORIG_PW" = "" ]; then |
| 213 | echo canceling... |
| 214 | break |
| 215 | fi |
| 216 | else |
| 217 | ORIG_PW="$2" |
| 218 | fi |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 219 | PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile) |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 220 | if [ "$ADD" = "Y" ]; then |
| 221 | echo "$1=enc:$PWD" >> $F |
| 222 | else |
| 223 | sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F |
| 224 | fi |
| 225 | cat $F |
| 226 | done |
| 227 | ;; |
| 228 | taillog) |
| 229 | sh /opt/app/osaaf/logs/taillog |
| 230 | ;; |
| 231 | --help | -?) |
| 232 | case "$1" in |
| 233 | "") |
| 234 | echo "--- Agent Container Comands ---" |
| 235 | echo " ls - Lists all files in Configuration" |
| 236 | echo " cat <file.props>> - Shows the contents (Prop files only)" |
| 237 | echo " validate - Runs a test using Configuration" |
| 238 | echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)" |
| 239 | echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)" |
| 240 | echo " bash - run bash in Container" |
| 241 | echo " Note: the following aliases are preset" |
| 242 | echo " cadi - CADI CmdLine tool" |
| 243 | echo " agent - Agent Java tool (see above help)" |
| 244 | echo "" |
| 245 | echo " --help|-? [cadi|agent] - This help, cadi help or agent help" |
| 246 | ;; |
| 247 | cadi) |
| 248 | echo "--- cadi Tool Comands ---" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 249 | $JAVA_CADI |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 250 | ;; |
| 251 | agent) |
| 252 | echo "--- agent Tool Comands ---" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 253 | $JAVA_AGENT |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 254 | ;; |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 255 | aafcli) |
| 256 | echo "--- aafcli Tool Comands ---" |
| 257 | $JAVA_AAFCLI |
| 258 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 259 | esac |
| 260 | echo "" |
| 261 | ;; |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 262 | ### Possible Dublin |
| 263 | # sample) |
| 264 | # echo "--- run Sample Servlet App ---" |
| 265 | # $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar:$CONFIG/bin/aaf-cadi-servlet-sample-*-sample.jar org.onap.aaf.sample.cadi.jetty.JettyStandalone ${NS}.props |
| 266 | # ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 267 | *) |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 268 | $JAVA_AGENT "$CMD" "$@" |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 269 | ;; |
| 270 | esac |
| 271 | fi |