Creating GCS Signed-URLs in Cloud Build with Bash fails with cryptic error gce

46 Views Asked by At

I am attempting to create a file that contains a couple of signed URLs to GET and PUT files into Google Cloud Storage using Cloud Build. I have developed the process and everything worked as expected on my local and in Cloud Build except for GCLOUD STORAGE SIGN-URL when using a bash script to generate it with the gcr.io/cloud-builders/gcloud image. For some reason it just spits out ERROR: (gcloud.storage.sign-url) gce

I have created an isolated test cloud build yaml to test this all in isolation as follows:

steps:
  - name: gcr.io/cloud-builders/gcloud
    args:
      - storage
      - sign-url
      - 'gs://bkt-n-XXXX/Exports.zip'
      - '--private-key-file=./prj-n-XXXX-12345.json'
      - '--http-verb=PUT'
      - '--duration=7h'
      - >-
        --headers=content-type=application/zip,host=storage.googleapis.com,x-goog-content-sha256=UNSIGNED-PAYLOAD
    id: Gcloud - Print to build Log
    entrypoint: gcloud
  - name: gcr.io/cloud-builders/gcloud
    id: Bash - Print to build log
    script: >
      #!/usr/bin/env bash

      gcloud storage sign-url
      gs://bkt-n-XXXX/Exports.zip 
      --private-key-file=./prj-n-XXXX-12345.json
      --http-verb=PUT  --duration=7h
      --headers=content-type=application/zip,host=storage.googleapis.com,x-goog-content-sha256=UNSIGNED-PAYLOAD
timeout: 18000s
logsBucket: bkt-n-XXXX/logs-XXXX/

With the following result; Step 0 prints the URL out fine but Step 1 fails with the GKE error. I need to use bash so I can > redirect it into a file for further processing.

BUILD
Starting Step #0 - "Gcloud - Print to build Log"
Step #0 - "Gcloud - Print to build Log": Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #0 - "Gcloud - Print to build Log": ---
Step #0 - "Gcloud - Print to build Log": expiration: '2024-01-12 09:05:34'
Step #0 - "Gcloud - Print to build Log": http_verb: PUT
Step #0 - "Gcloud - Print to build Log": resource: gs://bkt-n-XXXX/Exports.zip
Step #0 - "Gcloud - Print to build Log": signed_url: https://storage.googleapis.com/bkt-n-XXXX/Exports.zip?x-goog-signature=XX...XX
Finished Step #0 - "Gcloud - Print to build Log"
Starting Step #1 - "Bash - Print to build log"
Step #1 - "Bash - Print to build log": Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #1 - "Bash - Print to build log": ERROR: (gcloud.storage.sign-url) gce
Finished Step #1 - "Bash - Print to build log"
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 1

Any suggestions around this would be appreciated as running this particular Gcloud command (I've tried other to make sure the above should work) from bash seems to be strangely broken. I would prefer to not introduce python or some other language to just to this single step.

0

There are 0 best solutions below