[英]Is there a way to dynamically make github actions secrets available at runtime without explicitly defining each variable in your yaml?
在其当前格式中,您可以在存储库 UI 中定义 git 中心机密,并将它们添加到您的 github 操作 CI,如下所示:
- name: test secrets
shell: bash
run:
env:
SECRET_1: ${{ secrets.secret_1 }}
SECRET_2: ${{ secrets.secret_2 }}
但是,如果您想动态添加附加到该环境的所有秘密,这种方法很麻烦,尤其是当您的秘密定期更改时。 使用上述方法,每次更改都需要进行代码部署,这很不方便。 有没有人提出解决方案? 或者是否有任何内置语法可以加载所有秘密? 还是遵循某种模式的秘密?
可以插入秘密 ID,所以说您在触发工作流时根据输入调节您的秘密,这是我的实现方式:
workflow_dispatch:
inputs:
environment:
type: choice
description: Deployment environment
required: true
options:
- staging
- production
jobs:
steps:
# this is because the secrets in my GH is on uppercase so I need to manipulate the whole string based on the input
- id: AWSAccessKeyId
run: export AWSAKI=${{ format('AWS_ACCESS_KEY_ID_GREEN_{0}', github.event.inputs.environment) }} && echo "::set-output name=AWSAccessKeyIdValue::${AWSAKI^^}"
- id: AWSSecretAccessKey
run: export AWSSAK=${{ format('AWS_SECRET_ACCESS_KEY_GREEN_{0}', github.event.inputs.environment) }} && echo "::set-output name=AWSSecretAccessKeyValue::${AWSSAK^^}"
- run : npm run deploy-${{ github.event.inputs.environment }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets[steps.AWSAccessKeyId.outputs.AWSAccessKeyIdValue] }}
AWS_SECRET_ACCESS_KEY: ${{ secrets[steps.AWSSecretAccessKey.outputs.AWSSecretAccessKeyValue] }}
AWS_DEFAULT_REGION: ${{ github.event.inputs.aws_region }}
不,这是不可能的(而且将来也不会)。 正如这里所写,您必须清楚地显示您想在工作流程中使用的秘密,如下所示:
steps:
- name: Hello world action
with: # Set the secret as an input
super_secret: ${{ secrets.SuperSecret }}
env: # Or as an environment variable
super_secret: ${{ secrets.SuperSecret }}
这是有目的的。 由于作者想强制开发人员使用所需的确切秘密。 这只是解决安全问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.