blob: bddd42c9520c79d7a907eb8bef8b45278513082d [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}"}
Instrumental355b8862019-06-06 19:33:19 -050036aaf_deployed_version=${aaf_deployed_version:-"${VERSION}"}
Instrumentalfea400a2019-04-17 14:30:28 -050037cadi_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
Instrumental513471c2019-05-01 13:35:47 -050084# Should we clean up?
85if [ ! -e "${LOCAL}/VERSION" ] || [ "${VERSION}" != "$(cat ${LOCAL}/VERSION)" ]; then
86 echo "Clean up directory ${LOCAL}"
87 rm -Rf ${LOCAL}/org.osaaf.aaf.*props ${LOCAL}/org.osaaf.aaf.p12
88 ls ${LOCAL}
89fi
90echo "${VERSION}" > $LOCAL/VERSION
91
Instrumentalbc299c02018-09-25 06:42:31 -050092# Load up Cert/X509 Artifacts
93# echo "Check Signer Keyfile"
94FILE="$LOCAL/org.osaaf.aaf.signer.p12"
95if [ ! -e $FILE ]; then
96 mkdir -p $LOCAL
97 mkdir -p $PUBLIC
98 if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then
99 cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE
Instrumental284ad0a2018-10-24 07:01:09 -0500100 echo "Installed Signer P12"
101 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500102 else
103 echo "Decode"
104 base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE
105 base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12
106 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks
107 ln -s $PUBLIC/truststoreONAPall.jks $LOCAL
Instrumental365638c2018-10-01 15:26:03 -0500108 cp $CONFIG/cert/AAF_RootCA.cer $PUBLIC
109 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumental284ad0a2018-10-24 07:01:09 -0500110 echo "Setup ONAP Test CAs and Signers"
111 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500112 fi
113fi
114
Instrumentalbc299c02018-09-25 06:42:31 -0500115FILE="$LOCAL/org.osaaf.aaf.p12"
116if [ ! -e $FILE ]; then
117 if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then
118 cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE
Instrumental284ad0a2018-10-24 07:01:09 -0500119 echo "Installed AAF P12"
120 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500121 else
122 echo "Bootstrap Creation of Keystore from Signer"
123 cd $CONFIG/CA
124
Instrumental513471c2019-05-01 13:35:47 -0500125 # Redo all of this after Dublin
126 export cadi_x509_issuers="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
127 export signer_subj="/CN=intermediateCA_9/OU=OSAAF/O=ONAP/C=US"
Instrumentalbc299c02018-09-25 06:42:31 -0500128 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
129 cp aaf.bootstrap.p12 $FILE
130 if [ -n "$CADI_X509_ISSUERS" ]; then
131 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
132 fi
133 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
134 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
135
136 I=${BOOT_ISSUER##CN=};I=${I%%,*}
137 CM_CA_PASS="something easy"
138 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 -0500139 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumental284ad0a2018-10-24 07:01:09 -0500140 echo "Generated ONAP Test AAF certs"
141 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500142 fi
Instrumental9ec28952018-07-12 11:14:10 -0500143fi
144
145# Only initialize once, automatically...
Instrumentalbc299c02018-09-25 06:42:31 -0500146if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
Instrumental12414fe2019-01-22 10:27:32 -0600147 cp $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -0500148 for D in public etc logs; do
Instrumental12414fe2019-01-22 10:27:32 -0600149 mkdir -p $OSAAF/$D
150 cp $CONFIG/$D/* $OSAAF/$D
Instrumental4ad47632018-07-13 15:49:26 -0500151 done
Instrumental9c8a8b02018-07-16 18:41:10 -0500152
153 TMP=$(mktemp)
Instrumental12414fe2019-01-22 10:27:32 -0600154 for P in `env`; do
Instrumentalfea400a2019-04-17 14:30:28 -0500155 if [[ "$P" == aaf_* ]] || [[ "$P" == cadi_* ]]; then
Instrumental4ac37bf2019-04-10 13:01:30 -0500156 S="${P/_helm/.helm}"
157 S="${S/_oom/.oom}"
158 echo "$S" >> ${TMP}
Instrumental12414fe2019-01-22 10:27:32 -0600159 fi
160 done
Instrumentalbc299c02018-09-25 06:42:31 -0500161 cat $TMP
162
Instrumental9fe11532018-10-23 17:40:47 -0500163 $JAVA_AGENT config \
164 aaf@aaf.osaaf.org \
Instrumentalbc299c02018-09-25 06:42:31 -0500165 cadi_etc_dir=$LOCAL \
Instrumentalf64f4822019-04-30 10:19:21 -0500166 cadi_latitude=${cadi_latitude} \
167 cadi_longitude=${cadi_longitude} \
Instrumentalbc299c02018-09-25 06:42:31 -0500168 cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500169 rm ${TMP}
Instrumentalb3a68142019-07-24 14:42:22 -0500170 echo "cm_always_ignore_ips=${cm_always_ignore_ips:=false}" >> $LOCAL/org.osaaf.aaf.props;
Instrumental196000b2018-10-05 19:30:59 -0500171
172 # Cassandra Config stuff
173 # Default is expect a Cassandra on same Node
Instrumental12414fe2019-01-22 10:27:32 -0600174 CASS_HOST=${CASS_HOST:="aaf-cass"}
Instrumental9fe11532018-10-23 17:40:47 -0500175 CASS_PASS=$($JAVA_CADI digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental196000b2018-10-05 19:30:59 -0500176 CASS_NAME=${CASS_HOST/:*/}
Instrumentalfea400a2019-04-17 14:30:28 -0500177 sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTER:=$CASS_HOST}/" \
Instrumental196000b2018-10-05 19:30:59 -0500178 -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \
179 -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \
180 -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \
181 $LOCAL/org.osaaf.aaf.cassandra.props
Instrumentalbc299c02018-09-25 06:42:31 -0500182
183 if [ -n "$CM_CA_LOCAL" ]; then
184 if [ -n "$CM_CA_PASS" ]; then
Instrumental9fe11532018-10-23 17:40:47 -0500185 CM_CA_LOCAL=$CM_CA_LOCAL$($JAVA_CADI digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile)
Instrumentalbc299c02018-09-25 06:42:31 -0500186 fi
187 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
188 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
189 mv $FILE $FILE.backup
190 grep -v "cm_ca.local=" $FILE.backup > $FILE
191 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
Instrumental365638c2018-10-01 15:26:03 -0500192 echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE
Instrumentalbc299c02018-09-25 06:42:31 -0500193 fi
Instrumental284ad0a2018-10-24 07:01:09 -0500194 echo "Created AAF Initial Configurations"
195 INITIALIZED="true"
Instrumental4ad47632018-07-13 15:49:26 -0500196fi
Instrumental9ec28952018-07-12 11:14:10 -0500197
Instrumentalbc299c02018-09-25 06:42:31 -0500198
Instrumental4ad47632018-07-13 15:49:26 -0500199# Now run a command
Instrumental12414fe2019-01-22 10:27:32 -0600200CMD=$1
Instrumental9fe11532018-10-23 17:40:47 -0500201if [ -z "$CMD" ]; then
Instrumental284ad0a2018-10-24 07:01:09 -0500202 if [ -n "$INITIALIZED" ]; then
203 echo "Initialization Complete"
204 else
205 echo "No Additional Initialization required"
206 fi
Instrumental9fe11532018-10-23 17:40:47 -0500207else
Instrumental4ad47632018-07-13 15:49:26 -0500208 shift
Instrumental4ad47632018-07-13 15:49:26 -0500209 case "$CMD" in
210 ls)
211 echo ls requested
Instrumental12414fe2019-01-22 10:27:32 -0600212 find $OSAAF -depth
Instrumental4ad47632018-07-13 15:49:26 -0500213 ;;
214 cat)
215 if [ "$1" = "" ]; then
216 echo "usage: cat <file... ONLY files ending in .props>"
217 else
218 if [[ $1 == *.props ]]; then
219 echo
220 echo "## CONTENTS OF $3"
221 echo
222 cat "$1"
223 else
224 echo "### ERROR ####"
225 echo " \"cat\" may only be used with files ending with \".props\""
226 fi
227 fi
228 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500229 validate)
230 echo "## validate requested"
Instrumental9fe11532018-10-23 17:40:47 -0500231 $JAVA_AAFCLI perm list user aaf@aaf.osaaf.org
Instrumental4ad47632018-07-13 15:49:26 -0500232 ;;
Instrumentalbc299c02018-09-25 06:42:31 -0500233 onap)
Instrumental284ad0a2018-10-24 07:01:09 -0500234 #echo Initializing ONAP configurations.
Instrumentalbc299c02018-09-25 06:42:31 -0500235 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500236 bash)
Instrumental4ad47632018-07-13 15:49:26 -0500237 shift
Instrumentalbc299c02018-09-25 06:42:31 -0500238 cd $LOCAL || exit
Instrumental12414fe2019-01-22 10:27:32 -0600239 exec /bin/bash -c "$@"
Instrumental4ad47632018-07-13 15:49:26 -0500240 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500241 setProp)
Instrumentalbc299c02018-09-25 06:42:31 -0500242 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500243 FILES=$(grep -l "$1" ./*.props)
Instrumental9fe11532018-10-23 17:40:47 -0500244 if [ -z "$FILES" ]; then
245 if [ -z "$3" ]; then
246 FILES=org.osaaf.aaf.props
247 else
248 FILES="$3"
249 fi
Instrumental9c8a8b02018-07-16 18:41:10 -0500250 ADD=Y
251 fi
252 for F in $FILES; do
Instrumental9c8a8b02018-07-16 18:41:10 -0500253 if [ "$ADD" = "Y" ]; then
Instrumental12414fe2019-01-22 10:27:32 -0600254 echo "Changing $1 for $F"
Instrumentalaeb80c82018-08-21 10:24:08 -0500255 echo "$1=$2" >> $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500256 else
Instrumental9fe11532018-10-23 17:40:47 -0500257 echo "Changing $1 in $F"
Instrumental12414fe2019-01-22 10:27:32 -0600258 sed -i.backup -e "s/\\(${1}=\\).*/\\1${2}/" $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500259 fi
260 cat $F
261 done
262 ;;
263 encrypt)
Instrumentalbc299c02018-09-25 06:42:31 -0500264 cd $LOCAL || exit
Instrumental9c8a8b02018-07-16 18:41:10 -0500265 echo $1
266 FILES=$(grep -l "$1" ./*.props)
267 if [ "$FILES" = "" ]; then
Instrumentalbc299c02018-09-25 06:42:31 -0500268 FILES=$LOCAL/org.osaaf.aaf.cred.props
Instrumental9c8a8b02018-07-16 18:41:10 -0500269 ADD=Y
Instrumental4ad47632018-07-13 15:49:26 -0500270 fi
271 for F in $FILES; do
272 echo "Changing $1 in $F"
273 if [ "$2" = "" ]; then
274 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
275 echo " "
276 if [ "$ORIG_PW" = "" ]; then
277 echo canceling...
278 break
279 fi
280 else
281 ORIG_PW="$2"
282 fi
Instrumental9fe11532018-10-23 17:40:47 -0500283 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental9c8a8b02018-07-16 18:41:10 -0500284 if [ "$ADD" = "Y" ]; then
285 echo "$1=enc:$PWD" >> $F
286 else
287 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
288 fi
Instrumental4ad47632018-07-13 15:49:26 -0500289 cat $F
290 done
291 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500292 taillog)
Instrumental12414fe2019-01-22 10:27:32 -0600293 sh $OSAAF/logs/taillog
Instrumental9c8a8b02018-07-16 18:41:10 -0500294 ;;
Instrumentalca788dc2018-11-03 14:38:21 -0500295 wait)
296 bash $CONFIG/bin/pod_wait.sh wait $1
297 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500298 --help | -?)
299 case "$1" in
300 "")
301 echo "--- Agent Container Comands ---"
302 echo " ls - Lists all files in Configuration"
303 echo " cat <file.props>> - Shows the contents (Prop files only)"
304 echo " validate - Runs a test using Configuration"
Instrumental9c8a8b02018-07-16 18:41:10 -0500305 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
Instrumental4ad47632018-07-13 15:49:26 -0500306 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
307 echo " bash - run bash in Container"
308 echo " Note: the following aliases are preset"
309 echo " cadi - CADI CmdLine tool"
310 echo " agent - Agent Java tool (see above help)"
311 echo ""
312 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
313 ;;
314 cadi)
315 echo "--- cadi Tool Comands ---"
Instrumental9fe11532018-10-23 17:40:47 -0500316 $JAVA_CADI
Instrumental4ad47632018-07-13 15:49:26 -0500317 ;;
318 agent)
319 echo "--- agent Tool Comands ---"
Instrumental9fe11532018-10-23 17:40:47 -0500320 $JAVA_AGENT
321 ;;
322 aafcli)
323 echo "--- aafcli Tool Comands ---"
324 $JAVA_AAFCLI
Instrumental4ad47632018-07-13 15:49:26 -0500325 ;;
326 esac
327 echo ""
328 ;;
329 *)
Instrumental9fe11532018-10-23 17:40:47 -0500330 $JAVA_AGENT "$CMD" "$@" cadi_prop_files=$LOCAL/org.osaaf.aaf.props
Instrumental4ad47632018-07-13 15:49:26 -0500331 ;;
332 esac
333fi