Skip to content

PERMIT and Rules

A PERMIT is a signed file that records one decision: whether one plan may be deployed to one target. glassops gate makes the decision and writes the PERMIT. glassops deploy and glassops permit verify refuse to go on unless the PERMIT is genuine, still valid and about the thing being deployed. This page describes the PERMIT, the rules that feed it, and the evidence gate reads. The commands are in the CLI reference.


What a PERMIT is

The PERMIT is JSON in .glassops/permit.json, with the schema name glassops.permit/v1. It holds:

Field Meaning
id A random identifier, in hex
kind Optional. Absent means a deploy PERMIT, as every PERMIT before v1.3 was. operations means an operations PERMIT, made by gate --ops, which can never authorize a deploy. A reader older than v1.3 refuses a PERMIT that carries it
allow true or false. A deny is recorded as a PERMIT too
issued_at, expires_at When it was made and when it stops being valid. The lifetime is policy.permit_ttl, or less when the target's tier has deploy windows: the PERMIT then expires when the window that held the gate's clock closes, or when a blackout that covers the tier next begins
target The target name, tier, id and kind. The Id and kind are what the login reported, unless --no-connect was used. Then kind is the kind the config requires, from the tier or targets.<name>.kind, and kind_source is declared. kind_source is absent when the guard observed the kind or the kind is unknown. A reader older than the release that added it refuses a PERMIT that carries it
commit The commit the CI reported
plan_sha256 The hash of the plan files
config_sha256 The hash of glassops.yaml
change_set_sha256 The hash of plan_sha256 and the change set fields that say how the plan files are used: provider, dir, manifest, the destructive list in order, empty and full
deploy_command_sha256 Provider exec only, when gate ran with --deploy-command. The SHA-256 of the command as a JSON array of strings. The command text is never stored
exec_commands_sha256 Only when gate ran with --exec-command or --ops. The sorted SHA-256 of each exec step command that may run logged in to the target. A run text is hashed as a one element JSON array of strings. An operation whose run is a list is hashed as argv:v1, a newline, then the argument list its values make as a JSON array, so the two kinds of digest can never be equal. The text is never stored
operations Only for an operations PERMIT. The sorted names of the operations it was issued for. It is evidence, and the signature covers it. The command hashes above are what bind
operation_params Only for an operations PERMIT whose operations take params. For each operation, the value gate bound for each param: {"publish-site": {"site": "Portfolio"}}. A file param records {"value": "scripts/apex/x.apex", "blob": "<sha>"}, the file's git blob at the commit. The run takes its values from here and nowhere else. A reader older than v1.4 refuses a PERMIT that carries it
validation Optional. The deploy Id of a passed check-only validation, its test level and passed
validate_result Optional. Present whenever gate read results/validate.json in this run, whatever it said. It holds the validate deploy_id, its status as written, its test_level, the target name in the result, its plan_sha256, and matches, which is true when that target and plan are this PERMIT's target and plan. It holds no token, user name or URL. It is signed with the rest of the PERMIT. A gate older than v1.3 never writes it, and a reader older than v1.3 refuses a PERMIT that carries it
separation_of_duties How the separation of duties rule was met. See below
checks Every rule result, each with its rule name, outcome and detail
signature The algorithm, the key id and the signature value

A PERMIT binds to a specific target, commit, plan, change set and config. Change any of them after gate ran and the PERMIT no longer matches. A PERMIT with no change_set_sha256 was written by an older gate and is refused with a message saying so. Run gate again.


The signing key

By default the PERMIT is signed with HMAC-SHA256, as described here. On GitHub Actions you can sign keyless with Sigstore instead, which needs no key. See Sigstore signing. The rest of this section is about the HMAC key.

The key comes from the environment variable GLASSOPS_PERMIT_KEY, which holds base64 text that decodes to at least 32 bytes with at least 8 different byte values. Standard base64 is accepted with or without padding. A shorter key, or a placeholder such as one character repeated, is refused, and the error never contains the key. One way to make a key:

openssl rand -base64 48

