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

Ensure GCS release bucket has public-read defacl #206

Merged
merged 1 commit into from
Nov 15, 2016
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
2 changes: 1 addition & 1 deletion anago
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ check_prerequisites () {
# Verify write access to $RELEASE_BUCKET
# Insufficient for checking actual writability, but useful:
# ganpati list-members -g cloud-kubernetes-release -u $USER|fgrep -wq $USER
logecho -n "Checking writability to $RELEASE_BUCKET: "
logecho -n "Checking writability and ACLs on $RELEASE_BUCKET: "
if logrun release::gcs::ensure_release_bucket $RELEASE_BUCKET && \
logrun touch $tempfile && \
logrun gsutil cp $tempfile gs://$RELEASE_BUCKET && \
Expand Down
23 changes: 21 additions & 2 deletions lib/releaselib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,32 @@ release::set_release_version () {
}

###############################################################################
# Create a unique bucket name for releasing Kube and make sure it exists.
# Create GCS bucket for releasing Kube if necessary. Ensure that the default
# ACL allows public reading of artifacts.
# @param bucket - The gs release bucket name
# @return 1 if bucket can't be made
release::gcs::ensure_release_bucket() {
local bucket=$1
local current_defacl
local new_acl_file

if ! $GSUTIL ls "gs://$bucket" >/dev/null 2>&1 ; then
logecho -n "Creating Google Cloud Storage bucket $bucket: "
logrun -s $GSUTIL mb -p "$GCLOUD_PROJECT" "gs://$bucket" || return 1
logecho -n "Adding public-read default ACL on bucket $bucket: "
current_defacl=$(gsutil defacl get "gs://$bucket") || return 1
new_acl_file=$(mktemp)
echo "$current_defacl" | jq '. + [{"entity": "allUsers", "role": "READER"}]' \
> "$new_acl_file" || return 1
logrun -s $GSUTIL defacl set "$new_acl_file" "gs://$bucket" || return 1
logrun rm -f "$new_acl_file"
fi

if [[ $($GSUTIL defacl get "gs://$bucket" 2>/dev/null |\
jq -r '.[] | select(.entity == "allUsers") | .role') != 'READER' ]]; then
logecho "GCS bucket $bucket is missing default public-read ACL."
logecho "Please add allUsers: READER to the gs://$bucket defacl and try again."
return 1
fi
}

Expand Down Expand Up @@ -476,8 +493,10 @@ release::gcs::copy_release_artifacts() {
done

# Copy the main set from staging to destination
# We explicitly don't set an ACL in the cp call, since doing so will override
# any default bucket ACLs.
logecho -n "- Copying public release artifacts to $gcs_destination: "
logrun -s $GSUTIL -qm cp -a public-read -r $gcs_stage/* $gcs_destination/ || return 1
logrun -s $GSUTIL -qm cp -r $gcs_stage/* $gcs_destination/ || return 1

# This small sleep gives the eventually consistent GCS bucket listing a chance
# to stabilize before the diagnostic listing. There's no way to directly
Expand Down