Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gcp sa flow key cleanup #734

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions references/gcp-sa-auth-shared-flow/pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ SA_EMAIL="$SA_NAME@$PROJECT_ID.iam.gserviceaccount.com"
SCRIPTPATH="$( cd "$(dirname "$0")" || exit >/dev/null 2>&1 ; pwd -P )"
export PATH="$PATH:$SCRIPTPATH/../../tools/apigee-sackmesser/bin"

# create a service account without any roles and download the key


# create a service account without any roles if it doesn't exist
EXISTING_EMAIL=$(gcloud iam service-accounts list --filter="email=$SA_EMAIL" --format="get(email)")
if [ "$EXISTING_EMAIL" != "$SA_EMAIL" ]; then
gcloud iam service-accounts create "$SA_NAME"
fi

# Cleaning up existing service account keys for that SA
for SA_KEY_NAME in $(gcloud iam service-accounts keys list --iam-account="$SA_EMAIL" --format="get(name)" --filter="keyType=USER_MANAGED")
do
gcloud iam service-accounts keys delete "$SA_KEY_NAME" --iam-account="$SA_EMAIL" -q
done

# Create and download service account key
gcloud iam service-accounts keys create "$SCRIPTPATH/$SA_NAME-key.json" \
--iam-account "$SA_EMAIL"

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


curl -k --fail "https://$APIGEE_X_HOSTNAME/token-validation/v0/oauth"
curl -k --fail "https://$APIGEE_X_HOSTNAME/token-validation/v0/jwt"

for SA_KEY_NAME in $(gcloud iam service-accounts keys list --iam-account="$SA_EMAIL" --format="get(name)" --filter="keyType=USER_MANAGED")
do
gcloud iam service-accounts keys delete "$SA_KEY_NAME" --iam-account="$SA_EMAIL" -q
done
curl -k --fail "https://$APIGEE_X_HOSTNAME/token-validation/v0/jwt"
Loading