Skip to main content

pubsec

The commands and deploy need types that hold a secret value, a write token or a private key in memory, kept apart from pubrules, which only reads about secrets (their names, keys, lengths and declarations). The rule that draws the line: code that holds a secret, a write token or a key lives here; code that reads a declaration stays in pubrules.

pubsec has no runtime dependencies. Bitwarden's SDK is installed for a run, by hash, by the commands that write (see "Making a service account key"), and bws, gh and gcloud are programs it runs.

A repository runs its pinned pubsec as ./pubsec, which pubrules's sync writes beside ./pubrules wherever there is a with-secrets.json or a deploy block. It runs the release wheel pubrules pins, through uvx, checking its sha256 on every run:

./pubsec --version
./pubsec types

Services: ./with-secrets

A service runs every command that needs a secret through ./with-secrets:

./with-secrets terraform plan
./with-secrets scripts/setup-backup.sh

It reads a Bitwarden Secrets Manager project with the bws CLI, using a read-only machine account's token (BWS_ACCESS_TOKEN, or that line in the repository's git-ignored .env, or else one it asks for at the terminal, hidden, for that run), and runs the command with the secrets in its environment only: the calling shell never holds them, and no master password is asked for. It stops, naming the projects the token can see, when it cannot see the one configured. with-secrets.json is the repository's:

Setting Meaning
project The project's name or id
terraform.dir Where the Terraform files are
terraform.secrets declared: a secret named like a declared variable in upper case (HCLOUD_TOKEN for hcloud_token) goes as TF_VAR_hcloud_token and under no other name. map: the names terraform.names_from lists go as TF_VAR_secret_values (declare it ephemeral) and TF_VAR_secret_revisions
also Optional: {"project": "...", "names": [...]}, secrets taken by name from a second project (below)
aliases Optional: files (paths from the repository root), each {"aliases": {"NAME": "secret"}}, that also export the secret named secret as NAME, for a tool that reads a fixed name (the Tailscale Terraform provider reads TAILSCALE_OAUTH_CLIENT_ID). Keep each file next to the code that needs it. An alias of a secret Bitwarden does not have is reported and skipped

Every other secret goes under its name in upper case, - as _, and PUBRULES_SECRETS_PROJECT names the project they came from, so pubrules's deploy walk can tell a secret that is absent from one that was never read.

