This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

forgejo

Self-hosted Git forge, CI runners, and repository mirrors

Forgejo runs on an XCP-ng VM behind Traefik. Local Git links redirect to the canonical Forgejo hostname; public Git links redirect through the download server to GitHub. The two local Traefik nodes represent routes in the same proxy. Public Forgejo access passes through the ingress server, which requires a client certificate and opens a separate HTTPS connection to the service proxy. See Deployment for DNS, provisioning, and service configuration. The Mermaid source is authoritative; Bazel renders its light and dark SVGs.

Forgejo architectureForgejo architecture

Service Terraform consumes the shared repository catalog for organization-owned repositories and named administrator/developer roles. Vault continues to own OIDC login identities and service-specific access. See service Terraform for identity validation, state adoption, and the preserved automation grants.

Terraform reads each repository’s mirror settings and bootstraps the native Forgejo mirrors with destination credentials from Vault. Forgejo pushes the default branch, weekly release branches, tags, and LFS objects to GitHub and GitLab on commits and every eight hours. See mirror Terraform for setup and ref checks.

Forgejo push mirroringForgejo push mirroring

Setup Terraform creates a dedicated Ed25519 SSH commit-signing pair through the shared Vault SSH key tool. The pair is stored in KV v2 mount secrets at alwaldend.com/vault1/approles/src_infra_dc1_forgejo1/commit_signing, within the existing Forgejo AppRole namespace. Secret values never become Terraform attributes. Normal applies preserve the pair; an explicit bootstrap resource replacement validates and reuses the Vault record. Deletion or corruption of the cache requires restoration, not automatic regeneration.

Setup also publishes a sibling commit_signing_public entry with the public key and fingerprint. Its bootstrap runs after the private pair is available, so existing installations can publish it without rotating their key. Consumers can receive exact-path read access to this public-only entry.

Ansible reads that record through AL and installs the pair under /opt/forgejo/signing/, with mode 0600 on the private file and a service-owned 0700 directory. The existing recovery archive includes this directory. Deployment rejects a different existing private key; rotation is a separate operation. The service uses the public file instance.pub as SIGNING_KEY, FORMAT = ssh, and the Forgejo <noreply@forgejo.alwaldend.com> identity. Forgejo signs pull request merges and web or API file changes with this key. Repositories that inherit the instance’s collaborator trust model record the merging user’s identity as the Git committer and trust signatures from repository collaborators under Forgejo’s verification rules.

After separate live authorization, run setup Terraform before service-only Ansible deployment using the commands below. This does not require running service Terraform to obtain an API token first. Modern Git (2.34+) and OpenSSH ssh-keygen (8.2p1+) must be present on the service host. Verify /api/v1/signing-key.ssh and an instance-generated commit after activation. See the Forgejo 17 signing contract.

Forgejo is recreated on XCP-ng through Xen Orchestra, using the src_infra_dc1_forgejo1 resource set provisioned by infra/xcp_ng. VM provisioning authenticates to XO through Vault OIDC as Forgejo’s own AppRole. Its exact synchronized user receives the resource-set membership and an explicit administration ACL on the existing Forgejo VM; it does not use the shared infrastructure administrator token. These bindings must be applied by infra/xcp_ng/tf before Forgejo’s setup Terraform runs.

The canonical service URL is https://forgejo.alwaldend.com. Local https://git.alwaldend.com redirects there, preserving the path and query. Public DNS points the Git name at the Yandex download server, whose Traefik redirects ordinary web requests to https://github.com with the path and query preserved. Go discovery requests with go-get=1 receive metadata from the download server for git.alwaldend.com/alwaldend/src and its descendants, pointing to https://github.com/alwaldend/src.git. Unknown discovery prefixes return 404. The dc1 A record continues to select this Forgejo VM. The public CNAME remains owned by this component’s dnsconfig.json and DNS-only Terraform targets. Vault’s Forgejo URL and OIDC callback, shared AL login configuration, and runner instance URL use the canonical hostname. Vault’s certificate role retains both names so HTTPS also works on the local Git redirect. These are desired-state definitions; source changes alone do not apply Vault or Ansible configuration. The VM retains 192.168.10.40 and host1.forgejo.alwaldend.com. Its boot, Forgejo, and Traefik disks are 20, 40, and 5 GiB respectively.

See Terraform setup for the template, network, storage, and previous-state prerequisites. These commands create and configure a fresh service; they do not restore the destroyed Proxmox VM’s data.

