> ## Content Index
> Fetch the complete content index at: https://www.techielass.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# GitHub Actions Secrets
- URL: https://www.techielass.com/github-actions-secrets/
- Published: 2023-01-24T08:01:43.000Z
- Updated: 2023-12-07T14:47:59.000Z
- Description: In this blog post I explore the different ways in which you can store secret data within GitHub and how to recall them into a workflow.
- Author: Sarah Lean
- Tags: GitHub Actions

[GitHub Actions](https://docs.github.com/actions?ref=techielass.com) is a tool that can be used to automate processes that relate to code stored within a [repository](https://docs.github.com/get-started/quickstart/create-a-repo?ref=techielass.com). You can use it to automate your Continuous Integration/Continuous Deployment (CI/CD) processes.

  
When carrying out this kind of automation you need to be able to store sensitive data somewhere. [GitHub Actions Secrets](https://docs.github.com/actions/security-guides/encrypted-secrets?ref=techielass.com) can be used to store that sensitive data.  
GitHub allows you to store secrets at 3 different levels:

- Repository
- Environment
- Organization

In this article, we will look at those three levels, and how to call secrets in an example GitHub Actions workflow.

### Repository secrets

Repository secrets are tied to the repository they are created within. You can store 100 secrets per repository.  
  
**Add a repository secret**

Open your project’s repository and click on Settings in the top menu

![GitHub repository settings](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-repo.png)

GitHub repository settings

Click Secrets in the menu on the left-hand side.

Then select Actions.

![GitHub Actions menu](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-menu.png)

GitHub Actions menu

Click on New Repository Secret.

![GitHub New repository secret](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-new-secret.png)

GitHub New repository secret

Complete the following fields:  
 \- Name, give the secret a suitable name, and don’t use any space or special characters. Underscores are usable.  
 \- Value, enter the secrets.

![GitHub new secret](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-add-secret.png)

GitHub new secret

Click on Add Secret.

*You are able to update this secret whenever you need to change it.*

### Environment secrets

Within GitHub, you can specify different environments in which to target for your deployments, such as production, staging, or development.

If you have a public or an enterprise licence you can set environment-specific secrets that will only work for that environment.

There is a limit of secrets per environment, 100.  
  
**Add an environment secret when creating a new environment**

Open your project’s repository and click on Settings in the top menu

![GitHub repository settings](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-repo-1.png)

GitHub repository settings

Click Environments in the left hand side menu.

![GitHub menu](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-menu-env.png)

GitHub menu

Click on New environment.

![GitHub create new environment](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-new-environment.png)

GitHub create new environment

Enter a name for your environment and click Configure environment.

Configure the environment’s protection rules and deployment branches as you require them and then click on Add Secret.

![Configure GitHub environment secret](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-env-secret.png)

Configure GitHub environment secret

Complete the following fields:  
 \- Name, give the secret a suitable name, don’t use any space or special characters. Underscores are usable.  
 \- Value, enter the secrets.

Click on Add Secret.

![Add new GitHub environment secret](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-new-env-secret.png)

Add new GitHub environment secret

If you wish to change the secret or add others for that environment in the future you can do so through Settings > Secrets > Actions.

### Organization secrets

An organization within GitHub is a shared account for businesses or [open-source](https://www.techielass.com/what-is-open-source/) projects to collaborate across many projects.

In 2020 GitHub announced organization secrets. A way of sharing secrets across repositories.

There are access policies available which allow you to control which repositories have access to an organization secret.

**Add an organization secret**

Open your organization’s page in GitHub and click Settings in the top menu.

Click Secrets in the left menu.

Click on Actions.

![GitHub organisation secret](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-org-secret.png)

GitHub organisation secret

Now select New organization secret.

![Create new organisation secret](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-new-org-secret.png)

Create new organisation secret

Complete the following fields:  
 \- Name, give the secret a suitable name, don’t use any space or special characters. Underscores are usable.  
 \- Value, enter the secrets.  
 \- Repository access, select the relevant policy or repositories you wish to be able to see this secret.

Click on Add Secret. 

![Create new organisation secret](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2023/01/github-org-secret-create.png)

Create new organisation secret

### Using secrets in GitHub Actions workflows

Within GitHub Actions workflows [contexts](https://docs.github.com/en/actions/learn-github-actions/contexts?ref=techielass.com) are how GitHub pulls information from various sources. We can use the context of the secret to call your secret data in workflows.  
  
As an example, if you are trying to interact with Azure during a workflow. Perhaps you are [deploying an Azure Bicep template](https://www.techielass.com/deploy-azure-bicep-using-github-actions/). You need to provide GitHub with credentials to your Azure environment.

You might add a step such as:

```
- name: Azure Login
     uses: Azure/login@v1.4.3
     with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

```

Here we are using the GitHub Actions action [“Azure Login”](https://github.com/marketplace/actions/azure-login?ref=techielass.com). Our Azure credentials are stored within a repository secret and we are calling them into the workflow without exposing the information to the public.

### GitHub Actions Secrets - Security Best Practices

If you’d like to learn more about GitHub Actions please do check out [my other blog posts.](https://www.techielass.com/tag/github-actions/)