blob: 1a289d35d350ca864e11215556bea2650e6ff763 [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#
Instrumentalfea400a2019-04-17 14:30:28 -050024
25echo "# Properties passed in"
26 for P in `env`; do
27 if [[ "$P" == cadi* ]] || [[ "$P" == aaf* ]] || [[ "$P" == HOSTNAME* ]]; then
28 S="${P/_helm/.helm}"
29 S="${S/_oom/.oom}"
30 echo "$S"
31 fi
32 done
33
34# Set from CAP Based PROPS, if necessary
35aaf_env=${aaf_env:-"${AAF_ENV}"}
36aaf_release=${aaf_release:-"${VERSION}"}
37cadi_latitude=${cadi_latitude:-"${LATITUDE}"}
38cadi_longitude=${cadi_longitude:-"${LONGITUDE}"}
39cadi_x509_issuers=${cadi_x509_issuers:-"${CADI_X509_ISSUERS}"}
40aaf_locate_url=${aaf_locate_url:-"https://${HOSTNAME}:8095"}
41
Instrumental9ec28952018-07-12 11:14:10 -050042JAVA=/usr/bin/java
Instrumental9fe11532018-10-23 17:40:47 -050043
44OSAAF=/opt/app/osaaf
45LOCAL=$OSAAF/local
46DATA=$OSAAF/data
47PUBLIC=$OSAAF/public
Instrumentalbc299c02018-09-25 06:42:31 -050048CONFIG=/opt/app/aaf_config
Instrumental5451a502018-10-10 18:51:33 -050049
Instrumental9fe11532018-10-23 17:40:47 -050050JAVA_CADI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.CmdLine"
51JAVA_AGENT="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.cadi.configure.Agent"
52JAVA_AAFCLI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.auth.cmd.AAFcli"
Instrumentale2fa0e62019-02-07 11:09:32 -060053JAVA_AAFBATCH="$JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.batch.props -jar $CONFIG/bin/aaf-auth-batch-*-full.jar"
Instrumental9fe11532018-10-23 17:40:47 -050054
Instrumental5451a502018-10-10 18:51:33 -050055# If doesn't exist... still create
Instrumental12414fe2019-01-22 10:27:32 -060056mkdir -p $OSAAF
Instrumental5451a502018-10-10 18:51:33 -050057
Instrumental3505a522019-01-31 14:49:24 -060058# If not created by separate PV, create
59mkdir -p /opt/app/aaf/status
60
Instrumentalbc299c02018-09-25 06:42:31 -050061# Temp use for clarity of code
62FILE=
Instrumental9ec28952018-07-12 11:14:10 -050063
Instrumental365638c2018-10-01 15:26:03 -050064# Setup Bash, first time only
Instrumentale2fa0e62019-02-07 11:09:32 -060065if [ ! -e "$HOME/.bashrc" ] || [ -z "$(grep cadi $HOME/.bashrc)" ]; then
66 echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bashrc
67 echo "alias agent='$CONFIG/bin/agent.sh \$*'" >>$HOME/.bashrc
68 echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bashrc
69 echo "alias batch='$JAVA_AAFBATCH \$*'" >>$HOME/.bashrc
Instrumental365638c2018-10-01 15:26:03 -050070 chmod a+x $CONFIG/bin/agent.sh
Instrumentale2fa0e62019-02-07 11:09:32 -060071 . $HOME/.bashrc
Instrumental365638c2018-10-01 15:26:03 -050072fi
73
Instrumental9ec28952018-07-12 11:14:10 -050074# Only load Identities once
Instrumentalbc299c02018-09-25 06:42:31 -050075# echo "Check Identities"
76FILE="$DATA/identities.dat"
77if [ ! -e $FILE ]; then
78 mkdir -p $DATA
79 cp $CONFIG/data/sample.identities.dat $FILE
Instrumental284ad0a2018-10-24 07:01:09 -050080 echo "Set Identities"
81 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050082fi
83
84# Load up Cert/X509 Artifacts
85# echo "Check Signer Keyfile"
86FILE="$LOCAL/org.osaaf.aaf.signer.p12"
87if [ ! -e $FILE ]; then
88 mkdir -p $LOCAL
89 mkdir -p $PUBLIC
90 if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then
91 cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE
Instrumental284ad0a2018-10-24 07:01:09 -050092 echo "Installed Signer P12"
93 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050094 else
95 echo "Decode"
96 base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE
97 base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12
98 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks
99 ln -s $PUBLIC/truststoreONAPall.jks $LOCAL
Instrumental365638c2018-10-01 15:26:03 -0500100 cp $CONFIG/cert/AAF_RootCA.cer $PUBLIC
101 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumentalbc299c02018-09-25 06:42:31 -0500102 echo "cadi_keystore_password=something easy" >> $CONFIG/local/aaf.props
Instrumental284ad0a2018-10-24 07:01:09 -0500103 echo "Setup ONAP Test CAs and Signers"
104 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500105 fi
106fi
107
108# echo "Check keyfile"
109FILE="$LOCAL/org.osaaf.aaf.p12"
110if [ ! -e $FILE ]; then
111 if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then
112 cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE
Instrumental284ad0a2018-10-24 07:01:09 -0500113 echo "Installed AAF P12"
114 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500115 else
116 echo "Bootstrap Creation of Keystore from Signer"
117 cd $CONFIG/CA
118
119 # Remove this after Casablanca
120 CADI_X509_ISSUERS="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
121 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
122 cp aaf.bootstrap.p12 $FILE
123 if [ -n "$CADI_X509_ISSUERS" ]; then
124 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
125 fi
126 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
127 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
128
129 I=${BOOT_ISSUER##CN=};I=${I%%,*}
130 CM_CA_PASS="something easy"
131 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 -0500132 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumental284ad0a2018-10-24 07:01:09 -0500133 echo "Generated ONAP Test AAF certs"
134 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500135 fi
Instrumental9ec28952018-07-12 11:14:10 -0500136fi
137
138# Only initialize once, automatically...
Instrumentalbc299c02018-09-25 06:42:31 -0500139if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
Instrumental12414fe2019-01-22 10:27:32 -0600140 cp $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -0500141 for D in public etc logs; do
Instrumental12414fe2019-01-22 10:27:32 -0600142 mkdir -p $OSAAF/$D
143 cp $CONFIG/$D/* $OSAAF/$D
Instrumental4ad47632018-07-13 15:49:26 -0500144 done
Instrumental9c8a8b02018-07-16 18:41:10 -0500145
146 TMP=$(mktemp)
Instrumental12414fe2019-01-22 10:27:32 -0600147 for P in `env`; do
Instrumentalfea400a2019-04-17 14:30:28 -0500148 if [[ "$P" == aaf_* ]] || [[ "$P" == cadi_* ]]; then
Instrumental4ac37bf2019-04-10 13:01:30 -0500149 S="${P/_helm/.helm}"
150 S="${S/_oom/.oom}"
151 echo "$S" >> ${TMP}
Instrumental12414fe2019-01-22 10:27:32 -0600152 fi
153 done
Instrumental9c8a8b02018-07-16 18:41:10 -0500154
Instrumentalbc299c02018-09-25 06:42:31 -0500155 cat $TMP
156
Instrumental9fe11532018-10-23 17:40:47 -0500157 $JAVA_AGENT config \
158 aaf@aaf.osaaf.org \
Instrumentalbc299c02018-09-25 06:42:31 -0500159 cadi_etc_dir=$LOCAL \
160 cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500161 rm ${TMP}
Instrumental196000b2018-10-05 19:30:59 -0500162
163 # Cassandra Config stuff
164 # Default is expect a Cassandra on same Node
Instrumental12414fe2019-01-22 10:27:32 -0600165 CASS_HOST=${CASS_HOST:="aaf-cass"}
Instrumental9fe11532018-10-23 17:40:47 -0500166 CASS_PASS=$($JAVA_CADI digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental196000b2018-10-05 19:30:59 -0500167 CASS_NAME=${CASS_HOST/:*/}
Instrumentalfea400a2019-04-17 14:30:28 -0500168 sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTER:=$CASS_HOST}/" \
Instrumental196000b2018-10-05 19:30:59 -0500169 -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \
170 -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \
171 -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \
172 $LOCAL/org.osaaf.aaf.cassandra.props
Instrumentalbc299c02018-09-25 06:42:31 -0500173
174 if [ -n "$CM_CA_LOCAL" ]; then
175 if [ -n "$CM_CA_PASS" ]; then
Instrumental9fe11532018-10-23 17:40:47 -0500176 CM_CA_LOCAL=$CM_CA_LOCAL$($JAVA_CADI digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile)
Instrumentalbc299c02018-09-25 06:42:31 -0500177 fi
178 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
179 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
180 mv $FILE $FILE.backup
181 grep -v "cm_ca.local=" $FILE.backup > $FILE
182 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
Instrumental365638c2018-10-01 15:26:03 -0500183 echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE
Instrumentalbc299c02018-09-25 06:42:31 -0500184 fi
Instrumental284ad0a2018-10-24 07:01:09 -0500185 echo "Created AAF Initial Configurations"
186 INITIALIZED="true"
Instrumental4ad47632018-07-13 15:49:26 -0500187fi
Instrumental9ec28952018-07-12 11:14:10 -0500188
Instrumentalbc299c02018-09-25 06:42:31 -0500189
Instrumental4ad47632018-07-13 15:49:26 -0500190# Now run a command
Instrumental12414fe2019-01-22 10:27:32 -0600191CMD=$1
Instrumental9fe11532018-10-23 17:40:47 -0500192if [ -z "$CMD" ]; then
Instrumental284ad0a2018-10-24 07:01:09 -0500193 if [ -n "$INITIALIZED" ]; then
194 echo "Initialization Complete"
195 else
196 echo "No Additional Initialization required"
197 fi
Instrumental9fe11532018-10-23 17:40:47 -0500198else
Instrumental4ad47632018-07-13 15:49:26 -0500199 shift
Instrumental4ad47632018-07-13 15:49:26 -0500200 case "$CMD" in
201 ls)
202 echo ls requested
Instrumental12414fe2019-01-22 10:27:32 -0600203 find $OSAAF -depth
Instrumental4ad47632018-07-13 15:49:26 -0500204 ;;
205 cat)
206 if [ "$1" = "" ]; then
207 echo "usage: cat <file... ONLY files ending in .props>"
208 else
209 if [[ $1 == *.props ]]; then
210 echo
211 echo "## CONTENTS OF $3"
212 echo
213 cat "$1"
214 else
215 echo "### ERROR ####"
216 echo " \"cat\" may only be used with files ending with \".props\""
217 fi
218 fi
219 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500220 validate)
221 echo "## validate requested"
Instrumental9fe11532018-10-23 17:40:47 -0500222 $JAVA_AAFCLI perm list user aaf@aaf.osaaf.org
Instrumental4ad47632018-07-13 15:49:26 -0500223 ;;
Instrumentalbc299c02018-09-25 06:42:31 -0500224 onap)
Instrumental284ad0a2018-10-24 07:01:09 -0500225 #echo Initializing ONAP configurations.
Instrumentalbc299c02018-09-25 06:42:31 -0500226 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500227 bash)
Instrumental4ad47632018-07-13 15:49:26 -0500228 shift
Instrumentalbc299c02018-09-25 06:42:31 -0500229 cd $LOCAL || exit
Instrumental12414fe2019-01-22 10:27:32 -0600230 exec /bin/bash -c "$@"
Instrumental4ad47632018-07-13 15:49:26 -0500231 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500232 setProp)
Instrumentalbc299c02018-09-25 06:42:31 -0500233 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500234 FILES=$(grep -l "$1" ./*.props)
Instrumental9fe11532018-10-23 17:40:47 -0500235 if [ -z "$FILES" ]; then
236 if [ -z "$3" ]; then
237 FILES=org.osaaf.aaf.props
238 else
239 FILES="$3"
240 fi
Instrumental9c8a8b02018-07-16 18:41:10 -0500241 ADD=Y
242 fi
243 for F in $FILES; do
Instrumental9c8a8b02018-07-16 18:41:10 -0500244 if [ "$ADD" = "Y" ]; then
Instrumental12414fe2019-01-22 10:27:32 -0600245 echo "Changing $1 for $F"
Instrumentalaeb80c82018-08-21 10:24:08 -0500246 echo "$1=$2" >> $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500247 else
Instrumental9fe11532018-10-23 17:40:47 -0500248 echo "Changing $1 in $F"
Instrumental12414fe2019-01-22 10:27:32 -0600249 sed -i.backup -e "s/\\(${1}=\\).*/\\1${2}/" $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500250 fi
251 cat $F
252 done
253 ;;
254 encrypt)
Instrumentalbc299c02018-09-25 06:42:31 -0500255 cd $LOCAL || exit
Instrumental9c8a8b02018-07-16 18:41:10 -0500256 echo $1
257 FILES=$(grep -l "$1" ./*.props)
258 if [ "$FILES" = "" ]; then
Instrumentalbc299c02018-09-25 06:42:31 -0500259 FILES=$LOCAL/org.osaaf.aaf.cred.props
Instrumental9c8a8b02018-07-16 18:41:10 -0500260 ADD=Y
Instrumental4ad47632018-07-13 15:49:26 -0500261 fi
262 for F in $FILES; do
263 echo "Changing $1 in $F"
264 if [ "$2" = "" ]; then
265 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
266 echo " "
267 if [ "$ORIG_PW" = "" ]; then
268 echo canceling...
269 break
270 fi
271 else
272 ORIG_PW="$2"
273 fi
Instrumental9fe11532018-10-23 17:40:47 -0500274 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental9c8a8b02018-07-16 18:41:10 -0500275 if [ "$ADD" = "Y" ]; then
276 echo "$1=enc:$PWD" >> $F
277 else
278 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
279 fi
Instrumental4ad47632018-07-13 15:49:26 -0500280 cat $F
281 done
282 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500283 taillog)
Instrumental12414fe2019-01-22 10:27:32 -0600284 sh $OSAAF/logs/taillog
Instrumental9c8a8b02018-07-16 18:41:10 -0500285 ;;
Instrumentalca788dc2018-11-03 14:38:21 -0500286 wait)
287 bash $CONFIG/bin/pod_wait.sh wait $1
288 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500289 --help | -?)
290 case "$1" in
291 "")
292 echo "--- Agent Container Comands ---"
293 echo " ls - Lists all files in Configuration"
294 echo " cat <file.props>> - Shows the contents (Prop files only)"
295 echo " validate - Runs a test using Configuration"
Instrumental9c8a8b02018-07-16 18:41:10 -0500296 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
Instrumental4ad47632018-07-13 15:49:26 -0500297 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
298 echo " bash - run bash in Container"
299 echo " Note: the following aliases are preset"
300 echo " cadi - CADI CmdLine tool"
301 echo " agent - Agent Java tool (see above help)"
302 echo ""
303 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
304 ;;
305 cadi)
306 echo "--- cadi Tool Comands ---"
Instrumental9fe11532018-10-23 17:40:47 -0500307 $JAVA_CADI
Instrumental4ad47632018-07-13 15:49:26 -0500308 ;;
309 agent)
310 echo "--- agent Tool Comands ---"
Instrumental9fe11532018-10-23 17:40:47 -0500311 $JAVA_AGENT
312 ;;
313 aafcli)
314 echo "--- aafcli Tool Comands ---"
315 $JAVA_AAFCLI
Instrumental4ad47632018-07-13 15:49:26 -0500316 ;;
317 esac
318 echo ""
319 ;;
320 *)
Instrumental9fe11532018-10-23 17:40:47 -0500321 $JAVA_AGENT "$CMD" "$@" cadi_prop_files=$LOCAL/org.osaaf.aaf.props
Instrumental4ad47632018-07-13 15:49:26 -0500322 ;;
323 esac
324fi