feat(git): pick the Git signing key based on isWork - #648
Merged
Conversation
Work machines were signing commits with the personal SSH key, since gitSigningKey shipped a single default. Ship a second default for work devices and select between them using the existing isWork detection (Entra ID tenant name ending in "Microsoft"). The selection moved after the dsregcmd block so isWork is known, and a persisted gitSigningKey that still equals either shipped default is re-evaluated instead of treated as an override - otherwise a config written by an earlier chezmoi init would pin the wrong key forever. Only a genuinely custom key overrides. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: eb74b7a7-01e8-429c-be50-6ed621df0f8c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On work machines, Git commits were being signed with the personal SSH key.
gitSigningKeyshipped a single hardcoded default in.chezmoi.yaml.tmpl, so every machine got the same key unless it was overridden by hand in a local chezmoi config.What changed
Two defaults now ship: a personal key (unchanged) and a work key. The pick is driven by the
isWorkflag that already exists in the config template, derived fromdsregcmd /statusreporting an Entra ID tenant name ending inMicrosoft.Two details worth a look:
gitSigningKeyused to be resolved above the Entra ID detection block, soisWorkwas not yet known at that point. The variable is now initialised early (to keep the override check next to its documentation) and the default is chosen after detection runs.~/.config/chezmoi/chezmoi.yamlalready carriesgitSigningKey: "<personal key>"from an earlierchezmoi init, so a plain "only fall back when empty" rule would have pinned the wrong key forever. A value that still equals either shipped default is re-picked; only a genuinely custom key wins.Docs updated in
docs/git-signing.mdanddocs/chezmoi-variables.md.Testing
Three new cases in
tests/bash/op-shell-plugins.bats(work, non-work, stale-persisted-default) using a fakewslinfo+dsregcmd.exeonPATH, so they are deterministic regardless of the host running them. Full file passes (37 tests).validate-chezmoi.batspasses.Verified by hand on a work machine:
isWork: truerenderssigningkey = key::ssh-ed25519 AAAA...NHf9KPQ...in~/.config/git/config.Notes for the reviewer
chezmoi init(config data is only regenerated then) followed bychezmoi apply.ssh-add -lempty), so signing failed for both keys. Happy to amend with a signed commit if that matters for this repo.