git: verify Forgejo instance-signed commits locally (allowed_signers missing instance key) #64

Open
opened 2026-11-15 20:47:11 +00:00 by martin · 0 comments
Owner

Context

Discovered during the cluster repository transfer work (Personal/cluster#76), while checking whether commits stayed signed across the move.

Forgejo-side signing already works. The gap is local verification: git verify-commit on a server-generated merge commit reports No principal matched and %G? = U because the Forgejo instance signing key is missing from ~/.config/git/allowed_signers.

Current state (verified, Forgejo 17.0.1)

Instance signing is configured in /var/lib/forgejo/custom/conf/app.ini (generated by shared/base/modules/services/forgejo.nix):

[repository.signing]
CRUD_ACTIONS = always
FORMAT = ssh
INITIAL_COMMIT = always
MERGES = always
SIGNING_EMAIL = forgejo@martials.no
SIGNING_KEY = /run/forgejo/id_ed25519.pub
SIGNING_NAME = Forgejo Instance
WIKI = always

Instance public key (public material, safe to commit):

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILjVIQy6Fp8ckKcVYRxMnBI2/WAWciZuz39z4N99/ECY
SHA256:/en+e39PkqipWawBfJfUkbgr9Sk8wlCHJk0vBEcLVIo

Server-side verification is correct for both kinds of commit:

$ curl -s https://code.martials.no/api/v1/repos/Personal/cluster/git/commits/53840c0 | jq '.verification | {verified, reason}'
{
  "verified": true,
  "reason": "Forgejo Instance / SHA256:/en+e39PkqipWawBfJfUkbgr9Sk8wlCHJk0vBEcLVIo"
}

$ curl -s https://code.martials.no/api/v1/repos/Personal/cluster/git/commits/d4bc291 | jq '.verification | {verified, reason}'
{
  "verified": true,
  "reason": "martin / SHA256:4p1MoEl6avhC36SiOoBWBqXbIbh+bYhxfXjEJqOMvWo"
}

Local verification is inconsistent — user-signed commits are trusted, instance-signed merges are not:

$ git -C cluster verify-commit d4bc291          # author commit, signed by ~/.ssh/id_ed25519
Good "git" signature for git@martials.no with ED25519 key SHA256:4p1MoEl6avhC36SiOoBWBqXbIbh+bYhxfXjEJqOMvWo
$ git -C cluster log -1 --format='%G? %GS' d4bc291
G git@martials.no

$ git -C cluster verify-commit 53840c0          # squash merge, signed by the Forgejo instance key
Good "git" signature with ED25519 key SHA256:/en+e39PkqipWawBfJfUkbgr9Sk8wlCHJk0vBEcLVIo
No principal matched.
$ git -C cluster log -1 --format='%G? %GS' 53840c0
U

Root cause

shared/base/home-manager/development/git.nix builds the allowed signers file from host SSH keys only, all under one principal:

let
  email = "git@${common.domain}";
  allowedSigners = lib.concatMapStringsSep "\n" (system: "${email} ${system.ssh.publicKey}") (
    builtins.attrValues systems
  );
in
{
  home.file.".config/git/allowed_signers".text = "${allowedSigners}\n";
  # ...
  settings.gpg.ssh.allowedSignersFile = "${config.home.homeDirectory}/.config/git/allowed_signers";
}

The Forgejo instance key is never added, so signatures made by the server (squash merges, initial commits, CRUD actions, wiki edits) cannot be matched to a principal.

Proposed change

Add the instance signing key as an allowed signer, preferably single-sourced from the same module that configures [repository.signing] so the two cannot drift.

Option A — declare the public key as an option on the service module and consume it from the git module (which already receives systemConfig):

# shared/base/modules/services/forgejo.nix
options.my.services.forgejo.signing = {
  publicKey = lib.mkOption {
    type = lib.types.str;
    description = "Public key matching the SOPS-managed signing key used for [repository.signing].";
  };
  principal = lib.mkOption {
    type = lib.types.str;
    default = "forgejo@${common.domain}";
    description = "Principal (email-form) used when verifying instance-signed commits locally.";
  };
};

# shared/base/home-manager/development/git.nix
let
  hostSigners = lib.concatMapStringsSep "\n" (system: "${email} ${system.ssh.publicKey}") (builtins.attrValues systems);
  forgejo = systemConfig.my.services.forgejo;
  allowedSigners = lib.concatStringsSep "\n" [
    hostSigners
    "${forgejo.signing.principal} ${forgejo.signing.publicKey}"
  ];
in

Option B — if wiring the NixOS option into Home Manager is undesirable, append the key literally in the git module:

allowedSigners = lib.concatStringsSep "\n" [
  (lib.concatMapStringsSep "\n" (system: "${email} ${system.ssh.publicKey}") (builtins.attrValues systems))
  "forgejo@${common.domain} ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILjVIQy6Fp8ckKcVYRxMnBI2/WAWciZuz39z4N99/ECY"
];

Do not commit the private signing key; it stays in SOPS (forgejo/signing-key) and is materialised at /run/forgejo/id_ed25519.

Verification examples

# rebuild the affected hosts (nidaros hosts Forgejo, the others only need the file change)
$ just build nidaros
$ just build desktop

# after switching, server-signed merge commits must verify locally
$ git -C cluster verify-commit 53840c0
Good "git" signature for forgejo@martials.no with ED25519 key SHA256:/en+e39PkqipWawBfJfUkbgr9Sk8wlCHJk0vBEcLVIo
$ git -C cluster log -1 --format='%G? %GS' 53840c0
G forgejo@martials.no

# the allowed signers file must contain both families of keys
$ cat ~/.config/git/allowed_signers
git@martials.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILw1iNuPnX9NGt+UAvBDzkk26d1e4nF+XX2FMm+IRWtt
...
forgejo@martials.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILjVIQy6Fp8ckKcVYRxMnBI2/WAWciZuz39z4N99/ECY

Acceptance criteria

  • ~/.config/git/allowed_signers contains the Forgejo instance signing key under a dedicated principal (forgejo@${common.domain}).
  • The public key is single-sourced from the Forgejo service module (Option A) or explicitly documented if inlined (Option B); no duplicated literal that can silently drift from /run/forgejo/id_ed25519.pub.
  • git verify-commit on a server-signed merge commit reports Good "git" signature for forgejo@… and %G? = G.
  • User-signed commits remain G (git@martials.no principal).
  • just fmt clean and just build nidaros + one workstation host succeed.
  • Only public key material is committed; the private signing key stays in SOPS.
  • (Optional) AGENTS.md gets a short note that instance-signed merges verify under the forgejo@ principal, so U is not mistaken for an unsigned commit.

Out of scope

  • Woodpecker/bot commits: pushed over HTTPS with a token and unsigned, so they keep showing as unverified regardless of this change.
  • Branch protection requiring verified commits.
  • Any change to the Forgejo instance signing configuration itself; it already works.
## Context Discovered during the cluster repository transfer work (https://code.martials.no/Personal/cluster/issues/76), while checking whether commits stayed signed across the move. **Forgejo-side signing already works.** The gap is local verification: `git verify-commit` on a server-generated merge commit reports `No principal matched` and `%G?` = `U` because the Forgejo instance signing key is missing from `~/.config/git/allowed_signers`. ## Current state (verified, Forgejo 17.0.1) Instance signing is configured in `/var/lib/forgejo/custom/conf/app.ini` (generated by `shared/base/modules/services/forgejo.nix`): ```ini [repository.signing] CRUD_ACTIONS = always FORMAT = ssh INITIAL_COMMIT = always MERGES = always SIGNING_EMAIL = forgejo@martials.no SIGNING_KEY = /run/forgejo/id_ed25519.pub SIGNING_NAME = Forgejo Instance WIKI = always ``` Instance public key (public material, safe to commit): ``` ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILjVIQy6Fp8ckKcVYRxMnBI2/WAWciZuz39z4N99/ECY SHA256:/en+e39PkqipWawBfJfUkbgr9Sk8wlCHJk0vBEcLVIo ``` Server-side verification is correct for both kinds of commit: ```console $ curl -s https://code.martials.no/api/v1/repos/Personal/cluster/git/commits/53840c0 | jq '.verification | {verified, reason}' { "verified": true, "reason": "Forgejo Instance / SHA256:/en+e39PkqipWawBfJfUkbgr9Sk8wlCHJk0vBEcLVIo" } $ curl -s https://code.martials.no/api/v1/repos/Personal/cluster/git/commits/d4bc291 | jq '.verification | {verified, reason}' { "verified": true, "reason": "martin / SHA256:4p1MoEl6avhC36SiOoBWBqXbIbh+bYhxfXjEJqOMvWo" } ``` Local verification is inconsistent — user-signed commits are trusted, instance-signed merges are not: ```console $ git -C cluster verify-commit d4bc291 # author commit, signed by ~/.ssh/id_ed25519 Good "git" signature for git@martials.no with ED25519 key SHA256:4p1MoEl6avhC36SiOoBWBqXbIbh+bYhxfXjEJqOMvWo $ git -C cluster log -1 --format='%G? %GS' d4bc291 G git@martials.no $ git -C cluster verify-commit 53840c0 # squash merge, signed by the Forgejo instance key Good "git" signature with ED25519 key SHA256:/en+e39PkqipWawBfJfUkbgr9Sk8wlCHJk0vBEcLVIo No principal matched. $ git -C cluster log -1 --format='%G? %GS' 53840c0 U ``` ## Root cause `shared/base/home-manager/development/git.nix` builds the allowed signers file from host SSH keys only, all under one principal: ```nix let email = "git@${common.domain}"; allowedSigners = lib.concatMapStringsSep "\n" (system: "${email} ${system.ssh.publicKey}") ( builtins.attrValues systems ); in { home.file.".config/git/allowed_signers".text = "${allowedSigners}\n"; # ... settings.gpg.ssh.allowedSignersFile = "${config.home.homeDirectory}/.config/git/allowed_signers"; } ``` The Forgejo instance key is never added, so signatures made by the server (squash merges, initial commits, CRUD actions, wiki edits) cannot be matched to a principal. ## Proposed change Add the instance signing key as an allowed signer, preferably single-sourced from the same module that configures `[repository.signing]` so the two cannot drift. Option A — declare the public key as an option on the service module and consume it from the git module (which already receives `systemConfig`): ```nix # shared/base/modules/services/forgejo.nix options.my.services.forgejo.signing = { publicKey = lib.mkOption { type = lib.types.str; description = "Public key matching the SOPS-managed signing key used for [repository.signing]."; }; principal = lib.mkOption { type = lib.types.str; default = "forgejo@${common.domain}"; description = "Principal (email-form) used when verifying instance-signed commits locally."; }; }; # shared/base/home-manager/development/git.nix let hostSigners = lib.concatMapStringsSep "\n" (system: "${email} ${system.ssh.publicKey}") (builtins.attrValues systems); forgejo = systemConfig.my.services.forgejo; allowedSigners = lib.concatStringsSep "\n" [ hostSigners "${forgejo.signing.principal} ${forgejo.signing.publicKey}" ]; in ``` Option B — if wiring the NixOS option into Home Manager is undesirable, append the key literally in the git module: ```nix allowedSigners = lib.concatStringsSep "\n" [ (lib.concatMapStringsSep "\n" (system: "${email} ${system.ssh.publicKey}") (builtins.attrValues systems)) "forgejo@${common.domain} ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILjVIQy6Fp8ckKcVYRxMnBI2/WAWciZuz39z4N99/ECY" ]; ``` Do not commit the private signing key; it stays in SOPS (`forgejo/signing-key`) and is materialised at `/run/forgejo/id_ed25519`. ## Verification examples ```console # rebuild the affected hosts (nidaros hosts Forgejo, the others only need the file change) $ just build nidaros $ just build desktop # after switching, server-signed merge commits must verify locally $ git -C cluster verify-commit 53840c0 Good "git" signature for forgejo@martials.no with ED25519 key SHA256:/en+e39PkqipWawBfJfUkbgr9Sk8wlCHJk0vBEcLVIo $ git -C cluster log -1 --format='%G? %GS' 53840c0 G forgejo@martials.no # the allowed signers file must contain both families of keys $ cat ~/.config/git/allowed_signers git@martials.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILw1iNuPnX9NGt+UAvBDzkk26d1e4nF+XX2FMm+IRWtt ... forgejo@martials.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILjVIQy6Fp8ckKcVYRxMnBI2/WAWciZuz39z4N99/ECY ``` ## Acceptance criteria - [ ] `~/.config/git/allowed_signers` contains the Forgejo instance signing key under a dedicated principal (`forgejo@${common.domain}`). - [ ] The public key is single-sourced from the Forgejo service module (Option A) or explicitly documented if inlined (Option B); no duplicated literal that can silently drift from `/run/forgejo/id_ed25519.pub`. - [ ] `git verify-commit` on a server-signed merge commit reports `Good "git" signature for forgejo@…` and `%G?` = `G`. - [ ] User-signed commits remain `G` (`git@martials.no` principal). - [ ] `just fmt` clean and `just build nidaros` + one workstation host succeed. - [ ] Only public key material is committed; the private signing key stays in SOPS. - [ ] (Optional) `AGENTS.md` gets a short note that instance-signed merges verify under the `forgejo@` principal, so `U` is not mistaken for an unsigned commit. ## Out of scope - Woodpecker/bot commits: pushed over HTTPS with a token and unsigned, so they keep showing as unverified regardless of this change. - Branch protection requiring verified commits. - Any change to the Forgejo instance signing configuration itself; it already works.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Personal/nixos-configuration#64
No description provided.