On a host the operator names, an origin is refused when its account administers the instance or can push to a protected repository #71
No reviewers
Labels
No labels
agent-work
agent-working
ultracode
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
trevato-apps/forge!71
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "tdobbertin-espo/forge:feat/origin-guard"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on #70. This branch has that pull's commit as its first commit. Only the top commit is new. Land #70 first; the guard uses its scope words.
A forge keeps an origin's credential on the machine where its agents run. So the risk is the account that a person authorized. A token of an instance administrator, or a token that can push to a protected repository (a repository whose
maindeploys something), gives that power to every agent run. A team that runs many forges against one Forgejo needs to say "not those accounts" once, for every forge.The operator now names the hosts to guard. A host is guarded when it is in
FORGE_ORIGIN_CLIENT_ID, or when aFORGE_ORIGIN_DENY_PUSHrule covers it. On a guarded host, a credential is refused before it is stored when its account administers the instance (is_admin/site_admin), or when it can push to a protected repository (permissions.push)./repos/search?uid=sorted by id, with no fallback, at most 20 pages. The walk is complete only when the distinct repositories it saw equalX-Total-Count, and that count did not change between pages. Anything less fails closed (guard_unchecked). A confirmed hit always wins (can_push).needs_reauthwith the guard's sentence. A refresh never clears it.origin_paused, and the adapter refuses each request that is not a read. Settings → Origins says so and has Check again (POST /settings/origins/:id/check, once a minute). A check that has not run for a day refuses the origin.What is unchanged: a host that is not guarded behaves as before. With neither variable set, no host is guarded, so a person who runs their own Forgejo can still connect it as its administrator. One change to note: a forge that already sets
FORGE_ORIGIN_CLIENT_ID(for example through the chart'sforge.originClients) guards those hosts from this version on, so an administrator's account is refused there. If you prefer the guard to come only fromFORGE_ORIGIN_DENY_PUSH, that is one line inguarded(src/origins/operator.ts).docs/ORIGINS.md, "The operator guard", says all of this, and README's origin paragraph names the new variable.Environment
FORGE_ORIGIN_DENY_PUSH(new, optional): comma-separatedowner/namepatterns.*matches inside one part, a bareownermeansowner/*, andhost:patternlimits a rule to one host. A rule with no host covers every origin.FORGE_ORIGIN_CLIENT_IDkeeps its syntax; its hosts are now guarded too.Tests
bun 1.3.13, a scrubbed environment (no agent variables):
test/origin-guard.test.ts: 23 pass, 0 fail, against the fake origin with a real forge serving git: a pasted token and an OAuth consent, the exact and the wildcard rules, the walk's bound and its count, a refresh and the sweep, paused writes and Check again.bun test --timeout 60000call: 489 pass, 0 fail across 35 files.bun scripts/gate.tsandtsc --noEmit: clean.the 35 files
origin-guard, origin-token-scopes, following, forks, origins, origins-oauth, origins-operator, origins-reconnect, origins-security-auth, origins-security-provider, origins-security-push, origins-sync, origins-sync-settled, web-origins, web-origin-link, mcp-origins, mcp-origin-apps, push-through, trusted-hosts, trusted-hosts-ui, steps-lists, no-polling, refresh-meta, mirror-outbound, mirror-out, carried, migrate, migrate-after, tui-migrate, apps-feedback-mirror, and the five cross files reserved-names, studio, shards, check-list, hollow (each
test/<name>.test.ts).🤖 Generated with Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.