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

DAOSGCP-102 Changed packer scripts to use IAP with private IP #36

Merged
merged 2 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
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
36 changes: 12 additions & 24 deletions images/build_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,19 @@ configure_gcp_project() {
--role roles/iam.serviceAccountUser
fi

FWRULENAME="gcp-cloudbuild-ssh"

# Check if we have an ssh firewall rule for cloudbuild in place already
FWLIST=$(gcloud compute --project="${GCP_PROJECT}" \
firewall-rules list \
--filter name="${FWRULENAME}" \
--sort-by priority \
--format='value(name)')

if [[ -z ${FWLIST} ]]; then
# Setup firewall rule to allow ssh from clould build.
# FIXME: Needs to be fixed to restric to IP range
# for clound build only once we know what that is.
log "Setting up firewall rule for ssh and clouldbuild"
gcloud compute --project="${GCP_PROJECT}" firewall-rules create "${FWRULENAME}" \
--direction=INGRESS --priority=1000 --network=default --action=ALLOW \
--rules=tcp:22 --source-ranges=0.0.0.0/0
else
log "Firewall rule for ssh and cloud build already in place."
CHECK_ROLE_IAP_TUNL_RESR_ACCS=$(
gcloud projects get-iam-policy "${GCP_PROJECT}" \
--flatten="bindings[].members" \
--filter="bindings.role=roles/iap.tunnelResourceAccessor AND \
bindings.members=${CLOUD_BUILD_ACCOUNT}" \
--format="value(bindings.members[])"
)
if [[ "${CHECK_ROLE_IAP_TUNL_RESR_ACCS}" != "${CLOUD_BUILD_ACCOUNT}" ]]; then
gcloud projects add-iam-policy-binding "${GCP_PROJECT}" \
--member "${CLOUD_BUILD_ACCOUNT}" \
--role roles/iap.tunnelResourceAccessor
fi

}

build_images() {
Expand All @@ -321,10 +314,6 @@ build_images() {
fi
}

remove_firewall() {
gcloud -q compute --project="${GCP_PROJECT}" firewall-rules delete "${FWRULENAME}"
}

list_images() {
log "Image(s) created"
gcloud compute images list \
Expand All @@ -340,7 +329,6 @@ main() {
log_section "Building DAOS Image(s)"
configure_gcp_project
build_images
remove_firewall
list_images
}

Expand Down
4 changes: 4 additions & 0 deletions images/daos-client-image.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ source "googlecompute" "daos-client-hpc-centos-7" {
source_image_project_id = ["cloud-hpc-image-public"]
ssh_username = "packer"
zone = "${var.zone}"
state_timeout = "10m"
use_internal_ip = true
omit_external_ip = true
use_iap = true
}

build {
Expand Down
4 changes: 4 additions & 0 deletions images/daos-server-image.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ source "googlecompute" "daos-server-centos-7" {
source_image_project_id = ["centos-cloud"]
ssh_username = "packer"
zone = "${var.zone}"
state_timeout = "10m"
use_internal_ip = true
omit_external_ip = true
use_iap = true
}

build {
Expand Down