The key_id in the signature is the first eight hex characters of the SHA-256 of the key. It names the key without revealing it. permit verify and deploy refuse a PERMIT whose key_id differs from their own key's, with the message that it was signed with a different key.

The signature covers the whole PERMIT, with the signature value left out: keys sorted, no extra whitespace, times in UTC. The signature value must be standard padded base64, exactly as gate writes it. A PERMIT file with a field the format does not know, or with trailing data, is refused as unreadable, because such a field would not be covered by the signature.

The key must never be available to pull request jobs. Anyone who can run a job with the key can sign an allow. Put it in a protected CI environment that only the deploy job uses. glassops doctor adds a warning when GLASSOPS_PERMIT_KEY is set on a pull_request or pull_request_target run. See Deploy with GitHub.


What gate does

gate always writes a signed PERMIT, including when policy denies the deploy. The deny is part of the record. Before it does anything else, it deletes any PERMIT already at the output path, so a stale allow can never stand in for the current run.

Two things stop it before a PERMIT is written, and both exit 2: GLASSOPS_PERMIT_KEY is missing or unusable, and the plan file or the target cannot be found. Everything after that still produces a signed PERMIT.

The checks in the PERMIT come in this order: the guard check, the validation.bound check, the rule results, then any evidence.* failures. The guard is the org Id and tier check described in the CLI reference. With --no-connect it does not run, the PERMIT records the configured Id and the kind the tier requires, and the guard check is skipped.

gate also writes the facts it evaluated to .glassops/facts.json.

Fail closed

Missing evidence is never a pass.

  • A rule that needs a fact that is not there fails, or says so in its detail.
  • A tool or infrastructure problem while gathering evidence adds a failing evidence.<name> check. The PERMIT denies, is still signed and written, and gate exits 2 instead of 1. Examples: the guard refusing the target, a GitHub API call that fails, a result file that exists but cannot be read, a missing commit or plan hash, and plan files that no longer match the plan hash.
  • A rule set with no rules is a defect, never a pass. So is a rule source that returns no results.
  • Optional Rego rules run after the built-in rules and can only add denials. If opa or a policy file cannot be used, the PERMIT denies and gate exits 2.
  • Only the outcomes pass, skipped, waived_by_config and satisfied_by_approval allow. Any other outcome denies, including a misspelled or empty one.
  • gate owns the facts under change., ci. and target.. The change set file and earlier result files can never set them. From the earlier results in the results directory, gate reads only facts under validate., plan., analyze., test., check. and the provider's own prefix, such as salesforce.. change.destructive_count is the larger of the provider's count and the number of destructive manifests.

The ephemeral automatic PERMIT

A target of tier ephemeral whose login the guard accepted as a scratch org gets an automatic PERMIT. Only the org Id guard applies. The rules are not run, no GitHub API call is made, and the PERMIT carries an ephemeral check and a not_applicable separation of duties record. The tier decides, not the kind of org. A target of any other tier, such as drill or uat, gets every rule of its tier, the blackout cap on its expiry and the GitHub evidence, even when its org is a scratch org. The org kind is still recorded in the PERMIT's target.kind and in the target.kind fact. A target that names no tier but is listed under environments counts as tier ephemeral. The guard refuses a tier ephemeral target that is not a scratch org. The automatic PERMIT is issued only when the guard really ran and passed, so --no-connect on an ephemeral target runs the full rule set instead. The result fact gate.ephemeral says which happened.


What permit verify and deploy check

Both use the same verification, in this order. The first failure is the one reported.

permit verify, before the PERMIT checks:

  1. The key. A missing or unusable key is an error (exit 2) before anything else is read.
  2. The config, the target, the change set and the commit. A problem reading any of them is an error (exit 2).
  3. The PERMIT file. A missing file is an error (exit 2). A file that is not a readable PERMIT is a failure (exit 1).
  4. The plan files. If the files under .glassops/plan/ no longer hash to the change set's plan_sha256, the plan was edited after plan and the check fails (exit 1).

deploy, before the PERMIT checks, reads the target, the change set, the config hash and the commit, then checks the plan files the same way. In deploy every refusal is exit 2, because nothing may touch the target. The login comes after verification.

