Source control
An instance can keep its configuration (the whole instance as code) in a git repository: commit and push it from Management, Source control, pull and apply the repository's version with a dry run first, start from the repository so it is the source of truth and the backup, and let the instance push every change or pull at an interval. A branch per environment, signed commits, and a diverged branch resolved by a person (a side, or a pull request at the git host) are on this page too.
What it needs
- The
gitbinary. The container image includes it (andssh-keygenfor deploy keys); elsewhere put git on thePATH. Without it the status says so and every operation answers503. RUSTYBIN_STATE_DIR: the working copy lives in<state>/repo, the deploy key in<state>/repo.key.- A remote whose host passes the outbound policy:
the host of the configured remote is allowed under the purpose
gitonce set, and always-refused addresses stay refused. A local repository (a path or afile://URL, for tests and demos) needsRUSTYBIN_EGRESS_ALLOW_LOOPBACK=trueor theegress.allow_loopbacksetting.
git is held to what the policy checked: it connects to the addresses the policy
pinned (curl's resolve list for https, ssh's HostName for ssh, the host key still
checked under the remote's name), follows no redirect, may use only the remote's
transport (protocol.allow=never plus https, ssh or file), and runs with a cleared
environment (PATH and its own variables, never the instance's secrets). Transport
helpers (name::address remotes) are refused, and so is a remote's user name that
starts with - (it would reach git as an option).
What a repository writer can do
Anyone who can push to the repository controls what the document describes: the mocks, the settings it names, the registry and portal entries, the harness scenarios, the agents' rules and the health toggle, on the next pull with apply. (With verified pulls on, only when a signer the instance allows signed the commits.) Nothing more:
- Not the host's files. A symbolic link in the working copy (
specs/, the document, a spec) is refused when committing, git checks links out as plain files (core.symlinks=false), and a mock'sspec:file must be a relative path inside the repository (no.., no absolute path, no link). - Not the process environment. A pulled document is never expanded as text: a
${NAME}in a mock example stays that text. Undersecrets:a reference reads only the variable that seeds that very secret (assist.openai_key: ${RUSTYBIN_ASSIST_OPENAI_KEY}); a literal value, or another variable, is refused with a problem. (A file given toRUSTYBIN_CONFIG_FILEis the operator's own and is still expanded as before.) - Not secret values in answers. A diff names a secret's reference or says "a value", never the value, and the same reference on both sides is no change.
- Not where the instance sends requests.
egress.allow,egress.allow_loopback,assist.provider,assist.base_urlandproxy.client_ip_headerare never changed by a pulled document: a different value is a problem and the setting is kept as it is (prune leaves them alone too; the same value is quiet, so an export round-trips). The same holds foroauth.client_metadata_documents, which decides whether the instance fetches a client's document for a caller who has not signed in. A test in the document may name a gateway only when its saved copy already names that one, and a test schedule a webhook only when its saved copy already names that one. - Not who reads the portal.
portal.auth(a pull would open every item of apasswordportal) andportal.base_url(where Try it sends a tester's API key) are kept as they are, as above; the portal's items may be closed by a pull, never opened. - Not single sign-on. Every
sso.*setting (the issuer, the client, the role map, the default roles, the groups claim, the allowed domains, provisioning, the password sign-in) is kept as it is: a pusher would otherwise repoint the issuer or map their own group toadmin(Single sign-on). A different value is a problem, and prune leaves them alone. - Not wider roles. A pulled
roles:section never defines, changes or prunes a privileged role (one grantingusers.manageorsettings.security), never gives an existing role a permission it did not grant (any permission: its holders would gain it), and never creates a role thatsso.role_maporsso.default_rolesnames (the provider's groups would give it at the next sign-in). A role may narrow, and a new role nothing names is created (nobody holds it until someone withusers.manageassigns it). Each refusal is a problem, the role kept as it is. - Not the audit log's retention.
audit.retention_daysandaudit.max_bytesare kept as they are (a pusher would otherwise shorten the audit log to erase what they did); a different value is a problem. - Not the sign-in. In password mode a document never changes the console's user name or password hash (a change is a problem), and pruning never removes them, so a document without them cannot bring back the default password; a public instance refuses to clear the hash at all.
- Not who works in a project. A pulled
projects:section creates projects and changes their descriptions, never their members, and never prunes a project; a mock or saved test that exists is never moved to another project (project:), and a checkpoint from the repository never moves a mock between projects. Each is a problem, kept as it is (Projects). - Not other people's mocks. A prune deletes only the instance's own mocks: never a visitor's, an API key's or a running gateway scenario's, and never a mock the document names but could not read (an entry with a typo included).
- Not source control itself. No
git.*setting or secret is changed by a pulled document: not the remote, the branch, the directory, the automatic mode, commit signing, the token, the webhook secret or the signing key. A pusher cannot move an instance to another branch or repository, turn signing off or stop the webhook; a different value is a problem and the setting is kept (the export never carries the group, so only a hand-written document names one). A scenario'sfile:and a mock'sspec:are paths inside the repository, read from the commit: no.., no absolute path, no link. - Not the harness's credentials. Saved scenarios are exported with their API keys
and OAuth client secrets as
secret:stored, filled back from the saved scenario of the same name when applied, and only when the scenario's targets (scheme, host, port,hostoverride) are those of the saved one; the files under the harness state directory are sealed with the secrets key.
A pull reads the document and every spec it names whole, up to their supported sizes
(8 MiB for rustybin.yaml, the instance's spec limit for a spec): a larger file is an
error of the pull, never a shortened file. Each file's size is checked before it is
read.
Connect a repository
The git.* settings (Management, Source control, or PATCH /_rustybin/settings;
seeded by the RUSTYBIN_CONFIG_GIT* variables). Changing one needs git.write on
top of settings.write (the remote and the automatic mode decide where the whole
instance is pushed and what a pull applies), and secrets.write for git.token:
| Setting | Variable | Default | Meaning |
|---|---|---|---|
git.remote | RUSTYBIN_CONFIG_GIT | unset | https://host/org/repo.git (with a token), ssh://git@host/org/repo.git or git@host:org/repo.git (with the deploy key), or a local path. Never with credentials in the URL. |
git.branch | RUSTYBIN_CONFIG_GIT_REF | main | The branch the instance commits to and pulls from. |
git.path | RUSTYBIN_CONFIG_GIT_PATH | rustybin | The directory in the repository that holds rustybin.yaml and specs/ (empty for the root). |
git.auth | RUSTYBIN_CONFIG_GIT_AUTH | token | token for an https remote, deploy_key for an ssh remote. |
git.token (secret) | RUSTYBIN_CONFIG_GIT_TOKEN | unset | A personal access or deploy token. The instance hands it to git through GIT_ASKPASS, which answers the remote's own host only, never on a command line or in a URL, and never shows it again. |
git.username | x-access-token | The user name sent with the token (GitHub accepts any; GitLab deploy tokens have their own; Bitbucket wants the account). | |
git.author | Rustybin <rustybin@example.invalid> | Name <email> of the commits. | |
git.auto | RUSTYBIN_CONFIG_GIT_AUTO | off | push_on_change or pull, see Automatic mode. |
git.pull_every | 5m | The interval of the pull mode (1m to 24h). | |
git.webhook_secret (secret) | unset | The secret a git host signs push webhooks with, see A webhook instead of polling. | |
git.sign | false | Sign every commit this instance makes, see Signed commits. | |
git.signing_key (secret) | unset | The private key commits are signed with: an OpenSSH key without a passphrase. Never the deploy key, never shown again. | |
git.verify | false | Take the repository's side only when an allowed signer signed every commit since the last verified head, see Verified pulls. Turning it on trusts the head of that moment. | |
git.allowed_signers | empty | Who may sign what this instance pulls: at most 50 lines, a name and a public key each (ann ssh-ed25519 AAAA..., or the line of a .pub file). Public keys, not secrets. | |
git.host | auto | Whose API opens a pull request for a diverged branch: auto (GitHub or GitLab when the repository is on github.com or gitlab.com, nothing otherwise), none, github, gitlab or gitea (the kind of a self-hosted host; gitea is Gitea and Forgejo). | |
git.host_api | unset | The base URL of a self-hosted host's API (https://git.example.com/api/v3 for the github kind, https://git.example.com/api/v4 for gitlab, https://git.example.com/api/v1 for gitea). https only. Unset: the public host's API, else the kind's usual path on the repository's host. | |
git.host_token (secret) | unset | The token the git host's API opens a pull request with. Unset: git.token, when that is the authentication and the API is on the repository's own host. Never shown again. |
Deploy key. For an ssh remote, Generate the deploy key (POST /_rustybin/git/key) creates an ed25519 key in <state>/repo.key (mode 0600) and
shows its public half to add to the repository (a deploy key with write access on
GitHub or GitLab). The private half never leaves the instance; {"replace": true}
generates a new one. The remote's host key is accepted on first use into
<state>/repo.known_hosts.
# The deploy key for an ssh remote: none yet, then generated (the public half
# is what the repository gets; the private half stays in <state>/repo.key).
curl -s -H "Authorization: Bearer $ADMIN" "$A/_rustybin/git/key"
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{}' "$A/_rustybin/git/key"
Connect (POST /_rustybin/git/init) clones the branch into the working copy, or
initialises an empty working copy when the remote has no such branch yet (the first
push creates it). An existing working copy is pointed at the remote. With
RUSTYBIN_CONFIG_GIT set the instance connects at startup; otherwise set git.remote
and connect when ready:
# A third instance with nothing but a state directory: the repository is
# configured through the settings, then connected (cloned) on request.
PORT3=$(( PORT2 + 1 ))
while busy "$PORT3"; do PORT3=$(( PORT3 + 1 )); done
RUSTYBIN_HTTP_PORT=$PORT3 RUSTYBIN_HTTPS_PORT=0 RUSTYBIN_GRPC_PORT=0 RUSTYBIN_HOST=127.0.0.1 \
RUSTYBIN_LOG_LEVEL=warn RUSTYBIN_CONTROL_AUTH=open RUSTYBIN_ADMIN_TOKEN=$ADMIN \
RUSTYBIN_STATE_DIR="$work/state-c" RUSTYBIN_EGRESS_ALLOW_LOOPBACK=true \
"$BIN" &
pids+=($!)
C="http://127.0.0.1:$PORT3"
for _ in $(seq 1 100); do curl -fs -o /dev/null "$C/" && break; sleep 0.1; done
curl -s -X PATCH -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d "{\"values\": {\"git.remote\": \"file://$work/config.git\"}}" "$C/_rustybin/settings" >/dev/null
curl -s -X POST -H "Authorization: Bearer $ADMIN" "$C/_rustybin/git/init"
Every operation is admin-only, audited (rustybin::git log lines, the timeline in the
status), serialised by one lock (a call that finds it taken answers 409 with
busy: true: ask again in a moment, as the console does), and runs git with a timeout,
GIT_TERMINAL_PROMPT=0 and no global or system git configuration.
Status
GET /_rustybin/git (admin; ?fetch=true asks the remote) answers the configuration,
whether git is installed and the working copy exists, the last commit, ahead and
behind against the remote, the drift (the changes a commit would record: the
instance's export diffed against the working copy's document, as lines such as
mocks.orders: spec changed (2 operation(s) added)), the deploy key's public half,
signing (whether commits are signed, the signing key's public half and fingerprint),
divergence (what differs, when the branch has diverged) and the timeline of
operations. While another git operation holds the working copy the status answers
busy: true without the last commit, the counts, the drift or the divergence: that
says nothing about them yet, so ask again in a moment.
curl -s -H "Authorization: Bearer $ADMIN" "$A/_rustybin/git"
On an instance where nothing is connected yet, signing and divergence say so:
# The status says whether commits are signed and, on a diverged branch, what
# differs (null here: nothing has diverged).
GET {{base_url}}/_rustybin/git
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.signing.enabled" == false
jsonpath "$.signing.key_set" == false
jsonpath "$.divergence" == null
Commit and push
POST /_rustybin/git/commit {message} exports the instance as a bundle into
<repo>/<git.path>/ (rustybin.yaml and specs/, specs as files so a reviewer
diffs them) and commits; nothing to commit is an answer, not an error. POST /_rustybin/git/push pushes the branch. A commit is signed when git.sign is on
(Signed commits) and its answer says so (signed).
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"message": "Add the orders mock"}' "$A/_rustybin/git/commit"
curl -s -X POST -H "Authorization: Bearer $ADMIN" "$A/_rustybin/git/push"
In the console, Commit and push does both; Write the commit message asks the AI for one from the drift summary (Bring your own AI).
Checkpoints. checkpoints: ["demo-start"] also writes those
checkpoints of the instance to
<git.path>/checkpoints/<name>.json in the same commit (the console's commit card
lists them to tick; rustybin git commit --checkpoint demo-start). A checkpoint holds
mock data, so only a commit that names it writes one: the automatic mode never does,
and no commit stages anything else in that directory. Another instance lists them
after a pull and restores one with ?from=git:
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"message": "The demo-start checkpoint", "checkpoints": ["demo-start"]}' "$A/_rustybin/git/commit"
curl -s -X POST -H "Authorization: Bearer $ADMIN" "$A/_rustybin/git/push"
Pull and apply
POST /_rustybin/git/pull {apply, dry_run, prune} fetches and fast-forwards the
working copy; with apply it applies the repository's document through the
configuration document's apply.
The document and its spec: files are read from one commit (HEAD after the pull),
never from the working copy's files. A dry run reads the commit the pull would move
to (the remote branch) without moving the working copy and answers the diff, so the
preview and the apply read the same files; prune makes the document the whole
truth. The apply runs on the compile pool: when it stays busy the pull answers 503.
The console shows the diff first, then Pull and apply. Every pull also answers
checkpoints, the names of the repository's checkpoints at the commit it read; a pull
never restores one (POST /_rustybin/checkpoints/{name}/restore?from=git does, see
Checkpoints).
# A pull with a dry run shows what the repository would change (nothing here).
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"apply": true, "dry_run": true, "prune": true}' "$B/_rustybin/git/pull"
A diverged branch
The instance never merges. When the branch has diverged (commits here and commits
there), push and pull answer 409 with conflict, ahead, behind, options and
divergence: what differs. The status carries the same divergence (null when
nothing has diverged):
local_commitsandremote_commits: the commits of each side (ten at most);instance: what taking this instance's copy would change in the repository's document, andrepository: what taking the repository's copy would change here, both by section, as the lines of a diff.
curl -s -w '%{http_code}' -X POST -H "Authorization: Bearer $ADMIN" "$A/_rustybin/git/push"
# The status of a diverged branch says what differs: the commits of each
# side and what each way out would change, section by section.
curl -s -H "Authorization: Bearer $ADMIN" "$A/_rustybin/git?fetch=true"
POST /_rustybin/git/resolve {with, message, branch, dry_run, open} is the way out, and a
person chooses it: the automatic mode and the webhook never resolve a
divergence, they keep reporting it (the log, the timeline, the status and the
source_control_diverged check of the diagnostics).
with | What happens | dry_run answers |
|---|---|---|
instance | The local commits are dropped and this instance's configuration is committed on top of the remote's branch (the new commit's parent is the remote head), then pushed; message names the commit. Never a forced push: if the remote moved in between, the push is refused and nothing there changed. | The changes the commit would make to the repository's document |
repository | The working copy takes the remote's branch and its document is applied with prune, through the same checks as a pull. The local commits are dropped. | The apply's own dry run of the remote's document, validated exactly like the apply; the working copy does not move |
pull_request | Neither side wins yet. What the instance holds is committed (when it differs from its last commit) and the local branch is pushed to a new branch of the remote: branch, or a made name such as main-instance-20261109-153012. Nothing is applied, git.branch stays, and the answer names the branch and the base to open the pull request against. Never forced: a branch of that name with other commits is refused. With open: true the git host's API is then asked to open the pull request. | The branch and the commits it would carry; with open, what would be opened and where (would_open), and no call is made |
A preview of repository is the answer of a pull's dry run: applied.summary lists
what the document itself changes, and applied.results is the full account, with what
prune would unset or delete because the document does not name it.
# What a way out would change, before choosing it.
POST {{base_url}}/_rustybin/git/resolve
Authorization: Bearer {{admin_token}}
{"with": "repository", "dry_run": true}
HTTP 409
[Asserts]
jsonpath "$.error" contains "RUSTYBIN_STATE_DIR"
# A preview of a way out changes nothing: here, what taking the repository's
# copy would do to this instance (the payments mock would go).
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"with": "repository", "dry_run": true}' "$A/_rustybin/git/resolve"
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"with": "instance", "message": "Keep the instance configuration"}' "$A/_rustybin/git/resolve"
Through a pull request. pull_request is for a team that reviews configuration:
the merge happens at the git host, by a person, with the host's own tools for a
conflict in rustybin.yaml.
# The instance's side to a new branch, for a pull request at the git host.
POST {{base_url}}/_rustybin/git/resolve
Authorization: Bearer {{admin_token}}
{"with": "pull_request", "branch": "review/orders"}
HTTP 409
[Asserts]
jsonpath "$.error" contains "RUSTYBIN_STATE_DIR"
# Neither side wins here: this instance's side goes to a new branch, and a
# person opens a pull request from it at the git host. Nothing is applied.
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"with": "pull_request", "branch": "review/payments"}' "$A/_rustybin/git/resolve"
Open a pull request from that branch into the instance's branch. Until it is merged the instance still reads as diverged, on purpose. After a merge commit the instance's commits are part of the branch's history, so an ordinary pull fast-forwards and applies:
# The merge holds this instance's commits, so an ordinary pull fast-forwards.
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"apply": true, "prune": true}' "$A/_rustybin/git/pull"
After a squash or a rebase merge the history differs, the branch still reads as
diverged, and repository takes the merged result. Commits that named
checkpoints travel with the
pull_request branch; instance and repository drop the local commits, and with
them a checkpoint that was committed and never pushed (commit it again).
Opened by the git host
With open: true the instance does the last step too: after the push it asks the git
host's API to open the pull request from the new branch into the instance's branch, and
answers its address. That is the one thing it asks of a host. It never merges a pull
request, reviews one or comments on one.
Which host is the setting git.host:
git.host | The host | Its API |
|---|---|---|
auto (the default) | GitHub when the repository is on github.com, GitLab when it is on gitlab.com, by the exact host name. Anything else is none. | https://api.github.com, https://gitlab.com/api/v4 |
github | GitHub, or a GitHub Enterprise Server | git.host_api, else https://<the repository's host>/api/v3 |
gitlab | GitLab, or a self-managed GitLab (a merge request is its pull request) | git.host_api, else https://<the repository's host>/api/v4 |
gitea | Gitea or Forgejo (one API), always a host of your own | git.host_api, else https://<the repository's host>/api/v1 |
none | No host is ever called |
A self-hosted host is named on purpose: auto does not guess a kind from a name that
only looks like one. The gitea kind has no public host that auto recognises, so it
is always named. Other kinds of host are not supported; open the pull request by hand
there.
The token is the secret git.host_token: for GitHub a token that may write pull
requests on the repository (a fine-grained token with "Pull requests: read and write",
or a classic one with repo), for GitLab a personal, project or group access token
with the api scope, for Gitea or Forgejo an access token that may write the
repository (the write:repository scope). When it is unset the repository's own token (git.token) is
used, but only when that is the authentication of the remote and the API is on the
remote's own host (or is the public API of the public host the repository is on): a
token is never sent to a host other than the one it was set for. A deploy key cannot
call an API, so an ssh remote needs git.host_token. The token is sent to the API in
a header and is in no answer, log line or audit entry.
# Which host, where its API is (only for a self-hosted one: github.com and
# gitlab.com are recognised from the repository's address), and a token
# that may open pull requests. The token is a secret: stored sealed, never
# shown again.
curl -s -X PATCH -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d "{\"values\": {\"git.host\": \"github\", \"git.host_api\": \"$HOST_API\"}, \"secrets\": {\"git.host_token\": \"$HOST_TOKEN\"}}" \
"$A/_rustybin/settings"
The status says where a pull request would be opened, and what is missing:
host is {setting, kind, api, repository, token_set, token_from, ready, why}.
# Where a pull request would be opened through the git host's API: nowhere
# here (no repository is configured), and why.
GET {{base_url}}/_rustybin/git
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.host.setting" == "auto"
jsonpath "$.host.kind" == null
jsonpath "$.host.ready" == false
jsonpath "$.host.why" contains "no repository is configured"
The call. A preview first: with dry_run nothing is pushed and the host is not
called; would_open names the host, the two branches, the title and the body.
# What would be opened and where. Nothing is pushed and the host is not called.
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"with": "pull_request", "branch": "review/payments-2", "open": true, "dry_run": true}' "$A/_rustybin/git/resolve"
# Pushed, and the host is asked to open the pull request: one call.
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"with": "pull_request", "branch": "review/payments-2", "open": true, "message": "Payments, for review"}' "$A/_rustybin/git/resolve"
# The same, and the git host's API is asked to open the pull request.
POST {{base_url}}/_rustybin/git/resolve
Authorization: Bearer {{admin_token}}
{"with": "pull_request", "branch": "review/orders", "open": true}
HTTP 409
[Asserts]
jsonpath "$.error" contains "RUSTYBIN_STATE_DIR"
The answer is the answer of pull_request with:
host:{kind, api, repository}, where it was asked;opened: whether the host opened it;untrusted_pull_request:{number, url}as the host answered them. They are the host's words, not the instance's: the address is kept only when it is a plain web address, and the console shows it as a link to open in a new tab;already_open: true(withopened: false) when the host had one open already for the two branches:untrusted_pull_requestis then that one, see one that is already open;not_openedwhen it did not and none was found:{reason, why, status, untrusted_host_message}.
What the instance sends is its own text. The title is the first line of message
(or a default), and the body says that the instance and the branch have diverged and
lists, by name, what the instance holds that the repository's document lacks or holds
differently (forty names at most). Nothing of the repository's side is copied into it:
no name that only the repository has, no value of either side.
When the host does not open it, the branch stays pushed and the call still answers
200: the push went through, so open the pull request by hand as before. reason
says why:
reason | What happened |
|---|---|
token_refused | The host does not accept the token (401) |
not_permitted | The token may not open a pull request in that repository (403) |
not_found | The API does not know the repository, or the token may not see it (404): check git.host, git.host_api and the token's reach |
refused | The host refused the pull request (400, 409, 422): a branch it does not know or nothing to merge (or one already open that the host's list did not show) |
rate_limited | Too many calls for now (429) |
timeout | No answer within 20 seconds. Whether the host opened it is not known: look at the host |
redirected | The API answered a redirect, which is never followed: check git.host_api |
unreachable, host_error, bad_answer | The connection failed, the host answered another error, or its answer named no pull request |
egress_refused | The outbound policy refused the API's address when the call was made |
The call is made once and never repeated: a second call would open a second pull request on a host that was only slow.
One that is already open
A host refuses a second pull request for the same two branches. So when the host
refuses the request itself (400, 409 or 422, not a refusal of the token or the
repository), the instance asks it once which pull requests are open from the new branch
into the instance's branch. When there is one, the answer is that one instead of the
refusal: opened: false, already_open: true and its number and address under
untrusted_pull_request. The push went through all the same, so the open pull request
now holds what was pushed.
# The same call again: the host refuses a second pull request for the two
# branches, the instance asks which one is open, and answers that one.
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"with": "pull_request", "branch": "review/payments-2", "open": true}' "$A/_rustybin/git/resolve"
That read is the only other thing the instance asks of a host, it goes out the same way
as the opening call (the same token, purpose, timeout and bound), and the opening call
is not made again. An entry of the host's list that names other branches or is not
open is never taken. When the read finds nothing or fails, the refusal stands as it
was (not_opened with refused). A preview (dry_run) calls nothing, so it does not
say whether one is open. On Gitea and Forgejo the list has no filter by branch: the
instance looks among the fifty most recently updated open pull requests.
What is refused before anything is pushed is a 409 with a reason:
host_not_set (git.host is none, auto did not recognise the repository's host,
or the repository's path is not one the kind's API takes), host_token_missing, and
egress_refused. A preview is refused the same way.
A host that is named and cannot be asked is also a warning of the
diagnostics (source_control_host), before anyone tries.
The network. The call goes out under the outbound
policy's purpose git_host, whose rule is
exactly the API's host and port once a host is set up (the remote itself is the purpose
git): pinned addresses, no redirect followed, an answer read to 256 KiB at most. A
host on a private address needs its network in RUSTYBIN_EGRESS_ALLOW like any other
destination, and one on the same machine RUSTYBIN_EGRESS_ALLOW_LOOPBACK=true.
# The API of a self-hosted git host is an https address (the token goes to
# it): anything else is refused, and nothing is stored.
PATCH {{base_url}}/_rustybin/settings
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{ "values": { "git.host": "gitlab", "git.host_api": "http://git.example.com/api/v4" } }
HTTP 400
[Asserts]
jsonpath "$.error" == "invalid settings"
jsonpath "$.problems[0]" contains "must use https"
A document from the repository never changes git.host, git.host_api or
git.host_token, like every other git.* setting: someone who can push to the
repository cannot point the instance's token at an API of their own.
In the console the status shows what differs, and A diverged branch has the three ways out, each with Preview. Under the pull request way out, Open the pull request at the git host asks the host's API after the push; the box is off, with the reason, until a host and its token are set. The pull request's address is shown under the answer.
Branches
A branch per environment: one repository, a staging and a production branch, an
instance on each. The branch is the git.branch setting and nothing else: a
rustybin.yaml never names a branch, and a document from the repository never changes
git.branch (what a repository writer can do).
GET /_rustybin/git/branches lists the remote's branches (200 at most, with their
commits) and says which one the instance is on:
GET {{base_url}}/_rustybin/git/branches
Authorization: Bearer {{admin_token}}
HTTP 409
[Asserts]
jsonpath "$.error" contains "RUSTYBIN_STATE_DIR"
curl -s -H "Authorization: Bearer $ADMIN" "$A/_rustybin/git/branches"
POST /_rustybin/git/branch {branch, create, apply, dry_run, prune, message} moves
the instance:
- Switch to a branch the remote has. With
dry_runthe answer is what applying that branch's document would change, read from the commit and validated exactly like the apply, and nothing changes: not the setting, not the working copy. Without itgit.branchis stored, the working copy takes the branch, and its document is applied (prunemakes it the whole truth;apply: falsemoves the branch only). A branch whose document cannot be read is not switched to, and a switch that fails puts the setting and the working copy back. - Start a branch the remote does not have, with
create: true: the branch is created at the working copy's head,git.branchis stored, the instance's configuration is committed (message) and the branch is pushed.dry_runanswers what the commit would record.
# What switching to a branch would change, validated like the apply.
POST {{base_url}}/_rustybin/git/branch
Authorization: Bearer {{admin_token}}
{"branch": "staging", "dry_run": true, "prune": true}
HTTP 409
[Asserts]
jsonpath "$.error" contains "RUSTYBIN_STATE_DIR"
# The second instance is on main. What would moving it to staging change?
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"branch": "staging", "dry_run": true, "prune": true}' "$B/_rustybin/git/branch"
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"branch": "staging", "prune": true}' "$B/_rustybin/git/branch"
# A new branch from this instance's configuration.
POST {{base_url}}/_rustybin/git/branch
Authorization: Bearer {{admin_token}}
{"branch": "staging", "create": true, "message": "Start staging"}
HTTP 409
[Asserts]
jsonpath "$.error" contains "RUSTYBIN_STATE_DIR"
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"branch": "staging", "create": true, "message": "Start staging"}' "$A/_rustybin/git/branch"
The old branch keeps its commits, here and on the remote; nothing is deleted. The
webhook and the automatic mode follow the setting, so after a switch they work on the
new branch. With RUSTYBIN_SETTINGS_LOCK the branch is the environment's
(RUSTYBIN_CONFIG_GIT_REF) and a switch is refused.
Signed commits
A git host with branch protection may want every commit signed. With git.sign on,
the instance signs each commit it makes (yours, the automatic mode's, a resolve's) with
an SSH signature, which needs git 2.34 or later (the image has it).
The key is a key of its own, the secret git.signing_key: never the deploy key, since
a host registers a key that pushes and a key that vouches in different places.
POST /_rustybin/git/signing-key generates an ed25519 key and answers its public
half and its SHA256: fingerprint; GET answers them again. Register the public
key at the git host as a signing key (on GitHub: SSH keys, key type "Signing key"; on
GitLab: SSH keys with usage "Signing"), then turn git.sign on:
# The signing key's public half and fingerprint (none yet), never the key.
GET {{base_url}}/_rustybin/git/signing-key
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.signing.enabled" == false
jsonpath "$.signing.public" == null
jsonpath "$.signing.fingerprint" == null
POST {{base_url}}/_rustybin/git/signing-key
Authorization: Bearer {{admin_token}}
{"replace": false}
HTTP 409
[Asserts]
jsonpath "$.error" contains "RUSTYBIN_STATE_DIR"
# Generate the signing key: the answer is its public half and fingerprint,
# to register at the git host as a signing key. Then turn signing on.
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{}' "$A/_rustybin/git/signing-key"
curl -s -X PATCH -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"values": {"git.sign": true}}' "$A/_rustybin/settings" >/dev/null
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"message": "A signed commit"}' "$A/_rustybin/git/commit"
- A key of yours. Set the secret instead of generating (Management, Source
control, or
rustybin settings set-secret git.signing_key < key): an OpenSSH private key without a passphrase, pasted whole. It is kept as one line (the text between theBEGINandENDlines), sealed like every secret, at most 4096 bytes (an ed25519 or ECDSA key, or RSA up to 3072 bits). - Never shown. Every answer carries the public half and the fingerprint only. When
a commit is signed the key is written to
<state>/repo.signing.key(mode0600) for git, as the deploy key is in<state>/repo.key. - Never unsigned by accident. With
git.signon and no usable key (none set, one with a passphrase, git too old), a commit answers409with the reason and is not made. The status says so undersigning.problem, and so does thesource_control_signingcheck of the diagnostics. - The author is still
git.author; a host shows a commit as verified when that email belongs to the account the signing key is registered with.
Signing is about what the instance writes. What it reads is the next section.
Verified pulls
An instance that applies its repository on a pull, a webhook or a timer applies whatever
reaches the branch. With git.verify on (off by default), it takes the repository's side
only when a named signer signed it. It needs git 2.38 or later and ssh-keygen (the
image has both).
Who may sign is the setting git.allowed_signers: one line each, a name and a public
key (ann ssh-ed25519 AAAA...), or the line of a .pub file as a git host shows it (its
comment becomes the name). They are public keys, not secrets, and the status answers
their names and SHA256: fingerprints. The instance's own signing key
is allowed without being listed, while it is the current key. A line with an option
(cert-authority, namespaces) is refused: every signer is good for git signatures only.
# Who may sign what this instance pulls (a name and a public key each), then
# verification on: the head of this moment is trusted as it is.
curl -s -X PATCH -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d "{\"values\": {\"git.allowed_signers\": [\"instance-a $KEY\"], \"git.verify\": true}}" \
"$B/_rustybin/settings" >/dev/null
curl -s -H "Authorization: Bearer $ADMIN" "$B/_rustybin/git"
# The status says whether pulled commits are verified (off by default), who
# the allowed signers are and the last verified head.
GET {{base_url}}/_rustybin/git
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.verification.enabled" == false
jsonpath "$.verification.signers" count == 0
jsonpath "$.verification.verified_head" == null
jsonpath "$.verification.last_refusal" == null
# An allowed signer is a name and a public key, nothing more: a line with an
# option (a certificate authority here) is refused, and nothing is stored.
PATCH {{base_url}}/_rustybin/settings
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{ "values": { "git.allowed_signers": ["ann cert-authority ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPcTdrsIh7YkANjaKyUYQYzJTCVVKgE9HtCjRkTmaiXX"] } }
HTTP 400
[Asserts]
jsonpath "$.error" == "invalid settings"
jsonpath "$.problems[0]" contains "not an allowed signer"
What is verified is every commit between the last verified head and the new one, not only the tip, so a signed commit on top of an unsigned one is refused:
| A commit | Passes when |
|---|---|
| With one parent (or none) | An allowed signer signed it. SSH signatures only: an OpenPGP or X.509 signature, a git host's own web signature included, reads as no signature. |
| A merge of two parents | An allowed signer signed it, or its tree is exactly what merging its two parents gives (git merge-tree --write-tree). So a host's merge button works, and a merge that carries a change of its own (a conflict resolved by hand, an edit slipped in) needs a signer. Both parents are verified like any commit. |
| A merge of more than two parents | An allowed signer signed it. |
Where: on every path that takes the repository's side. A pull (and its dry run), the
webhook, the automatic mode, startup
from RUSTYBIN_CONFIG_GIT, resolve with repository and its
preview, a switch of branch and its preview, the first checkout of a new
working copy, and a checkpoint listed or restored from the repository.
Resolving with the instance's copy, a pull request branch and a push take nothing from
the repository and are not checked.
A refusal is 409 with reason: unverified, the commit and why. Nothing is
applied and the working copy does not move. The automatic mode and the webhook record
it in the timeline and apply nothing; the status keeps it under
verification.last_refusal and the source_control_verification check of the
diagnostics warns until a pull passes:
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"apply": true, "prune": true}' "$B/_rustybin/git/pull"
{
"error": "not verified: commit 3f9c2ab has no SSH signature. Nothing was applied and the working copy did not move (...)",
"reason": "unverified",
"commit": "3f9c2ab0c7d1e5a4b8f6d2c9e1a7b3f5d8c6e4a2",
"why": "has no SSH signature"
}
Squash and rebase merges are refused. A squash merge or a rebase merge made by the git host is a new commit, signed by the host or by nobody, and no allowed signer vouches for it. What a team does:
- Merge pull requests with a merge commit, and turn squash and rebase merging off for the repository (on GitHub: Settings, General, Pull Requests; on GitLab: Settings, Merge requests, Merge method "Merge commit"). The commits of the pull request are signed by their authors, and the merge commit passes as a clean merge.
- Or push signed commits: squash or rebase on your own machine, sign the result with a key the instance allows, and push it (a fast-forward of the branch).
- A merge with conflicts resolved in the host's editor carries a change of its own: resolve it locally and sign the merge commit.
The last verified head of each branch is kept in <state>/repo.verified.json. A
commit below it is never checked again, so replacing a key (a signer removed from the
list, a new signing key for the instance) does not reopen history: old commits stay
trusted, new ones need a key that is allowed now. A commit the instance makes itself
on a verified head is the verified head from then on, signed or not.
Turning it on trusts the head of that moment as it is, whatever is below it, and the
timeline says so (verification turned on: the head 3f9c2ab is trusted as it is); the
status answers it as verification.trusted. Turning it off forgets the verified heads,
so off and on again is how a person accepts a head as it stands, for example after
resolving a diverged branch with the instance's copy on top of commits nobody signed.
An instance that has git.verify on before it has a working copy trusts nothing: every
commit of the branch has to verify before the first checkout, so connect first and turn
verification on after.
A document from the repository never changes git.verify or git.allowed_signers
(nor any git.* setting), so what is pulled cannot turn its own check off. With
verification on and nobody allowed (no signer listed, no signing key), every new commit
is refused, and the status says so under verification.problem.
What the instance does not do: it does not trust a git host's web signature (that would trust every commit the host makes for anyone who can click merge), and it does not verify the commits it pushed itself at the host. Branch protection at the host is still worth having: it stops an unsigned commit before it reaches the branch, where this stops it before it reaches the instance.
History
GET /_rustybin/git/history lists the last 50 commits of the working copy with their
author, time, message and file counts; the console shows them under the actions, with
the timeline of operations and their outcomes.
Startup from the repository
RUSTYBIN_CONFIG_GIT=<remote> makes the instance clone the branch and apply the
document (with prune) before it serves, so the repository is the source of truth and a
fresh instance comes up configured:
# A second instance starts from the repository: it clones and applies the
# document before serving, so it holds the orders mock too.
RUSTYBIN_HTTP_PORT=$PORT2 RUSTYBIN_HTTPS_PORT=0 RUSTYBIN_GRPC_PORT=0 RUSTYBIN_HOST=127.0.0.1 \
RUSTYBIN_LOG_LEVEL=warn RUSTYBIN_CONTROL_AUTH=open RUSTYBIN_ADMIN_TOKEN=$ADMIN \
RUSTYBIN_STATE_DIR="$work/state-b" RUSTYBIN_EGRESS_ALLOW_LOOPBACK=true \
RUSTYBIN_CONFIG_GIT="file://$work/config.git" RUSTYBIN_CONFIG_GIT_REQUIRED=true \
"$BIN" &
| Variable | Default | Meaning |
|---|---|---|
RUSTYBIN_CONFIG_GIT | unset | The remote (seeds git.remote). |
RUSTYBIN_CONFIG_GIT_REF, _PATH, _AUTH, _AUTO, _TOKEN | Seed git.branch, git.path, git.auth, git.auto and the secret git.token. | |
RUSTYBIN_CONFIG_GIT_REQUIRED | false | A clone or apply failure at startup is fatal. By default it is a warning and the instance starts without the repository's configuration. |
An empty repository is not an error: the instance starts empty and its first push
creates the branch. The deploy key file, when the remote is ssh, is
<state>/repo.key (generate it once from a running instance, or put a key there).
Automatic mode
git.auto keeps the instance and the repository in sync without anyone clicking:
push_on_change: every 30 seconds the instance compares its export with the working copy's document and, when they differ, commits with a message naming the changes (Update mocks.orders: added; settings.portal.enabled: changed to on) and pushes. A failure is logged once until it changes. It never writes a checkpoint: those hold mock data and are committed only on request. Withgit.signon its commits are signed.pull: everygit.pull_everythe instance pulls and applies the repository with prune: the repository is the truth, console changes last until the next pull.
Neither mode ever resolves a diverged branch: the push or the pull is refused, nothing is applied, and the status and the diagnostics say so until a person chooses a way out.
Set one per instance and one direction per repository: an instance that pushes and another that pulls is a deployment pipeline; two that push to one branch end in conflicts for someone to resolve. One branch per environment keeps them apart (Branches).
The whole flow against a bare repository in a temporary directory:
git init --quiet --bare -b main config.git
# An instance with a state directory (the working copy lives in <state>/repo),
# the repository configured and, for a local repository, the loopback
# allowance of the outbound policy.
RUSTYBIN_HTTP_PORT=$PORT RUSTYBIN_HTTPS_PORT=0 RUSTYBIN_GRPC_PORT=0 RUSTYBIN_HOST=127.0.0.1 \
RUSTYBIN_LOG_LEVEL=warn RUSTYBIN_CONTROL_AUTH=open RUSTYBIN_ADMIN_TOKEN=$ADMIN \
RUSTYBIN_STATE_DIR="$work/state-a" RUSTYBIN_EGRESS_ALLOW_LOOPBACK=true \
RUSTYBIN_CONFIG_GIT="file://$work/config.git" \
"$BIN" &
A webhook instead of polling
git.auto: pull asks the remote every few minutes. To pull the moment someone pushes, set the
secret git.webhook_secret (Management, Source control, or rustybin settings set-secret) and
point your git host's push webhook at https://<instance>/_rustybin/git/webhook with the same
secret. The host signs each call (X-Hub-Signature-256 for GitHub, Gitea, Forgejo and
Bitbucket, X-Gitlab-Token for GitLab), and the signature is the credential, so the instance
has to be reachable from the host but no control token is given out.
A signed push to the configured branch pulls and applies as the automatic mode does, with
everything a repository writer can do limited the same way.
A push to another branch is ignored, a burst costs at most two pulls, and a call without
the right signature does nothing. Without the secret the route answers 404:
POST {{base_url}}/_rustybin/git/webhook
{"ref": "refs/heads/main"}
HTTP 404
[Asserts]
jsonpath "$.error" contains "git.webhook_secret"
Not in this version
A merge inside the instance: a diverged branch is resolved by naming a side, or in a pull request at the git host. Anything at the git host beyond opening that pull request or finding the one already open (merging it, a review, a comment), and git hosts other than GitHub and GitLab with their self-hosted variants, Gitea and Forgejo. Trusting a git host's own web signature when verifying pulls: a squash or rebase merge made by the host is refused, a merge commit passes as a clean merge.
On every surface
The same job from the API, the console, the command line, an agent and the configuration document.
| Surface | Where |
|---|---|
| API | GET /_rustybin/git, POST /_rustybin/git/init, /commit (with checkpoints), /push, /pull, /resolve (instance, repository, pull_request, with dry_run; open with pull_request: opened, already_open, untrusted_pull_request, not_opened), host in the status, the source_control_host check of GET /_rustybin/diagnostics, GET, POST /_rustybin/git/key, GET /_rustybin/git/history, GET /_rustybin/git/branches, POST /_rustybin/git/branch, GET, POST /_rustybin/git/signing-key; verification in the status and the 409 with reason: unverified of verified pulls; the repository's checkpoints: GET /_rustybin/checkpoints?from=git, POST /_rustybin/checkpoints/{name}/restore?from=git |
| Console | Management, Source control: the repository form, status (what differs on a diverged branch), connect, commit and push (with a checkpoint choice), pull, a diverged branch's three ways out with a preview (and Open the pull request at the git host, with its address shown after, and said when it was already open), branches (list, preview, switch, start), the deploy key, commit signing, verified pulls (the switch, the signers, the last verified head, the last refusal), history; Management, Checkpoints, In the repository |
| CLI | rustybin git status, init, commit (--checkpoint NAME), push, pull, resolve (--with instance, repository or pull-request, --branch, --dry-run, --open), key, history, branches, switch, branch, signing-key, signers (--add, --remove); rustybin checkpoint list --from-git, checkpoint restore NAME --from-git (reference) |
| Management MCP | git_status, git_init, git_commit (checkpoints), git_push, git_pull, git_resolve (open: confirmed, the address under untrusted_pull_request, already_open when the host had one), git_deploy_key, git_branches, git_switch_branch, git_signing_key, list_repository_checkpoints, restore_checkpoint with from: "git" (git_status answers verification, and the tools that take the repository's side answer the refusal: reason, commit, why); the prompt backup_to_git (agent page) |
rustybin.yaml | Never: the git.* settings (the remote, the branch, the token, signing) are not exported, and a document from the repository cannot change one, so a document in a repository cannot point the instance elsewhere. The settings themselves: git.branch, git.sign, the secret git.signing_key, git.verify, git.allowed_signers, git.host, git.host_api, the secret git.host_token |
| Environment | RUSTYBIN_CONFIG_GIT, _REF, _PATH, _AUTH, _TOKEN, _AUTO, _REQUIRED (configuration) |