Skip to content

Commit

Permalink
Merge pull request #1061 from spiffxp/empower-prow-viewers
Browse files Browse the repository at this point in the history
Create a prow.viewer custom org role
  • Loading branch information
k8s-ci-robot authored Jul 24, 2020
2 parents 0d432af + 2fb1f55 commit 2ca6276
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ resource "google_project_iam_member" "k8s_infra_prow_oncall" {
member = "group:k8s-infra-prow-oncall@kubernetes.io"
}

// Ensure k8s-infra-prow-viewers@kuberentes.io has prow.viewer access to this project
resource "google_project_iam_member" "k8s_infra_prow_viewers" {
project = local.project_id
# TODO: use data resource to get org role name instead of hardcode
role = "organizations/758905017065/roles/prow.viewer"
member = "group:k8s-infra-prow-viewers@kubernetes.io"
}

// Create GCP SA for pods
resource "google_service_account" "prow_build_cluster_sa" {
project = local.project_id
Expand Down
8 changes: 7 additions & 1 deletion infra/gcp/ensure-e2e-projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ function usage() {
echo > /dev/stderr
}

## setup custom role for prow troubleshooting
color 6 "Ensuring custom org role prow.viewer role exists"
(
ensure_custom_org_role_from_file "prow.viewer" "${SCRIPT_DIR}/roles/prow.viewer.yaml"
) 2>&1 | indent

## setup service accounts and ips for the prow build cluster

PROW_BUILD_SVCACCT=$(svc_acct_email "k8s-infra-prow-build" "prow-build")
Expand Down Expand Up @@ -133,7 +139,7 @@ for prj; do
gcloud \
projects add-iam-policy-binding "${prj}" \
--member "group:k8s-infra-prow-viewers@kubernetes.io" \
--role roles/viewer
--role $(custom_org_role_name "prow.viewer")

if [[ "${prj}" =~ k8s-infra-e2e.*scale ]]; then
color 6 "Empower k8s-infra-sig-scalability-oncall@kubernetes.io to admin e2e project: ${prj}"
Expand Down
36 changes: 36 additions & 0 deletions infra/gcp/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,39 @@ function ensure_custom_iam_role() {
--permissions "${permissions}"
fi
}

# Ensure that custom IAM role exists and is in sync with definition in file
# Arguments:
# $1: The role name (e.g. "prow.viewer")
# $2: The file (e.g. "/path/to/file.yaml")
function ensure_custom_org_role_from_file() {
if [ ! $# -eq 2 -o -z "$1" -o -z "$2" ]; then
echo "ensure_custom_org_role_from_file(name, file) requires 2 arguments" >&2
return 1
fi

local org="${GCP_ORG}"
local name="${1}"
local file="${2}"

if ! gcloud iam roles describe "${name}" --organization "${org}" \
>/dev/null 2>&1
then
# be noisy when creating a role
gcloud iam roles create "${name}" --organization "${org}" --file "${file}"
else
# be quiet when updating, only output name of role
gcloud iam roles update "${name}" --organization "${org}" --file "${file}" | grep ^name:
fi
}

function custom_org_role_name() {
if [ ! $# -eq 1 -o -z "$1" ]; then
echo "custom_org_role_name(name) requires 1 arguments" >&2
return 1
fi

local name="${1}"

echo "organizations/${GCP_ORG}/roles/${name}"
}
Loading

0 comments on commit 2ca6276

Please sign in to comment.