feat(P00): deprecation sweep + bash tooling gate + render contract + doc banners (v0.9 P00)
P00 — Re-architecture Foundation (deprecation/migration/test-infra/persona/docs). Deprecation sweep (REQ-068, REQ-072, REQ-089): - Add // Deprecated: doc comments to internal/daemon (R-001), internal/transport (REQ-073), internal/security/ca.go+csr.go (D-101/REQ-076), internal/engine/ dispatcher.go+peer.go (CLI-side scheduler), internal/cli/daemon.go. - orca daemon emits slog.Warn deprecation banner on every run (ungated); fires R-001 + v0.10-P05 drain-and-stop + v0.10-P14 deletion. - orca cert and orca node join (mTLS path) emit deprecation warnings; proxmox SSH path (the v0.9 replacement) does not warn. - Add --no-deprecation-warnings global flag on root command (PersistentPreRunE) for orca upgrade migrations. - 12 new daemon/cert/node deprecation tests in internal/cli/daemon_test.go (cli coverage 81.9%, warnDeprecated 100%). - Add DEPRECATED banners to v0.8 sections of ARCHITECTURE.md (verified the v0.9 supersession section + Supersession Table from prior turn are present). Bash tooling gate (grill C-06, C-15, C-16, C-17, C-18): - scripts/tests/test_helper.bash + example_test.bash — bats framework + helpers. - scripts/lib/orca-log.sh — slog-compatible JSON logging to syslog (C-17). - scripts/orca-verify-render.sh — render-contract validator skeleton (C-16). - scripts/tests/orca-log_test.bash + orca-verify-render_test.bash — 20 bats tests total (happy + failure paths per C-15). - .shellcheckrc — project shellcheck config. - Makefile: test-bash + lint-bash targets (graceful skip if tools missing); wired into test + lint targets. - internal/emit/contract.go + contract_test.go — versioned JSON render contract (orca.emit/v1) between Go emitters and bash appliers (C-16). - .ciagent/BASH_CAPABILITY_MAP_v0.9.md — maps shipped internal/transport capabilities to bash-side equivalents or accepted drops (C-18). - D-186 recorded in PROJECT.md: bash exempt from Go coverage gate; compensating control is bats + shellcheck + shfmt (C-06). verify-reqs: 90 requirements consistent. Build/test/lint/fmt all green. 20 bats tests pass. Go tests pass. No v0.8 code deleted — only marked deprecated (deletion deferred to v0.10-P14 per REQ-090 dual-write window). ---ci--- project: orca phase: P00 milestone: v0.9 status: execute ---/ci---
This commit is contained in:
+15
-1
@@ -42,6 +42,11 @@ func ServerCertPath() string { return certpaths.ServerCertPath() }
|
||||
func ServerKeyPath() string { return certpaths.ServerKeyPath() }
|
||||
|
||||
// NewCommand builds the `orca cert` command tree.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). The `orca cert` command tree is retained for the
|
||||
// dual-write window and scheduled for deletion in v0.10. See
|
||||
// .ciagent/PRD_v0.9.md.
|
||||
func NewCommand(log *slog.Logger) *cobra.Command {
|
||||
if log == nil {
|
||||
log = slog.Default()
|
||||
@@ -49,7 +54,16 @@ func NewCommand(log *slog.Logger) *cobra.Command {
|
||||
certCmd := &cobra.Command{
|
||||
Use: "cert",
|
||||
Short: "Manage orca certificates (CA, server, rotation)",
|
||||
Long: "Bootstrap a local CA, generate server certs, and rotate them.",
|
||||
Long: `Manage orca certificates (CA, server, rotation).
|
||||
|
||||
Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
(D-101/REQ-076). The ` + "`orca cert`" + ` command tree is retained for the
|
||||
dual-write window and scheduled for deletion in v0.10. See
|
||||
.ciagent/PRD_v0.9.md.`,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
warnDeprecated("orca cert is deprecated in v0.9: step-ca (D-101) now handles CA; orca cert will be removed in v0.10 — see .ciagent/PRD_v0.9.md")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
certCmd.AddCommand(newCAInitCmd(log))
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -26,8 +25,14 @@ var (
|
||||
var daemonCmd = &cobra.Command{
|
||||
Use: "daemon",
|
||||
Short: "Run the orca daemon (HTTP API + health checks)",
|
||||
Long: "Start the orca daemon. Listens on the configured address for health, API, and dispatch requests.",
|
||||
Long: `Start the orca daemon. Listens on the configured address for health, API, and dispatch requests.
|
||||
|
||||
Deprecated: v0.9 re-architecture replaces the orca daemon with SSH-push to
|
||||
bare servers (R-001 — no orca binary on servers). The daemon is repurposed to
|
||||
drain-and-stop in v0.10-P05 and scheduled for deletion in v0.10-P14. See
|
||||
.ciagent/PRD_v0.9.md.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
warnDeprecated("orca daemon is deprecated in v0.9 and will be repurposed to 'drain-and-stop' in v0.10-P05; the v0.9 re-architecture (R-001) removes the orca binary from servers — see .ciagent/PRD_v0.9.md")
|
||||
db, closer, err := openDB()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -97,5 +102,4 @@ func init() {
|
||||
daemonCmd.Flags().StringVar(&daemonAddr, "addr", ":8080", "listen address")
|
||||
daemonCmd.Flags().StringVar(&pprofAddr, "pprof", "", "enable pprof endpoint on <addr> (e.g. :6060); unauthenticated, operator-only")
|
||||
rootCmd.AddCommand(daemonCmd)
|
||||
_ = slog.Default // keep import if unused above
|
||||
}
|
||||
|
||||
+221
-1
@@ -1,6 +1,12 @@
|
||||
package cli
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDaemonPprofFlag(t *testing.T) {
|
||||
f := daemonCmd.Flags().Lookup("pprof")
|
||||
@@ -11,3 +17,217 @@ func TestDaemonPprofFlag(t *testing.T) {
|
||||
t.Errorf("--pprof default = %q, want empty", f.DefValue)
|
||||
}
|
||||
}
|
||||
|
||||
// captureSlog swaps slog.Default() for a text handler writing to buf,
|
||||
// returning a buffer and a restore func. Tests use this to observe
|
||||
// warnDeprecated output (which uses the package-level slog.Default).
|
||||
func captureSlog(t *testing.T) (*bytes.Buffer, func()) {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
prev := slog.Default()
|
||||
logger := slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelWarn}))
|
||||
slog.SetDefault(logger)
|
||||
return &buf, func() { slog.SetDefault(prev) }
|
||||
}
|
||||
|
||||
// runDaemonHermetic invokes daemonCmd.RunE with a context that is
|
||||
// already cancelled and an unbindable --addr, so the long-running
|
||||
// server start short-circuits and RunE returns quickly without
|
||||
// touching the network. It returns whatever RunE returned and the
|
||||
// captured slog buffer.
|
||||
func runDaemonHermetic(t *testing.T, suppressWarnings bool) (string, error) {
|
||||
t.Helper()
|
||||
_, cleanup := initTestEnv(t)
|
||||
defer cleanup()
|
||||
resetRootFlags(t)
|
||||
|
||||
buf, restore := captureSlog(t)
|
||||
defer restore()
|
||||
|
||||
if suppressWarnings {
|
||||
_ = rootCmd.PersistentFlags().Set("no-deprecation-warnings", "true")
|
||||
}
|
||||
|
||||
daemonAddr = "127.0.0.1:99999" // unbindable: port outside uint16 range → ListenAndServe fails fast
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // already-done context: the select returns via <-ctx.Done() immediately
|
||||
|
||||
cmd := daemonCmd
|
||||
cmd.SetOut(&bytes.Buffer{})
|
||||
cmd.SetErr(&bytes.Buffer{})
|
||||
cmd.SetArgs(nil)
|
||||
cmd.SetContext(ctx)
|
||||
|
||||
err := cmd.RunE(cmd, nil)
|
||||
return buf.String(), err
|
||||
}
|
||||
|
||||
// TestDaemonEmitsDeprecationWarning verifies REQ-068: `orca daemon`
|
||||
// emits a slog.Warn deprecation banner on every run.
|
||||
func TestDaemonEmitsDeprecationWarning(t *testing.T) {
|
||||
out, _ := runDaemonHermetic(t, false)
|
||||
if !strings.Contains(out, "orca daemon is deprecated in v0.9") {
|
||||
t.Errorf("expected deprecation warning in slog output, got:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, "R-001") {
|
||||
t.Errorf("deprecation warning should reference R-001, got:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDaemonDeprecationWarningSuppressed verifies that
|
||||
// --no-deprecation-warnings suppresses the deprecation banner (for
|
||||
// `orca upgrade` migrations).
|
||||
func TestDaemonDeprecationWarningSuppressed(t *testing.T) {
|
||||
out, _ := runDaemonHermetic(t, true)
|
||||
if strings.Contains(out, "deprecated in v0.9") {
|
||||
t.Errorf("--no-deprecation-warnings should suppress the deprecation warning, got:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDaemonStillRuns verifies deprecation ≠ removal: the daemon
|
||||
// command's RunE is still wired and callable. We don't assert on the
|
||||
// error value (the hermetic short-circuit may return nil or a
|
||||
// shutdown-related error), only that the command did not fail *because*
|
||||
// of the deprecation notice.
|
||||
func TestDaemonStillRuns(t *testing.T) {
|
||||
_, err := runDaemonHermetic(t, false)
|
||||
if err != nil && strings.Contains(err.Error(), "deprecated") {
|
||||
t.Errorf("daemon must not error due to deprecation, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWarnDeprecatedGate verifies the package-level helper that gates
|
||||
// deprecation warnings on the --no-deprecation-warnings flag.
|
||||
func TestWarnDeprecatedGate(t *testing.T) {
|
||||
t.Run("emits by default", func(t *testing.T) {
|
||||
buf, restore := captureSlog(t)
|
||||
defer restore()
|
||||
noDeprecationWarnings = false
|
||||
warnDeprecated("test-deprecation-marker")
|
||||
if !strings.Contains(buf.String(), "test-deprecation-marker") {
|
||||
t.Errorf("expected warning emitted, got: %s", buf.String())
|
||||
}
|
||||
})
|
||||
t.Run("suppressed when flag set", func(t *testing.T) {
|
||||
buf, restore := captureSlog(t)
|
||||
defer restore()
|
||||
noDeprecationWarnings = true
|
||||
defer func() { noDeprecationWarnings = false }()
|
||||
warnDeprecated("should-not-appear")
|
||||
if strings.Contains(buf.String(), "should-not-appear") {
|
||||
t.Errorf("expected no warning when --no-deprecation-warnings set, got: %s", buf.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestNoDeprecationWarningsFlagRegistered verifies the
|
||||
// --no-deprecation-warnings persistent flag exists on rootCmd.
|
||||
func TestNoDeprecationWarningsFlagRegistered(t *testing.T) {
|
||||
f := rootCmd.PersistentFlags().Lookup("no-deprecation-warnings")
|
||||
if f == nil {
|
||||
t.Fatal("--no-deprecation-warnings persistent flag not registered on rootCmd")
|
||||
}
|
||||
if f.DefValue != "false" {
|
||||
t.Errorf("--no-deprecation-warnings default = %q, want false", f.DefValue)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCertEmitsDeprecationWarning verifies REQ-068: `orca cert`
|
||||
// subcommands emit a deprecation banner.
|
||||
func TestCertEmitsDeprecationWarning(t *testing.T) {
|
||||
_, cleanup := initTestEnv(t)
|
||||
defer cleanup()
|
||||
resetRootFlags(t)
|
||||
|
||||
buf, restore := captureSlog(t)
|
||||
defer restore()
|
||||
|
||||
var out bytes.Buffer
|
||||
rootCmd.SetOut(&out)
|
||||
rootCmd.SetErr(&out)
|
||||
rootCmd.SetArgs([]string{"cert", "fingerprint", "--which", "ca"})
|
||||
_ = rootCmd.Execute()
|
||||
|
||||
logged := buf.String()
|
||||
if !strings.Contains(logged, "orca cert is deprecated in v0.9") {
|
||||
t.Errorf("expected cert deprecation warning, got:\n%s", logged)
|
||||
}
|
||||
if !strings.Contains(logged, "step-ca") {
|
||||
t.Errorf("deprecation warning should mention step-ca, got:\n%s", logged)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCertDeprecationWarningSuppressed verifies --no-deprecation-warnings
|
||||
// suppresses the cert deprecation banner.
|
||||
func TestCertDeprecationWarningSuppressed(t *testing.T) {
|
||||
_, cleanup := initTestEnv(t)
|
||||
defer cleanup()
|
||||
resetRootFlags(t)
|
||||
_ = rootCmd.PersistentFlags().Set("no-deprecation-warnings", "true")
|
||||
|
||||
buf, restore := captureSlog(t)
|
||||
defer restore()
|
||||
|
||||
var out bytes.Buffer
|
||||
rootCmd.SetOut(&out)
|
||||
rootCmd.SetErr(&out)
|
||||
rootCmd.SetArgs([]string{"cert", "fingerprint", "--which", "ca"})
|
||||
_ = rootCmd.Execute()
|
||||
|
||||
if strings.Contains(buf.String(), "orca cert is deprecated") {
|
||||
t.Errorf("--no-deprecation-warnings should suppress cert warning, got:\n%s", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
// TestNodeJoinMTLSEmitsDeprecationWarning verifies REQ-068: the mTLS
|
||||
// join path (`orca node join` without --type proxmox) warns that the
|
||||
// mTLS join path is deprecated.
|
||||
func TestNodeJoinMTLSEmitsDeprecationWarning(t *testing.T) {
|
||||
_, cleanup := initTestEnv(t)
|
||||
defer cleanup()
|
||||
resetRootFlags(t)
|
||||
|
||||
buf, restore := captureSlog(t)
|
||||
defer restore()
|
||||
|
||||
var out bytes.Buffer
|
||||
rootCmd.SetOut(&out)
|
||||
rootCmd.SetErr(&out)
|
||||
rootCmd.SetArgs([]string{"node", "join", "--name", "dep-warning", "--addr", "10.0.0.55:8443"})
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
t.Fatalf("node join: %v", err)
|
||||
}
|
||||
|
||||
logged := buf.String()
|
||||
if !strings.Contains(logged, "mTLS join path is deprecated") {
|
||||
t.Errorf("expected mTLS join deprecation warning, got:\n%s", logged)
|
||||
}
|
||||
if !strings.Contains(logged, "R-001") {
|
||||
t.Errorf("deprecation warning should reference R-001, got:\n%s", logged)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNodeJoinProxmoxNoMTLSDeprecationWarning verifies the deprecation
|
||||
// warning does NOT fire for the proxmox SSH path (that path is the
|
||||
// v0.9 replacement, not the deprecated mTLS path).
|
||||
func TestNodeJoinProxmoxNoMTLSDeprecationWarning(t *testing.T) {
|
||||
_, cleanup := initTestEnv(t)
|
||||
defer cleanup()
|
||||
resetRootFlags(t)
|
||||
|
||||
buf, restore := captureSlog(t)
|
||||
defer restore()
|
||||
|
||||
var out bytes.Buffer
|
||||
rootCmd.SetOut(&out)
|
||||
rootCmd.SetErr(&out)
|
||||
// proxmox path errors on missing --host before reaching the warning,
|
||||
// and never calls joinLocal, so no mTLS deprecation warning fires.
|
||||
rootCmd.SetArgs([]string{"node", "join", "--type", "proxmox", "--password", "x"})
|
||||
_ = rootCmd.Execute()
|
||||
|
||||
if strings.Contains(buf.String(), "mTLS join path is deprecated") {
|
||||
t.Errorf("proxmox path must not emit mTLS deprecation warning, got:\n%s", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ func resetRootFlags(t *testing.T) {
|
||||
rootCmd.SetErr(&buf)
|
||||
_ = rootCmd.PersistentFlags().Set("system", "false")
|
||||
_ = rootCmd.PersistentFlags().Set("json", "false")
|
||||
_ = rootCmd.PersistentFlags().Set("no-deprecation-warnings", "false")
|
||||
resetCommandFlags()
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,13 @@ Node types (via --type):
|
||||
|
||||
// joinLocal is the existing localhost/Linux node join flow (fingerprint
|
||||
// check + registry.Insert).
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces daemon-to-daemon mTLS join
|
||||
// with SSH-push bootstrap (R-001). The mTLS join path is retained for
|
||||
// the dual-write window and scheduled for deletion in v0.10-P14. See
|
||||
// .ciagent/PRD_v0.9.md.
|
||||
func joinLocal(cmd *cobra.Command) error {
|
||||
warnDeprecated("orca node join (mTLS path): v0.9 R-001 replaces daemon-to-daemon mTLS join with SSH-push bootstrap; the mTLS join path is deprecated — see .ciagent/PRD_v0.9.md")
|
||||
if joinName == "" {
|
||||
return fmt.Errorf("--name is required")
|
||||
}
|
||||
|
||||
+16
-3
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -50,15 +51,27 @@ over feature richness.`,
|
||||
}
|
||||
|
||||
var (
|
||||
jsonOutput bool
|
||||
systemNamespace bool
|
||||
configPath string
|
||||
jsonOutput bool
|
||||
systemNamespace bool
|
||||
configPath string
|
||||
noDeprecationWarnings bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVar(&jsonOutput, "json", false, "output in JSON format")
|
||||
rootCmd.PersistentFlags().BoolVar(&systemNamespace, "system", false, "use system-level namespace root (/root/.orca) instead of user-level (~/.orca)")
|
||||
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "path to config.hcl (overrides ~/.orca/config.hcl)")
|
||||
rootCmd.PersistentFlags().BoolVar(&noDeprecationWarnings, "no-deprecation-warnings", false, "suppress v0.9 deprecation warnings (use during `orca upgrade` migrations)")
|
||||
}
|
||||
|
||||
// warnDeprecated emits a v0.9 deprecation warning via slog.Warn unless
|
||||
// the --no-deprecation-warnings global flag is set. Callers pass a
|
||||
// human-readable message describing what changed. REQ-068.
|
||||
func warnDeprecated(msg string) {
|
||||
if noDeprecationWarnings {
|
||||
return
|
||||
}
|
||||
slog.Warn(msg)
|
||||
}
|
||||
|
||||
func configFromCtx(ctx context.Context) *config.Config {
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
// - structured JSON via writeJSON
|
||||
// - no secrets in logs
|
||||
// - input validation on path/query/body
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces this with SSH-push to bare
|
||||
// servers (no orca binary on servers) per R-001. The orca daemon is
|
||||
// repurposed to drain-and-stop in v0.10-P05 and scheduled for deletion
|
||||
// in v0.10-P14. See .ciagent/PRD_v0.9.md R-001/R-006. The dual-write
|
||||
// window (REQ-090/REQ-085) keeps this package compiling until v0.10-P14.
|
||||
package daemon
|
||||
|
||||
import (
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// Package emit defines the render-format contract between Go-side emitters
|
||||
// and bash-side appliers (grill C-16). Every rendered artifact is a JSON
|
||||
// object with a versioned schema; both sides validate against it to prevent
|
||||
// emitter/applier drift.
|
||||
package emit
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// SchemaVersion is the canonical versioned schema identifier for render
|
||||
// contracts. Bump the suffix when the contract shape changes.
|
||||
const SchemaVersion = "orca.emit/v1"
|
||||
|
||||
// Kind enumerates the rendered-artifact kinds. Each maps to an emitter
|
||||
// implementation and a matching bash-side applier.
|
||||
type Kind string
|
||||
|
||||
const (
|
||||
KindSystemd Kind = "systemd"
|
||||
KindTraefik Kind = "traefik"
|
||||
KindSyncthing Kind = "syncthing"
|
||||
KindSudoers Kind = "sudoers"
|
||||
KindSSHD Kind = "sshd"
|
||||
KindEnvFile Kind = "envfile"
|
||||
KindCredential Kind = "credential"
|
||||
)
|
||||
|
||||
// Artifact is a single rendered file destined for a peer. The bash-side
|
||||
// applier reads this JSON and writes Content to Path with the given Mode.
|
||||
type Artifact struct {
|
||||
SchemaVersion string `json:"schema_version"`
|
||||
Kind Kind `json:"kind"`
|
||||
Path string `json:"path"`
|
||||
Content string `json:"content"`
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
// Validate checks that an Artifact conforms to the render contract.
|
||||
// Returns a structured error if any field is missing or invalid.
|
||||
func (a *Artifact) Validate() error {
|
||||
if a.SchemaVersion != SchemaVersion {
|
||||
return fmt.Errorf("emit: schema_version mismatch: got %q want %q", a.SchemaVersion, SchemaVersion)
|
||||
}
|
||||
if a.Kind == "" {
|
||||
return errors.New("emit: kind is required")
|
||||
}
|
||||
if a.Path == "" {
|
||||
return errors.New("emit: path is required")
|
||||
}
|
||||
if a.Mode == "" {
|
||||
return errors.New("emit: mode is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal serializes an Artifact to JSON for transport to the bash applier.
|
||||
func (a *Artifact) Marshal() ([]byte, error) {
|
||||
if err := a.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(a)
|
||||
}
|
||||
|
||||
// UnmarshalArtifact parses a JSON byte slice into an Artifact and validates
|
||||
// it against the contract. The bash-side applier (via orca-verify-render.sh)
|
||||
// uses this same validation; the bash side rejects unparseable input with a
|
||||
// structured error, never silently (grill C-16).
|
||||
func UnmarshalArtifact(data []byte) (*Artifact, error) {
|
||||
var a Artifact
|
||||
if err := json.Unmarshal(data, &a); err != nil {
|
||||
return nil, fmt.Errorf("emit: unmarshal: %w", err)
|
||||
}
|
||||
if err := a.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &a, nil
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package emit
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestArtifactValidate_valid(t *testing.T) {
|
||||
a := &Artifact{
|
||||
SchemaVersion: SchemaVersion,
|
||||
Kind: KindSystemd,
|
||||
Path: "/etc/systemd/system/orca-alloc.service",
|
||||
Content: "[Service]\nExecStart=/bin/true\n",
|
||||
Mode: "0644",
|
||||
}
|
||||
if err := a.Validate(); err != nil {
|
||||
t.Fatalf("expected valid, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactValidate_schemaVersionMismatch(t *testing.T) {
|
||||
a := &Artifact{SchemaVersion: "orca.emit/v0", Kind: KindSystemd, Path: "/x", Mode: "0644"}
|
||||
err := a.Validate()
|
||||
if err == nil {
|
||||
t.Fatal("expected error for mismatched schema_version")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "schema_version mismatch") {
|
||||
t.Fatalf("expected schema_version error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactValidate_missingKind(t *testing.T) {
|
||||
a := &Artifact{SchemaVersion: SchemaVersion, Path: "/x", Mode: "0644"}
|
||||
err := a.Validate()
|
||||
if err == nil || !strings.Contains(err.Error(), "kind is required") {
|
||||
t.Fatalf("expected kind-required error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactValidate_missingPath(t *testing.T) {
|
||||
a := &Artifact{SchemaVersion: SchemaVersion, Kind: KindTraefik, Mode: "0644"}
|
||||
err := a.Validate()
|
||||
if err == nil || !strings.Contains(err.Error(), "path is required") {
|
||||
t.Fatalf("expected path-required error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactValidate_missingMode(t *testing.T) {
|
||||
a := &Artifact{SchemaVersion: SchemaVersion, Kind: KindSudoers, Path: "/x"}
|
||||
err := a.Validate()
|
||||
if err == nil || !strings.Contains(err.Error(), "mode is required") {
|
||||
t.Fatalf("expected mode-required error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalValidate_rejectsInvalid(t *testing.T) {
|
||||
a := &Artifact{SchemaVersion: "bad", Kind: "", Path: "", Mode: ""}
|
||||
if _, err := a.Marshal(); err == nil {
|
||||
t.Fatal("expected Marshal to reject invalid artifact")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalArtifact_valid(t *testing.T) {
|
||||
raw := `{"schema_version":"orca.emit/v1","kind":"systemd","path":"/x","content":"c","mode":"0644"}`
|
||||
a, err := UnmarshalArtifact([]byte(raw))
|
||||
if err != nil {
|
||||
t.Fatalf("expected valid, got %v", err)
|
||||
}
|
||||
if a.Kind != KindSystemd {
|
||||
t.Fatalf("expected kind systemd, got %s", a.Kind)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalArtifact_rejectsBadJSON(t *testing.T) {
|
||||
if _, err := UnmarshalArtifact([]byte("not json")); err == nil {
|
||||
t.Fatal("expected error for bad JSON")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalArtifact_rejectsSchemaMismatch(t *testing.T) {
|
||||
raw := `{"schema_version":"orca.emit/v2","kind":"x","path":"/x","mode":"0644"}`
|
||||
if _, err := UnmarshalArtifact([]byte(raw)); err == nil {
|
||||
t.Fatal("expected error for schema mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
orig := &Artifact{
|
||||
SchemaVersion: SchemaVersion,
|
||||
Kind: KindSyncthing,
|
||||
Path: "/etc/syncthing/config.xml",
|
||||
Content: "<config/>",
|
||||
Mode: "0600",
|
||||
}
|
||||
data, err := orig.Marshal()
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal: %v", err)
|
||||
}
|
||||
back, err := UnmarshalArtifact(data)
|
||||
if err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
if back.Path != orig.Path || back.Kind != orig.Kind || back.Mode != orig.Mode {
|
||||
t.Fatalf("round-trip mismatch: %+v vs %+v", orig, back)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllKinds(t *testing.T) {
|
||||
for _, k := range []Kind{KindSystemd, KindTraefik, KindSyncthing, KindSudoers, KindSSHD, KindEnvFile, KindCredential} {
|
||||
a := &Artifact{SchemaVersion: SchemaVersion, Kind: k, Path: "/x", Mode: "0644"}
|
||||
if err := a.Validate(); err != nil {
|
||||
t.Errorf("kind %s: %v", k, err)
|
||||
}
|
||||
// verify it marshals
|
||||
if _, err := json.Marshal(a); err != nil {
|
||||
t.Errorf("marshal kind %s: %v", k, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,11 @@ import (
|
||||
)
|
||||
|
||||
// Dispatcher is the public surface; constructed via NewDispatcher.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces peer dispatch with a CLI-side
|
||||
// scheduler + SSH-push (no orca binary on servers per R-001). The
|
||||
// Dispatcher is retained for the dual-write window and scheduled for
|
||||
// deletion in v0.10-P14. See .ciagent/PRD_v0.9.md R-001/R-006.
|
||||
type Dispatcher struct {
|
||||
log *slog.Logger
|
||||
capacity *store.CapacityRepo
|
||||
|
||||
@@ -16,6 +16,11 @@ import (
|
||||
)
|
||||
|
||||
// Peer is a remote orca node reachable over mTLS.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces peer dispatch with a CLI-side
|
||||
// scheduler + SSH-push (no orca binary on servers per R-001). The Peer
|
||||
// type is retained for the dual-write window and scheduled for deletion
|
||||
// in v0.10-P14. See .ciagent/PRD_v0.9.md R-001/R-006.
|
||||
type Peer struct {
|
||||
NodeID string
|
||||
Address string // host:port (the peer's daemon listener)
|
||||
@@ -27,6 +32,11 @@ type Peer struct {
|
||||
|
||||
// PeerRegistry tracks known peers. Methods are safe for concurrent
|
||||
// use; the underlying map is guarded by a sync.RWMutex.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces peer dispatch with a CLI-side
|
||||
// scheduler + SSH-push (no orca binary on servers per R-001). The
|
||||
// PeerRegistry is retained for the dual-write window and scheduled for
|
||||
// deletion in v0.10-P14. See .ciagent/PRD_v0.9.md R-001/R-006.
|
||||
type PeerRegistry struct {
|
||||
mu sync.RWMutex
|
||||
peers map[string]*Peer
|
||||
|
||||
@@ -16,27 +16,51 @@ import (
|
||||
|
||||
// CAValidity is how long a CA cert is valid. Per D-013, the CA is long-lived
|
||||
// (10 years) because manual rotation is expensive.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). This constant is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
const CAValidity = 10 * 365 * 24 * time.Hour
|
||||
|
||||
// ServerCertValidity is the default validity window for server certs. D-013
|
||||
// says server certs are short-lived (90 days) to limit the compromise window.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). This constant is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
const ServerCertValidity = 90 * 24 * time.Hour
|
||||
|
||||
// CAKeySize is the RSA key size used for both CA and server certs. 3072 is
|
||||
// the minimum we accept for v0.2 — matches REQ-033 spirit and Go's stdlib
|
||||
// defaults for new RSA keys are typically 2048 or 4096. 3072 is the
|
||||
// sweet spot for balance of safety and key-gen latency.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). This constant is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
const CAKeySize = 3072
|
||||
|
||||
// CAMode is the file mode used when persisting the CA private key. REQ-033
|
||||
// requires 0600.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). This constant is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
const CAMode os.FileMode = 0o600
|
||||
|
||||
// CACPEMMode is the file mode used when persisting the CA public cert.
|
||||
// REQ-033 requires 0644 (public, but still mode-pinned).
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). This constant is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
const CACPEMMode os.FileMode = 0o644
|
||||
|
||||
// File names used inside the CA directory.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). These constants are retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
const (
|
||||
CACertFile = "ca.crt"
|
||||
CAKeyFile = "ca.key"
|
||||
@@ -44,6 +68,10 @@ const (
|
||||
|
||||
// CA wraps a loaded CA. Use CAInit to mint a new one, LoadCA to read an
|
||||
// existing one from disk.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). The CA type is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
type CA struct {
|
||||
Cert *x509.Certificate
|
||||
Key *rsa.PrivateKey
|
||||
@@ -60,6 +88,10 @@ type CA struct {
|
||||
// commonName is the CA's CommonName (typically an org/cluster identifier).
|
||||
// Returns a *CA wrapping the loaded cert + key. The CA is valid for
|
||||
// CAValidity from now.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). CAInit is retained for the dual-write window and scheduled
|
||||
// for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
func CAInit(dir, commonName string) (*CA, error) {
|
||||
if dir == "" {
|
||||
return nil, errors.New("CAInit: dir is required")
|
||||
@@ -133,6 +165,10 @@ func CAInit(dir, commonName string) (*CA, error) {
|
||||
|
||||
// LoadCA reads a previously-initialized CA from disk. Returns a *CA or an
|
||||
// error. Verifies file modes (REQ-033).
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). LoadCA is retained for the dual-write window and scheduled
|
||||
// for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
func LoadCA(dir string) (*CA, error) {
|
||||
if dir == "" {
|
||||
return nil, errors.New("LoadCA: dir is required")
|
||||
@@ -187,6 +223,10 @@ func LoadCA(dir string) (*CA, error) {
|
||||
// EnforceFileModes refuses to operate if ca.crt / ca.key do not have the
|
||||
// required modes (REQ-033). Returns nil on success. Callers (daemon start,
|
||||
// CA loaders) MUST call this and abort on error.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). EnforceFileModes is retained for the dual-write window
|
||||
// and scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
func EnforceFileModes(dir string) error {
|
||||
certPath := filepath.Join(dir, CACertFile)
|
||||
keyPath := filepath.Join(dir, CAKeyFile)
|
||||
@@ -217,6 +257,10 @@ func EnforceFileModes(dir string) error {
|
||||
// in PEM form. The resulting cert is valid for ServerCertValidity and
|
||||
// inherits the SANs from the CSR (DNS, IP). If the CSR has no SANs, the
|
||||
// call fails — REQ-036 requires server certs to have identifying SANs.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). SignCSR is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
func (c *CA) SignCSR(csrPEM []byte) ([]byte, error) {
|
||||
if c == nil || c.Cert == nil || c.Key == nil {
|
||||
return nil, errors.New("SignCSR: nil CA")
|
||||
@@ -266,6 +310,10 @@ func (c *CA) SignCSR(csrPEM []byte) ([]byte, error) {
|
||||
// Fingerprint returns the SHA-256 hex fingerprint of the CA cert. Useful
|
||||
// for the operator to communicate to peers out-of-band; peers then pin
|
||||
// this value at `orca node join --ca-fingerprint <sha>`.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). CA.Fingerprint is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
func (c *CA) Fingerprint() string {
|
||||
return FingerprintOf(c.Cert.Raw)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ import (
|
||||
// Validation: dns entries must be syntactically valid hostnames; ip entries
|
||||
// must be parseable by net.ParseIP. Bad inputs are rejected up-front so
|
||||
// the operator gets a clear error before signing.
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces the internal CA with step-ca
|
||||
// (D-101/REQ-076). GenerateCSR is retained for the dual-write window and
|
||||
// scheduled for deletion in v0.10-P14. See .ciagent/PRD_v0.9.md.
|
||||
func GenerateCSR(commonName string, sans []string) (keyPEM, csrPEM []byte, err error) {
|
||||
if commonName == "" {
|
||||
return nil, nil, errors.New("GenerateCSR: commonName is required")
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
// gRPC, no ConnectRPC, no third-party transport libraries. This keeps
|
||||
// the binary lean (matches the minimalist pillar) and the trust chain
|
||||
// auditable (one library: the Go stdlib).
|
||||
//
|
||||
// Deprecated: v0.9 re-architecture replaces this with
|
||||
// internal/sshpush (REQ-073). The daemon-to-daemon mTLS transport is
|
||||
// removed because servers no longer run the orca binary (R-001); the
|
||||
// CLI pushes config via SSH instead. Scheduled for deletion in
|
||||
// v0.10-P14. See .ciagent/PRD_v0.9.md R-001/R-006.
|
||||
package transport
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user