From 9461f01d3602aef9437e448b8ba461831fbe79a1 Mon Sep 17 00:00:00 2001 From: Cole Wagner Date: Fri, 14 May 2021 17:09:59 -0700 Subject: [PATCH] =?UTF-8?q?Update=20create-build-cluster.sh=20to=20make=20?= =?UTF-8?q?pod=20utils=20use=20workload=20identit=E2=80=A6=20(#22177)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update create-build-cluster.sh to make pod utils use workload identity and generate default decoration config. * Update prow/create-build-cluster.sh, change CL to PR. Co-authored-by: Chao Dai <45011425+chaodaiG@users.noreply.github.com> Co-authored-by: Chao Dai <45011425+chaodaiG@users.noreply.github.com> --- prow/create-build-cluster.sh | 74 ++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/prow/create-build-cluster.sh b/prow/create-build-cluster.sh index dd306f753924..8947333f141e 100755 --- a/prow/create-build-cluster.sh +++ b/prow/create-build-cluster.sh @@ -25,12 +25,9 @@ set -o errexit set -o nounset set -o pipefail -ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" - # Specific to Prow instance PROW_INSTANCE_NAME="${PROW_INSTANCE_NAME:-}" CONTROL_PLANE_SA="${CONTROL_PLANE_SA:-}" -GCS_BUCKET="${GCS_BUCKET:-gs://${PROW_INSTANCE_NAME}}" PROW_SECRET_ACCESSOR_SA="${PROW_SECRET_ACCESSOR_SA:-kubernetes-external-secrets-sa@k8s-prow.iam.gserviceaccount.com}" PROW_DEPLOYMENT_DIR="${PROW_DEPLOYMENT_DIR:-./config/prow/cluster}" @@ -42,6 +39,7 @@ TEAM="${TEAM:-}" PROJECT="${PROJECT:-${PROW_INSTANCE_NAME}-build-${TEAM}}" ZONE="${ZONE:-us-west1-b}" CLUSTER="${CLUSTER:-${PROJECT}}" +GCS_BUCKET="${GCS_BUCKET:-gs://${PROJECT}}" # Only needed for creating cluster MACHINE="${MACHINE:-n1-standard-8}" @@ -67,12 +65,26 @@ if ! (${SED} --version 2>&1 | grep -q GNU); then return 1 fi +# Create temp dir to work in and clone k/t-i + +origdir="$( pwd -P )" +tempdir="$( mktemp -d )" +echo +echo "Temporary files produced are stored at: ${tempdir}" +echo +cd "${tempdir}" +git clone https://github.com/kubernetes/test-infra --depth=1 +cd "${origdir}" + +ROOT_DIR="${tempdir}/test-infra" + function main() { parseArgs "$@" prompt "Create project" createProject prompt "Create/ensure GCS job result bucket" ensureBucket prompt "Create cluster" createCluster - prompt "Create a SA and secret for uploading results to GCS" createUploadSASecret + prompt "Create a service account for uploading results to GCS" createUploadSA + prompt "Generate necessary core Prow configuration" genConfig prompt "Generate kubeconfig credentials for Prow" gencreds echo "All done!" } @@ -151,15 +163,26 @@ function ensureBucket() { fi fi } -function createUploadSASecret() { +function createUploadSA() { getClusterCreds - local sa="prow-pod-utils" + local sa="prowjob-default-sa" local saFull="${sa}@${PROJECT}.iam.gserviceaccount.com" - # Create a service account for uploading to GCS. - gcloud beta iam service-accounts create "${sa}" --project="${PROJECT}" --description="SA for Prow's pod utilities to use to upload job results to GCS." --display-name="Prow Pod Utilities" - # Generate private key and attach to the service account. - gcloud iam service-accounts keys create "sa-key.json" --project="${PROJECT}" --iam-account="${saFull}" - kubectl create secret generic "service-account" -n "test-pods" --from-file="service-account.json=sa-key.json" + # Create a GCP service account for uploading to GCS + gcloud beta iam service-accounts create "${sa}" --project="${PROJECT}" --description="Default SA for ProwJobs to use to upload job results to GCS." --display-name="ProwJob default SA" + # Ensure workload identity is enabled on the cluster + "${ROOT_DIR}/workload-identity/enable-workload-identity.sh" "${PROJECT}" "${ZONE}" "${CLUSTER}" + # Create a k8s service account to associate with the GCP service account + kubectl apply -f - <&2 cat "$origdir/$outfile" >&2