Skip to content

Commit 1d000aa

Browse files
committedMay 3, 2024
fix: gcp sa flow key cleanup
1 parent 7d3e1d8 commit 1d000aa

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed
 

‎references/gcp-sa-auth-shared-flow/pipeline.sh

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ SA_EMAIL="$SA_NAME@$PROJECT_ID.iam.gserviceaccount.com"
2222
SCRIPTPATH="$( cd "$(dirname "$0")" || exit >/dev/null 2>&1 ; pwd -P )"
2323
export PATH="$PATH:$SCRIPTPATH/../../tools/apigee-sackmesser/bin"
2424

25-
# create a service account without any roles and download the key
25+
26+
27+
# create a service account without any roles if it doesn't exist
2628
EXISTING_EMAIL=$(gcloud iam service-accounts list --filter="email=$SA_EMAIL" --format="get(email)")
2729
if [ "$EXISTING_EMAIL" != "$SA_EMAIL" ]; then
2830
gcloud iam service-accounts create "$SA_NAME"
2931
fi
32+
33+
# Cleaning up existing service account keys for that SA
34+
for SA_KEY_NAME in $(gcloud iam service-accounts keys list --iam-account="$SA_EMAIL" --format="get(name)" --filter="keyType=USER_MANAGED")
35+
do
36+
gcloud iam service-accounts keys delete "$SA_KEY_NAME" --iam-account="$SA_EMAIL" -q
37+
done
38+
39+
# Create and download service account key
3040
gcloud iam service-accounts keys create "$SCRIPTPATH/$SA_NAME-key.json" \
3141
--iam-account "$SA_EMAIL"
3242

@@ -48,9 +58,4 @@ sackmesser deploy --googleapi -d "$SCRIPTPATH"/test/token-validation \
4858

4959

5060
curl -k --fail "https://$APIGEE_X_HOSTNAME/token-validation/v0/oauth"
51-
curl -k --fail "https://$APIGEE_X_HOSTNAME/token-validation/v0/jwt"
52-
53-
for SA_KEY_NAME in $(gcloud iam service-accounts keys list --iam-account="$SA_EMAIL" --format="get(name)" --filter="keyType=USER_MANAGED")
54-
do
55-
gcloud iam service-accounts keys delete "$SA_KEY_NAME" --iam-account="$SA_EMAIL" -q
56-
done
61+
curl -k --fail "https://$APIGEE_X_HOSTNAME/token-validation/v0/jwt"

0 commit comments

Comments
 (0)