Skip to content

objectsigner: Add context to Sign and KeyID to ssh signer#11

Merged
pjbgf merged 2 commits into
mainfrom
expand-sign
Jun 23, 2026
Merged

objectsigner: Add context to Sign and KeyID to ssh signer#11
pjbgf merged 2 commits into
mainfrom
expand-sign

Conversation

@pjbgf

@pjbgf pjbgf commented Jun 22, 2026

Copy link
Copy Markdown
Member

Evolve the per-signer API so signing can be cancelled and so callers can identify the signing key.

  • The ssh, gpg and program signers' Sign method now takes a context.Context. The program signer threads it into the external binary invocation; the ssh and gpg signers sign locally and accept the context for interface uniformity.
  • The ssh signer gains a KeyID method returning the SHA256 fingerprint of its public key.

Tests and examples are updated for the new signature. The auto plugin, which depends on the ssh and gpg modules, will be updated once these are released.

Copilot AI review requested due to automatic review settings June 22, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the object signer plugins’ APIs to support context-aware signing (for cancellation/timeout propagation) and adds an SSH key identifier helper for callers.

Changes:

  • Extend Sign for the SSH/GPG/program signers to accept context.Context.
  • Thread context.Context through the program signer’s external command execution.
  • Add KeyID() to the SSH signer (SHA256 public-key fingerprint) and update tests/examples accordingly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
plugin/objectsigner/ssh/ssh.go Add context.Context to Sign and introduce KeyID() for SSH key fingerprinting.
plugin/objectsigner/ssh/ssh_test.go Update signing calls for new Sign(ctx, r) signature; add KeyID test.
plugin/objectsigner/ssh/example_test.go Update example to pass a context into Sign.
plugin/objectsigner/program/program.go Update Sign to accept/propagate context into external invocation.
plugin/objectsigner/program/program_test.go Update tests to call Sign with a context.
plugin/objectsigner/gpg/gpg.go Add context.Context to Sign (accepted for API uniformity).
plugin/objectsigner/gpg/gpg_test.go Update signing calls for new Sign(ctx, r) signature.
plugin/objectsigner/gpg/example_test.go Update example to pass a context into Sign.
Comments suppressed due to low confidence (1)

plugin/objectsigner/program/program.go:167

  • Sign now takes a context.Context, but if a caller passes nil this will eventually reach exec.CommandContext (via newExecCommand) and panic. To keep the method safe and maintain the pre-context behavior, default a nil context to context.Background() (or return an error) before invoking commandContext.
// Sign reads message and returns the signature produced by the external
// binary. The context cancels the external program invocation.
func (s *signer) Sign(ctx context.Context, message io.Reader) ([]byte, error) {
	if message == nil {
		return nil, ErrNilMessage
	}

	switch s.format {
	case FormatOpenPGP, FormatX509:
		return s.signStdio(ctx, message)
	case FormatSSH:
		return s.signSSH(ctx, message)
	default:
		return nil, fmt.Errorf("%w: %q", ErrUnsupportedFormat, s.format)
	}
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugin/objectsigner/program/program.go
Evolve the per-signer API so signing can be cancelled and so callers
can identify the signing key.

- The ssh, gpg and program signers' Sign method now takes a
  context.Context. The program signer threads it into the external
  binary invocation; the ssh and gpg signers sign locally and accept
  the context for interface uniformity.
- The ssh signer gains a KeyID method returning the SHA256 fingerprint
  of its public key.

Tests and examples are updated for the new signature. The auto plugin,
which depends on the ssh and gpg modules, will be updated once these
are released.

Assisted-by: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Paulo Gomes <paulo@entire.io>
Comment thread plugin/objectsigner/program/program_test.go Outdated
Comment thread plugin/objectsigner/program/program_test.go Outdated
Tie each signing call's context to the test lifecycle. Go 1.24's
t.Context() is cancelled when the test ends, so the program signer's
external subprocess is torn down automatically if a test fails or times
out, rather than running under a detached context.Background(). Also
replace the manual `defer cancel()` in the context-threading test with
t.Cleanup(cancel).

Assisted-by: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Paulo Gomes <paulo@entire.io>
Entire-Checkpoint: f374e2d424ba
@pjbgf pjbgf merged commit cbc3be6 into main Jun 23, 2026
6 checks passed
@pjbgf pjbgf deleted the expand-sign branch June 23, 2026 16:06
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.

3 participants