1
0
mirror of synced 2025-12-23 21:07:12 -05:00
Files
docs/content/actions/reference/encrypted-secrets.md
Amy Burns c70adf6702 Codespaces Megabranch - Docs audit and re-org, Landing and Guides page, Secrets doc (#19227)
* reorganizing security and access sections

* updating delete doc

* making vscode doc moore os agnostic

* updating developing in a codespace

* fixing broken links

* fixing some broken links

* fixing broken topic

* fixing broken link

* Managing users permissions for your organization and other stuff (#19231)

* Add new 'Managing user permissions for your organization' article

* Revise 'Managing access and security for Codespaces' and screenshot

* Add codespaces to org repo permissions article

* Apply suggestions from code review

Co-authored-by: Amy Burns <timeyoutakeit@github.com>

* fixing title to match slug

* fixing broken link

* updating personalization doc

* updating troubleshooting guide

* updating creating doc

* adding information about when secrets are used

* removing secrets stuff from this PR

* Addig order of operations for codespaces

* self review fixes

* Apply suggestions from code review

Co-authored-by: Allison Weins <3174849+2percentsilk@users.noreply.github.com>

* renaming quickstart to correct pattern:

* Apply suggestions from code review

Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com>

* rewriting re. review comments

* Codespaces landingpage (#19053)

* adding new tables and linking to info on audit logs

* editing some text:

* adding new info on how to add image registry login

* adding link and fixing table

* formatting

* formatting

* Apply suggestions from code review

Co-authored-by: Laura Coursen <lecoursen@github.com>

* updaing private image registry secret info and other improvements

* some minor fixes

* fixing test errors

* rewriting registry secret section

* rewriting registry secret section

* updating link to reflect title

* Update content/github/developing-online-with-codespaces/managing-encrypted-secrets-for-codespaces.md

Co-authored-by: Laura Coursen <lecoursen@github.com>

* updating bullet point

* moving codespaces to top-level item

* fixing duplicated redirect

* Adding some organization for contributors

* adding learning codespaces to index file

* do not error out if category array is empty

* Apply suggestions from code review

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>

* fixing broken link

* testing what is possible for the landing page

* adding first run of landing page

* adding new video and intro text

* add landing page scaffolding

* Update codespaces_code_examples.yml

* lint

* fixing issues in branch

* fixing nav

* fixing broken directs

* Creating guides sub-landing page

* adding topics

* removing unused toopic

* removing instant

* updating landing page and guides page

* updating versioning

* removing unused topic

* removing other versions:

* actually fixing broken links

* fixing title

* fixing intro to suit the landing page

* Apply suggestions from code review

Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com>

* adding video

* adding video

* adding correct link for video

* removing duplicated guides

Co-authored-by: Laura Coursen <lecoursen@github.com>
Co-authored-by: Sarah Schneider <sarahs@github.com>
Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
Co-authored-by: Rachael Sewell <rachmari@github.com>
Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com>

* rewording and reorganizing code samples

* fixing some feedback from engineering

* Adding doc on Secrets in codespaces (#19248)

* adding secrets docs

* fixing some broken links

* fixing some more broken redirects

* copy edit and updating limits for secrets

* adding limits for users

* Apply suggestions from code review

Co-authored-by: Felicity Chapman <felicitymay@github.com>

* adding feedback

Co-authored-by: Felicity Chapman <felicitymay@github.com>

* updating beta banner

* adding quickstarts to landing page

* removing availability section from reusable

Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com>
Co-authored-by: Allison Weins <3174849+2percentsilk@users.noreply.github.com>
Co-authored-by: Laura Coursen <lecoursen@github.com>
Co-authored-by: Sarah Schneider <sarahs@github.com>
Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
Co-authored-by: Rachael Sewell <rachmari@github.com>
Co-authored-by: Felicity Chapman <felicitymay@github.com>
2021-05-11 17:29:34 +00:00

14 KiB

title, intro, product, redirect_from, versions
title intro product redirect_from versions
Encrypted secrets Encrypted secrets allow you to store sensitive information in your organization{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" %}, repository, or repository environments{% else %} or repository{% endif %}. {% data reusables.gated-features.actions %}
/github/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets
/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets
/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
free-pro-team enterprise-server github-ae
* >=2.22 *

{% data reusables.actions.enterprise-beta %} {% data reusables.actions.environments-beta %} {% data reusables.actions.enterprise-github-hosted-runners %} {% data reusables.actions.ae-beta %}

About encrypted secrets

Secrets are encrypted environment variables that you create in an organization{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" or currentVersion == "github-ae@latest" %}, repository, or repository environment{% else %} or repository{% endif %}. The secrets that you create are available to use in {% data variables.product.prodname_actions %} workflows. {% data variables.product.prodname_dotcom %} uses a libsodium sealed box to help ensure that secrets are encrypted before they reach {% data variables.product.prodname_dotcom %} and remain encrypted until you use them in a workflow.

{% data reusables.github-actions.secrets-org-level-overview %}

{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" or currentVersion == "github-ae@latest" %} For secrets stored at the environment level, you can enable required reviewers to control access to the secrets. A workflow job cannot access environment secrets until approval is granted by required approvers. {% endif %}

Naming your secrets

{% data reusables.codespaces.secrets-naming %}. For example, {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" or currentVersion == "github-ae@latest" %}a secret created at the environment level must have a unique name in that environment, {% endif %}a secret created at the repository level must have a unique name in that repository, and a secret created at the organization level must have a unique name at that level.

{% data reusables.codespaces.secret-precedence %}{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" or currentVersion == "github-ae@latest" %} Similarly, if an organization, repository, and environment all have a secret with the same name, the environment-level secret takes precedence.{% endif %}

To help ensure that {% data variables.product.prodname_dotcom %} redacts your secret in logs, avoid using structured data as the values of secrets. For example, avoid creating secrets that contain JSON or encoded Git blobs.

Accessing your secrets

To make a secret available to an action, you must set the secret as an input or environment variable in the workflow file. Review the action's README file to learn about which inputs and environment variables the action expects. For more information, see "Workflow syntax for {% data variables.product.prodname_actions %}."

You can use and read encrypted secrets in a workflow file if you have access to edit the file. For more information, see "Access permissions on {% data variables.product.prodname_dotcom %}."

{% warning %}

Warning: {% data variables.product.prodname_dotcom %} automatically redacts secrets printed to the log, but you should avoid printing secrets to the log intentionally.

{% endwarning %}

{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" or currentVersion == "github-ae@latest" %} Organization and repository secrets are read when a workflow run is queued, and environment secrets are read when a job referencing the environment starts. {% endif %}

You can also manage secrets using the REST API. For more information, see "Secrets."

Limiting credential permissions

When generating credentials, we recommend that you grant the minimum permissions possible. For example, instead of using personal credentials, use deploy keys or a service account. Consider granting read-only permissions if that's all that is needed, and limit access as much as possible. When generating a personal access token (PAT), select the fewest scopes necessary.

Creating encrypted secrets for a repository

{% data reusables.github-actions.permissions-statement-secrets-repository %}

{% data reusables.repositories.navigate-to-repo %} {% data reusables.repositories.sidebar-settings %} {% data reusables.github-actions.sidebar-secret %}

  1. Click New repository secret.
  2. Type a name for your secret in the Name input box.
  3. Enter the value for your secret.
  4. Click Add secret.

If your repository {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0"or currentVersion == "github-ae@latest" %}has environment secrets or {% endif %}can access secrets from the parent organization, then those secrets are also listed on this page.

{% note %}

Note: Users with collaborator access can use the REST API to manage secrets for a repository. For more information, see "{% data variables.product.prodname_actions %} secrets API."

{% endnote %}

{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" or currentVersion == "github-ae@latest" %}

Creating encrypted secrets for an environment

{% data reusables.github-actions.permissions-statement-secrets-environment %}

{% data reusables.repositories.navigate-to-repo %} {% data reusables.repositories.sidebar-settings %} {% data reusables.github-actions.sidebar-environment %}

  1. Click on the environment that you want to add a secret to.
  2. Under Environment secrets, click Add secret.
  3. Type a name for your secret in the Name input box.
  4. Enter the value for your secret.
  5. Click Add secret. {% endif %}

Creating encrypted secrets for an organization

When creating a secret in an organization, you can use a policy to limit which repositories can access that secret. For example, you can grant access to all repositories, or limit access to only private repositories or a specified list of repositories.

{% data reusables.github-actions.permissions-statement-secrets-organization %}

{% data reusables.organizations.navigate-to-org %} {% data reusables.organizations.org_settings %} {% data reusables.github-actions.sidebar-secret %}

  1. Click New organization secret.
  2. Type a name for your secret in the Name input box.
  3. Enter the Value for your secret.
  4. From the Repository access dropdown list, choose an access policy.
  5. Click Add secret.

Reviewing access to organization-level secrets

You can check which access policies are being applied to a secret in your organization.

{% data reusables.organizations.navigate-to-org %} {% data reusables.organizations.org_settings %} {% data reusables.github-actions.sidebar-secret %}

  1. The list of secrets includes any configured permissions and policies. For example: Secrets list
  2. For more details on the configured permissions for each secret, click Update.

Using encrypted secrets in a workflow

{% note %}

Note: {% data reusables.actions.forked-secrets %}

{% endnote %}

To provide an action with a secret as an input or environment variable, you can use the secrets context to access secrets you've created in your repository. For more information, see "Context and expression syntax for {% data variables.product.prodname_actions %}" and "Workflow syntax for {% data variables.product.prodname_actions %}."

{% raw %}

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 }}

{% endraw %}

Avoid passing secrets between processes from the command line, whenever possible. Command-line processes may be visible to other users (using the ps command) or captured by security audit events. To help protect secrets, consider using environment variables, STDIN, or other mechanisms supported by the target process.

If you must pass secrets within a command line, then enclose them within the proper quoting rules. Secrets often contain special characters that may unintentionally affect your shell. To escape these special characters, use quoting with your environment variables. For example:

Example using Bash

{% raw %}

steps:
  - shell: bash
    env:
      SUPER_SECRET: ${{ secrets.SuperSecret }}
    run: |
      example-command "$SUPER_SECRET"

{% endraw %}

Example using PowerShell

{% raw %}

steps:
  - shell: pwsh
    env:
      SUPER_SECRET: ${{ secrets.SuperSecret }}
    run: |
      example-command "$env:SUPER_SECRET"

{% endraw %}

Example using Cmd.exe

{% raw %}

steps:
  - shell: cmd
    env:
      SUPER_SECRET: ${{ secrets.SuperSecret }}
    run: |
      example-command "%SUPER_SECRET%"

{% endraw %}

Limits for secrets

You can store up to 1,000 secrets per organization{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" or currentVersion == "github-ae@latest" %}, 100 secrets per repository, and 100 secrets per environment{% else %} and 100 secrets per repository{% endif %}. A workflow may use up to 100 organization secrets and 100 repository secrets.{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.0" or currentVersion == "github-ae@latest" %} Additionally, a job referencing an environment may use up to 100 environment secrets.{% endif %}

Secrets are limited to 64 KB in size. To use secrets that are larger than 64 KB, you can store encrypted secrets in your repository and save the decryption passphrase as a secret on {% data variables.product.prodname_dotcom %}. For example, you can use gpg to encrypt your credentials locally before checking the file in to your repository on {% data variables.product.prodname_dotcom %}. For more information, see the "gpg manpage."

{% warning %}

Warning: Be careful that your secrets do not get printed when your action runs. When using this workaround, {% data variables.product.prodname_dotcom %} does not redact secrets that are printed in logs.

{% endwarning %}

  1. Run the following command from your terminal to encrypt the my_secret.json file using gpg and the AES256 cipher algorithm.
$ gpg --symmetric --cipher-algo AES256 my_secret.json
  1. You will be prompted to enter a passphrase. Remember the passphrase, because you'll need to create a new secret on {% data variables.product.prodname_dotcom %} that uses the passphrase as the value.

  2. Create a new secret that contains the passphrase. For example, create a new secret with the name LARGE_SECRET_PASSPHRASE and set the value of the secret to the passphrase you selected in the step above.

  3. Copy your encrypted file into your repository and commit it. In this example, the encrypted file is my_secret.json.gpg.

  4. Create a shell script to decrypt the password. Save this file as decrypt_secret.sh.

#!/bin/sh

# Decrypt the file
mkdir $HOME/secrets
# --batch to prevent interactive command
# --yes to assume "yes" for questions
gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" \
--output $HOME/secrets/my_secret.json my_secret.json.gpg
  1. Ensure your shell script is executable before checking it in to your repository.
$ chmod +x decrypt_secret.sh
$ git add decrypt_secret.sh
$ git commit -m "Add new decryption script"
$ git push
  1. From your workflow, use a step to call the shell script and decrypt the secret. To have a copy of your repository in the environment that your workflow runs in, you'll need to use the actions/checkout action. Reference your shell script using the run command relative to the root of your repository.

{% raw %}

name: Workflows with large secrets

on: push

jobs:
  my-job:
    name: My Job
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Decrypt large secret
        run: ./.github/scripts/decrypt_secret.sh
        env:
          LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
      # This command is just an example to show your secret being printed
      # Ensure you remove any print statements of your secrets. GitHub does
      # not hide secrets that use this workaround.
      - name: Test printing your secret (Remove this step in production)
        run: cat $HOME/secrets/my_secret.json

{% endraw %}