The PERMIT checks, shared by both. Before all of them, a PERMIT whose kind is operations is refused by name, so deploy stops with a message that says it is an operations PERMIT, before any login. A kind that is not deploy or operations is refused too. permit verify prints the kind, as the check and the fact permit.kind.

  1. It is signed and has a change_set_sha256.
  2. The signature: the algorithm is HMAC-SHA256, the key id matches, and the value verifies. With Sigstore signing the algorithm is sigstore-bundle and cosign checks the certificate identity, the issuer and the repository instead of a key id.
  3. The schema is glassops.permit/v1.
  4. allow is true.
  5. It has not expired.
  6. Its lifetime is sound: issued_at is set and not more than 5 minutes ahead of this clock, expires_at is after issued_at, and the lifetime is no longer than policy.permit_ttl.
  7. The target name matches.
  8. The target Id matches. Ids compare on their canonical form, so a 15 and an 18 character form of one Id are equal.
  9. The commit matches.
  10. The plan hash matches.
  11. The config hash matches.
  12. The change set hash matches.
  13. For deploy -- <command> or permit verify --deploy-command <command> with provider exec, the PERMIT binds that exact command. A PERMIT with no deploy_command_sha256, or a different one, is refused.
  14. For a pipeline exec step with a target on any tier but ephemeral, the PERMIT lists that step's command in exec_commands_sha256. A PERMIT that does not is refused, and the step logs in to nothing.

Checking the signature first means a forged or damaged PERMIT is rejected before any of its contents are trusted. deploy additionally compares the PERMIT against the deployed commit, which is the CI's commit, or git rev-parse HEAD when the CI reports none.

After the PERMIT verifies and before it logs in, deploy checks the working tree. git rev-parse HEAD must be the PERMIT's commit, and git status --porcelain --untracked-files=no must be empty, so no tracked file is modified or staged. Untracked files, such as .glassops itself, are not looked at. The refusal is exit 2 and names the commit and up to 10 modified paths, never file contents. When git is missing or the directory is not a repository, deploy refuses too.

deploy --resume <job> is accepted only when .glassops/results/deploy.json names that job, the same PERMIT Id and target, and records deploy.timed_out as true. Anything else is exit 2.


Operations PERMIT

Some production commands are not a deploy and have no plan: a heartbeat query, a cache refresh, a failure event written after a smoke test. glassops gate --ops <name>[,<name>] issues a PERMIT of kind operations for them. The operations are declared under operations in glassops.yaml, see Operations. The config is bound by config_sha256, so the commands are part of what was reviewed.

An operations PERMIT differs from a deploy PERMIT in these ways:

Deploy PERMIT Operations PERMIT
kind absent operations
plan_sha256, change_set_sha256 the plan and change set hashes empty
exec_commands_sha256 the commands named with --exec-command, if any the SHA-256 of each named operation's run text, or of the argument list a list run makes with its values
operations absent the operation names
operation_params absent the value of each param, and the blob of each file param
Lifetime policy.permit_ttl policy.operations.ttl, default 15 minutes
Signing policy.permit.signing, identity, issuer policy.operations.signing, identity and issuer where set, else the policy.permit values. The repository is shared
Run from any ref the default branch only
Approval separation of duties, as configured a schedule_ok operation is approved by the reviewed config. Any other operation needs the approval a deploy needs

What gate --ops checks, in the PERMIT's checks:

  • guard: the org Id and tier guard on the operations' one target, logged in with its default login, as for a deploy.
  • default_branch: the run's ref is the repository's default branch. See glassops gate for where the default branch comes from. A pull request, a tag or any other branch is denied, so a branch cannot add an operation and run it.
  • tree: git HEAD is the run's commit and no tracked file is modified, the check deploy makes. The script a command runs is then the reviewed one.
  • config_commit: glassops.yaml is committed. The commit that last changed it is recorded.
  • blackout, unless policy.operations.blackout is false. window, only when policy.operations.window is true. Each is recorded as skipped, with the reason, when it does not apply. The PERMIT also expires at a blackout start, and at a window end when the window rule applies, when either is before policy.operations.ttl.
  • separation_of_duties: for operations that are all schedule_ok, a pass whose mechanism is config_commit. The PERMIT's separation_of_duties block has mode reviewed_config and the mechanism config_commit:<sha>. Otherwise the configured rule applies, as it does to a deploy.
  • plan_not_empty, coverage_min, destructive_needs_label, analyzer_max_severity and validate_passed are skipped with the detail operations PERMIT, no plan.
  • command.<operation>: one pass per operation whose run is a list, whose detail is the exact argument list and the values, such as runs ["sf","community","publish","--name","Portfolio","--json"] as an argument list, with no shell, with site="Portfolio".

