Skip to content

Using an environment

broker-run mints a workload token, fetches the named secrets from an environment and runs a command with them in its environment. In an Amp orb it mints a 60-second Amp token; in a GitHub Actions job it uses the job’s OIDC token. It needs BROKER_URL (https) and BROKER_AUDIENCE, which are not secret. --bundle is the older name for --environment.

Install it from a release tarball, so your lockfile pins its hash, and run it from node_modules/.bin:

Terminal window
bun add https://github.com/mylescarrick/portona/releases/download/v0.4.1/portona-0.4.1.tgz
./node_modules/.bin/broker-run --environment outlearn/sync --env EMDASH_TOKEN,EMDASH_URL \
-- bun run ./scripts/sync.ts

Portona isn’t published to npm, so never run it with a bare bunx broker-run or npx broker-run: when it isn’t installed, those download whatever package has that name from npm and hand it your workload’s token. client/broker-run.ts has no dependencies beyond Bun, so you can also copy it into your repository and run it with bun.

The job needs id-token: write, and the GitHub environment its grant pins. GitHub’s environment (production here) and Portona’s environment (webapp/production) are separate names: the grant’s environment claim must match the job’s GitHub environment. This job matches the gh-webapp-deploy grant in Environments and grants:

on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
- run: >-
./node_modules/.bin/broker-run --environment webapp/production
--env TWILIO_ACCOUNT_SID,TWILIO_AUTH_TOKEN -- ./scripts/deploy.sh
env:
BROKER_URL: https://portona.example.workers.dev
BROKER_AUDIENCE: urn:portona:example

broker-run uses GitHub’s token whenever ACTIONS_ID_TOKEN_REQUEST_URL is set, which GitHub does only for jobs with id-token: write. Before a grant gives a workflow production secrets, pin its actions by commit SHA, protect the branch it runs from, and add required reviewers to the GitHub environment where your plan allows.

  • Only the names you ask for. broker-run asks Portona for exactly the --env names, so a grant narrowed to some names works, and Portona refuses the whole request if any name isn’t granted or has no secret. Only those names are passed to the command: an environment can’t set PATH or anything else you didn’t ask for. With a Portona older than 0.4, which returns the whole environment, the same filter applies.
  • Nothing printed or written. It never prints values or Portona’s replies, and never writes them to disk.
  • No forwarding. It refuses redirects, so the token can’t be sent anywhere but BROKER_URL. It refuses a BROKER_URL that isn’t https, loopback excepted.
  • A faithful wrapper. It forwards signals to the command and passes its exit code through.

client/broker-run.ts has no dependencies beyond Bun, so it can also be copied into a repository.

Once delivered, the command and anything it starts can read, print or send the values elsewhere. Run only trusted commands, and don’t log their environment.

Anyone who can run code as the grant’s user in the grant’s project can mint a token and fetch what it allows. Amp grants pin the user and project, not a specific thread or command. GitHub grants pin the workflow file, so anyone who can push that file to the pinned branch can change what it does with the secrets. Narrow each grant to the names one job needs.