Repository navigation
Support signing commits with SSH key - #1035
Merged
Merged
Conversation
hiddeco
force-pushed
the
feat/ssh-commit-signing
branch
from
May 29, 2026 12:57
76ac390 to
20ebc65
Compare
hiddeco
force-pushed
the
feat/ssh-commit-signing
branch
from
June 13, 2026 11:16
20ebc65 to
c955d31
Compare
hiddeco
marked this pull request as ready for review
June 13, 2026 11:16
hiddeco
force-pushed
the
feat/ssh-commit-signing
branch
from
June 13, 2026 11:32
c955d31 to
b843b95
Compare
matheuscscp
reviewed
Jun 13, 2026
matheuscscp
left a comment
Member
There was a problem hiding this comment.
Mostly LGTM, a few important nits in the API package
hiddeco
force-pushed
the
feat/ssh-commit-signing
branch
4 times, most recently
from
June 15, 2026 06:38
bbca0c7 to
479b089
Compare
Add an optional Type field (gpg|ssh) to SigningKey on api/v1. When empty the controller defaults to 'gpg' so existing manifests behave identically; selecting 'ssh' reads an SSH private key from the 'identity' Secret data key, matching the convention used by GitRepository SSH transport auth. Fix a pre-existing inconsistency on SecretRef: it was tagged +required but used json:",omitempty", which let a zero-value omit a CRD-required field on marshal. Drop the omitempty. Signed-off-by: Hidde Beydals <[email protected]>
Mechanical regeneration after adding the Type field on SigningKey. Only the CRD changed: deepcopy is unaffected (SigningKeyType is a string alias that copies by value) and go.mod/go.sum were already tidy. The api-docs target (`make api-docs`) was already broken on main before this branch due to the pre-existing ObservedPolicies map type alias tripping gen-crd-api-reference-docs; it is not a regression of this task. Signed-off-by: Hidde Beydals <[email protected]>
Generates ed25519 and ECDSA P-256 SSH keypairs at test time, returning PEM-encoded private keys plus the matching gossh.PublicKey for verify assertions. Mirrors the existing GetSigningKeyPair helpers so the new SSH-signing tests do not require checked-in key files. Signed-off-by: Hidde Beydals <[email protected]>
ioutil has been deprecated since Go 1.16. Switch the in-tree directory copy helper to os.ReadDir, which returns fs.DirEntry; the symlink check moves from Mode() to Type() (DirEntry exposes only the file-type bits). Signed-off-by: Hidde Beydals <[email protected]>
The function always populates 'password'; drop the misleading 'when provided' qualifier. Signed-off-by: Hidde Beydals <[email protected]>
Extracts the signing-key constants and the type-detection pure function into a dedicated file inside internal/source. detectSigningType validates that the referenced Secret contains the key expected for the declared signing-key type (gpg -> git.asc, ssh -> identity), with table-tested coverage of every case. The resolveSigner dispatcher is also added with placeholder leaf loaders; Tasks 6 and 7 fill them in. Signed-off-by: Hidde Beydals <[email protected]>
Lifts the existing OpenPGP load path from getSigningEntity in git.go into a dedicated leaf function in signing.go. Preserves the existing error strings verbatim so downstream log-scraping is unaffected. Returns a signature.Signer via the new signature.NewOpenPGPSigner constructor instead of the typed *openpgp.Entity. Signed-off-by: Hidde Beydals <[email protected]>
Reads the SSH private key from the 'identity' field and the optional passphrase from 'password' (matching the Flux SSH-auth Secret format), then delegates to signature.NewSSHSigner from pkg/git. Surfaces the encrypted-without-passphrase case with a message symmetric to the GPG path so operators have one common runbook entry. Signed-off-by: Hidde Beydals <[email protected]>
Exercises the full path through resolveSigner against a fake client: the no-SigningKey case, missing-Secret case, GPG and SSH happy paths, and both type-mismatch error cases. Signed-off-by: Hidde Beydals <[email protected]>
GetSigningKeyPair previously serialized the OpenPGP private key before encrypting it, so the returned bytes were always unencrypted regardless of the passphrase argument. Encrypt first, then serialize via SerializePrivateWithoutSigning (the variant that does not re-sign identities, which would fail on an encrypted key). The bug went unnoticed because the prior Test_getSigningEntity test only exercised the encrypted-with-passphrase path, which silently succeeded as if unencrypted. The new Test_loadGPGSigner subtests added in the SSH-signing migration exercise both branches and require the serialized bytes to actually be encrypted. Signed-off-by: Hidde Beydals <[email protected]>
Bumps fluxcd/pkg/git to the minor that exposes the generic signature.Signer interface and the NewOpenPGPSigner / NewSSHSigner constructors. The controller now resolves a Signer via the new resolveSigner dispatcher in signing.go, removes the old typed *openpgp.Entity path from git.go, and appends WithSigner conditionally at the commit call site to avoid the typed-nil interface hazard the new generic field introduces. Retires the legacy Test_getSigningEntity unit test; its coverage moved to signing_test.go alongside the new dispatcher leaves. Updates the SourceManager.CommitAndPush fixture to set the explicit GPG type now that detectSigningType requires it (the apiserver default does not apply to in-memory test objects). Signed-off-by: Hidde Beydals <[email protected]>
Adds two end-to-end tests that drive the reconciler to push a commit
signed via the new SSH signing path: one for ed25519, one for
ecdsa-sha2-nistp256. Each test in-process-verifies the produced gpgsig
header through sshsig.Verify against the matching public key, so the
namespace ("git"), hash, and armor format are all checked.
The ECDSA case exercises the non-ed25519 SSH path explicitly so the
algorithm allowlist is not silently ed25519-only.
Signed-off-by: Hidde Beydals <[email protected]>
Adds an SSH-signing subsection alongside the existing OpenPGP content on the v1 spec page. Covers the type discriminator, the SSH-auth Secret reuse pattern (same-namespace only), the supported algorithm list, and the OpenSSH-format constraint with a pointer at ssh-keygen -p for key conversion. Signed-off-by: Hidde Beydals <[email protected]>
hiddeco
force-pushed
the
feat/ssh-commit-signing
branch
from
June 15, 2026 06:40
479b089 to
ec7b052
Compare
matheuscscp
reviewed
Jun 15, 2026
Adds a third reconciler test that drives a commit signed by a passphrase-protected ed25519 SSH key, alongside the existing unencrypted ed25519 and ecdsa-sha2-nistp256 cases. The test verifies the produced signature in-process via sshsig.Verify so the decrypt path through signature.NewSSHSigner is actually covered, and is not just constructed. The test also picks up the GetSSHSigningKeySecret helper in internal/testutil, which until now had no callers — so the passphrase plus identity layout it returns is exercised by the suite rather than left as dead code. Teardown is registered through t.Cleanup rather than defer so that a teardown failure does not short-circuit other cleanups and is still attributed to this test. Signed-off-by: Hidde Beydals <[email protected]>
hiddeco
added a commit
to fluxcd/flux2
that referenced
this pull request
Jun 18, 2026
Closes a pre-existing gap where the ImageUpdateAutomation SigningKey
field was reachable only by hand-editing the rendered YAML. The two
new flags --signing-key-secret and --signing-key-type populate the
spec.git.commit.signingKey block directly.
When --signing-key-secret is set without --signing-key-type, the run
function leaves spec.git.commit.signingKey.type empty so the
controller's documented default ('gpg' when type is unset[1]) applies
server-side rather than baking the choice into the rendered YAML.
Validation rejects --signing-key-type without --signing-key-secret
and rejects values outside {gpg, ssh}, using the typed
SigningKeyType constants exported from the image-automation-
controller API so the validator and populator share a single source
of truth.
[1]: fluxcd/image-automation-controller#1035
Signed-off-by: Hidde Beydals <[email protected]>
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.
Depends on fluxcd/pkg#1141 and fluxcd/pkg#1222