An operations PERMIT can never authorize a deploy. deploy, and an exec step that carries its own run, refuse it by name before any login. A deploy PERMIT cannot authorize an operation either. The permit verify command checks an operations PERMIT without a plan. It checks the signature, expiry, a lifetime of at most policy.operations.ttl, the target, the commit and the config hash, and that each operation the PERMIT lists is still declared on this target with the command the PERMIT binds. Because the commands are bound by hash, a PERMIT for one operation does not serve another operation with a different command, and an edited run no longer matches.

A PERMIT with a kind field cannot be read by a glassops older than v1.3, which refuses fields it does not know. Update the verifying side first.

Param values

An operation whose run is a list can take params. The values are bound at gate: gate --ops publish-site --param site=Portfolio checks each value against its limits before any rule runs, records it in operation_params, and binds the digest of the argument list the values make. A bad or missing value stops gate with exit 2 and no PERMIT. A file value must be tracked in git at the commit and unchanged in the working tree, and the PERMIT records its blob.

The operation step and glassops op read the values from the PERMIT only. They rebuild the argument list from the config and those values, check that its digest is bound, check each file blob at HEAD and in the working tree, and run the program with no shell. A value edited in the PERMIT file fails the signature. A value that no longer fits its limits, or a changed template, no longer gives the bound digest. A new value needs a new gate. The PR comment from report and the permit verify output show the values, so whoever approves sees the exact command.

An HMAC key held by a scheduled job is a bigger exposure than one held by a deploy job behind an environment approval. Sigstore keyless signing ties the signature to the workflow's identity, so a PERMIT made by a fork or another workflow fails verification. Set policy.operations.signing: sigstore to require it for operations, see Sigstore signing. With it set, an HMAC PERMIT is refused on its algorithm. When the scheduled job is a different workflow from the deploy, also set policy.operations.identity to that workflow, see policy.operations.

Rego rules see permit.kind in the facts, deploy or operations, and one permit.params.<operation>.<param> fact per bound value, so a team can write rules of its own for operations and their values.


Validation binding and quick deploy

