Pulumi ESC GitHub Action
Pulumi ESC GitHub Action
The Pulumi ESC GitHub Action injects secrets and configuration from a Pulumi ESC environment into your GitHub Actions workflows.
- The action opens the environment you name in the required
environmentinput and injects its environment variables (the keys undervalues.environmentVariables) into the current workflow. For each value undervalues.files, the action writes a temporary file and sets an environment variable of the same name to the file's path. - To inject only some of the variables, list them in the
export-environment-variablesinput. The default is to inject all of them. - The action does not install the Pulumi CLI. If a later step runs
pulumicommands, add thepulumi/actionsaction to install it.
Authentication
Before using the Pulumi ESC GitHub Action, your workflow must authenticate with Pulumi Cloud. There are two supported approaches.
OIDC (recommended)
The recommended approach uses OpenID Connect (OIDC) with the pulumi/auth-actions GitHub Action. Rather than storing a long-lived Pulumi access token as a repository secret, OIDC allows GitHub Actions to exchange a short-lived identity token for a scoped Pulumi access token at runtime.
Before you can use OIDC, you must configure Pulumi Cloud to trust GitHub Actions as an OIDC issuer. Follow the Configuring OpenID Connect for GitHub guide to complete this one-time setup in your Pulumi organization.
Once that trust relationship is established, add the following permissions block to your workflow so that GitHub can issue OIDC tokens:
permissions:
id-token: write
contents: readThen include a pulumi/auth-actions step before any ESC action steps:
- name: Authenticate with Pulumi Cloud
uses: pulumi/auth-actions@v2
with:
organization: your-org
requested-token-type: urn:pulumi:token-type:access_token:organizationThe id-token: write permission is required for GitHub Actions to issue OIDC tokens to your workflow. The requested-token-type value determines the scope of the resulting Pulumi token; see token types for details on which types are available for your Pulumi edition.
Access token
As an alternative to OIDC, you can authenticate with a long-lived Pulumi access token. Store the token as a repository secret and set it as the PULUMI_ACCESS_TOKEN environment variable in your workflow:
env:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}The action does not read credentials saved by an earlier pulumi login step, so set the token with the environment variable or with the action's pulumi-access-token input.
Long-lived access tokens are simpler to set up but require you to manage token rotation and ensure the token has appropriate permissions for your workflow.
Example
This example shows how to inject all environment variables from the tinyco/someProject/myEnv environment into the GitHub Workflow from where it is called.
on:
- pull_request
permissions:
id-token: write
contents: read
jobs:
test-all-key-injection:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Authenticate with Pulumi Cloud
uses: pulumi/auth-actions@v2
with:
organization: pulumi
requested-token-type: urn:pulumi:token-type:access_token:organization
- name: Inject ESC environment variables
uses: pulumi/esc-action@v4
with:
environment: 'tinyco/someProject/myEnv'
- name: Verify environment variables were injected
run: |
echo "Testing env injection..."
echo "FOO=$FOO"
echo "SOME_IMPORTANT_KEY=$SOME_IMPORTANT_KEY"
echo "TEST_ENV=$TEST_ENV"Use cases
- Injecting secrets into GitHub Actions: The GitHub Action can be used to inject secrets into GitHub Actions workflows, allowing you to dynamically access your secrets from ESC as they are needed, rather than storing them in GitHub Secrets as long-lived static secrets. This allows you to leverage many of ESC's key features, such as automatic secret rotation and short-lived dynamic credentials and secrets and prevents secret sprawl.
- Running ESC commands in GitHub Actions: To run
pulumi envcommands in a workflow, install the Pulumi CLI withpulumi/actionsand authenticate as described above. This lets you use ESC as part of your CI/CD pipeline and create, update, or open environments automatically as part of your workflow.
Importing secrets from GitHub Actions
If you have existing secrets in GitHub that you would like to import into ESC, you can run a one-time GitHub Action workflow like the following:
name: Export secrets to ESC
on:
- workflow_dispatch
permissions:
id-token: write
contents: read
jobs:
export-to-esc:
runs-on: ubuntu-latest
name: Export GitHub secrets to ESC
steps:
- name: Install Pulumi CLI
uses: pulumi/actions@v7
- name: Authenticate with Pulumi Cloud
uses: pulumi/auth-actions@v2
with:
organization: pulumi
requested-token-type: urn:pulumi:token-type:access_token:organization
- name: Export secrets to ESC
run: |
pulumi env get $ESC_ENVIRONMENT || pulumi env init $ESC_ENVIRONMENT
echo "$GITHUB_SECRETS" | python3 -c 'import sys, yaml, json; j=json.loads(sys.stdin.read()); print(yaml.safe_dump({"values": {"environmentVariables": {name: {"fn::secret": value} for (name, value) in j.items() if name != "github_token"}}}))' | pulumi env edit $ESC_ENVIRONMENT -f -
shell: bash
env:
ESC_ENVIRONMENT: myorg/myproject/myenvironment
GITHUB_SECRETS: ${{ toJSON(secrets) }}This workflow will export all GitHub secrets available to that repository into the specified ESC environment. You can run this workflow manually from the GitHub Actions UI.