GitHub actions secrets
The GitHub actions sync destination allows Vault to safely synchronize secrets as GitHub organization, repository, or environment secrets. This is a low footprint option that enables your applications to benefit from Vault-managed secrets without requiring them to connect directly with Vault. This guide walks you through the configuration process.
Prerequisites:
- Ability to read or create KVv2 secrets
- Ability to create GitHub fine-grained or personal tokens (or a GitHub application) with access to modify organization and/or repository secrets
- Ability to create sync destinations and associations on your Vault server
Setup
- To get started with syncing Vault secrets to your GitHub, you will need a configured GitHub application or an access token that has write permission on the target sync location in GitHub for "Secrets". The "Secrets" permissions in GitHub automatically includes read-only "Metadata" access.
Pitfalls of using an access token
Access tokens are tied to a user account and can be revoked at any time, causing disruptions to the sync process. GitHub applications are long-lived and do not expire. Using a GitHub application for authentication is preferred over using a personal access token.Repositories
Use vault write
to configure a repository sync destination with an access token:
For example:
Environments
Use vault write
to configure an environment sync destination:
For example:
Organizations
Beta feature
Beta functionality is stable but possibly incomplete and subject to change. We strongly discourage using beta features in production deployments of Vault
Beta limitations:
- You cannot update visibility (
organization_visibility
) after creating a secrets sync destination. - You cannot update the list of repositories with access to synced secrets
(
selected_repository_names
) after creating a secrets sync destination.
Sync secrets to GitHub organization to share those secrets across repositories in the organizations. You choose to make secrets global to the organization, limited to private/internal repos, or limited to specifically named repositories.
Refer to the Secrets sync API docs for detailed configuration information.
Warning
Organization secrets are not visible to private repositories for GitHub Free accounts.
Use vault write
to configure an organization sync destination:
For example:
Usage
If you do not already have a KVv2 secret to sync, mount a new KVv2 secrets engine.
Output:
Create secrets you wish to sync with a target GitHub repository for Actions.
Output:
Create an association between the destination and a secret to synchronize.
Output:
Navigate to your GitHub repository settings to confirm your secret was successfully created.
Moving forward, any modification on the Vault secret will be propagated in near-real time to its GitHub secrets counterpart. Creating a new secret version in Vault will create a new version in GitHub. Deleting the secret or the association in Vault will delete the secret in GitHub as well.
Security
Note
Vault syncs secrets differently depending on whether you have configured
secret-key
or secret-path
granularity:
secret-key
granularity splits KVv2 secrets from Vault into key-value pairs and stores the pairs as distinct entries in GitHub. For example,secrets.key1="val1"
andsecrets.key2="val2"
.secret-path
granularity stores secrets as a single JSON string that contains all the associated key-value pairs. For example,{"key1":"val1", "key2":"val2"}
.
Since GitHub limits secrets to single-value secrets, the sync granularity defaults to secret-key
.
If using the secret-path granularity, it is strongly advised to mask individual values for each sub-key to prevent the unintended disclosure of secrets in any GitHub Action outputs. The following snippet illustrates how to mask each secret values:
If the GitHub destination uses the default secret-key
granularity, the values are masked by GitHub automatically.
GitHub application
Instead of authenticating with a personal access token, you can choose to authenticate with a custom GitHub application.
Start by following the GitHub instructions for installing a GitHub app. to install your GitHub application on a specified repository and note the assigned installation ID.
Your installation ID is in the app URL
You can find your assigned installation ID in the URL path parameter:
https://github.com/settings/installations/<INSTALLATION_ID>
Then add your GitHub application to your Vault instance.
To use your GitHub application with Vault:
- The application must have permission to read and write secrets.
- You must generate a private key for the application on GitHub.
- The application must be installed on the repository you want to sync secrets with.
- You must know the application ID assigned by GitHub.
- You must know the installation ID assigned by GitHub.
Callback, redirect URLs, and webhooks are not required at this time.
To configure the application in Vault, use vault write
with the
sys/sync/github-apps
endpoint to assign a unique name and set the relevant
information:
Fingerprint verification
Vault returns the fingerprint of the private_key provided to ensure that the correct private key was configured and that it was not tampered with along the way. You can compare the fingerprint to the one provided by GitHub. For more information, see Verifying private keys.
Next, use vault write
with the sys/sync/destinations/gh
endpoint to
configure a GitHub destination that references your new GitHub application:
You can now use your GitHub application to sync secrets with your GitHub repository.
API
Please see the secrets sync API for more details.