Skip to content

Commit

Permalink
Merge pull request #43 from CedrickArmel/feat/etl
Browse files Browse the repository at this point in the history
fix: sa impersonnation by wi
  • Loading branch information
CedrickArmel authored Oct 12, 2024
2 parents 5a758e4 + 7fad25d commit 51a7004
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/etl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jobs:
chmod +x scripts/trigger.sh
./scripts/trigger.sh -p ${{ secrets.PROJECT_ID }} \
-r ${{ secrets.REGION }} \
-t build-beam-image
-t build-beam-image \
-i ${{ secrets.SERVICE_ACCOUNT }}
-
name: Install Poetry
run: |
Expand Down
3 changes: 1 addition & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ resource "google_iam_workload_identity_pool_provider" "gcp_gha_oidc_provider" {
attribute_mapping = {
"google.subject" = "assertion.sub"
"attribute.aud" = "assertion.aud"
"attribute.actor" = "assertion.actor"
}
attribute_condition = "assertion.sub=='${var.gha_assertion_sub}' && assertion.aud=='${var.gha_assertion_aud}' && assertion.actor=='${var.gha_assertion_actor}'"
attribute_condition = "assertion.sub=='${var.gha_assertion_sub}' && assertion.aud=='${var.gha_assertion_aud}'"
oidc {
issuer_uri = "https://token.actions.githubusercontent.com"
}
Expand Down
16 changes: 11 additions & 5 deletions scripts/trigger.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
usage() {
echo "Usage: $0 -p <project> -r <region> -t <trigger> [-b <branch>] [-s <substitutions>]"
echo "Usage: $0 -p <project> -r <region> -t <trigger> [-b <branch>] [-s <substitutions>] [-i <impersonate-service-account>]"
exit 1
}

Expand All @@ -11,6 +11,7 @@ while getopts "p:r:t:b:s:" opt; do
t) trigger="$OPTARG";;
b) branch="$OPTARG";;
s) substitutions="$OPTARG";;
i) impersonate="$OPTARG";;
*) usage;;
esac
done
Expand All @@ -25,18 +26,23 @@ export CLOUDSDK_CORE_DISABLE_PROMPTS=1
# Set the project
gcloud config set project "$project"

IMPERSONATE_FLAG=""
if [ -n "$impersonate" ]; then
IMPERSONATE_FLAG="--impersonate-service-account=$impersonate"
fi

# Run the gcloud command based on whether the branch and substitutions are provided
if [ -z "$substitutions" ]; then
if [ -z "$branch" ]; then
BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --quiet --format="value(metadata.build.id)")
BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" $IMPERSONATE_FLAG --quiet --format="value(metadata.build.id)")
else
BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --branch="$branch" --quiet --format="value(metadata.build.id)")
BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --branch="$branch" $IMPERSONATE_FLAG --quiet --format="value(metadata.build.id)")
fi
else
if [ -z "$branch" ]; then
BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --substitutions="$substitutions" --quiet --format="value(metadata.build.id)")
BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --substitutions="$substitutions" $IMPERSONATE_FLAG --quiet --format="value(metadata.build.id)")
else
BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --substitutions="$substitutions" --branch="$branch" --quiet --format="value(metadata.build.id)")
BUILD_ID=$(gcloud beta builds triggers run "$trigger" --region="$region" --substitutions="$substitutions" $IMPERSONATE_FLAG --branch="$branch" --quiet --format="value(metadata.build.id)")
fi
fi

Expand Down
11 changes: 3 additions & 8 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ variable "gcp_enabled_services" {
"dataform.googleapis.com",
"datapipelines.googleapis.com",
"cloudscheduler.googleapis.com",
"iamcredentials.googleapis.com",
"iam.googleapis.com",
"iap.googleapis.com",
"ml.googleapis.com",
Expand Down Expand Up @@ -68,6 +69,7 @@ variable "gcp_service_accounts" {
"roles/logging.logWriter",
"roles/ml.developer",
"roles/secretmanager.secretAccessor",
"roles/iam.serviceAccountTokenCreator",
"roles/storage.admin",
]
sa_id = "neurips-ml-sa"
Expand All @@ -86,16 +88,9 @@ variable "gha_assertion_aud" {
variable "gha_assertion_sub" {
description = "GHA workload identity JWk token sub attribute"
type = string
default = "CedrickArmel/neurips_adc:ref:refs/heads/main"
default = "repo:CedrickArmel/neurips_adc:ref:refs/heads/main"
}

variable "gha_assertion_actor" {
description = "GHA workload identity JWk token actor attribute"
type = string
default = "CedrickArmel"
}


#########
# Secrets
variable "gcp_iam_infra_sa_account_id" {
Expand Down

0 comments on commit 51a7004

Please sign in to comment.