Fresh host hardening can outlast the ten-minute Vault token. Run host setup and service deployment separately to obtain fresh authentication for each phase. Ansible creates the missing Vault OIDC login source after starting Forgejo; existing active Vault sources are preserved.

Before configuring Forgejo with Terraform, set TF_VAR_vault_oauth_source_id to the verified ID of the active vault OIDC source, as described in service Terraform. Its narrowly scoped Vault entity-read policy must be provisioned first so the required external users can be created.

The guest disables IPv4 redirect acceptance so its traffic uses the configured gateway. LAN clients must also retain symmetric routes: same-interface router redirects can otherwise make connections fail. Router redirect policy and stale client route caches must be resolved before relying on LAN access.

bazel run //infra/forgejo/tf_setup:tf_setup.apply
bazel run //infra/forgejo/ansible:ansible -- --skip-tags traefik,forgejo,forgejo_oidc
bazel run //infra/forgejo/ansible:ansible -- --tags traefik,forgejo,forgejo_oidc
bazel run //infra/forgejo/tf:tf.apply

1 - Ansible

Ansible setup

The Ansible package installs the common Forgejo theme through the managed custom header. Forgejo’s Light, Dark, and Auto modes use the website’s neutral palette, font stack, and corner radii. Auto follows the browser preference. The header also carries the mobile pull request diff styles.

Forgejo uses the shared Alwaldend monogram as its SVG favicon and navigation logo. The forgejo_branding tag updates only those public assets.

2 - Forgejo DNS

Owner-local DNS Terraform

This root manages the records in dnsconfig.json using //infra/forgejo/dns:tf.<operation>. Follow the shared transfer procedure before operating this root.

3 - Native push mirrors

Forgejo native HTTPS push mirror configuration

Terraform bootstraps native Forgejo HTTPS push mirrors for repositories declared in the catalog. The packaged push_mirror API command reconciles mirrors on Terraform resource creation and when the desired branch filter changes. Vault supplies the separate GitHub and GitLab destination credentials under the Forgejo AppRole’s push_mirrors/<destination> paths. Tokens stay out of Terraform state.

