feat(archied): connection commit identity and SSH commit signing (#1816)
deploy / plan (push) Failing after 2s
deploy / gate (push) Skipped
deploy / archied-image (push) Skipped
deploy / agent-image (push) Skipped
deploy / dist-zip (push) Skipped

This commit is contained in:
sam committed 2026-11-09 00:05:32 +11:00
1 parent ad63692781
commit ac98b68bda
9 files changed
+105 -16

No files matched your search

+1
View File
@@ -84,6 +84,7 @@ require (
github.com/google/uuid v1.6.0
github.com/hashicorp/go-hclog v1.6.3
github.com/hashicorp/go-plugin v1.8.0
github.com/hiddeco/sshsig v0.2.0
github.com/jackc/pgx/v5 v5.11.0
github.com/klauspost/compress v1.20.3
github.com/moby/moby/api v1.56.1
+2
View File
@@ -104,6 +104,8 @@ github.com/hashicorp/go-plugin v1.8.0 h1:ie8S6RRY8RvB2usYZv+AAZ/wBvx2AU5p5QeP5j/
github.com/hashicorp/go-plugin v1.8.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8=
github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
github.com/hiddeco/sshsig v0.2.0 h1:gMWllgKCITXdydVkDL+Zro0PU96QI55LwUwebSwNTSw=
github.com/hiddeco/sshsig v0.2.0/go.mod h1:nJc98aGgiH6Yql2doqH4CTBVHexQA40Q+hMMLHP4EqE=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
+21 -7
View File
@@ -6,6 +6,8 @@ import (
"fmt"
"strings"
"github.com/go-git/go-git/v6"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/daemon"
"github.com/samcharles93/archie-core/internal/domain/access"
@@ -107,8 +109,18 @@ func (b *boot) openRepositoryConnection(ctx context.Context, principal access.Pr
}
}
cfg := b.cfgHolder.Get()
botUser, botEmail := commitIdentity(cfg, connection.Type, username)
out.Trees = &worktree.Manager{WorkDir: worktree.OrgWorkDir(cfg.WorkDir, string(principal.Org)), Token: token, AuthUser: username, BaseURL: host, BotUser: botUser, BotEmail: botEmail, Log: b.log}
botUser, botEmail := commitIdentity(cfg, connection, username)
var signer git.Signer
if connection.SigningKey.Key != "" {
key, err := b.secrets.Resolve(connection.SigningKey)
if err != nil || key == "" {
return failure("signing_key_unavailable", fmt.Sprintf("The signing key for %s is unavailable. Check its secret reference.", connection.Name))
}
if signer, err = worktree.NewSSHSigner([]byte(key)); err != nil {
return failure("signing_key_invalid", fmt.Sprintf("The signing key for %s is not an OpenSSH private key.", connection.Name))
}
}
out.Trees = &worktree.Manager{WorkDir: worktree.OrgWorkDir(cfg.WorkDir, string(principal.Org)), Token: token, AuthUser: username, BaseURL: host, BotUser: botUser, BotEmail: botEmail, Signer: signer, Log: b.log}
out.Forge = b.connectionForge(ctx, connection, principal.Org, token)
if operation == config.OperationPR {
if _, disabled := out.Forge.(*forge.NoopForge); disabled {
@@ -118,10 +130,12 @@ func (b *boot) openRepositoryConnection(ctx context.Context, principal access.Pr
return out, nil
}
// commitIdentity is the author of commits made through a connection. A
// control-plane connection leaves the root bot fields empty, so its account
// signs the commits instead of nobody.
func commitIdentity(cfg config.Config, forgeType, account string) (string, string) {
// commitIdentity is the author of commits made through a connection: its
// configured commit identity, else the root bot fields, else its account.
func commitIdentity(cfg config.Config, connection config.ForgeConnection, account string) (string, string) {
if connection.CommitName != "" {
return connection.CommitName, configuration.DefaultBotEmail(connection.Type, connection.CommitName, connection.CommitEmail)
}
if cfg.BotUser != "" {
return cfg.BotUser, cfg.BotEmail
}
@@ -129,5 +143,5 @@ func commitIdentity(cfg config.Config, forgeType, account string) (string, strin
if user == "" {
user = "archie"
}
return user, configuration.DefaultBotEmail(forgeType, user, "")
return user, configuration.DefaultBotEmail(connection.Type, user, connection.CommitEmail)
}
+14 -7
View File
@@ -64,25 +64,32 @@ func ValidOperation(op string) bool { return slices.Contains(Operations(), op) }
// instance's root configuration.
type ForgeConnection struct {
// ID is the stable reference a repository binding and a permission name.
ID string `toml:"id" json:"id" yaml:"id"`
ID string `json:"id"`
// Name is the operator-facing label.
Name string `toml:"name" json:"name" yaml:"name"`
Name string `json:"name"`
// Type selects the forge implementation: the name of an enabled forge
// extension, or the compiled-in forge of that name.
Type string `toml:"type" json:"type" yaml:"type"`
Type string `json:"type"`
// Host is the forge's host, e.g. "github.com".
Host string `toml:"host" json:"host" yaml:"host"`
Host string `json:"host"`
// Account is the external account the credential authenticates as. It is
// recorded, and checked against the account a verification actually
// reached; it is never used to infer authority.
Account string `toml:"account" json:"account" yaml:"account"`
Account string `json:"account"`
// Token references the credential. The connection records the reference,
// never a token value.
Token SecretRef `toml:"token" json:"token" yaml:"token"`
Token SecretRef `json:"token"`
// CommitName and CommitEmail author commits made through the connection.
// Empty falls back to the account and the forge's default email.
CommitName string `json:"commit_name,omitempty"`
CommitEmail string `json:"commit_email,omitempty"`
// SigningKey references an OpenSSH private key that signs those commits.
// Unset leaves them unsigned.
SigningKey SecretRef `json:"signing_key,omitzero"`
// Permits names, per execution identity ID, the operations that identity
// may perform through this connection. An identity with no entry may
// perform none: the connection itself is not a grant.
Permits map[string][]string `toml:"permits" json:"permits,omitempty" yaml:"permits"`
Permits map[string][]string `json:"permits,omitempty"`
}
// Permitted reports whether the identity may perform op through this
@@ -118,6 +118,9 @@ func validateForgeConnection(c config.ForgeConnection) error {
if (c.Token.Engine == "") != (c.Token.Key == "") {
return fmt.Errorf("connection %q: the credential reference needs both an engine and a key", c.ID)
}
if (c.SigningKey.Engine == "") != (c.SigningKey.Key == "") {
return fmt.Errorf("connection %q: the signing key reference needs both an engine and a key", c.ID)
}
for _, id := range slices.Sorted(maps.Keys(c.Permits)) {
operations := c.Permits[id]
if strings.TrimSpace(id) == "" {
+33
View File
@@ -0,0 +1,33 @@
package worktree
import (
"bytes"
"context"
"fmt"
"io"
"github.com/go-git/go-git/v6"
"github.com/hiddeco/sshsig"
"golang.org/x/crypto/ssh"
)
// sshSigner signs commits the way `git -c gpg.format=ssh` does, so forges
// verify them against the account's SSH signing key.
type sshSigner struct{ key ssh.Signer }
// NewSSHSigner parses an OpenSSH private key for commit signing.
func NewSSHSigner(privateKey []byte) (git.Signer, error) {
key, err := ssh.ParsePrivateKey(privateKey)
if err != nil {
return nil, fmt.Errorf("parse signing key: %w", err)
}
return sshSigner{key: key}, nil
}
func (s sshSigner) Sign(_ context.Context, message io.Reader) ([]byte, error) {
sig, err := sshsig.Sign(message, s.key, sshsig.HashSHA512, "git")
if err != nil {
return nil, fmt.Errorf("ssh sign: %w", err)
}
return bytes.TrimSpace(sshsig.Armor(sig)), nil
}
+4 -2
View File
@@ -45,6 +45,8 @@ type Manager struct {
AuthUser string
BotUser string
BotEmail string
// Signer signs bot commits; nil leaves them unsigned.
Signer git.Signer
// BaseURL overrides the forge host. Set from config [forge].host.
// Empty falls back to https://github.com.
BaseURL string
@@ -574,7 +576,7 @@ func (m *Manager) setIdentity(r *git.Repository) error {
}
cfg.User.Name = m.BotUser
cfg.User.Email = m.BotEmail
// Disable commit signing; go-git cannot sign.
// go-git signs through Signer; a user-level gpgsign must not apply.
cfg.Raw.Section("commit").SetOption("gpgsign", "false")
if err := r.SetConfig(cfg); err != nil {
return fmt.Errorf("write repo config: %w", err)
@@ -627,7 +629,7 @@ func (m *Manager) CommitAll(ctx context.Context, dir, message string) (bool, err
return false, err
}
sig := m.signature()
if _, err := wt.Commit(message, &git.CommitOptions{Author: sig, Committer: sig}); err != nil {
if _, err := wt.Commit(message, &git.CommitOptions{Author: sig, Committer: sig, Signer: m.Signer}); err != nil {
return false, fmt.Errorf("commit: %w", err)
}
return true, nil
+23
View File
@@ -98,6 +98,29 @@ const unavailable = computed(() => !!connection.value.type && !extensions.forges
<SettingRow label="Credential">
<div role="group" aria-label="Credential"><SecretRefField :model-value="connection.token" @update:model-value="(token) => patch({ token })" :id-prefix="`connection-${props.index}-token`" /></div>
</SettingRow>
<SettingRow label="Commit author" :for="`connection-${props.index}-commit-name`">
<div class="flex flex-wrap items-center gap-3">
<Input
:id="`connection-${props.index}-commit-name`"
:model-value="connection.commit_name ?? ''"
@update:model-value="(value: string | number) => patch({ commit_name: String(value) || undefined })"
class="max-w-56"
:placeholder="connection.account || 'archie'"
aria-label="Commit author name"
/>
<Input
:model-value="connection.commit_email ?? ''"
@update:model-value="(value: string | number) => patch({ commit_email: String(value) || undefined })"
class="max-w-72 font-mono"
type="email"
placeholder="archie@example.com"
aria-label="Commit author email"
/>
</div>
</SettingRow>
<SettingRow label="Signing key">
<div role="group" aria-label="Signing key"><SecretRefField :model-value="connection.signing_key ?? { engine: '', key: '' }" @update:model-value="(ref) => patch({ signing_key: ref.engine || ref.key ? ref : undefined })" :id-prefix="`connection-${props.index}-signing-key`" /></div>
</SettingRow>
<SettingRow label="Permitted operations">
<div class="w-full space-y-2" role="group" aria-label="Permitted operations">
<div
+4
View File
@@ -9,6 +9,10 @@ export interface Connection {
host: string;
account: string;
token: { engine: string; key: string };
commit_name?: string;
commit_email?: string;
/** OpenSSH private key that signs commits made through the connection. */
signing_key?: { engine: string; key: string };
/** Permitted operations per execution identity ID. */
permits?: Record<string, string[]>;
}