Open anthonyWalter opened 1 year ago
I just faced the same issue, after considerable digging, I found this SO answer that successfully passed secretEnv to kaniko via docker run
https://stackoverflow.com/a/69242433
the relevant code in the ans:
- id: Build
name: gcr.io/cloud-builders/docker
entrypoint: /bin/bash
args:
- -c
- |
docker run \
--network=cloudbuild \
-v /workspace:/workspace \
gcr.io/kaniko-project/executor:latest \
--dockerfile /workspace/Dockerfile \
--build-arg=GITHUBTOKEN=$$GITHUBTOKEN \
--destination=gcr.io/$PROJECT_ID/myapp:$SHORT_SHA \
--cache=true \
--context dir:///workspace/
secretEnv: ['GITHUBTOKEN']
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/github_machine_user_pat/versions/latest
env: GITHUBTOKEN
@anthonyWalter
a side question related to using secretEnv
, what are reasons to use secretEnv
for passing secrets (like keys, private token, etc)?
I understand that saving secrets in repo is a big no no, but why are passing them as plain text env var insider the ephemeral GCP Cloud Build environment is a concern?
I assume that implies the env var contents are actually leaked/exposed to some external system? (maybe the in the logs?)
Thanks!
Expected $$CONTENTFUL_CONTENT_DELIVERY_API_LEY and $$CONTENTFUL_SPACE_ID to be replaced by the actual secret value
In the docs you linked, it's running bash -c ...
to expand the environment variables instead of running kaniko/executor
. That's how those are being expanded in that case.
I assume that implies the env var contents are actually leaked/exposed to some external system?
Build args and env vars are stored into the docker image, generally the secrets used to build the image sometimes aren't meant to be accessible to people using the image (especially if you are building a public image).
based on #993 you can do it like so:
- name: "gcr.io/kaniko-project/executor:latest"
args:
- --destination=gcr.io/$PROJECT_ID/community-image
- --cache=true
- --build-arg=CONTENTFUL_CONTENT_DELIVERY_API_KEY
- --build-arg=CONTENTFUL_SPACE_ID
secretEnv: ["CONTENTFUL_CONTENT_DELIVERY_API_KEY", "CONTENTFUL_SPACE_ID"]
when build-arg is left without value, it will look for environment variables
Actual behavior
Expected behavior
Expected $$CONTENTFUL_CONTENT_DELIVERY_API_LEY and $$CONTENTFUL_SPACE_ID to be replaced by the actual secret value like stated in gcloud docs : https://cloud.google.com/build/docs/securing-builds/use-secrets#access-utf8-secrets
If not what is the detailed solution to pass secrets from gcp cloudrun to cloudbuild kaniko
To Reproduce Run the build and wait for value to be replaced by $VALUE_NAME instead of the actual value
Additional Information
Docker file
Triage Notes for the Maintainers
--cache
flag