blob: 78f6693b0798817b3cb2b80dc3e0ca5fee225737 [file] [log] [blame]
Instrumental4ad47632018-07-13 15:49:26 -05001#!/bin/bash
Instrumental7a1817b2018-11-05 11:11:15 -06002#########
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#
Instrumental9ec28952018-07-12 11:14:10 -050021# This script is run when starting aaf_config Container.
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#
24JAVA=/usr/bin/java
Instrumental9fe11532018-10-23 17:40:47 -050025
26OSAAF=/opt/app/osaaf
27LOCAL=$OSAAF/local
28DATA=$OSAAF/data
29PUBLIC=$OSAAF/public
Instrumentalbc299c02018-09-25 06:42:31 -050030CONFIG=/opt/app/aaf_config
Instrumental5451a502018-10-10 18:51:33 -050031
Instrumental9fe11532018-10-23 17:40:47 -050032JAVA_CADI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.CmdLine"
33JAVA_AGENT="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.cadi.configure.Agent"
34JAVA_AAFCLI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.auth.cmd.AAFcli"
35
Instrumental5451a502018-10-10 18:51:33 -050036# If doesn't exist... still create
37mkdir -p /opt/app/osaaf
38
Instrumentalbc299c02018-09-25 06:42:31 -050039# Temp use for clarity of code
40FILE=
Instrumental9ec28952018-07-12 11:14:10 -050041
Instrumental365638c2018-10-01 15:26:03 -050042# Setup Bash, first time only
Instrumental9fe11532018-10-23 17:40:47 -050043if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep cadi $HOME/.bash_aliases)" ]; then
44 echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bash_aliases
Instrumental365638c2018-10-01 15:26:03 -050045 echo "alias agent='$CONFIG/bin/agent.sh EMPTY \$*'" >>$HOME/.bash_aliases
Instrumental9fe11532018-10-23 17:40:47 -050046 echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bash_aliases
Instrumental365638c2018-10-01 15:26:03 -050047 chmod a+x $CONFIG/bin/agent.sh
48 . $HOME/.bash_aliases
49fi
50
Instrumental9ec28952018-07-12 11:14:10 -050051# Only load Identities once
Instrumentalbc299c02018-09-25 06:42:31 -050052# echo "Check Identities"
53FILE="$DATA/identities.dat"
54if [ ! -e $FILE ]; then
55 mkdir -p $DATA
56 cp $CONFIG/data/sample.identities.dat $FILE
Instrumental284ad0a2018-10-24 07:01:09 -050057 echo "Set Identities"
58 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050059fi
60
61# Load up Cert/X509 Artifacts
62# echo "Check Signer Keyfile"
63FILE="$LOCAL/org.osaaf.aaf.signer.p12"
64if [ ! -e $FILE ]; then
65 mkdir -p $LOCAL
66 mkdir -p $PUBLIC
67 if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then
68 cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE
Instrumental284ad0a2018-10-24 07:01:09 -050069 echo "Installed Signer P12"
70 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050071 else
72 echo "Decode"
73 base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE
74 base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12
75 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks
76 ln -s $PUBLIC/truststoreONAPall.jks $LOCAL
Instrumental365638c2018-10-01 15:26:03 -050077 cp $CONFIG/cert/AAF_RootCA.cer $PUBLIC
78 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumentalbc299c02018-09-25 06:42:31 -050079 echo "cadi_keystore_password=something easy" >> $CONFIG/local/aaf.props
Instrumental284ad0a2018-10-24 07:01:09 -050080 echo "Setup ONAP Test CAs and Signers"
81 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050082 fi
83fi
84
85# echo "Check keyfile"
86FILE="$LOCAL/org.osaaf.aaf.p12"
87if [ ! -e $FILE ]; then
88 if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then
89 cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE
Instrumental284ad0a2018-10-24 07:01:09 -050090 echo "Installed AAF P12"
91 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050092 else
93 echo "Bootstrap Creation of Keystore from Signer"
94 cd $CONFIG/CA
95
96 # Remove this after Casablanca
97 CADI_X509_ISSUERS="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
98 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
99 cp aaf.bootstrap.p12 $FILE
100 if [ -n "$CADI_X509_ISSUERS" ]; then
101 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
102 fi
103 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
104 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
105
106 I=${BOOT_ISSUER##CN=};I=${I%%,*}
107 CM_CA_PASS="something easy"
108 CM_CA_LOCAL="org.onap.aaf.auth.cm.ca.LocalCA,$LOCAL/org.osaaf.aaf.signer.p12;aaf_intermediate_9;enc:"
Instrumental365638c2018-10-01 15:26:03 -0500109 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumental284ad0a2018-10-24 07:01:09 -0500110 echo "Generated ONAP Test AAF certs"
111 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500112 fi
Instrumental9ec28952018-07-12 11:14:10 -0500113fi
114
115# Only initialize once, automatically...
Instrumentalbc299c02018-09-25 06:42:31 -0500116if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
117 rsync -avzh --exclude=.gitignore $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -0500118 for D in public etc logs; do
Instrumentalbc299c02018-09-25 06:42:31 -0500119 rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental4ad47632018-07-13 15:49:26 -0500120 done
Instrumental9c8a8b02018-07-16 18:41:10 -0500121
122 TMP=$(mktemp)
123 echo aaf_env=${AAF_ENV} >> ${TMP}
Instrumental575c9822018-10-19 11:13:05 -0500124 echo aaf_release=${VERSION} >> ${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500125 echo cadi_latitude=${LATITUDE} >> ${TMP}
126 echo cadi_longitude=${LONGITUDE} >> ${TMP}
Instrumentalbc299c02018-09-25 06:42:31 -0500127 echo cadi_x509_issuers=${CADI_X509_ISSUERS} >> ${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500128 echo aaf_register_as=${AAF_REGISTER_AS} >> ${TMP}
Instrumental93871ff2018-10-15 07:37:28 -0500129 AAF_LOCATOR_AS=${AAF_LOCATOR_AS:=$AAF_REGISTER_AS}
Instrumental5451a502018-10-10 18:51:33 -0500130 echo aaf_locate_url=https://${AAF_LOCATOR_AS}:8095 >> ${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500131
Instrumentalbc299c02018-09-25 06:42:31 -0500132 cat $TMP
133
Instrumental9fe11532018-10-23 17:40:47 -0500134 $JAVA_AGENT config \
135 aaf@aaf.osaaf.org \
Instrumentalbc299c02018-09-25 06:42:31 -0500136 cadi_etc_dir=$LOCAL \
137 cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500138 rm ${TMP}
Instrumental196000b2018-10-05 19:30:59 -0500139
140 # Cassandra Config stuff
141 # Default is expect a Cassandra on same Node
Instrumental93871ff2018-10-15 07:37:28 -0500142 CASS_HOST=${CASS_HOST:="aaf_cass"}
Instrumental9fe11532018-10-23 17:40:47 -0500143 CASS_PASS=$($JAVA_CADI digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental196000b2018-10-05 19:30:59 -0500144 CASS_NAME=${CASS_HOST/:*/}
Instrumental14f37072018-10-09 08:32:06 -0500145 sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTERS:=$CASS_HOST}/" \
Instrumental196000b2018-10-05 19:30:59 -0500146 -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \
147 -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \
148 -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \
149 $LOCAL/org.osaaf.aaf.cassandra.props
Instrumentalbc299c02018-09-25 06:42:31 -0500150
151 if [ -n "$CM_CA_LOCAL" ]; then
152 if [ -n "$CM_CA_PASS" ]; then
Instrumental9fe11532018-10-23 17:40:47 -0500153 CM_CA_LOCAL=$CM_CA_LOCAL$($JAVA_CADI digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile)
Instrumentalbc299c02018-09-25 06:42:31 -0500154 fi
155 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
156 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
157 mv $FILE $FILE.backup
158 grep -v "cm_ca.local=" $FILE.backup > $FILE
159 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
Instrumental365638c2018-10-01 15:26:03 -0500160 echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE
Instrumentalbc299c02018-09-25 06:42:31 -0500161 fi
Instrumental284ad0a2018-10-24 07:01:09 -0500162 echo "Created AAF Initial Configurations"
163 INITIALIZED="true"
Instrumental4ad47632018-07-13 15:49:26 -0500164fi
Instrumental9ec28952018-07-12 11:14:10 -0500165
Instrumentalbc299c02018-09-25 06:42:31 -0500166
Instrumental4ad47632018-07-13 15:49:26 -0500167# Now run a command
168CMD=$2
Instrumental9fe11532018-10-23 17:40:47 -0500169if [ -z "$CMD" ]; then
Instrumental284ad0a2018-10-24 07:01:09 -0500170 if [ -n "$INITIALIZED" ]; then
171 echo "Initialization Complete"
172 else
173 echo "No Additional Initialization required"
174 fi
Instrumental9fe11532018-10-23 17:40:47 -0500175else
Instrumental4ad47632018-07-13 15:49:26 -0500176 shift
177 shift
178 case "$CMD" in
179 ls)
180 echo ls requested
181 find /opt/app/osaaf -depth
182 ;;
183 cat)
184 if [ "$1" = "" ]; then
185 echo "usage: cat <file... ONLY files ending in .props>"
186 else
187 if [[ $1 == *.props ]]; then
188 echo
189 echo "## CONTENTS OF $3"
190 echo
191 cat "$1"
192 else
193 echo "### ERROR ####"
194 echo " \"cat\" may only be used with files ending with \".props\""
195 fi
196 fi
197 ;;
198 update)
Instrumentalbc299c02018-09-25 06:42:31 -0500199 rsync -uh --exclude=.gitignore $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -0500200 for D in public data etc logs; do
Instrumentalbc299c02018-09-25 06:42:31 -0500201 rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental4ad47632018-07-13 15:49:26 -0500202 done
203 ;;
204 validate)
205 echo "## validate requested"
Instrumental9fe11532018-10-23 17:40:47 -0500206 $JAVA_AAFCLI perm list user aaf@aaf.osaaf.org
Instrumental4ad47632018-07-13 15:49:26 -0500207 ;;
Instrumentalbc299c02018-09-25 06:42:31 -0500208 onap)
Instrumental284ad0a2018-10-24 07:01:09 -0500209 #echo Initializing ONAP configurations.
Instrumentalbc299c02018-09-25 06:42:31 -0500210 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500211 bash)
Instrumental4ad47632018-07-13 15:49:26 -0500212 shift
Instrumentalbc299c02018-09-25 06:42:31 -0500213 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500214 /bin/bash "$@"
215 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500216 setProp)
Instrumentalbc299c02018-09-25 06:42:31 -0500217 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500218 FILES=$(grep -l "$1" ./*.props)
Instrumental9fe11532018-10-23 17:40:47 -0500219 if [ -z "$FILES" ]; then
220 if [ -z "$3" ]; then
221 FILES=org.osaaf.aaf.props
222 else
223 FILES="$3"
224 fi
Instrumental9c8a8b02018-07-16 18:41:10 -0500225 ADD=Y
226 fi
227 for F in $FILES; do
Instrumental9c8a8b02018-07-16 18:41:10 -0500228 if [ "$ADD" = "Y" ]; then
Instrumental9fe11532018-10-23 17:40:47 -0500229 echo "Changing $1 to $F"
Instrumentalaeb80c82018-08-21 10:24:08 -0500230 echo "$1=$2" >> $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500231 else
Instrumental9fe11532018-10-23 17:40:47 -0500232 echo "Changing $1 in $F"
233 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500234 fi
235 cat $F
236 done
237 ;;
238 encrypt)
Instrumentalbc299c02018-09-25 06:42:31 -0500239 cd $LOCAL || exit
Instrumental9c8a8b02018-07-16 18:41:10 -0500240 echo $1
241 FILES=$(grep -l "$1" ./*.props)
242 if [ "$FILES" = "" ]; then
Instrumentalbc299c02018-09-25 06:42:31 -0500243 FILES=$LOCAL/org.osaaf.aaf.cred.props
Instrumental9c8a8b02018-07-16 18:41:10 -0500244 ADD=Y
Instrumental4ad47632018-07-13 15:49:26 -0500245 fi
246 for F in $FILES; do
247 echo "Changing $1 in $F"
248 if [ "$2" = "" ]; then
249 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
250 echo " "
251 if [ "$ORIG_PW" = "" ]; then
252 echo canceling...
253 break
254 fi
255 else
256 ORIG_PW="$2"
257 fi
Instrumental9fe11532018-10-23 17:40:47 -0500258 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental9c8a8b02018-07-16 18:41:10 -0500259 if [ "$ADD" = "Y" ]; then
260 echo "$1=enc:$PWD" >> $F
261 else
262 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
263 fi
Instrumental4ad47632018-07-13 15:49:26 -0500264 cat $F
265 done
266 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500267 taillog)
268 sh /opt/app/osaaf/logs/taillog
269 ;;
Instrumentalca788dc2018-11-03 14:38:21 -0500270 wait)
271 bash $CONFIG/bin/pod_wait.sh wait $1
272 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500273 --help | -?)
274 case "$1" in
275 "")
276 echo "--- Agent Container Comands ---"
277 echo " ls - Lists all files in Configuration"
278 echo " cat <file.props>> - Shows the contents (Prop files only)"
279 echo " validate - Runs a test using Configuration"
Instrumental9c8a8b02018-07-16 18:41:10 -0500280 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
Instrumental4ad47632018-07-13 15:49:26 -0500281 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
282 echo " bash - run bash in Container"
283 echo " Note: the following aliases are preset"
284 echo " cadi - CADI CmdLine tool"
285 echo " agent - Agent Java tool (see above help)"
286 echo ""
287 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
288 ;;
289 cadi)
290 echo "--- cadi Tool Comands ---"
Instrumental9fe11532018-10-23 17:40:47 -0500291 $JAVA_CADI
Instrumental4ad47632018-07-13 15:49:26 -0500292 ;;
293 agent)
294 echo "--- agent Tool Comands ---"
Instrumental9fe11532018-10-23 17:40:47 -0500295 $JAVA_AGENT
296 ;;
297 aafcli)
298 echo "--- aafcli Tool Comands ---"
299 $JAVA_AAFCLI
Instrumental4ad47632018-07-13 15:49:26 -0500300 ;;
301 esac
302 echo ""
303 ;;
304 *)
Instrumental9fe11532018-10-23 17:40:47 -0500305 $JAVA_AGENT "$CMD" "$@" cadi_prop_files=$LOCAL/org.osaaf.aaf.props
Instrumental4ad47632018-07-13 15:49:26 -0500306 ;;
307 esac
308fi