Support for sharing secrets between jobs #13082
Replies: 11 comments 19 replies
-
Thanks @danielmarbach. I appreciate the helpful example - this isn't something that we support today but your use case makes a lot of sense and is something that we'll consider in the future. I've added this to the backlog. Thanks again for the helpful feedback. |
Beta Was this translation helpful? Give feedback.
-
To add to this we should have a way to target jobs that can use secrets. I don't want to have someone print or use a secret from a called workflow job in a caller workflow step afterwards. |
Beta Was this translation helpful? Give feedback.
-
Could this be handled by having the setup job run an API operation to either create a temporary repo secret using an easily constructed naming convention, or simply update a statically assigned secret each run that can be leveraged by subsequent jobs? You could add the temporary secret's ID as an output that the consuming job(s) reference for the value (the secret name/ID) and then utilizes as appropriate? It'd be less "clunky" and could also be used for other workflows, or if it's an organization level secret instead, be used by other repos in the org. Perhaps as a method to share that temporary infrastructure? |
Beta Was this translation helpful? Give feedback.
-
I've run into this exact requirement myself, see https://github.com/orgs/community/discussions/29880 for more details on my use-case. |
Beta Was this translation helpful? Give feedback.
-
Any updates on this? |
Beta Was this translation helpful? Give feedback.
-
FYI in the meantime we moved away from using multiple jobs towards having custom actions with setup and teardown. I will try to update the links in this issue to point to the previous version |
Beta Was this translation helpful? Give feedback.
-
Hi, we at Telia Company have a similar requirement that grows out of company directives. They require easy modular reusable workflows and proper secret handling. For secrets Vault is used. So here is what we struggle with: We have a re-usable workflow that deploys any helm chart from either the git repo or a remote helm repo. For lots of use cases that re-usable workflow must be provided with secrets that are external to that workflow. So what we tried to do is this: name: Build and deploy
on:
push:
branches:
- "*"
tags:
- "v*"
jobs:
build:
uses: telia-company/devx-cicd-workflows-and-actions/.github/workflows/build-helm.yml@main
with:
squad: "popsicle"
chartValueFiles: values/sit.yaml
# these secrets are ok, and can be loaded inside the re-usable workflow, they are always the same
secrets:
repositoryUsername: ${{ secrets.ARCUS_JFROG_WRITER_USERNAME }}
repositoryPassword: ${{ secrets.ARCUS_JFROG_WRITER_PASSWORD }}
vault:
runs-on: ["telia-managed"]
steps:
- name: Import Secrets
uses: hashicorp/[email protected]
id: vault
with:
url: https://some.url
namespace: Hid100007639
# these must be on the repository anyway
token: ${{ secrets.ARCUS_VAULT_TOKEN }}
# here starts the problem, these secrets must come into the next job
secrets: |
kv/data/github secret1;
kv/data/github secret2
deploy-sit:
needs: [ "vault" ]
uses: telia-company/devx-cicd-workflows-and-actions/.github/workflows/deploy-helm.yml@main
with:
squad: popsicle
namespace: infra
chartValueFiles: values/sit.yaml
releaseName: arcus
secrets:
# here is the problem, this is not easy possible, outputs are rightfully redacted as this are secrets and we do not have another way
chartValues: |
secret1: ${{ needs.vault.secrets.secret1 }}
secret2: ${{ needs.vault.secrets.secret2 }}
k8sConfig: this should also come from vault What we want is a way to simply and safe share secrets between jobs in one run. It would be great if a workflow like outputs could get secrets like feature so those are available through needs context. Or any other solution of course :) regards |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
BACKGROUND CONTEXTAlthough there are now docs on masking and passing secrets between jobs or workflows (as @romain-cambonie linked), it didn't meet requirements like:
PROBLEM STATEMENTSWith these factors in mind, the main blockers are:
PROPOSED SOLUTION
WORKING EXAMPLEThese methods are sourced from DevSecTop/TF-via-PR (permalink) repository, which hosts a reusable workflow to run Terraform commands via PR comments, like a CLI. As a bonus, any number of secrets can be securely passed into the reusable workflow to be used as environment variables, for example. The repository also contains recent GitHub Actions workflow runs to verify that the secrets remain masked throughout. # caller-workflow.yml
jobs:
credentials:
runs-on: ubuntu-latest
outputs:
CREDENTIAL1: ${{ steps.credentials.outputs.CREDENTIAL1 }}
CREDENTIAL2: ${{ steps.credentials.outputs.CREDENTIAL2 }}
steps:
- name: Output encoded credentials
id: credentials
env:
CREDENTIAL1: ${{ secrets.CREDENTIAL1 }}
CREDENTIAL2: ${{ secrets.CREDENTIAL2 }}
run: |
echo "CREDENTIAL1=$(echo $CREDENTIAL1 | base64 -w0 | base64 -w0)" >> $GITHUB_OUTPUT
echo "CREDENTIAL2=$(echo $CREDENTIAL2 | base64 -w0 | base64 -w0)" >> $GITHUB_OUTPUT
reusable-workflow:
needs: credentials
uses: reusable-workflow.yml
secrets:
env_vars: |
CREDENTIAL1=${{ needs.credentials.outputs.CREDENTIAL1 }}
CREDENTIAL2=${{ needs.credentials.outputs.CREDENTIAL2 }} # reusable-workflow.yml
on:
workflow_call:
secrets:
env_vars:
required: true
jobs:
parse-credentials:
runs-on: ubuntu-latest
env:
env_vars: ${{ secrets.env_vars }}
steps:
- name: Decode credentials as environment variables
run: |
for i in $env_vars; do
i=$(echo $i | sed 's/=.*//g')=$(echo ${i#*=} | base64 -di | base64 -di)
echo ::add-mask::${i#*=}
printf '%s\n' "$i" >> $GITHUB_ENV
done
- name: Validate credentials
run: |
# Secrets are now available as masked environment variable.
echo $CREDENTIAL1 # or ${{ env.CREDENTIAL1 }}
echo $CREDENTIAL2 # or ${{ env.CREDENTIAL2 }} Where:
FLAWS
|
Beta Was this translation helpful? Give feedback.
-
This makes reusable workflows useless when we want to download some secrets from somewhere and pass it to reusable workflows. |
Beta Was this translation helpful? Give feedback.
-
It would be really fantastic if Github supported secrets in "outputs" variables for jobs. I wouldn't care if it's a separate section named "secret outputs" or keep things in outputs and have the ability to add a "secret: true" flag. In workflows with multiple jobs, it would be really nice to only have to make one call to secrets providers and then be able to use that secret throughout the whole workflow via output. Separate sections example:
Flag example:
|
Beta Was this translation helpful? Give feedback.
-
actions/runner#1498 (comment)
Beta Was this translation helpful? Give feedback.
All reactions