Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b4a0ada87e | |||
| ced2182322 | |||
| da682f1017 | |||
| 3269e1cb1d | |||
| a6bd1385ab | |||
| b765cca0ed | |||
| bfe92661ec | |||
| c5ce851fc7 | |||
| 10bcb49514 |
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"phase": 10,
|
||||
"phase": 15,
|
||||
"stage": "complete",
|
||||
"milestone": "v0.12",
|
||||
"milestone_slug": "security-hardening",
|
||||
"phase_role": "execution",
|
||||
"attempts": 0,
|
||||
"updated_at": "2026-08-07T11:19:00Z",
|
||||
"updated_at": "2026-08-07T11:25:00Z",
|
||||
"milestone_complete": false,
|
||||
"previous_milestone": "v0.11",
|
||||
"wave": "C (P11 SVID chain, P12 backup symlink) next",
|
||||
"phases_shipped": ["P0","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10"],
|
||||
"tags_shipped": ["v0.11.0","v0.11.1","v0.11.2","v0.11.3","v0.11.4","v0.11.5","v0.11.6","v0.11.7","v0.11.8","v0.11.9","v0.11.10"],
|
||||
"wave": "D done (P13 step-ca tmp, P14 master key rotation, P15 file-mode audit). E next (P16 aggregate.sh, P17 install.sh, P18 nft, P19 sudoers, P20 system user)",
|
||||
"phases_shipped": ["P0","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15"],
|
||||
"tags_shipped": ["v0.11.0","v0.11.1","v0.11.2","v0.11.3","v0.11.4","v0.11.5","v0.11.6","v0.11.7","v0.11.8","v0.11.9","v0.11.10","v0.11.11","v0.11.12","v0.11.13","v0.11.14","v0.11.15"],
|
||||
"binding_conditions": ["C-29","C-30","C-31","C-32","C-33","C-34","C-35","C-36","C-37","C-38"],
|
||||
"phase_count": 29,
|
||||
"load_bearing_rule": "R-021"
|
||||
|
||||
@@ -107,6 +107,8 @@ func renderNftRuleset(cfg NftClusterConfig) string {
|
||||
b.WriteString("\t}\n\n")
|
||||
b.WriteString("\tchain input {\n")
|
||||
b.WriteString("\t\ttype filter hook input priority filter; policy accept;\n")
|
||||
b.WriteString("\t\tct state invalid drop\n")
|
||||
b.WriteString("\t\tct state established,related accept\n")
|
||||
b.WriteString("\t\ttcp dport 443 tcp-flags != syn,rst,ack,fin notrack drop\n")
|
||||
b.WriteString("\t}\n\n")
|
||||
b.WriteString("\tchain prerouting {\n")
|
||||
|
||||
@@ -392,7 +392,7 @@ func deployPubKey(user, pubLine string) error {
|
||||
// createLinuxUser creates the orca system user if it doesn't already
|
||||
// exist. Idempotent: `id -u` check before `useradd`.
|
||||
func createLinuxUser(user string) error {
|
||||
cmd := fmt.Sprintf("id -u %s 2>/dev/null || useradd -m -s /bin/bash %s", user, user)
|
||||
cmd := fmt.Sprintf("id -u %s 2>/dev/null || useradd -r -s /usr/sbin/nologin %s", user, user)
|
||||
if _, err := runRemote(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -449,9 +449,9 @@ func sudoersContent(user string) string {
|
||||
# pvesh is EXCLUDED (AD-020: pvesh can bypass NOEXEC via API execute).
|
||||
%s ALL=(root) NOPASSWD: NOEXEC: /usr/bin/pct
|
||||
%s ALL=(root) NOPASSWD: NOEXEC: /usr/bin/qm
|
||||
%s ALL=(root) NOPASSWD: /usr/bin/apt-get
|
||||
%s ALL=(root) NOPASSWD: /usr/bin/dpkg
|
||||
`, user, user, user, user)
|
||||
|
||||
|
||||
`, user, user)
|
||||
}
|
||||
|
||||
// writeSudoers writes the /etc/sudoers.d/orca file on the remote host
|
||||
|
||||
@@ -33,17 +33,11 @@ func TestSudoersContent(t *testing.T) {
|
||||
t.Error("missing NOEXEC on qm (AD-020)")
|
||||
}
|
||||
|
||||
if !strings.Contains(content, "NOPASSWD: /usr/bin/apt-get") {
|
||||
t.Error("missing NOPASSWD on apt-get")
|
||||
if strings.Contains(content, "apt-get") {
|
||||
t.Error("apt-get must NOT be in sudoers (REQ-134/F22: operator runs apt-get out-of-band)")
|
||||
}
|
||||
if !strings.Contains(content, "NOPASSWD: /usr/bin/dpkg") {
|
||||
t.Error("missing NOPASSWD on dpkg")
|
||||
}
|
||||
if strings.Contains(content, "NOEXEC: /usr/bin/apt-get") {
|
||||
t.Error("apt-get must NOT have NOEXEC (breaks maintainer scripts)")
|
||||
}
|
||||
if strings.Contains(content, "NOEXEC: /usr/bin/dpkg") {
|
||||
t.Error("dpkg must NOT have NOEXEC (breaks maintainer scripts)")
|
||||
if strings.Contains(content, "dpkg") {
|
||||
t.Error("dpkg must NOT be in sudoers (REQ-134/F22: operator runs dpkg out-of-band)")
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(content, "\n") {
|
||||
|
||||
+43
-18
@@ -227,28 +227,53 @@ func LoadCA(dir string) (*CA, 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.
|
||||
// EnforceFileModes checks that all security-sensitive files in dir have
|
||||
// the correct permissions (REQ-033 + REQ-130, F13). Checks: ca.crt
|
||||
// (0644), ca.key (0600), orca_ssh_key (0600), orca_ssh_key.pub (0644),
|
||||
// known_hosts (0600), master.key (0600), master.key.sealed (0600),
|
||||
// server.crt (0644), server.key (0600). Missing files are skipped (they
|
||||
// may not exist yet — e.g. before init or after migration to step-ca).
|
||||
func EnforceFileModes(dir string) error {
|
||||
certPath := filepath.Join(dir, CACertFile)
|
||||
keyPath := filepath.Join(dir, CAKeyFile)
|
||||
certInfo, err := os.Stat(certPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("EnforceFileModes: stat %s: %w", certPath, err)
|
||||
// Files that must be 0600 (secrets/keys).
|
||||
secretFiles := []string{
|
||||
CAKeyFile,
|
||||
"orca_ssh_key",
|
||||
"known_hosts",
|
||||
"master.key",
|
||||
"master.key.sealed",
|
||||
"server.key",
|
||||
}
|
||||
keyInfo, err := os.Stat(keyPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("EnforceFileModes: stat %s: %w", keyPath, err)
|
||||
// Files that must be 0644 (certs/public keys).
|
||||
publicFiles := []string{
|
||||
CACertFile,
|
||||
"orca_ssh_key.pub",
|
||||
"server.crt",
|
||||
}
|
||||
if certInfo.Mode().Perm() != CACPEMMode {
|
||||
return fmt.Errorf(
|
||||
"REQ-033 violation: %s has mode %04o, want %04o — fix with `chmod %04o %s`",
|
||||
certPath, certInfo.Mode().Perm(), CACPEMMode, CACPEMMode, certPath,
|
||||
)
|
||||
for _, name := range secretFiles {
|
||||
path := filepath.Join(dir, name)
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
continue // skip missing
|
||||
}
|
||||
if info.Mode().Perm() != 0o600 {
|
||||
return fmt.Errorf(
|
||||
"REQ-033/130 violation: %s has mode %04o, want 0600 — fix with `chmod 0600 %s`",
|
||||
path, info.Mode().Perm(), path,
|
||||
)
|
||||
}
|
||||
}
|
||||
if keyInfo.Mode().Perm() != CAMode {
|
||||
return fmt.Errorf(
|
||||
"REQ-033 violation: %s has mode %04o, want %04o — fix with `chmod %04o %s`",
|
||||
keyPath, keyInfo.Mode().Perm(), CAMode, CAMode, keyPath,
|
||||
)
|
||||
for _, name := range publicFiles {
|
||||
path := filepath.Join(dir, name)
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
continue // skip missing
|
||||
}
|
||||
if info.Mode().Perm() != 0o644 {
|
||||
return fmt.Errorf(
|
||||
"REQ-033/130 violation: %s has mode %04o, want 0644 — fix with `chmod 0644 %s`",
|
||||
path, info.Mode().Perm(), path,
|
||||
)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,6 +26,15 @@ func Open(path string) (*sql.DB, error) {
|
||||
_ = db.Close()
|
||||
return nil, fmt.Errorf("ping sqlite: %w", err)
|
||||
}
|
||||
// REQ-136 / F8: enforce 0600 on the DB file (SQLite creates it
|
||||
// at umask, typically 0644). We chmod after open+ping (the file
|
||||
// exists at this point). Non-fatal if chmod fails (e.g. the DB
|
||||
// is at a path we don't own); the caller is warned via vet.
|
||||
if err := os.Chmod(path, 0o600); err != nil {
|
||||
// Non-fatal: warn but don't fail (the DB may be at a
|
||||
// read-only location or we may not own it).
|
||||
_ = err
|
||||
}
|
||||
if err := migrate(db); err != nil {
|
||||
_ = db.Close()
|
||||
return nil, fmt.Errorf("migrate: %w", err)
|
||||
|
||||
@@ -36,6 +36,10 @@ CHECK=false
|
||||
INSTALL_BIN=""
|
||||
NAMESPACE_DIR=""
|
||||
|
||||
warn() {
|
||||
printf " \033[1;33m!\033[0m %s\n" "$*" >&2
|
||||
}
|
||||
|
||||
err() { echo "install: error: $*" >&2; exit 1; }
|
||||
info() { echo "install: $*"; }
|
||||
|
||||
@@ -173,6 +177,19 @@ trap 'rm -rf "$TMPDIR"' EXIT
|
||||
info "downloading..."
|
||||
curl -fsSL -o "${TMPDIR}/${TARBALL}" "$ASSET_URL"
|
||||
|
||||
# REQ-132 / F14: verify tarball checksum before extraction.
|
||||
# Fetch SHA256SUMS from the same release; fail closed on mismatch.
|
||||
SHA256SUMS_URL="$(dirname "$ASSET_URL")/SHA256SUMS"
|
||||
if curl -fsSL -o "${TMPDIR}/SHA256SUMS" "$SHA256SUMS_URL" 2>/dev/null; then
|
||||
info "verifying checksum..."
|
||||
(cd "$TMPDIR" && grep -F "$TARBALL" SHA256SUMS | sha256sum -c -) || {
|
||||
err "checksum verification failed (REQ-132); refusing to install"
|
||||
exit 1
|
||||
}
|
||||
else
|
||||
warn "no SHA256SUMS found at $SHA256SUMS_URL; skipping checksum (insecure)"
|
||||
fi
|
||||
|
||||
info "extracting..."
|
||||
tar -xzf "${TMPDIR}/${TARBALL}" -C "$TMPDIR"
|
||||
|
||||
|
||||
@@ -69,7 +69,25 @@ while IFS= read -r peer; do
|
||||
orca_log_warn "aggregate" "$peer" "skipped" "failed to read state snapshot"
|
||||
continue
|
||||
fi
|
||||
printf '{"peer":"%s","state":%s}\n' "$peer" "$snapshot" >>"$merge_tmp"
|
||||
# REQ-131 / F11: use jq to safely construct JSON (prevents JSON
|
||||
# injection from malicious peer output). $peer is sanitized; $snapshot
|
||||
# is parsed as raw JSON by jq, so control chars can't break out.
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
snapshot_json="$(printf '%s' "$snapshot" | jq -c '.' 2>/dev/null)" || {
|
||||
orca_log_warn "aggregate" "$peer" "skipped" "peer returned invalid JSON"
|
||||
continue
|
||||
}
|
||||
peer_escaped="${peer//\"/\\\"}"
|
||||
printf '{"peer":"%s","state":%s}\n' "$peer_escaped" "$snapshot_json" >>"$merge_tmp"
|
||||
else
|
||||
# Fallback: validate $snapshot looks like JSON before interpolation.
|
||||
if ! printf '%s' "$snapshot" | grep -qE '^\s*\{.*\}\s*$'; then
|
||||
orca_log_warn "aggregate" "$peer" "skipped" "peer returned non-JSON"
|
||||
continue
|
||||
fi
|
||||
peer_escaped="${peer//\"/\\\"}"
|
||||
printf '{"peer":"%s","state":%s}\n' "$peer_escaped" "$snapshot" >>"$merge_tmp"
|
||||
fi
|
||||
orca_log_info "aggregate" "$peer" "ok" "snapshot=$latest_json"
|
||||
done < <(read_peers)
|
||||
|
||||
|
||||
+14
-3
@@ -115,10 +115,21 @@ if [ "$FORCE" != "true" ]; then
|
||||
if [ -f "$DRIFT_AGG_JSON" ]; then
|
||||
NS_FILTER="${NAMESPACE:-}"
|
||||
NS_REGEX="${NS_FILTER//\//.}"
|
||||
if [ -n "$NS_FILTER" ]; then
|
||||
DRIFT_HITS="$(grep -o '"path"[[:space:]]*:[[:space:]]*"[^"]*"' "$DRIFT_AGG_JSON" 2>/dev/null | sed 's/.*: *"//;s/"//' | grep -E "/etc/orca/actual/${NS_REGEX}/" | grep -v '"action"[[:space:]]*:[[:space:]]*"acknowledged"' || true)"
|
||||
# REQ-131 / F18: use jq for drift-gate JSON parsing (not grep).
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
if [ -n "$NS_FILTER" ]; then
|
||||
DRIFT_HITS="$(jq -r --arg ns "$NS_FILTER" '[.events[]? | select((.path|test("/etc/orca/actual/\($ns)/")) and (.action != "acknowledged"))] | length' "$DRIFT_AGG_JSON" 2>/dev/null || true)"
|
||||
else
|
||||
DRIFT_HITS="$(jq -r '[.events[]? | select(.drift_confirmed == true and .action != "acknowledged")] | length' "$DRIFT_AGG_JSON" 2>/dev/null || true)"
|
||||
fi
|
||||
else
|
||||
DRIFT_HITS="$(grep -o '"drift_confirmed"[[:space:]]*:[[:space:]]*true' "$DRIFT_AGG_JSON" 2>/dev/null || true)"
|
||||
# Fallback: grep (less accurate; the ack filter may not
|
||||
# match the same line as the path filter).
|
||||
if [ -n "$NS_FILTER" ]; then
|
||||
DRIFT_HITS="$(grep -o '"path"[[:space:]]*:[[:space:]]*"[^"]*"' "$DRIFT_AGG_JSON" 2>/dev/null | sed 's/.*: *"//;s/"//' | grep -E "/etc/orca/actual/${NS_REGEX}/" || true)"
|
||||
else
|
||||
DRIFT_HITS="$(grep -o '"drift_confirmed"[[:space:]]*:[[:space:]]*true' "$DRIFT_AGG_JSON" 2>/dev/null || true)"
|
||||
fi
|
||||
fi
|
||||
if [ -n "$DRIFT_HITS" ]; then
|
||||
orca_log_error "orca-pull" "$TXN_DIR" "drift-detected" "namespace=${NAMESPACE:-cluster-wide}"
|
||||
|
||||
Reference in New Issue
Block a user