4. Secrets and Tokens
The ability to keep secret values is an essential feature in any CI/CD pipeline implementation tool because some parameters/variables are sensitive information that cannot be stored openly. Further, programmatically allowing access to third parties may be necessary. Authentication should be provided using tokens.
This chapter explores the options for keeping secrets in GitHub Actions and generating tokens to provide programmatic access to GitHub. Secrets are important in any CI/CD pipeline implementation tool. They protect sensitive information, such as connection strings and passwords, and keep passwords or other secrets applied in application configuration settings. Secrets New secret Once a secret is created, the value cannot be seen again, but it can be utilized in the workflows. If required, you can either remove or update the secret to a new value. Secrets in GitHub organizations Organization secrets are available to private repositories with the paid plans. Organization secrets are available in public repos through workflows. Characters: Alphanumeric characters are used in secret names; however, secrets cannot start with a number. Only an underscore can separate parts of a secret name. Spaces and other special characters are not allowed in secret names. Unique: Secret names must be unique at the repo or organization level, and names are case sensitive. If you define a secret name at the organization level and use the same secret name in the organization’s repo, precedence is given to the repo-level secret.
GITHUB_ Prefix: You cannot use GITHUB_ in secret names; it results in an error. Note that GitHub always redacts the secrets printed in workflow logs; however, you should take care to not accidentally print the secrets to logs. Only up to 100 secrets per workflow is supported. The size of a secret is limited to 64 KB. If the secret is larger than 64 KB, storing an encrypted secret in the GitHub repo and keeping a decrypted password is recommended. This section discussed creating and using secrets with GitHub workflows, including limitations and naming considerations. In your workflow, you might need to push changes to your repo or add a label. Or you might want to create an issue in the GitHub repo while the workflow is executing. To do these activities, the workflow requires authentication. GITHUB_TOKEN Permissions Permission Access for Repo Access for Forked Repos Actions read/write Read Checks read/write Read Contents read/write Read Deployments read/write Read Issues read/write Read metadata read Read packages read/write Read pull requests read/write Read repository projects read/write read statuses read/write read Except for metadata, all other repo-related areas have read/write permissions in a workflow with GITHUB_TOKEN. For example, you can use GITHUB_TOKEN and create an issue from a workflow. Creating an issue for a failed build job is a good use case. Let’s try to understand this with an example. Generate issue on failure GitHub issue created by a workflow If the permissions of GITHUB_TOKEN is not sufficient to perform the activity you need, you may create a personal access token (PAT) in GitHub and store it as a secret. Then utilize it in the workflows for authentication purposes. This section discussed GITHUB_TOKEN with workflows and looked at an example scenario of creating an issue from a workflow job failure, in which a token is useful. This chapter explored the capability to use secrets and considerations when using secrets. It looked at the GITHUB_TOKEN, which lets you authenticate and perform several actions with GitHub repos and the REST API. The next chapter explores artifacts and cashing workflow dependencies.Defining and Using Secrets
Repo-Level Secrets
Organization-Level Secrets
Naming Secrets
Using Secrets in Workflows
Limitations with Secrets
GITHUB_TOKEN
Summary