The branch filter combines the catalog’s default branch with releases/*. Forgejo also sends all tags and uses its native HTTPS LFS transfer. The mirrors synchronize on commits and every eight hours.

The command adopts a matching HTTPS mirror without writing to Forgejo. Forgejo’s API requires deleting and recreating a mirror to change its filter. Before either creation or replacement, the command checks that the source advertises trunk and that every existing destination head and tag matches Forgejo’s object ID. It also obtains the destination credential before deleting the old entry. A failed replacement can be retried through Terraform.

The first filtered sync prunes previously mirrored development branches from the destination. Confirm that pruning is intended before applying the plan. The preflight requires their tips to be recoverable from the source. The command requires Git on the controller. Refresh cannot detect remote drift. Removing the Terraform resource leaves the live mirror in place.

Add a github or gitlab entry under forgejo.push_mirrors in the repository’s catalog file. See src.json for an example. Set username and vault_key for each destination and include the corresponding destination forge in the same repository file. Use oauth2 for GitLab or the PAT owner’s GitHub login. Store the token field in the Forgejo AppRole’s push_mirrors/<vault_key> record.

bazel run //infra/forgejo/tf_mirrors:tf.plan
bazel run //infra/forgejo/tf_mirrors:tf.apply

4 - OpenSpec

4.1 - Specifications

4.1.1 - Infra forgejo

4.1.1.1 - Forgejo infrastructure specification

Describe the Forgejo service owned by infra/forgejo, including Xen Orchestra provisioning, Ansible service configuration, and Terraform account and repository management. The tf_setup, ansible, and tf packages are implementation stages of this owner. This baseline records source guarantees and prerequisites; it does not verify live service health or restore earlier Forgejo data.

Baseline revision: 550d7e79b1f5fdbc2b6017b75178471d6914082f. Observed: 2026-09-08. Sources: owner README, BUILD, and the implementation links below.

Setup SHALL provision Forgejo through Xen Orchestra in the src_infra_dc1_forgejo1 resource set using the owner’s Vault AppRole and packaged XO OIDC login flow. The VM SHALL declare 20 GiB boot, 40 GiB Forgejo, and 5 GiB Traefik disks. Ansible SHALL verify the expected sizes of xvdb and xvdc before applying the service roles that use them.

Sources: setup contract, setup BUILD, VM definition, and deployment playbook.

  • WHEN Ansible gathers disks that do not match the expected Forgejo and Traefik device names and sizes
  • THEN its pre-task assertion fails before the service roles run

Forgejo SHALL configure https://git.alwaldend.com/ as its canonical root URL, bind its HTTP service to loopback port 3000, and enable the built-in SSH service on port 3005. Traefik SHALL route the canonical hostname, the inventory hostname, and forgejo.alwaldend.com to that HTTP service with the Vault certificate resolver.

Sources: service variables, Forgejo configuration, and Traefik routing.

  • WHEN the Traefik routing template is rendered with the owner’s variables
  • THEN the canonical and legacy hostnames resolve to the same configured loopback service
  • AND generated Forgejo URLs use the canonical Git hostname

The deployment playbook SHALL create a missing vault OIDC authentication source after configuring the Forgejo service. It SHALL preserve one existing active OAuth2 source and reject multiple matches, an inactive source, or a source of another type. Creation SHALL obtain client credentials from the injected environment and suppress secret-bearing task output.

Source: deployment playbook.

  • WHEN Forgejo reports exactly one active OAuth2 source named vault
  • THEN the bootstrap accepts it and skips source creation
  • WHEN more than one vault source is discovered, or its type or active state is incompatible
  • THEN the bootstrap assertion fails rather than selecting or replacing an arbitrary source

Service Terraform SHALL require a verified positive integer Vault OAuth source ID, discover login users from the owning Vault group through at most two nested group levels, and use entity UUIDs as external login names. Managed accounts SHALL be protected from deletion. The shared repository catalog SHALL own named organization administrator and developer assignments and organization-owned repository identities. Catalog members and Vault access-group members SHALL belong to the discovered login population. Existing Vault service-administrator, package-writer, and automation-writer grants SHALL be retained; the src automation writer group SHALL resolve to exactly one user. A catalog developer SHALL NOT also receive administrator access through the retained Vault groups.

Sources: service Terraform contract, users, access validation, and repository access. The shared catalog contract owns repository naming and named-role assignments; its adoption change records the source migration and pending verification.

  • WHEN a login group extends beyond two nested levels, an access-group member is outside the login population, or the automation writer count is not one
  • THEN the corresponding Terraform condition rejects the configuration
  • AND Terraform does not silently omit the unsupported membership
  • WHEN a catalog administrator or developer is assigned organization access
  • THEN that assignment uses the discovered account’s existing Vault entity UUID and verified OAuth source mapping
  • AND the assignment does not create a password-based replacement account
  • WHEN shared named roles are adopted
  • THEN existing Vault service administration, package-writing, and automation-writer grants remain configured
  • AND the catalog developer receives feature-branch and pull-request access without a default-branch push or merge bypass
  • AND an overlapping administrator grant for that developer fails validation

5 - Tf

Terraform config

This package configures Forgejo organizations, repositories, and access from the shared repository catalog. The catalog owns named administrators, developers, repository identities, and destination names. Its Terraform module supplies the consumer’s repository projection. First-party names remain stable across forges; external fork and mirror names retain their original upstream identity.

Repository resources preselect deletion of eligible pull request source branches in Forgejo’s web merge form. The pinned provider sends the setting on repository creation and update and does not detect out-of-band changes to this field during refresh.

Before applying, provision the Vault OIDC authentication source with Ansible and set TF_VAR_vault_oauth_source_id to its verified positive numeric ID. Obtain the ID from forgejo admin auth list on the instance using the service’s config and work path; confirm that the vault source is active and uses OpenID Connect with the expected Vault issuer. Do not assume source IDs survive instance recreation.

Terraform discovers users from the authoritative Vault src_infra_dc1_forgejo1_users login group, then looks up their entities, following the PVE Terraform pattern. Discovery includes direct members and two levels of nested groups, covering the current administrator membership. Deeper nesting fails validation rather than silently omitting accounts. Each account uses its Vault entity UUID as the OIDC login name and its canonical username/email metadata. No local password or user impersonation is used. The Forgejo AppRole receives the existing group/entity lookup permissions, as PVE does. Apply those Vault group memberships before running this package.

The accounts are protected from Terraform deletion. OIDC group claims retain ownership of administrator/restricted status after login. If a user already exists outside this state, verify its source and login-name mapping before importing it; never replace an existing account to resolve a name collision. Resource addresses remain keyed by Vault entity name, preserving existing managed users. The Forgejo service identity may already exist from the first OIDC login: verify and import it before applying its newly discovered resource.

Named organization administrator and developer assignments come from the catalog and must resolve to the discovered Vault login population. The Developer team can read repositories, write feature branches, and open pull requests. Its members receive no default-branch push or merge bypass.

Existing service administration remains sourced from src_infra_dc1_forgejo1_admins and its direct child groups. Those grants are retained for entities with a Vault AppRole alias, alongside catalog administrators. The separate instance-wide OIDC administrator claim remains owned by Vault. Validation rejects a catalog developer who also receives administrator access through those Vault groups. Package writers and the repository automation writer retain the grants from src_infra_dc1_forgejo1_package_writers and src_infra_dc1_forgejo1_src_writers. These dedicated groups avoid granting service permissions to AppRole credential issuers. The existing singleton collaborator still requires exactly one discovered writer. Access-group members outside the login population also fail validation.

Repository adoption preserves remote IDs. The existing singleton repository address has an explicit move to its catalog key, while account and service access addresses remain stable. Import an existing untracked destination before applying; never recreate it to resolve a name collision. Review the full plan before execution and obtain separate approval for any deletion or replacement. The retained branch rules continue to own administrator and automation-writer exceptions.

bazel run //infra/forgejo/tf:tf.plan
bazel run //infra/forgejo/tf:tf.apply

terraform_data.runners["secure1"] bootstraps the repository-scoped secure1.dev.alwaldend.com runner for alwaldend/src through the packaged local tool. Its credentials are cached in KV v2 mount secrets at alwaldend.com/vault1/approles/src_infra_dc1_forgejo1/runners/secure1, within the Forgejo AppRole’s existing namespace. The worker receives no controller API credential. This declaration creates credentials; host configuration and consumer read access remain owned by their deployment and Vault policies.

The provisioner runs only when its stable Terraform resource is created. It has no timestamp, executable hash or replacement trigger. Normal applies and tool changes do not rerun registration. An explicit replacement reuses the Vault cache. The token is written directly to Vault and is never a Terraform attribute. Removing the resource preserves the runner and cached credentials. The local tool’s README owns its failure and reconciliation contract.

Runner registration consumes an existing repository and uses its identity from the shared catalog. Provision the repository first on a fresh service. A targeted runner bootstrap does not reconcile the service’s repository resources.

6 - Tf setup

Terraform setup

This package creates a Xen Orchestra VM in the src_infra_dc1_forgejo1 resource set. infra/forgejo/BUILD.bazel authenticates with Forgejo’s own Vault AppRole and the packaged XO OIDC login plugin. The plugin supplies a temporary XO token and revokes it on shutdown; no infrastructure administrator token is loaded. The setup HTTP backend remains owned by the same Forgejo config.

It also bootstraps the instance commit-signing key directly into Vault through a stable creation-only resource. Run this stage before Ansible, which requires that cache. The provisioner receives the existing Vault environment without loading a Forgejo API credential. Plans do not run generation; normal applies do not rotate or refresh an existing key.

Before running this package, bootstrap the AppRole’s XO OIDC user and apply its resource-set membership and existing VM ACL through infra/xcp_ng/tf. Subjects are matched by immutable Vault entity UUID under the configured OIDC issuer, not by login name or AppRole group membership. See XO authentication.

Defaults select the imported Fedora 44 template, local storage and wired network by name from the Forgejo resource set. Override TF_VAR_xoa_template_name, TF_VAR_xoa_storage_name, and TF_VAR_xoa_network_name for another assignment. Native provider lookups run as Forgejo’s own identity and reject ambiguous matches. No infrastructure UUID defaults are required; resolved IDs are passed to the XO API. The template must contain a single boot disk no larger than 20 GiB, Fedora, and cloud-init. Bootstrap installs Xen guest tools. The pinned Fedora 44 image uses predictable interface naming; xoa_guest_interface defaults to enX0 for its first Xen interface and can be overridden for another template. The selected network must carry 192.168.10.0/24; gateway and DNS default to 192.168.10.1 (the wired router) and can be overridden with the Terraform variables.

The PVE-based infra/cloud_init:xen_linux target supplies the shared Ansible user and CA configuration through the repository template rule. Terraform adds the hostname and static network configuration from ../dns/dnsconfig.json. After cloud-init completes, verify that /dev/xvda is the boot disk, /dev/xvdb is the 40 GiB Forgejo disk, and /dev/xvdc is the 5 GiB Traefik disk before running Ansible, which creates filesystems on the latter two devices.

The old Proxmox VM was destroyed and its obsolete Terraform state binding was removed without issuing a destroy. This package now uses only XO. There is no cross-provider state move or data restoration in this package.

bazel run //infra/forgejo/tf_setup:tf_setup.plan
bazel run //infra/forgejo/tf_setup:tf_setup.apply

Manage records through the dedicated DNS root.