Search code examples
dockergoogle-cloud-platformgoogle-cloud-build

Cloud Build docker image unable to write files locally - fail to open file... permission denied


Using Service Account credentials, I am successful at running Cloud Build to spin up gsutil, move files from gs into the instance, then copy them back out. All is good.

One of the Cloud Build steps successfully loads a docker image from outside source, it loads fine and reports its own help info successfully. But when run, it fails with the error message: "fail to open file "..intermediary_work_product_file." permission denied.

For the app I'm running in this step, this error is typically produced when the file cannot be written to its default location. I've set dir = "/workspace" to confirm the default.

So how do I grant read/write permissions to the app running inside a Cloud Build step to write its own intermediary work product to the local folders? The Cloud Build itself is running fine using Service Account credentials. Have tried adding more permissions including with Storage, Cloud Run, Compute Engine, App Engine admin roles. But the same error.

I assume that the credentials used to create the instance are passed to the run time. Have dug deep into the GCP CloudBuild documentation and examples, but found no answers.

There must be something fundamental I'm overlooking.


Solution

  • I had a similar problem; the snippet I was looking for in my cloudbuild manifest was:

      - id: perms
        name: "gcr.io/cloud-builders/git"
        entrypoint: "chmod"
        args: ["-v", "-R", "a+rw", "."]
        dir: "path/to/some/dir"