Skip to content

Commit f4b2c67

Browse files
committed
test(e2e/ssh): verify commit signature with git verify-commit
Add Step 4 to the SSH signing test that cryptographically verifies the commit is actually signed: - Reads the public key used for signing - Creates an allowed signers file inside the workspace - Runs git verify-commit HEAD and asserts "Good" signature - Runs git log --show-signature and confirms the signature is associated with the correct email principal
1 parent 196187d commit f4b2c67

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

e2e/tests/ssh/ssh.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,65 @@ var _ = ginkgo.Describe("devpod ssh test suite", ginkgo.Label("ssh"), ginkgo.Ord
191191
gomega.ContainSubstring("signed test commit"),
192192
"git commit should succeed with the signed test commit message",
193193
)
194+
195+
// Step 4: Verify the commit is actually signed with a valid SSH signature.
196+
// Read the public key that was used for signing so we can build
197+
// an allowed-signers file inside the workspace for verification.
198+
pubKeyBytes, err := os.ReadFile(
199+
keyPath + ".pub",
200+
) // #nosec G304 -- test file with controlled path
201+
framework.ExpectNoError(err)
202+
pubKey := strings.TrimSpace(string(pubKeyBytes))
203+
204+
verifyCmd := strings.Join([]string{
205+
"cd /tmp/test-sign-repo",
206+
// Create allowed signers file mapping the test email to our public key
207+
"echo 'test@example.com " + pubKey + "' > /tmp/allowed_signers",
208+
"git config gpg.ssh.allowedSignersFile /tmp/allowed_signers",
209+
// Verify the commit signature is valid
210+
"git verify-commit HEAD 2>&1",
211+
}, " && ")
212+
213+
stdout, stderr, err = f.ExecCommandCapture(ctx, []string{
214+
"ssh",
215+
"--agent-forwarding",
216+
"--start-services",
217+
tempDir,
218+
"--command", verifyCmd,
219+
})
220+
ginkgo.GinkgoWriter.Printf("verify stdout: %s\n", stdout)
221+
ginkgo.GinkgoWriter.Printf("verify stderr: %s\n", stderr)
222+
framework.ExpectNoError(err)
223+
224+
// git verify-commit writes signature details to stderr
225+
combined := stdout + stderr
226+
gomega.Expect(combined).To(
227+
gomega.ContainSubstring("Good"),
228+
"git verify-commit should report a good SSH signature",
229+
)
230+
231+
// And confirm the signature log shows the correct principal
232+
logCmd := "cd /tmp/test-sign-repo && git log --show-signature -1 2>&1"
233+
stdout, stderr, err = f.ExecCommandCapture(ctx, []string{
234+
"ssh",
235+
"--agent-forwarding",
236+
"--start-services",
237+
tempDir,
238+
"--command", logCmd,
239+
})
240+
ginkgo.GinkgoWriter.Printf("log stdout: %s\n", stdout)
241+
ginkgo.GinkgoWriter.Printf("log stderr: %s\n", stderr)
242+
framework.ExpectNoError(err)
243+
244+
combined = stdout + stderr
245+
gomega.Expect(combined).To(
246+
gomega.ContainSubstring("Good"),
247+
"git log --show-signature should report a good signature",
248+
)
249+
gomega.Expect(combined).To(
250+
gomega.ContainSubstring("test@example.com"),
251+
"signature should be associated with the test email principal",
252+
)
194253
},
195254
)
196255

0 commit comments

Comments
 (0)