also takes secrets a command needs from a project the token in .env is better off not seeing, such as an administrator's keys. Only those named are read: their ids come from the project's identifiers (Bitwarden's SDK, fetched with uv by hash), which hold no value, and each is read by its id. When the token in use does not see that project, pubsec asks for one that does at the terminal, for that run: it is not echoed or kept, and the command never gets it. Without a terminal the run stops. A name in both projects is taken from the second, and said. Every run that reads Bitwarden reads them, so each run asks; pubsec ci-values can send them too, and a run with PUBSEC_VALUES reads neither project.

A typed token is kept nowhere, and the command does not get it: a kept one is in its BWS_ACCESS_TOKEN. So a laptop needs no .env, and a token that also reads the second project of also is asked for once. Without a terminal, as in CI, a run with no token stops.

./with-secrets is one line, which pubrules manages: it runs ./pubsec run --cwd "$PWD" -- COMMAND, so the repository's pinned pubsec does the work, in the directory it is called from, and needs uv (for ./pubsec) and bws. pubsec run can be called directly too:

./pubsec run -- terraform plan        # in the repository's root
./pubsec run --cwd "$PWD" -- make deploy

Its exit code is the command's, 127 when the command is not there and 126 when it may not run, and 1, before anything runs, for a setting it can't use.

Sending secrets to a repository

A repository names the values it needs in its pubrules.json. A GitHub App has three, and may have a fourth, its client id, in github_app, which may also be a list of apps. secrets lists any others, each with a kind of secret or variable:

"github_app": {
  "id":              { "from": "some-app-id", "to": "SOME_APP_ID" },
  "installation_id": { "from": "some-app-installation-id", "to": "SOME_APP_INSTALLATION_ID" },
  "key":             { "from": "some-app-key", "to": "SOME_APP_KEY" },
  "client_id":       { "from": "some-app-client-id", "to": "SOME_APP_CLIENT_ID" }
},
"secrets": [
  { "from": "some-token", "to": "SOME_TOKEN", "kind": "secret" },
  { "from": "some-user", "to": "SOME_USER", "kind": "variable" },
  { "from": "some-deploy-key", "to": "SOME_DEPLOY_KEY", "kind": "secret", "environment": "some-env" }
]

from is the secret's name in the Bitwarden project ./with-secrets reads, and to its name on GitHub. An app's id, installation id and client id go as variables and its key as a secret, on the repository origin points at and no other. environment, on an entry in secrets, puts it in that GitHub environment, which must already exist, instead of the repository's own:

./with-secrets ./pubsec app-secrets --check   # checks only, sends nothing
./with-secrets ./pubsec app-secrets

It writes nothing until every one is there and looks right (digits for an app's ids, Iv and then letters, digits and . for its client id, BEGIN and END lines for its key, and not empty for the others). It prints names and lengths, never a value, and each value reaches gh on its standard input. An app installed on several owners has a different installation id on each, so each repository names its own owner's. A workflow mints the app's token with actions/create-github-app-token, which takes the client id as client-id (its app-id is deprecated), and the key. pubrules sync --check checks both blocks.

A workflow's values, without a Bitwarden token

A workflow that runs through ./pubsec run, such as Terraform's, reads the whole Bitwarden project with a BWS_ACCESS_TOKEN. Instead, a laptop can send the values that workflow needs to its GitHub environment, as one secret, PUBSEC_VALUES. with-secrets.json names them by their Bitwarden names:

"ci_values": { "environment": "terraform", "names": ["some-token", "other-token"] }
./pubsec ci-values --check   # what the environment has, sends nothing
./pubsec ci-values

It reads Bitwarden as ./with-secrets does, so it needs no ./with-secrets in front. The secret is JSON: each name with its value and its last change, which Terraform's map mode takes as the value's revision, the same from a laptop and from CI. With PUBSEC_VALUES in its environment, pubsec run reads the named values from it, asks Bitwarden nothing and needs no bws; the command sees neither it nor PUBRULES_SECRETS_PROJECT, as these are not the whole project. Values it lacks, or that with-secrets.json does not name, stop the run or stay out of it.

Any workflow on any branch can read a repository's or an organization's secret, so it sends to an environment only, and refuses one that does not limit its deployment branches to names (or to protected branches). A value missing in Bitwarden, or more than GitHub's 48 KB, stops it before anything is sent. Values go to gh on its standard input, and only names and lengths are printed.

GitHub masks PUBSEC_VALUES in a log as a whole, not each value in it, so a workflow masks them itself before anything runs (pubhost's terraform.yml). Nothing there notices a value that changes in Bitwarden: send them again. --check exits 1 when the secret is missing, or a named value changed after it was sent; which names it holds cannot be read back.

Organization secrets for selected repositories

An app that several repositories share, such as one that reads data across the organization, is set once on the organization instead of in each repository. The org_secrets block in the pubrules.json that holds the organization's apps names its values, by the same slots as github_app (any of id, installation_id, key and client_id), the organization, and the repositories that may read them. It may be a list of such blocks, one per app:

"org_secrets": {
  "org": "some-org",
  "repositories": ["some-repo"],
  "app": {
    "client_id": { "from": "some-app-client-id", "to": "SOME_APP_CLIENT_ID" },
    "key":       { "from": "some-app-key", "to": "SOME_APP_KEY" }
  }
}
./with-secrets ./pubsec org-secrets --check   # reports how GitHub differs, writes nothing
./with-secrets ./pubsec org-secrets

As in app-secrets, the ids and the client id go as organization variables (vars.SOME_APP_CLIENT_ID: a client id is no secret, and a variable's value can be checked) and the key as an organization secret. Each is visible to selected repositories, and the listed ones are added to its selection one at a time, so a repository already selected stays and none is ever taken off; to take one off, do it on GitHub. One that exists visible to all or to private repositories is never narrowed: the run refuses, before writing anything, to change it.

It checks the values as app-secrets does (digits, Iv, BEGIN and END lines), then asks GitHub what it has, shows that, and writes, with no prompt: it only sets the named values and adds repositories. A missing value, a repository that is not there, or a gh login that may not manage the organization's secrets stops it before anything is written. --check says, for each, whether it exists, is visible to selected repositories, and which listed repositories it is not visible to, and for a variable whether its value is Bitwarden's; it exits 1 on any difference. A secret's value is never compared, as GitHub never returns one.

It runs as your gh login, which must be an organization owner's with the admin:org scope (gh auth refresh -h github.com -s admin:org). A secret's value reaches gh secret set --no-store on its standard input, which seals it to the organization's public key and prints only the sealed box, and that reaches gh api on its standard input; gh secret set --org --repos is not used, as it replaces the selection. No value is printed or on a command line.

Creating a GitHub App

pubsec github-app create makes an app with GitHub's manifest flow and puts its four values in Bitwarden, under names pubsec app-secrets can then send on. The manifest is the repository's own: GitHub's fields, and a pubrules section GitHub never sees (the name it had when this command was pubrules's), naming the owner (org or user), the Bitwarden project (its name or id) and the prefix of the secrets' names:

{
  "name": "some-app",
  "url": "https://example.org",
  "public": false,
  "default_permissions": { "contents": "read" },
  "pubrules": {
    "org": "some-org",
    "bitwarden_project": "some-project",
    "secret_prefix": "some-app"
  }
}
./pubsec github-app create --dry-run some-app.json   # shows the plan, and does nothing
./pubsec github-app create some-app.json

It goes in this order, so that a refusal comes before there is an app to clean up:

  1. It shows the app, the project and the four names: some-app-app-id, some-app-app-key, some-app-installation-id and some-app-client-id. --dry-run ends here.
  2. It asks for a Bitwarden access token with write access to the project, at a hidden prompt. It is never read from .env or a file and never kept, and it reaches bws only in its environment. ./with-secrets' read-only token will not do for the writes.
  3. It looks for the names in the project, among the secrets' identifiers, which Bitwarden's SDK gives without any value, and refuses if one is there. --replace overwrites them instead.
  4. A server on 127.0.0.1 opens a page that posts the manifest to GitHub, with a random state that must come back. You confirm the app on GitHub, which redirects to the server with a code, and the code becomes the app and its key.
  5. Your browser opens the app's install page. Signing with the new key, pubsec watches GET /app/installations until the app is installed on the owner, takes the installation's id, and says which repositories it reaches: all of them, or the list of those selected. Opening that page may install the app on every repository straight away, with no step in which to choose. To narrow it, go to the owner's settings, then GitHub Apps, then Configure beside the app, and pick "Only select repositories"; the run has printed the link. The installation's id stays the same, so this can wait until after the run.
  6. It writes them, with no prompt, and says which it created and which it replaced: step 3 already refused any name in the project unless --replace was given. If a write fails it offers to try the ones left with another token.

The key is never printed or written to disk: it stays in memory, so if the run ends before it is written, it is gone, and pubsec gives the app's settings page, where you make a new one or delete the app. The same goes for the webhook secret, which GitHub also returns and pubsec does not keep, and for the client secret, unless the manifest asks for it (below). The values are written with Bitwarden's SDK, which takes them in memory, so the key is on no command line (see "Making a service account key" for how it is installed).

An app that signs people in (it has callback_urls, and its server swaps an OAuth code for a user's token) needs that client secret too. Add "keep_oauth_client": true to the pubrules section, and step 1 lists one more name, some-app-client-secret. Step 6 writes it with the other four, from GitHub's own answer, so there is nothing to copy from the app's settings page. If GitHub's answer has none, pubsec says so and writes the other four.

A pull token for ghcr.io is no app's to give, so it stays a manual step.

Making a service account key

pubsec service-account-key create makes a Google Cloud service account key and puts it in Bitwarden, so an app outside Google Cloud can have one without the key ever being in a file, on a command line, or in Terraform's state:

./pubsec service-account-key create --dry-run --account NAME@PROJECT.iam.gserviceaccount.com --secret some-key
./pubsec service-account-key create --account NAME@PROJECT.iam.gserviceaccount.com --secret some-key

It shows the plan, and asks for a Bitwarden access token with write access to the project, at a hidden prompt, as github-app create does. The project is the one with-secrets.json names, or --bitwarden-project. It refuses if the secret is there, found by name among the identifiers; --replace overwrites it. On a typed yes, gcloud writes the key to pubsec's pipe, and Bitwarden's SDK writes it, base64-encoded, from memory. If that write fails the new key is deleted from Google. The account's other keys are left working, and listed, so whatever holds one can move over before it is deleted.

The SDK is not a dependency of pubsec: the command installs it with uv for that run alone, by the hashes in src/pubsec/bitwarden-sdk.lock. Its wheels are under Bitwarden's own SDK licence, not pubsec's.

Backing up signing keys

A repository names every signing key it uses, and where it is backed up, in pubrules.json:

"signing_keys": [
  {"path": "corpus/.publet/signing.key",
   "bitwarden": {"project": {"id": "PROJECT-UUID", "name": "Pub"},
                 "name": "pub-signing-key-example"}}
]

The project is found by its id; name is a label for people, and a run warns when Bitwarden's name for the project has changed. A plain string is taken as an id when it is a UUID, else as a name, in any case.

path is from the repository's root, or from the home directory when it starts with ~/: a key kept outside any repository, such as one under ~/.config, is declared by the repository whose tools use it. pubrules sync --check refuses a block it can't use.

pubsec signing-key backup [--under DIR] [--dry-run]

reads the declarations of this repository, or of every repository directly under DIR, and writes each declared key that is on this machine and not yet in its project, with Bitwarden's SDK, from memory. The access token, which must be able to read and write those projects, is asked for at a hidden prompt. A secret already there is found by name among the project's identifiers, and only the values of those named as the declared keys are read, to compare: one with the same value is left alone; another value under the same name is never overwritten and fails the run, as do two different keys declared under one name. A key pubrules.json does not declare, at corpus/.publet/signing.key or .publet/signing.key, is pointed out. --dry-run lists what it would write and asks for nothing. No key or token is printed or put on a command line.

Making what a service needs

pubrules's deploy walk checks every need of a repository's deploy block, and with --fulfil makes what is missing (pubdeploy's README, "Declaring what a service needs"). Nine of its types are pubsec's, installed under the entry-point group sustenaut.needs, so a repository's deploy.providers lists pubsec at the release pubrules pins (pubrules sync adds it). ./pubsec types lists them:

type its check its fulfil it needs
bitwarden.secret the secret is in the Bitwarden project ./with-secrets read: its length none: a person puts it there ./with-secrets
bitwarden.generated as bitwarden.secret, and the value has its shape a new value of its shape, written to Bitwarden, and kept for the Secret it fills a write token
bitwarden.adopt the secret is in Bitwarden; when it is not, whether its secret (a Secret's key in the cluster) holds a value of its format (a regular expression) and shape to keep: missing if so, blocked if not (bitwarden.generated should make one then) the cluster's value copied into Bitwarden, with its note, and kept for the Secret it came from: never printed kubectl that reads Secrets (the admin channel or the plane), a write token
gcp.service-account-key the key in Bitwarden is one of the account's live keys a new key, written to Bitwarden, deleted from Google if that fails gcloud, a write token
gcp.workload-identity the workload's Kubernetes ServiceAccount may act as the Google account through the Workload Identity pool (roles/iam.workloadIdentityUser on the account, read from its IAM policy), so the workload needs no key none: it proposes the grant, and with granted_in the row in that Terraform file gcloud that may read the account's IAM policy
github.secret it is set, on the repository or in its environment gh secret set of what the secrets and github_app blocks name, from Bitwarden, as pubsec app-secrets does ./with-secrets
github.variable it is set, and is Bitwarden's value when one is named; one the variables block declares is the state file's, and only proposed. With its default (the variables block's, version 2: the code's own constant, any JSON value), one unset or empty, as a deploy renders a variable nothing sets, is ready at its default, and one set to a value equal to it, compared canonically, says so gh variable set, as above ./with-secrets
github.deploy-settings the five names the server's deploy job reads are set on the repository or its server environment each the secrets block names, set from Bitwarden ./with-secrets
k8s.secret the Secret has its keys, each value of a known shape having it; over the deploy channel, its key names alone a Secret manifest from the values of the needs that fill it, on kubectl's standard input, then a restart of each Deployment in the cluster whose pods read it kubectl that writes

The write token is asked for by pubsec's sustenaut.walk hook, bitwarden = "pubsec.walk:prepare": before a walk fulfils a need that wants one, at a terminal, pubrules calls it, and it asks once in the process, at a hidden prompt, for a Bitwarden access token with write access to the project ./with-secrets read (PUBRULES_SECRETS_PROJECT, else with-secrets.json's). The writer it gives the walk keeps the token in the process only, finds the secret to update by name among the identifiers, and writes the value from memory with the SDK. Without a terminal, the token is read from the file PUBSEC_WRITE_TOKEN_FILE names (the convergence engine's Fulfil mounts one from a Secret), never from an argument or a plain environment variable. A walk from GitHub Actions, or with --yes and no terminal and no such file, asks for none, and those needs are unknown, saying so.

A value moves only on a standard input: never in an argv, a file, a log or the journal. pubrules is installed wherever a deploy block is walked or checked, CI included, and pubsec with it, as sync --check validates every need with its type's schema; in CI without a write token pubsec reads nothing. The trust boundary is the token, not the code.

The provider contract

pubsec imports nothing of pubrules at runtime. A check or a fulfil uses the walk's Context by these names alone, which pubrules lists in its README under "Provider contract" and does not change without saying so in its changelog: root, config, block, namespace, unit, channel, kubectl, server, gh, send, bitwarden_writer, http_get, env, now, rendered, offline, slug, zones, resolve, values, types, needs, results, sleep and dispatched. It returns its own Result, with state, summary, fix, details, fixable and step. tests/steps/test_contract.py fails when pubsec uses another name or imports pubrules.

Developing

make venv     # .venv from tests/requirements.lock, with this checkout editable
make check    # ./pubrules sync --check, and the Gherkin suite with its coverage

The suite runs every command end to end against stand-ins for bws, gh, gcloud, uv, a browser and Bitwarden's SDK, and the seven types through pubrules's own walk (pubrules is a test dependency, pinned in tests/requirements.txt). Every fake value in the deploy scenarios holds a canary, and tests/steps/test_canary.py fails when one reaches an output, the journal, an exception's text or a command line.

Releasing

With pubrel, like the other Sustenaut packages. A pull request that changes src/ or pyproject.toml records what it changes (pubrel add fixed "…", or internal for no release), and CI checks it. To release, run pubrel prepare on an up-to-date main in a checkout holding the release key (corpus/.publet, gitignored): it sets version in pyproject.toml (__version__ reads it), signs the release and opens its pull request. Merging that tags vX.Y.Z and makes the release, and wheel.yml then attaches pubsec-X.Y.Z-py3-none-any.whl, the wheel pubrules pins by its sha256.

Licence

Apache-2.0.

Metadata

Release files for pubsec 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pubsec 0.6.0
File Interpreter ABI Platform Actions
pubsec-0.6.0-py3-none-any.whl Python 3 none any Details for pubsec-0.6.0-py3-none-any.whl

Release files / pubsec-0.6.0-py3-none-any.whl

Download URL pubsec-0.6.0-py3-none-any.whl
Size 77.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fbc536063c635c7cf86543ee15da625bf9f6da3114502674d4983964ff245e6
BLAKE2b-256 checksum
How to use checksums
583f27a724b91946d2aeb9d957d3aa09176fc7133e04138a1208f6d3f892013a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for pubsec 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for pubsec-0.6.0-py3-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page