fix: remove public key deployment from deploy-keys

Deploy-keys now only:
- Creates /var/lib/syncserver/ssh/keys on remote
- Uploads private keys of all other machines to that path
- Populates known_hosts with all other machine hosts

No longer touches authorized_keys or reads server public key.
This commit is contained in:
2026-07-09 20:58:48 -04:00
parent 048b99921e
commit c7337a3bbc
4 changed files with 5 additions and 40 deletions
-12
View File
@@ -7,7 +7,6 @@ import (
"fmt"
"log/slog"
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
@@ -350,7 +349,6 @@ func (h *MachineHandler) DeployKeys(w http.ResponseWriter, r *http.Request) {
}
serverKeyPath := h.cfg.SSHDir() + "/id_ed25519"
serverPubKeyPath := h.cfg.SSHDir() + "/id_ed25519.pub"
if m.SSHKeyID != nil {
sshKeyRepo := models.NewSSHKeyRepository(h.db)
@@ -360,14 +358,6 @@ func (h *MachineHandler) DeployKeys(w http.ResponseWriter, r *http.Request) {
}
}
serverPubKey := ""
if req.IncludeServerKey {
data, err := os.ReadFile(serverPubKeyPath)
if err == nil {
serverPubKey = string(data)
}
}
allMachines, err := repo.GetAll()
if err != nil {
slog.Warn("failed to fetch machines for auto-detect", "error", err)
@@ -406,13 +396,11 @@ func (h *MachineHandler) DeployKeys(w http.ResponseWriter, r *http.Request) {
result, err := sshmanager.DeployKeysToMachine(
context.Background(),
serverKeyPath,
serverPubKey,
m.Host,
m.Port,
m.SSHUser,
keys,
knownHostsHosts,
req.IncludeServerKey,
)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
+1 -23
View File
@@ -8,7 +8,6 @@ import (
"net"
"os"
"path/filepath"
"strings"
"time"
"golang.org/x/crypto/ssh"
@@ -26,7 +25,7 @@ type DeployResult struct {
Errors []string
}
func DeployKeysToMachine(ctx context.Context, serverKeyPath, serverPubKey string, host string, port int, user string, keys []DeployKey, knownHostsHosts []string, addServerPubKey bool) (*DeployResult, error) {
func DeployKeysToMachine(ctx context.Context, serverKeyPath string, host string, port int, user string, keys []DeployKey, knownHostsHosts []string) (*DeployResult, error) {
result := &DeployResult{Success: true, Messages: []string{}, Errors: []string{}}
addr := fmt.Sprintf("%s:%d", host, port)
@@ -163,27 +162,6 @@ func DeployKeysToMachine(ctx context.Context, serverKeyPath, serverPubKey string
}
}
if addServerPubKey && serverPubKey != "" {
session3, err := conn.NewSession()
if err != nil {
result.Errors = append(result.Errors, fmt.Sprintf("session for authorized_keys: %v", err))
result.Success = false
} else {
session3.Stdout = &stdout
session3.Stderr = &stderr
pubKeyClean := strings.TrimSpace(serverPubKey)
err := session3.Run(fmt.Sprintf("mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '%s' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys", pubKeyClean))
session3.Close()
if err != nil {
slog.Warn("deploy: adding to authorized_keys failed", "host", host, "error", err)
result.Errors = append(result.Errors, fmt.Sprintf("adding to authorized_keys: %v (stderr: %s)", err, stderr.String()))
result.Success = false
} else {
result.Messages = append(result.Messages, fmt.Sprintf("Added server public key to %s@%s:~/.ssh/authorized_keys", user, host))
}
}
}
slog.Info("deploy keys result", "host", host, "success", result.Success, "messages", len(result.Messages), "errors", len(result.Errors))
return result, nil
}
+1 -2
View File
@@ -125,12 +125,11 @@ export interface DeployKeysResponse {
export interface DeployKeysOptions {
known_hosts_host?: string;
include_server_key?: boolean;
}
export async function deployKeys(machineId: number, options?: DeployKeysOptions): Promise<DeployKeysResponse> {
return api<DeployKeysResponse>(`/api/machines/${machineId}/deploy-keys`, {
method: 'POST',
body: options ?? { include_server_key: true },
body: options ?? {},
});
}
+1 -1
View File
@@ -217,7 +217,7 @@ export default function Machines() {
async function handleDeployKeys(m: Machine) {
setDeployModal({ machine: m, result: null, loading: true });
try {
const result = await deployKeys(m.id, { include_server_key: true });
const result = await deployKeys(m.id);
setDeployModal({ machine: m, result, loading: false });
} catch (e: unknown) {
setDeployModal({ machine: m, result: { success: false, messages: [], errors: [(e as Error).message] }, loading: false });