gate can bind a check-only validation into the PERMIT, so deploy can quick deploy it instead of deploying again. It binds the validation only when all of these hold for .glassops/results/validate.json:

  • The result passed.
  • It is for the same target name.
  • It was a check-only run with a deploy Id.
  • It records the plan hash it validated (validate.plan_sha256) and that hash equals the current plan.
  • It records the change set hash it validated (validate.change_set_sha256, the same hash as the PERMIT's change_set_sha256) and that hash equals the current change set. A validate result written before this fact existed has none, so it is not bound. Run validate again.
  • It did not record that no tests ran. A validation with salesforce.tests_total 0 is not bound, because the target refuses to quick deploy it.

The PERMIT then carries validation with the deploy Id and the recorded test level. The validation.bound check says whether it was bound and why not. It never denies. Without a bound validation, deploy runs a full deploy.

How deploy uses it depends on salesforce.deploy.quick in glassops.yaml:

Value Behaviour
prefer (default) Quick deploy the bound validation. If the target refuses it, fall back to a full deploy and record salesforce.quick_refused
require Quick deploy only. With no passed validation in the PERMIT, deploy fails with exit 1 before any login. If the target refuses the quick deploy, no full deploy runs
off Always run a full deploy

The target refuses a quick deploy when the validation was never run, was already deployed, or is more than ten days old. It also refused one in testing when another deploy reached the target after the validation, so run any other deploy to the same target after deploy, not between validate and deploy.

At RunRelevantTests, Salesforce picks the tests from the Apex in the change set. A change set with no Apex class or trigger runs no tests, so its validation is not bound and deploy runs a full deploy. Do not combine RunRelevantTests with quick: require, or every change set with no Apex fails at deploy.


The v1 rules

gate runs these seven rules, in this order. Every rule runs, so the PERMIT lists every reason for a deny. Only a fail outcome denies. The outcomes are pass, fail, skipped, waived_by_config and satisfied_by_approval.

Rule Outcomes
plan_not_empty fail if the plan has no changes, or the facts do not say. Otherwise pass
window.<tier> See below
blackout See below
coverage_min See below
destructive_needs_label See below
separation_of_duties See below
analyzer_max_severity See below

gate then checks validate_passed on its own.

window.<tier>

Named after the target's tier, such as window.prod. Configured as policy.windows.<tier>, a list of weekly windows with days, from, to and tz.

  • skipped when no window is configured for the tier.
  • pass when now is inside any window for the tier.
  • fail when now is outside every window, or a window cannot be used (an unknown time zone or a bad clock).
  • fail, under the plain name window, when the tier is unknown and any window is configured anywhere.

Times are wall clock times in the window's zone, so the window moves with daylight saving time. A window is from up to but not including to. A window whose to is earlier than its from runs past midnight and belongs to the day it starts on. A window where from equals to never matches.

blackout

Configured as policy.blackouts, a list with from and to dates (YYYY-MM-DD), optional tiers and an optional reason. Dates are compared in UTC, because a blackout has no time zone, and both ends are included.

  • skipped when no blackouts are configured.
  • fail when today (UTC) falls in a blackout that covers the target's tier. An empty tiers list covers every tier. When the tier is not known, every blackout in range counts.

The rule refuses a gate that runs inside a blackout. gate also ends the PERMIT when the next blackout for the tier begins, so a PERMIT issued earlier expires before it and is refused inside it. deploy does not look at blackouts itself, because the config is bound into the PERMIT by hash and the expiry is checked at deploy. - pass otherwise.

coverage_min

Configured as policy.rules.coverage_min, a whole number from 0 to 100.

  • skipped when it is not set.
  • fail when the plan facts do not list the changed Apex classes.
  • Otherwise it checks each changed Apex class against the per class coverage facts from the validate result. A class below the minimum fails. A class with no coverage fact fails too, unless it is a test class. Salesforce reports no coverage for test classes. plan reads each changed class file and records the ones annotated @IsTest (any case, with or without arguments) in the fact salesforce.apex_test_classes. Those are treated as test classes whatever their names, and the detail says how many and why. A @IsTest method inside a normal class does not make the class a test class. An Apex interface or enum has no executable lines, so Salesforce lists no coverage for it. plan also records the changed classes whose top level type is an interface or enum in the fact salesforce.apex_nonexecutable_types. Those are not measured, and the detail gives their count. An abstract class is a class and is still measured, and so is a class that implements an interface or holds an inner interface. A type in that fact that does have a coverage entry is still held to the minimum. A plan file written before these facts existed has neither, and then a name ending in Test or _Test marks a test class and an interface with no coverage fails as before.
  • skipped when the change set has no Apex class with coverage to measure, such as a change with no Apex or only test classes. A rule that measured nothing never reads as a pass.
  • pass when every measured class is at or above the minimum.

validate_passed

Configured as policy.rules.validate_passed with tiers. It covers [prod] when it is not set, and an empty tiers list switches it off. It is checked by gate itself, after the rules above, and does not run for an ephemeral target.

  • skipped when the target's tier is not covered, when this run has no validate result, or when the validate result is for another target or another plan.
  • fail when the validate of this plan for this target did not pass. A failed validate then denies the PERMIT, so no deploy starts after a red validate.
  • pass when it passed.

The rule reads the validate result file, which is not signed, only to deny. It can never allow a deploy that another rule denies.

destructive_needs_label

Configured as policy.rules.destructive_needs_label with a label and optional tiers. An empty tiers list covers every tier.

  • skipped when it is not set, or the target's tier is not covered.
  • fail when the tier is unknown, or the facts do not say how many destructive changes the plan has.
  • pass when the plan has no destructive changes.
  • With destructive changes: fail when no pull request was found, or the pull request lacks the label. pass when it has the label.

This rule has unit tests but has not yet run against a real repository.

separation_of_duties

Configured as policy.rules.separation_of_duties with tiers and an optional approval. It makes sure the person who deploys is not the author of the change.

  • skipped when the rule is not set.
  • waived_by_config when the target's tier is not in tiers. An empty tiers list turns the rule off everywhere, because every tier is then outside the list.
  • Enforced when the tier is in tiers. The author is the pull request author and the deployer is the CI actor, compared without regard to case.
    • With no approval configured, it passes when both are known and differ, and fails when either is unknown or they are the same.
    • With an approval configured, it passes when they differ. When they are the same or unknown, it looks for a configured approval and gives satisfied_by_approval, or fail when none is found.

Two kinds of approval can satisfy the rule:

Mechanism Configured as Counts when
environment approval.environment The run has an approved review for that environment
label approval.label and approval.approvers The pull request has the label, and the person who added it is one of the approvers

A label approver may be the pull request author. The explicit approval by a listed approver is the control.

Label approval has unit tests but has not yet run against a real repository. Environment approval has run on a real project.

The PERMIT's separation_of_duties block records the result. Its mode is enforced, waived_by_config, satisfied_by_approval or not_applicable (the rule is off, or the PERMIT is an ephemeral automatic one). It also holds the author, the deployer and, for an approval, the mechanism and approver.

analyzer_max_severity

Configured as policy.rules.analyzer_max_severity, a whole number from 1 to 5, where 1 is the worst.

  • skipped when it is not set.
  • skipped when there are no analyze facts, because the analyzer did not run. This is the one place a missing fact does not fail: a limit with no analysis behind it is not enforced until analysis exists.
  • fail when the facts show any violations at the configured severity or worse.
  • pass otherwise.

Configuration example

version: 1
provider: salesforce
targets:
  prod:
    id: 00D000000000000
    tier: prod
    branch: main
    auth: { method: jwt, username: $SF_PROD_USERNAME, client_id: $SF_CLIENT_ID, key: $SF_JWT_KEY }
policy:
  permit_ttl: 2h
  windows:
    prod:
      - { days: [tue, thu], from: "18:00", to: "22:00", tz: America/Chicago }
  blackouts:
    - { from: "2026-12-20", to: "2027-01-03", tiers: [prod], reason: holiday freeze }
  rules:
    coverage_min: 85
    destructive_needs_label:
      label: destructive-ok
      tiers: [prod]
    separation_of_duties:
      tiers: [prod]
      approval:
        environment: glassops-deploy
    analyzer_max_severity: 2
salesforce:
  test_level:
    prod: RunLocalTests
  deploy:
    quick: prefer

permit_ttl is a duration from 5 minutes to 24 hours. The default is 2 hours.


Evidence gate reads from GitHub

Some rules need facts that only GitHub knows. When the CI is GitHub and a token is available in GITHUB_TOKEN or GH_TOKEN, gate reads them through the GitHub API. Without a token it reads nothing, the facts stay absent, and the rules that need them fail. The ephemeral automatic PERMIT makes no API calls. GITHUB_API_URL overrides the API address.

Read Used for Token permission
GET /repos/{repo}/pulls/{number} on a pull_request run Pull request author and labels pull-requests: read
GET /repos/{repo}/commits/{sha}/pulls on a push The merged pull request for the commit, its author and labels pull-requests: read
GET /repos/{repo}/actions/runs/{run_id}/approvals Environment approvals for this run actions: read
GET /repos/{repo}/issues/{number}/events Who added the approval label, only when approval.label is configured and the pull request has it issues: read

On a push, the actor is GITHUB_ACTOR, the person who pushed or merged. A push that was not merged from a pull request has no author, and a rule that needs one fails. A call that fails adds an evidence.ci.* failure, so gate denies and exits 2.

The job also needs contents: write for deploy, because it pushes the glassops/deployed/<target> tag. Without it the deploy still succeeds and only the tag push warns.