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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user