Deploy with GitHub
This guide sets up pull request checks and a deploy to production on GitHub. Two reusable workflows in this repository run the glassops container image for you. Your repository calls them with a few lines each. examples/consumer/ is the smallest working layout, and glassops init writes a similar glassops.yaml and workflow into your project. For what a PERMIT is, see PERMIT and rules.
| Reusable workflow | Runs | Triggered by |
|---|---|---|
glassops-pr.yml |
glassops run pr |
pull_request |
glassops-deploy.yml |
glassops run deploy, in a protected environment |
a push to main |
The pipelines are the ones in your glassops.yaml. See Run a pipeline for the defaults.
Prerequisites
- A
glassops.yamlwith a Dev Hub target and a target namedprodwith tierprod, each with a login. See the configuration reference and Authentication. - A GitHub environment named
glassops-deploy. Give it required reviewers if you want an approval before the deploy job runs, and a deployment branch rule that allowsmainonly. The run's approval is read as evidence for the separation of duties rule. - The variables in the table below.
- A Salesforce connected app that allows the JWT bearer flow, for the logins. Salesforce describes it in Authorize an org using the JWT bearer flow. You get the consumer key (
SF_CLIENT_ID) from the connected app, and you keep the private key that matches its certificate (SF_JWT_KEY).
| Variable | Used by | Where it lives |
|---|---|---|
SF_JWT_KEY |
The JWT login of every target: the private key, as PEM text | Repository secret |
SF_CLIENT_ID |
The JWT login of every target: the connected app's consumer key | Repository secret |
SF_USERNAME |
The Dev Hub target's login | Repository secret |
SF_DEVHUB_ORG_ID |
The Dev Hub target's id, which the guard checks the login against |
Repository secret |
SF_PROD_USERNAME |
The prod target's login |
Repository secret |
SF_PROD_ORG_ID |
The prod target's id, checked by the guard |
Repository secret |
GLASSOPS_PERMIT_KEY |
gate signs the PERMIT with it, deploy verifies it. Make one with openssl rand -base64 48. It must decode to at least 32 bytes |
Secret of the glassops-deploy environment, never of the repository |
The names are the ones in the glassops.yaml that glassops init writes. If your auth and id fields name other variables, use those names instead.
The key must never be available to pull request jobs. Anyone who can run a job with the key can sign an allow PERMIT. A secret held only in the glassops-deploy environment reaches only jobs that name that environment, and you control which branches may use it. glassops doctor warns when GLASSOPS_PERMIT_KEY is set on a pull_request or pull_request_target run.
Pull requests
Save this as .github/workflows/pr.yml:
name: glassops pr
on:
pull_request:
permissions:
contents: read
jobs:
glassops:
uses: glassops-platform/glassops/.github/workflows/glassops-pr.yml@v1
permissions:
contents: read
pull-requests: write
security-events: write
with:
targets: devhub
secrets:
SF_JWT_KEY: ${{ secrets.SF_JWT_KEY }}
SF_CLIENT_ID: ${{ secrets.SF_CLIENT_ID }}
SF_USERNAME: ${{ secrets.SF_USERNAME }}
SF_DEVHUB_ORG_ID: ${{ secrets.SF_DEVHUB_ORG_ID }}
SF_PROD_USERNAME: ${{ secrets.SF_PROD_USERNAME }}
SF_PROD_ORG_ID: ${{ secrets.SF_PROD_ORG_ID }}
Permissions. The calling job must grant pull-requests: write, because the workflow grants it to its job so that glassops report can post the pull request comment. A called workflow cannot hold more than its caller grants, so a caller that grants less is refused when the run starts. A pull request from a fork gets a read-only token whatever the caller grants, so there the comment warns and is not posted, and the run is not affected.
The workflow checks out full history, runs glassops run pr, uploads the SARIF file to code scanning, and keeps the results as an artifact. It never receives the permit key.
| Input | Default | Meaning |
|---|---|---|
image |
ghcr.io/glassops-platform/glassops:v1 |
The container image. Pass the glassops-analyzer image when analyze.enabled is true |
targets |
Space separated target names to log in to before the pipeline, so a bad login fails early | |
upload-sarif |
true |
Upload the SARIF file. Needs code scanning on the repository |
Deploy
Save this as .github/workflows/deploy.yml:
name: glassops deploy
on:
push:
branches: [main]
permissions:
contents: read
jobs:
glassops:
uses: glassops-platform/glassops/.github/workflows/glassops-deploy.yml@v1
permissions:
contents: write
actions: read
issues: read
pull-requests: read
id-token: write
with:
environment: glassops-deploy
secrets:
GLASSOPS_PERMIT_KEY: ${{ secrets.GLASSOPS_PERMIT_KEY }}
SF_JWT_KEY: ${{ secrets.SF_JWT_KEY }}
SF_CLIENT_ID: ${{ secrets.SF_CLIENT_ID }}
SF_USERNAME: ${{ secrets.SF_USERNAME }}
SF_DEVHUB_ORG_ID: ${{ secrets.SF_DEVHUB_ORG_ID }}
SF_PROD_USERNAME: ${{ secrets.SF_PROD_USERNAME }}
SF_PROD_ORG_ID: ${{ secrets.SF_PROD_ORG_ID }}
glassops-deploy.yml takes the inputs image, environment (default glassops-deploy) and targets, like the pull request workflow.
The permit key is passed by name. The caller must list GLASSOPS_PERMIT_KEY under secrets, because a called workflow does not see environment secrets unless the caller passes them. The workflow declares the secret required: true, so a caller that omits it fails. The value lives only as a secret of the protected glassops-deploy environment. Do not add it as a repository secret. The deploy job runs in that environment, so the reviewers and branch rules you set there apply to it.
Permissions. The calling job needs these, because a called workflow cannot hold more than its caller grants:
| Permission | Why |
|---|---|
contents: write |
The runner pushes the glassops/deployed/prod tag |
actions: read |
gate reads this run's environment approvals |
pull-requests: read |
gate reads the pull request behind the commit, its author and labels |
issues: read |
gate reads who added an approval label |
id-token: write |
Sigstore keyless signing of the PERMIT, when policy.permit.signing is sigstore. The reusable workflow grants it to its job, so the caller must grant it too or GitHub refuses to start the run. HMAC signing does not use it |
What the deploy job does
- Checks out full history. A shallow clone is an error, never an empty plan.
- Installs a
glassopscommand on the runner that runs the image withdocker run --rm, one container per command, with the workspace mounted at/work. The checkout, the tag push and the uploads run on the runner, not in the container. - Logs in to each target in
targets, when set, withglassops doctor --auth --target <name>. - Runs
glassops run deploy. With the default pipeline that isplan --target prod,validate --target prod,gate --target prod,deploy --target prod,verify --target prodandreport. - Pushes the deployed tag.
deploymoves the git tagglassops/deployed/prodinside the container, but the container has no git credentials, so its own push is only a warning. A runner step after the container exits pushes theglassops/deployed/*tags with the checkout's credentials. Without that tag, the nextplanhas no record of this deploy and starts from the merge base instead. - Runs
glassops report(also after a failure), and uploads.glassops/results/,plan.jsonandpermit.jsonas theglassops-deploy-evidenceartifact.
One deploy runs at a time per environment. A queued deploy waits and is never cancelled.
How the steps fit together
- Plan. With
--target prodand no--from,planstarts from theglassops/deployed/prodtag. If that tag does not exist yet, this is the first deploy and the whole source is planned. - Validate. A check-only validate against
prod. It records which plan it validated, sogatecan bind it into the PERMIT. - Gate. Evaluates the rules and writes
.glassops/permit.json. A deny exits 1, so the run stops here and the deploy never starts. - Deploy. Verifies the PERMIT, then logs in and deploys. When the PERMIT holds a passed validation of this plan, it quick deploys it.
- Report. Runs after a failed step, writes the run summary and SARIF, and exits with the worst status of the results.
Notes
- The references say
@v1.@v1follows the latest 1.x release, and the:v1image tag moves with it. For a reproducible run, pin a release tag such as@v1.0.0or a commit SHA, and set theimageinput to a version tag such as1.0.0or to an image digest. - Separation of duties needs the rule in
glassops.yaml. When the person who merges is also the pull request author, the rule fails unless an approval satisfies it. Setapproval.environment: glassops-deployso an approval of the environment satisfies the rule. See PERMIT and rules. - The container runs as root, so files it writes under
.glassops/are owned by root on the runner. - The warning about the tag push inside the container appears on every deploy. That is expected, because the runner step pushes the tag.
Other CI systems and single commands
glassops is one binary, so any CI can run glassops run pr and glassops run deploy with the same glassops.yaml. On GitHub, the glassops-platform/glassops action runs one command in the container, for steps that do not fit a pipeline: