Secrets in CI/CD and GitHub Actions, with service tokens
Pipelines and servers can't type a password. A Stash service token gives them the environment variables of one environment, and nothing else.
A token scoped to one environment
Create a service token in the project's Service tokens tab or with stash tokens create. It can only read (or read and write) the secrets of one project environment, can expire, and is printed once, alone on stdout, so you can pipe it straight into your CI's secret store.
- Use
readaccess unless the pipeline needs to change secrets. - The token acts with the permissions of the person who created it and stops working if that person leaves the organization.
- Revoke it at any time from the same tab or with
stash tokens revoke.
$ stash tokens create github-actions --project my-app --env prod --access read --expires-in-days 90 | gh secret set STASH_TOKEN
GitHub Actions
Save the token as a repository secret named STASH_TOKEN. With it set, stash run, stash pull and stash secrets resolve the project and environment from the token: no login, no flags.
# .github/workflows/deploy.yml
jobs:
deploy:
runs-on: ubuntu-latest
env:
STASH_TOKEN: ${{ secrets.STASH_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Install Stash CLI
run: |
curl -fsSL https://github.com/bushcoding/stash/releases/latest/download/install.sh | sh
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- run: stash run -- npm run deployServers and Docker
Any machine with the CLI can start your app with the token. Pass it to the container at runtime, for example with docker run -e STASH_TOKEN, and never bake it into the image. Tools that read a file can get one with stash pull --file .env --force.
$ export STASH_TOKEN=stash_st_... $ stash run -- node server.js
Or let Stash push the variables
If you prefer the platform to hold the values, connect an integration. Each Stash environment maps to Vercel's Production, Preview or Development targets, or to GitHub repository or environment secrets. With auto-sync, every change in Stash is pushed, and Stash only removes variables it created itself.
Limits per plan
Starter includes 3 service tokens per project and 1 integration (Vercel or GitHub). Pro includes 50 service tokens and 10 integrations per project.