Skip to content

Commit 751ec2b

Browse files
committed
Exclude default ssh-keygen from custom program detection
Rename hasSSHSignProgram to hasCustomSSHSignProgram and exclude the git default value "ssh-keygen", which works with go-git's native SSH agent signing. Only truly external programs like 1Password's op-ssh-sign should skip native signing. Entire-Checkpoint: fe883bace626
1 parent 7b53945 commit 751ec2b

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

cmd/entire/cli/objectsigner.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ func RegisterObjectSigner() {
3737
return nil
3838
}
3939

40-
// When gpg.ssh.program is configured (e.g. 1Password's op-ssh-sign),
41-
// signing happens via an external binary that go-git cannot invoke.
42-
// Skip native signing silently — checkpoint commits will be unsigned,
43-
// which is acceptable since signing is best-effort.
44-
if auto.Format(merged.GPG.Format) == auto.FormatSSH && hasSSHSignProgram(merged.Raw) {
45-
logging.Debug(context.Background(), "skipping native SSH commit signing: gpg.ssh.program is configured")
40+
// When a custom gpg.ssh.program is configured (e.g. 1Password's
41+
// op-ssh-sign), signing happens via an external binary that go-git
42+
// cannot invoke. Skip native signing silently — checkpoint commits
43+
// will be unsigned, which is acceptable since signing is best-effort.
44+
// The default program is "ssh-keygen", which works with go-git's
45+
// native SSH agent signing and does not need to be skipped.
46+
if auto.Format(merged.GPG.Format) == auto.FormatSSH && hasCustomSSHSignProgram(merged.Raw) {
47+
logging.Debug(context.Background(), "skipping native SSH commit signing: custom gpg.ssh.program is configured")
4648
return nil
4749
}
4850

@@ -85,14 +87,20 @@ var scopeName = map[config.Scope]string{
8587
config.SystemScope: "system",
8688
}
8789

88-
// hasSSHSignProgram checks whether gpg.ssh.program is set in the raw config.
90+
// hasCustomSSHSignProgram checks whether gpg.ssh.program is set to a
91+
// non-default value in the raw config. The git default is "ssh-keygen",
92+
// which works with go-git's native SSH agent signing. Custom programs
93+
// (e.g. 1Password's op-ssh-sign) use a separate signing mechanism that
94+
// go-git cannot invoke.
8995
// go-git's Config struct does not expose this field, so we read it directly.
90-
func hasSSHSignProgram(raw *format.Config) bool {
96+
func hasCustomSSHSignProgram(raw *format.Config) bool {
9197
if raw == nil {
9298
return false
9399
}
94100

95-
return raw.Section("gpg").Subsection("ssh").Option("program") != ""
101+
program := raw.Section("gpg").Subsection("ssh").Option("program")
102+
103+
return program != "" && program != "ssh-keygen"
96104
}
97105

98106
func loadScopedConfig(source plugin.ConfigSource, scope config.Scope) *config.Config {

cmd/entire/cli/objectsigner_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
format "github.com/go-git/go-git/v6/plumbing/format/config"
77
)
88

9-
func TestHasSSHSignProgram(t *testing.T) {
9+
func TestHasCustomSSHSignProgram(t *testing.T) {
1010
t.Parallel()
1111

1212
tests := []struct {
@@ -25,14 +25,23 @@ func TestHasSSHSignProgram(t *testing.T) {
2525
want: false,
2626
},
2727
{
28-
name: "gpg.ssh.program set",
28+
name: "custom program set",
2929
raw: func() *format.Config {
3030
c := format.New()
3131
c.Section("gpg").Subsection("ssh").SetOption("program", "/Applications/1Password.app/Contents/MacOS/op-ssh-sign")
3232
return c
3333
}(),
3434
want: true,
3535
},
36+
{
37+
name: "default ssh-keygen is not custom",
38+
raw: func() *format.Config {
39+
c := format.New()
40+
c.Section("gpg").Subsection("ssh").SetOption("program", "ssh-keygen")
41+
return c
42+
}(),
43+
want: false,
44+
},
3645
{
3746
name: "gpg section exists but no ssh.program",
3847
raw: func() *format.Config {
@@ -48,9 +57,9 @@ func TestHasSSHSignProgram(t *testing.T) {
4857
t.Run(tt.name, func(t *testing.T) {
4958
t.Parallel()
5059

51-
got := hasSSHSignProgram(tt.raw)
60+
got := hasCustomSSHSignProgram(tt.raw)
5261
if got != tt.want {
53-
t.Errorf("hasSSHSignProgram() = %v, want %v", got, tt.want)
62+
t.Errorf("hasCustomSSHSignProgram() = %v, want %v", got, tt.want)
5463
}
5564
})
5665
}

0 commit comments

Comments
 (0)