Skip to content

setup(git): set up commit signing on windows, --no-gpg-sign was the only way past it - #394

Open
landsman wants to merge 1 commit into
mainfrom
setup/windows-commit-signing
Open

landsman wants to merge 1 commit into
mainfrom
setup/windows-commit-signing

Conversation

@landsman

@landsman landsman commented Dec 4, 2026

Copy link
Copy Markdown
Owner

commit.gpgsign and gpg.format = ssh arrive with the repo's .gitconfig
include, and nothing on Windows ever configured a key, so every commit on the
T480 stopped at:

fatal: either user.signingkey or gpg.ssh.defaultKeyCommand needs to be configured

The only way past that is --no-gpg-sign, which is how this repo collected
unsigned commits authored by an address that does not exist.

apply.ps1 now has a == git signing step that leaves nothing to answer: the
three config values make git writes on the other OSes, the ssh-agent
service enabled and started, the key added to it, the signer line appended, and
the public half printed to register as a signing key. The key itself stays in
1Password, so when it is not there the step says so and the rest of the run
carries on.

Which ssh-keygen signs is not a free choice

Two OpenSSH installs are on the machine and they do not share an agent.
Measured, with the key held in a Git Bash agent:

agent signing program result
Git Bash (unix socket) ssh-keygen git ships signs, %G? = G
Git Bash (unix socket) native ssh-keygen.exe No private key found for public key

Only the service agent outlives the shell that started it and survives a
reboot, which is what signing from an IDE needs, so gpg.ssh.program points at
C:\Windows\System32\OpenSSH\ssh-keygen.exe — the half that can reach it.

Two things that are deliberate

  • No 2>&1 on either ssh-add call. Under $ErrorActionPreference = 'Stop',
    redirecting a native command's stderr into the success stream raises a
    terminating NativeCommandError and takes the whole run down. Left alone it
    just prints, which is wanted anyway — it says why the agent could not be
    reached.
  • The agent is read back after adding, rather than trusting the exit code.
    An exit code says the command ran, not that the agent took the key, and
    agent holds is a claim that gets believed for months.

Also drops the "user.email is still the repo placeholder" wording from the
== git step: .gitconfig has carried no address since the include-order fix.
The * arm stays, for a machine whose own global config still holds the old
one.

Checked

  • apply.ps1 parses under Windows PowerShell 5.1 and stayed ASCII-only.
  • The new step was run against a sandboxed $HOME with a throwaway key, with
    the service cmdlets stubbed: correct paths, fingerprint and signer line, and
    idempotent — a second run adds nothing and does not duplicate the
    allowed_signers line.
  • With the agent unreachable it reports not in the agent instead of claiming
    the key is held.

Not checked

That the native ssh-keygen reaches the service agent. The service ships
Disabled, enabling it needs elevation, and there is no key on this machine
yet. It follows from the table above, but it is inference, not a measurement —
git log --show-signature -1 on the first commit after the key is restored is
what settles it.

The commit in this PR is itself unsigned, for the reason the PR fixes: there is
no key on the machine yet. The squash-merge commit on main is signed by the
forge.

…nly way past it

commit.gpgsign and gpg.format = ssh arrive with the repo's .gitconfig include,
and nothing on Windows ever configured a key, so every commit here stopped at

    fatal: either user.signingkey or gpg.ssh.defaultKeyCommand needs to be configured

The only way past that is --no-gpg-sign, which is how this repo collected
unsigned commits. apply.ps1 now has a `== git signing` step that leaves nothing
to answer: the three config values `make git` writes on the other OSes, the
ssh-agent service enabled and started, the key added to it, the signer line
appended, and the public half printed to register. The key itself stays in
1Password, so when it is not there the step says so and the run carries on.

Which ssh-keygen signs is not a free choice. Two OpenSSH installs are on the
machine and they do not share an agent: the one git ships (MSYS, a Unix socket
in SSH_AUTH_SOCK) and the Windows one (a named pipe, served by the service).
Measured with a key held in a Git Bash agent, git's own ssh-keygen signs with
it and the native one answers "No private key found for public key". Only the
service agent survives a reboot, which is what signing from an IDE needs, so
gpg.ssh.program points at the native binary.

Two things the step does not do by accident. It never redirects ssh-add's
stderr: under $ErrorActionPreference = 'Stop', 2>&1 on a native command raises
a terminating NativeCommandError and takes the whole run down. And it reads the
agent back after adding rather than trusting the exit code, because "agent
holds" is a claim that gets believed for months.

Also drops the "user.email is still the repo placeholder" wording from the
== git step: .gitconfig has carried no address since the include-order fix. The
`*` arm stays, for a machine whose own global config still holds the old one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant