1*af546375SCole Faust#!/bin/bash 2*af546375SCole Faust 3*af546375SCole Faust# Copyright 2021 Google LLC 4*af546375SCole Faust# 5*af546375SCole Faust# Redistribution and use in source and binary forms, with or without 6*af546375SCole Faust# modification, are permitted provided that the following conditions are 7*af546375SCole Faust# met: 8*af546375SCole Faust# 9*af546375SCole Faust# * Redistributions of source code must retain the above copyright 10*af546375SCole Faust# notice, this list of conditions and the following disclaimer. 11*af546375SCole Faust# * Redistributions in binary form must reproduce the above 12*af546375SCole Faust# copyright notice, this list of conditions and the following disclaimer 13*af546375SCole Faust# in the documentation and/or other materials provided with the 14*af546375SCole Faust# distribution. 15*af546375SCole Faust# * Neither the name of Google LLC nor the names of its 16*af546375SCole Faust# contributors may be used to endorse or promote products derived from 17*af546375SCole Faust# this software without specific prior written permission. 18*af546375SCole Faust# 19*af546375SCole Faust# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20*af546375SCole Faust# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21*af546375SCole Faust# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22*af546375SCole Faust# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23*af546375SCole Faust# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24*af546375SCole Faust# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25*af546375SCole Faust# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26*af546375SCole Faust# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27*af546375SCole Faust# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28*af546375SCole Faust# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29*af546375SCole Faust# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30*af546375SCole Faust 31*af546375SCole Faust# This script is used to generate the project configurations needed to 32*af546375SCole Faust# end-to-end test Downscoping with Credential Access Boundaries in the Auth 33*af546375SCole Faust# library. 34*af546375SCole Faust# 35*af546375SCole Faust# In order to run this script, you need to fill in the project_id and 36*af546375SCole Faust# service_account_email variables. 37*af546375SCole Faust# 38*af546375SCole Faust# This script needs to be run once. It will do the following: 39*af546375SCole Faust# 1. Sets the current project to the one specified. 40*af546375SCole Faust# 2. Creates a GCS bucket in the specified project. 41*af546375SCole Faust# 3. Gives the specified service account the objectAdmin role for this bucket. 42*af546375SCole Faust# 4. Creates two text files to be uploaded to the created bucket. 43*af546375SCole Faust# 5. Uploads both text files. 44*af546375SCole Faust# 6. Prints out the identifiers (bucket ID, first object ID, second object ID) 45*af546375SCole Faust# to be used in the accompanying tests. 46*af546375SCole Faust# 7. Deletes the created text files in the current directory. 47*af546375SCole Faust# 48*af546375SCole Faust# The same service account used for this setup script should be used for 49*af546375SCole Faust# the integration tests. 50*af546375SCole Faust# 51*af546375SCole Faust# It is safe to run the setup script again. A new bucket is created along with 52*af546375SCole Faust# new objects. If run multiple times, it is advisable to delete 53*af546375SCole Faust# unused buckets. 54*af546375SCole Faust 55*af546375SCole Faustsuffix="" 56*af546375SCole Faust 57*af546375SCole Faustfunction generate_random_string () { 58*af546375SCole Faust local valid_chars=abcdefghijklmnopqrstuvwxyz0123456789 59*af546375SCole Faust for i in {1..8} ; do 60*af546375SCole Faust suffix+="${valid_chars:RANDOM%${#valid_chars}:1}" 61*af546375SCole Faust done 62*af546375SCole Faust} 63*af546375SCole Faust 64*af546375SCole Faustgenerate_random_string 65*af546375SCole Faust 66*af546375SCole Faustbucket_id="cab-int-bucket-"${suffix} 67*af546375SCole Faustfirst_object="cab-first-"${suffix}.txt 68*af546375SCole Faustsecond_object="cab-second-"${suffix}.txt 69*af546375SCole Faust 70*af546375SCole Faust# Fill in. 71*af546375SCole Faustproject_id="" 72*af546375SCole Faustservice_account_email="" 73*af546375SCole Faust 74*af546375SCole Faustgcloud config set project ${project_id} 75*af546375SCole Faust 76*af546375SCole Faust# Create the GCS bucket. 77*af546375SCole Faustgsutil mb -b on -l us-east1 gs://${bucket_id} 78*af546375SCole Faust 79*af546375SCole Faust# Give the specified service account the objectAdmin role for this bucket. 80*af546375SCole Faustgsutil iam ch serviceAccount:${service_account_email}:objectAdmin gs://${bucket_id} 81*af546375SCole Faust 82*af546375SCole Faust# Create both objects. 83*af546375SCole Faustecho "first" >> ${first_object} 84*af546375SCole Faustecho "second" >> ${second_object} 85*af546375SCole Faust 86*af546375SCole Faust# Upload the created objects to the bucket. 87*af546375SCole Faustgsutil cp ${first_object} gs://${bucket_id} 88*af546375SCole Faustgsutil cp ${second_object} gs://${bucket_id} 89*af546375SCole Faust 90*af546375SCole Faustecho "Bucket ID: "${bucket_id} 91*af546375SCole Faustecho "First object ID: "${first_object} 92*af546375SCole Faustecho "Second object ID: "${second_object} 93*af546375SCole Faust 94*af546375SCole Faust# Cleanup. 95*af546375SCole Faustrm ${first_object} 96*af546375SCole Faustrm ${second_object} 97