简体   繁体   English

可以在公共仓库中使用 GitHub Secrets 吗?

[英]Is it okay to use GitHub Secrets with a public repo?

I have a private repo with a GitHub Action that pushes the code to an AWS S3 bucket when there's a new push to the master branch.我有一个带有 GitHub 操作的私有仓库,当有新的推送到主分支时,它会将代码推送到 AWS S3 存储桶。 I need a pair of access keys to be able to push the contents and I'm storing them as GitHub Secrets and referencing them as environment variables in the build script.我需要一对访问密钥才能推送内容,并将它们存储为 GitHub Secrets 并将它们作为构建脚本中的环境变量引用。 Now I would like to make this repo public in the near future, and I was wondering if it's a safe thing to do.现在我想在不久的将来公开这个 repo,我想知道这样做是否安全。 The workflow (.github/workflows/main.yml) itself for the action is indeed publicly visible and what it does, but it only has the single command aws s3 cp myfile s3://my-bucket and absolutely no access keys in the code itself.该操作的工作流 (.github/workflows/main.yml) 本身确实是公开可见的,它的作用是什么,但它只有一个命令aws s3 cp myfile s3://my-bucket并且绝对没有访问密钥代码本身。

Is it safe to use GitHub Secrets for the Actions in a public repo?将 GitHub Secrets 用于公共回购中的操作是否安全? I am the sole owner and only contributor, this will not change in the future.我是唯一的所有者和唯一的贡献者,这在未来不会改变。 I might switch to CodePipeline with a webhook later but wanted to try GitHub Actions first.稍后我可能会使用 webhook 切换到 CodePipeline,但想先尝试 GitHub Actions。 Thanks.谢谢。

Yes, secrets are safe to use in public repositories but there are some things you should be careful about.是的,秘密在公共存储库中使用是安全的,但有些事情你应该小心。

  • All secrets are automatically masked in build logs and show as *** .所有秘密都在构建日志中自动屏蔽并显示为*** However, if during your workflow you create a sensitive credential from a secret (eg base64 an API key) then you should mask the new value so it doesn't leak in the build log.但是,如果在您的工作流程中,您从一个秘密(例如 base64 和 API 密钥)创建了一个敏感凭证,那么您应该屏蔽新值,这样它就不会在构建日志中泄漏。

     echo "::add-mask::My sensitive value"
  • If you are very concerned about the security of your secrets, I would also suggest not using third party GitHub actions directly by following the action's tags or branches.如果您非常关心您的秘密的安全性,我还建议您不要直接使用第三方 GitHub 操作,只需遵循操作的标签或分支。 Fork the action and use your fork in workflows.分叉操作并在工作流程中使用您的分叉 This will prevent the possibility of someone modifying an action you are using to capture secrets being used by the action, and send them to some external server under their control.这将防止有人修改您用来捕获该操作所使用的秘密的操作,并将其发送到他们控制下的某个外部服务器。

    Alternatively, use the action directly and reference the commit hash for the version you want to target.或者,直接使用该操作并为您要定位的版本引用提交 hash。

     - uses: thirdparty/foo-action@172ec762f2ac8e050062398456fccd30444f8f30
  • Use two-factor authentication (2FA) on your account.在您的帐户上使用双重身份验证 (2FA) If your account is compromised, it's trivial for an attacker to create a workflow and export your secrets.如果您的帐户遭到入侵,攻击者很容易创建工作流并导出您的机密。

  • Repository collaborators or any organization users with write access are able to create a workflow to export secrets.存储库协作者或任何具有write权限的组织用户都能够创建工作流来导出机密。 So manage access to your repository carefully.因此,请谨慎管理对存储库的访问。

Points related to pull requests:与拉取请求相关的要点:

  • Public repository pull_request events triggered by forks do not have access to secrets, except for the default GITHUB_TOKEN .由分叉触发的公共存储库pull_request事件无权访问机密, 默认的GITHUB_TOKEN Additionally, The GITHUB_TOKEN has read-only access when an event is triggered by a forked repository .此外,当事件由分叉存储库触发时, GITHUB_TOKEN具有只读访问权限 These are intentional restrictions enforced by GitHub Actions to prevent an attacker creating a pull request containing a workflow that captures secrets, or uses secrets to perform operations.这些是 GitHub 操作强制实施的有意限制,以防止攻击者创建包含捕获机密或使用机密执行操作的工作流的拉取请求。
  • The pull_request_target event does not have secret restrictions for events triggered by forks. pull_request_target事件对分叉触发的事件没有秘密限制。 By default it checks out the last commit on the base branch, but it is possible to checkout the pull request HEAD.默认情况下,它会检出基础分支上的最后一次提交,但可以检出拉取请求 HEAD。 Choosing to do this requires extreme caution.选择这样做需要格外小心。 Passing secrets to any code that could be modified in a pull request could allow an attacker to write code to export secrets.将机密传递给可以在拉取请求中修改的任何代码都可能允许攻击者编写代码来导出机密。

Yes, it appears so.是的,看起来是这样。 According to Github , you have organization-level access control policies to who can access your secrets. 根据 Github ,您对谁可以访问您的机密具有组织级别的访问控制策略。

For secrets stored at the organization-level, you can use access policies to control which repositories can use organization secrets.对于存储在组织级别的机密,您可以使用访问策略来控制哪些存储库可以使用组织机密。 Organization-level secrets let you share secrets between multiple repositories, which reduces the need for creating duplicate secrets.组织级机密允许您在多个存储库之间共享机密,从而减少创建重复机密的需要。 Updating an organization secret in one location also ensures that the change takes effect in all repository workflows that use that secret.在一个位置更新组织机密还可以确保更改在使用该机密的所有存储库工作流中生效。

Whether the repository is public or private does not affect this, and that makes sense.存储库是公共的还是私有的都不会影响这一点,这是有道理的。 Public projects need secrets, too.公共项目也需要秘密。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM