Skip to content

Commit

Permalink
reorganize files
Browse files Browse the repository at this point in the history
  • Loading branch information
jshihstsci committed Jan 3, 2024
1 parent 36788b2 commit 8e55401
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion terraform/deploy_ami_rotation_codebuild_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd ${CALCLOUD_BUILD_DIR}/iac/codebuild
pwd

#./copy-cert # copy the cert from CI node AMI and replace the cert in current dir
cert-update
source hst_admin_role_shim.sh cert-update

set -o pipefail && docker build -f Dockerfile -t ${AMIROTATION_DOCKER_IMAGE_UNSCANNED} --build-arg aws_env="${aws_env}" --build-arg CALCLOUD_VER="${CALCLOUD_VER}" .
amirotation_docker_build_status=$?
Expand Down
6 changes: 3 additions & 3 deletions terraform/deploy_docker_builds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi

# naming is confusing here but "modeling" directory plus "training" image is correct
cd ${CALCLOUD_BUILD_DIR}/modeling
cert-update
source hst_admin_role_shim.sh cert-update
#cp /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem certs/tls-ca-bundle.pem # copy the cert from CI node AMI
set -o pipefail && docker build -f Dockerfile -t ${TRAINING_DOCKER_IMAGE} .
training_docker_build_status=$?
Expand All @@ -32,7 +32,7 @@ fi

# jobPredict lambda env
cd ${CALCLOUD_BUILD_DIR}/lambda/JobPredict
cert-update
source hst_admin_role_shim.sh cert-update
#cp /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem certs/tls-ca-bundle.pem # copy the cert from CI node AMI
set -o pipefail && docker build -f Dockerfile -t ${PREDICT_DOCKER_IMAGE} .
model_docker_build_status=$?
Expand All @@ -43,7 +43,7 @@ fi

# caldp image
cd ${CALDP_BUILD_DIR}
cert-update
source hst_admin_role_shim.sh cert-update
#cp /etc/ssl/certs/ca-bundle.crt tls-ca-bundle.pem # copy the cert from CI node AMI
set -o pipefail && docker build -f Dockerfile -t ${CALDP_DOCKER_IMAGE} --build-arg CAL_BASE_IMAGE="${CAL_BASE_IMAGE}" .
caldp_docker_build_status=$?
Expand Down
2 changes: 1 addition & 1 deletion terraform/deploy_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ CSYS_VER=${CAL_BASE_IMAGE##*:}
CSYS_VER=`echo $CSYS_VER | cut -f1,2 -d'_'` #split by underscores, keep the first two
export CSYS_VER=`echo $CSYS_VER | awk '{print tolower($0)}'`

# get repo_url here for the central ecr repo
export PATH=`pwd`/tools:${PATH}
2 changes: 1 addition & 1 deletion tools/cert-list → terraform/tools/cert-list
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/env python3

"""This script is used to dump out cert subjects and issuers in order
to follow the chain of certs from JH to a root authority.
Expand Down
2 changes: 1 addition & 1 deletion tools/cert-update → terraform/tools/cert-update
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/env python3

# This script downloads and cleans the SSL cert needed for Docker builds
# to transit the STScI packet inspection firewall on AWS. Originally
Expand Down
44 changes: 44 additions & 0 deletions terraform/tools/hst_admin_role_shim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#/bin/bash
# This script assumes the hst_reprocessing_admin_role, runs a given command using that role, and then switches back to original role

# Set region
export AWS_DEFAULT_REGION="us-east-1"

# Role to assume
ACCOUNT_ID=`aws sts get-caller-identity --output=text | awk '{ print $1 }'`
HST_ADMIN_ARN="arn:aws:iam::${ACCOUNT_ID}:role/hst_reprocessing_admin_role"

# Grab parameters
COMMAND_TO_RUN=$*

# Save current AWS credentials
CURRENT_AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
CURRENT_AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
CURRENT_AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN

#Assume role, run command, and switch back
printf "\n Assuming role..."
if CREDENTIALS=`aws sts assume-role --role-arn $HST_ADMIN_ARN --role-session-name temp_admin_session --duration-seconds 3599` ; then

export AWS_ACCESS_KEY_ID=`echo ${CREDENTIALS} | python -c "import sys, json, os; temp=json.load(sys.stdin)['Credentials']['AccessKeyId'];print(temp)"`
export AWS_SECRET_ACCESS_KEY=`echo ${CREDENTIALS} | python -c "import sys, json, os; temp=json.load(sys.stdin)['Credentials']['SecretAccessKey'];print(temp)"`
export AWS_SESSION_TOKEN=`echo ${CREDENTIALS} | python -c "import sys, json, os; temp=json.load(sys.stdin)['Credentials']['SessionToken'];print(temp)"`

printf "\n Role assumed:"
aws sts get-caller-identity

printf "\n Running command\n"
$COMMAND_TO_RUN

printf "\n Switching back to original role"
export AWS_ACCESS_KEY_ID=$CURRENT_AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$CURRENT_AWS_SECRET_ACCESS_KEY
export AWS_SESSION_TOKEN=$CURRENT_AWS_SESSION_TOKEN

printf "\n Role switched back:"
aws sts get-caller-identity

else
printf "\n==========================\n\n - Error assuming role. Aborting execution\n\n"
exit 1
fi

0 comments on commit 8e55401

Please sign in to comment.