mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-28 16:58:31 +01:00
scripts/render_installers.go used strings.ReplaceAll on the signing key placeholder, which also rewrote the unpinned-key sentinel in install.sh and install.ps1 and caused rendered installers to skip ssh-keygen signature verification. Pin only the key assignment and refuse changed templates. Update scripts/install.ps1 to invoke ssh-keygen directly and stream raw binary bytes into stdin instead of calling cmd.exe /d /s /c (whose outer-quote stripping breaks quoted paths) or Start-Process -RedirectStandardInput (which re-encodes binary payloads). In scripts/install.sh, derive curl's sha256// public-key pin from the certificate verified by --server-fingerprint and pass --pinnedpubkey on all six curl request lists so subsequent requests remain bound to the verified peer even with -k. Contract-Neutral: Security hardening of installer verification and privilege boundaries without public contract delta
83 lines
3.1 KiB
Go
83 lines
3.1 KiB
Go
//go:build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
const installerSSHPublicKeyPlaceholder = "__PULSE_INSTALLER_SSH_PUBLIC_KEY__"
|
|
|
|
// installerSSHPublicKeyPins are the assignments that receive the pinned key.
|
|
// Each installer repeats the placeholder once more, as the sentinel its
|
|
// pinned-key check compares the assignment with. That occurrence must reach
|
|
// the rendered installer unchanged: rewritten, the check compares the key with
|
|
// itself and download signatures are never verified.
|
|
var installerSSHPublicKeyPins = map[string]string{
|
|
"install.sh": `PINNED_INSTALLER_SSH_PUBLIC_KEY="` + installerSSHPublicKeyPlaceholder + `"`,
|
|
"install.ps1": `$PinnedInstallerSshPublicKey = "` + installerSSHPublicKeyPlaceholder + `"`,
|
|
}
|
|
|
|
func main() {
|
|
sourceDir := flag.String("source-dir", "", "directory containing install.sh and install.ps1")
|
|
outputDir := flag.String("output-dir", "", "directory to write rendered installers into")
|
|
installerSSHPublicKey := flag.String("installer-ssh-public-key", "", "OpenSSH public key to pin into rendered installers")
|
|
allowEmptyInstallerSSHPublicKey := flag.Bool("allow-empty-installer-ssh-public-key", false, "allow unsigned/dev installer rendering without a pinned installer SSH public key")
|
|
flag.Parse()
|
|
|
|
if strings.TrimSpace(*sourceDir) == "" || strings.TrimSpace(*outputDir) == "" {
|
|
fail("source-dir and output-dir are required")
|
|
}
|
|
if strings.TrimSpace(*installerSSHPublicKey) == "" && !*allowEmptyInstallerSSHPublicKey {
|
|
fail("installer-ssh-public-key is required for rendered installers")
|
|
}
|
|
|
|
if err := os.MkdirAll(*outputDir, 0o755); err != nil {
|
|
fail(fmt.Sprintf("create output dir: %v", err))
|
|
}
|
|
|
|
for _, name := range []string{"install.sh", "install.ps1"} {
|
|
if err := renderInstaller(*sourceDir, *outputDir, name, strings.TrimSpace(*installerSSHPublicKey)); err != nil {
|
|
fail(err.Error())
|
|
}
|
|
}
|
|
}
|
|
|
|
func renderInstaller(sourceDir, outputDir, name, installerSSHPublicKey string) error {
|
|
sourcePath := filepath.Join(sourceDir, name)
|
|
content, err := os.ReadFile(sourcePath)
|
|
if err != nil {
|
|
return fmt.Errorf("read %s: %w", name, err)
|
|
}
|
|
|
|
rendered, err := pinInstallerSSHPublicKey(name, string(content), installerSSHPublicKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
outputPath := filepath.Join(outputDir, name)
|
|
if err := os.WriteFile(outputPath, []byte(rendered), 0o755); err != nil {
|
|
return fmt.Errorf("write %s: %w", name, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func pinInstallerSSHPublicKey(name, template, installerSSHPublicKey string) (string, error) {
|
|
pin := installerSSHPublicKeyPins[name]
|
|
// Refuse a template whose pin or sentinel changed rather than guess which
|
|
// occurrence is which.
|
|
if pin == "" || strings.Count(template, pin) != 1 || strings.Count(template, installerSSHPublicKeyPlaceholder) != 2 {
|
|
return "", fmt.Errorf("render %s: installer signature pin template changed", name)
|
|
}
|
|
pinned := strings.Replace(pin, installerSSHPublicKeyPlaceholder, installerSSHPublicKey, 1)
|
|
return strings.Replace(template, pin, pinned, 1), nil
|
|
}
|
|
|
|
func fail(message string) {
|
|
fmt.Fprintln(os.Stderr, message)
|
|
os.Exit(1)
|
|
}
|