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

Using Secret Manager with Cloud Run at runtime not buildtime #84

Open
MarkEdmondson1234 opened this issue Jul 31, 2020 · 6 comments
Open
Labels
enhancement New feature or request

Comments

@MarkEdmondson1234
Copy link
Owner

Something based on this? https://medium.com/google-cloud/secret-manager-improve-cloud-run-security-without-changing-the-code-634f60c541e6

Ideally don't want any secrets embedded at build time, only runtime.

@marton-balazs-kovacs
Copy link

Hi,

I am trying to do something similar by building and deploying a Dockerfile that runs a plumber API, in which I would like to push to a public git repository. I stored my ssh as a secret but I am not quite sure how to get it in my API. Do you have any recommendations? Thanks for your help!

@MarkEdmondson1234
Copy link
Owner Author

I'm not 100% what you are trying to do but you could download auth keys from google cloud storage using googleCloudStorageR when the plumber instance starts and Cloud Run would be authorised with the Cloud Run service email you grant bucket access too. That is similar to how it would work with Secrets Manager, but no R wrapper function exists yet aside one you make yourself with googleAuthR, and I guess you would want that.

I would prefer the secrets not being in the Docker at build time, but only at run time for security. It may be via the link above that you can do this via gcloud and changing the Dockerfile a bit.

@marton-balazs-kovacs
Copy link

Thank you for the response.

I want to combine basically the cr_buildstep_gitsetup the cr_buildstep_docker and the cr_buildstep_run to deploy a plumber API that pushes to a Github repo upon requests. I tried to combine them based on the detailed vignettes but I got lost. Sorry if I am misunderstanding something obvious.

@MarkEdmondson1234
Copy link
Owner Author

MarkEdmondson1234 commented Sep 13, 2020

There is a demo of this in the recent update for parallel cloud run with authenticated calls, code in inst/docker/parallel_cloudrun/build.R

library(googleCloudRunner)

bs <- c(
  cr_buildstep_secret("mark-edmondson-gde-auth",
      decrypted = "inst/docker/parallel_cloudrun/plumber/auth.json"),
  cr_buildstep_docker("cloudrun_parallel",
                      dir = "inst/docker/parallel_cloudrun/plumber",
                      kaniko_cache = TRUE),
  cr_buildstep_run("parallel-cloudrun",
                   image = "gcr.io/$PROJECT_ID/cloudrun_parallel:$BUILD_ID",
                   allowUnauthenticated = FALSE,
                   env_vars = "BQ_AUTH_FILE=auth.json,BQ_DEFAULT_PROJECT_ID=$PROJECT_ID")
)

by <- cr_build_yaml(bs)
cr_build_write(by, file = "inst/docker/parallel_cloudrun/cloudbuild.yml")

repo <- cr_buildtrigger_repo("MarkEdmondson1234/googleCloudRunner")
cr_buildtrigger("inst/docker/parallel_cloudrun/cloudbuild.yml",
                "parallel-cloudrun",
                trigger = repo,
                includedFiles = "inst/docker/parallel_cloudrun/**")

# get the Cloud Run URL
cr <- cr_run_get("parallel-cloudrun")

This still includes the auth file within the Cloud Run docker container which is what the original issue is trying to avoid, but it works.

@MarkEdmondson1234
Copy link
Owner Author

@marton-balazs-kovacs the above is included in this new use case https://code.markedmondson.me/googleCloudRunner/articles/usecases.html#run-private-r-micro-services-on-cloud-run-1

@marton-balazs-kovacs
Copy link

That is amazing! Thank you. I will give it a try!

@MarkEdmondson1234 MarkEdmondson1234 added the enhancement New feature or request label Feb 9, 2021
@MarkEdmondson1234 MarkEdmondson1234 changed the title Using Secret Manager with Cloud Run Using Secret Manager with Cloud Run at runtime not buildtime Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants