load-secrets-action with a 1Password Connect Server or a 1Password Service Account. See the video below for a brief introduction to using the GitHub Action with a service account.
Similar to regular GitHub repository secrets , 1Password automatically masks sensitive fields that appear in GitHub Actions logs. If one of these values accidentally gets printed, it’s replaced with
***.Requirements
You can configure the action to authenticate to 1Password with either a service account or a Connect server.- Service account
- Connect
Before using the Load secrets from 1Password GitHub Action with a service account, you must:
- Sign up for 1Password.
- Create a service account.
- Have the service account token on hand.
Get started
The steps to get started vary depending on whether you use a service account or a Connect server.- Service account
- Connect
- Add the Load secrets from 1Password GitHub Action to your workflow. See Adding an action to your workflow .
-
Add the service account token to your workflow.
Create a secret for your GitHub repository named
OP_SERVICE_ACCOUNT_TOKENand set it to the service account token value. Visit Using secrets in GitHub Actions to learn how. -
Configure your workflow.
Use the
1password/load-secrets-action/configureaction to specify the token of the service account you plan to get secrets from. The following example uses theconfigurecommand to set theservice-account-tokento theOP_SERVICE_ACCOUNT_TOKENsecret.config.yml -
Load a secret.
Use the
1password/load-secrets-actionaction to set an environment variable to a secret reference URI that points to where a secret is stored in your 1Password account. The following example sets theSECRETenvironment variable to the value of a field titledsecretwithin an item titledhello-worldsaved in a vault titledapp-cicd.The action makes the referenced secret available as theconfig.ymlSECRETenvironment variable for the next steps.
Reference
The following sections document the action inputs and secret reference syntax for the Load secrets from 1Password GitHub Action .Action inputs
The following table contains the availableconfigure action inputs.
| Action input | Environment variable | Description |
|---|---|---|
connect-host | OP_CONNECT_HOST | The Connect server, hostname, IP address, or instance URL. |
connect-token | OP_CONNECT_TOKEN | The Connect server token. |
service-account-token | OP_SERVICE_ACCOUNT_TOKEN | The service account token. |
Secret reference syntax
Secret reference URIs point to where a secret is saved in your 1Password account using the names (or unique identifiers) of the vault, item, section, and field where the information is stored.Example
The following example shows how to reference thesecret-access-key field of the aws item in the app-cicd vault.
config.yml
- Vault:
app-cicd - Item:
aws - Field:
secret-access-key
Usage examples
You can load secrets using the action in two ways:Use secrets from the action’s output
You can use the Load secrets from 1Password GitHub Action to access secrets as environment variables.- Service account
- Connect
The following examples show how to load a secret from a service account and print the output when a
push event occurs.You need to set an ID for the step to access its outputs. See outputs.<output_id> .- Simple example
- Advanced example
The following example shows how to use a service account to load (and print) a secret (as the
SECRET env variable) from 1Password. When you print a secret, 1Password automatically replaces it with ***.config.yml
Export secrets as environment variables
You can use the Load secrets from 1Password GitHub Action to use loaded secret outputted from thesteps.step-id.outputs.secret-name.
- Service account
- Connect
The following examples show how to use a service account to load a 1Password secret as an environment variable.
- Simple example
- Advanced example
The following example shows how to use a service account to load a secret as an environment variable named
SECRET. When you print a secret, 1Password automatically replaces it with ***.config.yml
Troubleshooting
If you try to create items using 1Password CLI in your GitHub pipelines (without usingload-secrets-action), the command fails with the following error:
-
Get the template for the category of item you want to create:
- Edit the template to add your information.
-
Pipe the item content to the command: