Compare commits
2 Commits
3a3291c40e
...
e7f4ff8fa9
| Author | SHA1 | Date |
|---|---|---|
|
|
e7f4ff8fa9 | |
|
|
e1b499f362 |
|
|
@ -0,0 +1,22 @@
|
|||
# Platform components
|
||||
|
||||
The platform stack keeps one OpenTofu state file, but Jeannie exposes isolated
|
||||
component applies. A component apply passes only that component's resource
|
||||
addresses as `-target` arguments; OpenTofu includes required dependencies and
|
||||
does not apply unrelated platform resources.
|
||||
|
||||
Run these on the Debian homelab host with the active cluster profile:
|
||||
|
||||
```bash
|
||||
LAB_CLUSTER_PROFILE=pimox ./jeannie platform monitoring
|
||||
LAB_CLUSTER_PROFILE=pimox ./jeannie platform logging
|
||||
LAB_CLUSTER_PROFILE=pimox ./jeannie platform argocd
|
||||
LAB_CLUSTER_PROFILE=pimox ./jeannie platform all
|
||||
```
|
||||
|
||||
Available components are `calico`, `metrics`, `dns`, `metallb`, `ingress`,
|
||||
`storage`, `argocd`, `security`, `logging`, `monitoring`, and `tools`.
|
||||
|
||||
Targeted applies skip the legacy existing-resource adoption pass, which avoids
|
||||
touching unrelated platform state during a small change. Use `platform all`
|
||||
for the full reconciliation and adoption path.
|
||||
|
|
@ -22,12 +22,51 @@ import (
|
|||
|
||||
const maxOutputBytes = 1 << 20
|
||||
|
||||
// allowedCommands is the remote API command boundary. Keep this list aligned
|
||||
// with the public top-level cases in ./jeannie. Internal __up-task and the
|
||||
// recursive remote command are intentionally excluded.
|
||||
var allowedCommands = map[string]bool{
|
||||
"capacity": true, "capacity-advisor": true, "capacity-limits": true,
|
||||
"cluster-profile": true, "doctor-cluster": true, "doctor-edge": true,
|
||||
"doctor-gitea": true, "doctor-homelab": true, "doctor-k8s": true,
|
||||
"doctor-rpi": true, "explain": true, "inventory-check": true,
|
||||
"map": true, "route-inventory": true, "scorecard": true, "status": true,
|
||||
"help": true, "up": true, "plan": true,
|
||||
"cluster-profile": true, "rebuild-cluster": true, "stop-cluster": true,
|
||||
"start-cluster": true, "cleanup-debian-k8s": true,
|
||||
"status": true, "capacity": true, "capacity-advisor": true,
|
||||
"capacity-limits": true, "recover-plan": true, "gitops-status": true,
|
||||
"platform": true, "edge": true, "edge-cache-flush": true,
|
||||
"promote": true, "cert-check": true, "release-snapshot": true,
|
||||
"backup-status": true, "synthetic-checks": true, "resource-budget": true,
|
||||
"control-plane": true, "artifact-cache": true,
|
||||
"blockchain-devnet": true, "blockchain-test": true,
|
||||
"blockchain-wallet": true, "golden-ledger": true,
|
||||
"route-inventory": true, "explain": true, "recover-power": true,
|
||||
"heal": true, "self-heal": true, "incident": true,
|
||||
"safety-case": true, "agent-sandbox": true, "scorecard": true,
|
||||
"grafana-dashboards": true, "sso-grafana": true, "sso-gitea": true,
|
||||
"sso": true, "dex-secret": true, "gitea-runner-secret": true,
|
||||
"workers": true, "change-journal": true, "map": true,
|
||||
"validate": true, "access-audit": true, "kubeconfig-readonly": true,
|
||||
"apps": true, "website-translation-model": true,
|
||||
"website-ollama-listen": true, "ollama-setup": true,
|
||||
"deploy-gitea": true, "deploy-api": true, "deploy-heimdall": true,
|
||||
"deploy-dex": true, "deploy-matrix": true, "deploy-ai-stack": true,
|
||||
"deploy-ai-tools": true, "deploy-omniroute": true, "deploy-hermes": true,
|
||||
"rpi-services": true, "bootstrap-gitea-repo": true, "backup-gitea": true,
|
||||
"backup": true, "drill-restore": true, "drill-gitea-restore": true,
|
||||
"drill-pihole-restore": true, "install-gitea-runner": true,
|
||||
"move-prometheus-stack-workers": true, "doctor-versions": true,
|
||||
"doctor-edge": true, "doctor-homelab": true, "doctor-gitea": true,
|
||||
"doctor-rpi": true, "doctor-cluster": true, "doctor-k8s": true,
|
||||
"preflight": true, "doctor-preapply": true, "inventory-check": true,
|
||||
"state-backup": true, "fix-debian-docker-root": true,
|
||||
"secrets-init": true, "secrets-check": true, "tailnet-policy-check": true,
|
||||
"ai-index": true, "ai-check": true, "ask": true, "ai-evals": true,
|
||||
"ai-scheduler": true, "ai-memory": true, "model-observe": true,
|
||||
"impact": true, "review-last-change": true,
|
||||
"security-scan": true, "security-prepare": true, "security-zap": true,
|
||||
"security-k8s": true, "security-host": true, "security-trivy": true,
|
||||
"security-secrets": true, "security-nuclei": true, "security-web": true,
|
||||
"security-logs": true, "security-runtime": true,
|
||||
"security-attack-path": true, "prompt-injection-lab": true,
|
||||
"red-blue": true, "openwrt": true, "nuke": true,
|
||||
}
|
||||
|
||||
type executeRequest struct {
|
||||
|
|
|
|||
|
|
@ -13,53 +13,92 @@ import (
|
|||
)
|
||||
|
||||
func TestServerRequiresTokenAndAllowlistsCommands(t *testing.T) {
|
||||
s := &server{exec: make(map[string]*execution), token: "secret"}
|
||||
repo := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(repo, "jeannie"), []byte("#!/bin/sh\nexit 0\n"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := &server{exec: make(map[string]*execution), repoRoot: repo, token: "secret"}
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/v1/execute", s.auth(s.execute))
|
||||
requestBody, _ := json.Marshal(executeRequest{Command: "nuke"})
|
||||
body := bytes.NewBuffer(requestBody)
|
||||
req, err := http.NewRequest(http.MethodPost, "/v1/execute", body)
|
||||
if err != nil { t.Fatal(err) }
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
response := httptest.NewRecorder()
|
||||
mux.ServeHTTP(response, req)
|
||||
if response.Code != http.StatusUnauthorized { t.Fatalf("status = %d", response.Code) }
|
||||
if response.Code != http.StatusUnauthorized {
|
||||
t.Fatalf("status = %d", response.Code)
|
||||
}
|
||||
|
||||
body = bytes.NewBuffer(requestBody)
|
||||
req, err = http.NewRequest(http.MethodPost, "/v1/execute", body)
|
||||
if err != nil { t.Fatal(err) }
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer secret")
|
||||
response = httptest.NewRecorder()
|
||||
mux.ServeHTTP(response, req)
|
||||
if response.Code != http.StatusForbidden { t.Fatalf("status = %d", response.Code) }
|
||||
if response.Code != http.StatusAccepted {
|
||||
t.Fatalf("status = %d", response.Code)
|
||||
}
|
||||
|
||||
requestBody, _ = json.Marshal(executeRequest{Command: "remote"})
|
||||
body = bytes.NewBuffer(requestBody)
|
||||
req, err = http.NewRequest(http.MethodPost, "/v1/execute", body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer secret")
|
||||
response = httptest.NewRecorder()
|
||||
mux.ServeHTTP(response, req)
|
||||
if response.Code != http.StatusForbidden {
|
||||
t.Fatalf("status = %d", response.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerExecutesAllowlistedCommand(t *testing.T) {
|
||||
repo := t.TempDir()
|
||||
jeannie := filepath.Join(repo, "jeannie")
|
||||
if err := os.WriteFile(jeannie, []byte("#!/bin/sh\nprintf 'remote-ok %s\\n' \"$1\"\n"), 0755); err != nil { t.Fatal(err) }
|
||||
if err := os.WriteFile(jeannie, []byte("#!/bin/sh\nprintf 'remote-ok %s\\n' \"$1\"\n"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := &server{exec: make(map[string]*execution), repoRoot: repo}
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/v1/execute", s.auth(s.execute))
|
||||
mux.HandleFunc("/v1/executions/", s.auth(s.execution))
|
||||
payload, _ := json.Marshal(executeRequest{Command: "status"})
|
||||
req, err := http.NewRequest(http.MethodPost, "/v1/execute", bytes.NewReader(payload))
|
||||
if err != nil { t.Fatal(err) }
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
response := httptest.NewRecorder()
|
||||
mux.ServeHTTP(response, req)
|
||||
if response.Code != http.StatusAccepted { t.Fatalf("status = %d", response.Code) }
|
||||
if response.Code != http.StatusAccepted {
|
||||
t.Fatalf("status = %d", response.Code)
|
||||
}
|
||||
var queued execution
|
||||
if err := json.NewDecoder(response.Body).Decode(&queued); err != nil { t.Fatal(err) }
|
||||
if err := json.NewDecoder(response.Body).Decode(&queued); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var completed execution
|
||||
for deadline := time.Now().Add(2 * time.Second); time.Now().Before(deadline); {
|
||||
req, err = http.NewRequest(http.MethodGet, "/v1/executions/"+queued.ID, nil)
|
||||
if err != nil { t.Fatal(err) }
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
response = httptest.NewRecorder()
|
||||
mux.ServeHTTP(response, req)
|
||||
if err := json.NewDecoder(response.Body).Decode(&completed); err != nil { t.Fatal(err) }
|
||||
if completed.Status == "succeeded" { break }
|
||||
if err := json.NewDecoder(response.Body).Decode(&completed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if completed.Status == "succeeded" {
|
||||
break
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
if completed.Status != "succeeded" || !strings.Contains(completed.Output, "remote-ok status") {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
# Jeannie Remote API
|
||||
|
||||
Phase 1 adds a private remote-execution API. The local Jeannie remote client
|
||||
submits a read-only command to a Jeannie API running on Debian. The Debian
|
||||
process executes the existing Jeannie entrypoint; command logic is not
|
||||
duplicated in the API.
|
||||
The private remote-execution API exposes the public Jeannie command surface.
|
||||
The local Jeannie remote client submits a command to a Jeannie API running on
|
||||
Debian. The Debian process executes the existing Jeannie entrypoint; command
|
||||
logic is not duplicated in the API.
|
||||
|
||||
## Run locally
|
||||
|
||||
|
|
@ -20,8 +20,11 @@ From a client with network access:
|
|||
JEANNIE_REMOTE_TOKEN='replace-with-a-secret'
|
||||
./jeannie remote status
|
||||
|
||||
The initial allowlist contains read-only commands only. Execution state is
|
||||
stored in memory and command output is returned through
|
||||
`GET /v1/commands` returns the complete remotely enabled command list. Internal
|
||||
`__up-task` and recursive `remote` dispatch are excluded. This API therefore
|
||||
has the same authority as the bearer token and should remain private; commands
|
||||
such as `nuke`, `rebuild-cluster`, and `stop-cluster` are available remotely.
|
||||
Execution state is stored in memory and command output is returned through
|
||||
GET /v1/executions/{id}. It is not a public edge service and does not accept
|
||||
arbitrary shell commands.
|
||||
|
||||
|
|
|
|||
5
jeannie
5
jeannie
|
|
@ -115,7 +115,8 @@ Observability And GitOps
|
|||
dex-secret {ensure|file} Generate/check SOPS-encrypted Dex bootstrap secrets.
|
||||
gitea-runner-secret {migrate|apply|file} Convert/apply the Gitea runner SOPS secret.
|
||||
gitops-status Print focused Argo CD health and sync status.
|
||||
platform Deploy platform stack only.
|
||||
platform [all|calico|metrics|dns|metallb|ingress|storage|argocd|security|logging|monitoring|tools]
|
||||
Deploy one platform component or the full platform stack.
|
||||
edge Deploy/check the OCI edge stack only.
|
||||
edge-cache-flush Clear Nginx, Varnish, and Squid edge caches.
|
||||
promote {plan|validate|rollback APP} Run canary promotion gates and rollback plan.
|
||||
|
|
@ -259,7 +260,7 @@ case "${1:-}" in
|
|||
require_debian_server "platform"
|
||||
jeannie_log_start "platform"
|
||||
jeannie_step_plan 1
|
||||
run_step "Platform OpenTofu apply" platform_apply
|
||||
run_step "Platform OpenTofu apply" platform_apply "${2:-all}"
|
||||
echo "Log: ${JEANNIE_LOG_FILE}"
|
||||
;;
|
||||
edge)
|
||||
|
|
|
|||
|
|
@ -524,6 +524,14 @@ adopt_apps_existing_resources() {
|
|||
"supply-chain-policy"
|
||||
}
|
||||
|
||||
tofu_apply_has_targets() {
|
||||
local arg
|
||||
for arg in "$@"; do
|
||||
[[ "${arg}" == -target=* ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
ensure_homelab_node_labels() {
|
||||
local control_plane_node="${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-${LAB_CONTROL_PLANE_NODE_NAME:-debian}}"
|
||||
local raspberry_node="${LAB_RASPBERRY_NODE_NAME:-raspberry}"
|
||||
|
|
@ -636,7 +644,7 @@ tofu_apply_with_kubernetes_retry() {
|
|||
while true; do
|
||||
echo "OpenTofu ${stack} apply still hit Kubernetes API/OpenAPI read errors after ${attempt} attempt(s); trying guarded -refresh=false apply ${refresh_attempt}/${refresh_fallback_attempts}." >&2
|
||||
ensure_kubernetes_api_ready_for_tofu_stack "${stack}"
|
||||
if [[ "${stack}" == "bootstrap/platform" ]]; then
|
||||
if [[ "${stack}" == "bootstrap/platform" ]] && ! tofu_apply_has_targets "$@"; then
|
||||
adopt_platform_existing_resources
|
||||
elif [[ "${stack}" == "bootstrap/apps" ]]; then
|
||||
adopt_apps_existing_resources
|
||||
|
|
@ -668,7 +676,7 @@ tofu_apply_with_kubernetes_retry() {
|
|||
echo "OpenTofu ${stack} apply hit a transient Kubernetes API/OpenAPI error; waiting for API stability before retry ${attempt}/${max_attempts}..." >&2
|
||||
rm -f "${output_file}"
|
||||
ensure_kubernetes_api_ready_for_tofu_stack "${stack}"
|
||||
if [[ "${stack}" == "bootstrap/platform" ]]; then
|
||||
if [[ "${stack}" == "bootstrap/platform" ]] && ! tofu_apply_has_targets "$@"; then
|
||||
adopt_platform_existing_resources
|
||||
elif [[ "${stack}" == "bootstrap/apps" ]]; then
|
||||
adopt_apps_existing_resources
|
||||
|
|
@ -679,8 +687,18 @@ tofu_apply_with_kubernetes_retry() {
|
|||
|
||||
run_tofu_stack() {
|
||||
local stack="$1"
|
||||
shift
|
||||
local auto_approve="${LAB_AUTO_APPROVE:-true}"
|
||||
local -a apply_args=()
|
||||
local target
|
||||
|
||||
# Component applies use OpenTofu targets. Dependencies are still included by
|
||||
# OpenTofu, while unrelated platform resources remain untouched.
|
||||
while (($#)); do
|
||||
target="$1"
|
||||
apply_args+=("-target=${target}")
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ "${stack}" == "bootstrap/cluster" ]]; then
|
||||
ensure_cluster_worker_var_file
|
||||
|
|
@ -715,7 +733,7 @@ run_tofu_stack() {
|
|||
|
||||
tofu -chdir="${REPO_ROOT}/${stack}" init
|
||||
ensure_kubernetes_api_ready_for_tofu_stack "${stack}"
|
||||
if [[ "${stack}" == "bootstrap/platform" ]]; then
|
||||
if [[ "${stack}" == "bootstrap/platform" ]] && ! tofu_apply_has_targets "${apply_args[@]}"; then
|
||||
adopt_platform_existing_resources
|
||||
fi
|
||||
if [[ "${stack}" == "bootstrap/apps" ]]; then
|
||||
|
|
@ -7618,7 +7636,74 @@ apps() {
|
|||
platform_apply() {
|
||||
require_debian_server "platform"
|
||||
|
||||
run_tofu_stack "bootstrap/platform"
|
||||
local component="${1:-all}"
|
||||
local -a targets=()
|
||||
|
||||
case "${component}" in
|
||||
all)
|
||||
;;
|
||||
calico)
|
||||
targets=(
|
||||
helm_release.calico_crds
|
||||
null_resource.calico_helm_recovery
|
||||
helm_release.calico
|
||||
null_resource.calico_ready
|
||||
)
|
||||
;;
|
||||
metrics)
|
||||
targets=(helm_release.metrics_server null_resource.metrics_server_ready)
|
||||
;;
|
||||
dns)
|
||||
targets=(
|
||||
kubernetes_manifest.nodelocal_dns_service_account
|
||||
kubernetes_manifest.nodelocal_dns_upstream_service
|
||||
kubernetes_manifest.nodelocal_dns_config_map
|
||||
kubernetes_manifest.nodelocal_dns_daemonset
|
||||
kubernetes_manifest.nodelocal_dns_metrics_service
|
||||
)
|
||||
;;
|
||||
metallb)
|
||||
targets=(helm_release.metallb null_resource.metallb_l2_config)
|
||||
;;
|
||||
ingress)
|
||||
targets=(helm_release.traefik)
|
||||
;;
|
||||
storage)
|
||||
targets=(helm_release.openebs kubernetes_storage_class_v1.openebs_hostpath_retain)
|
||||
;;
|
||||
argocd)
|
||||
targets=(helm_release.argocd null_resource.argocd_ready null_resource.argocd_private_repo)
|
||||
;;
|
||||
security)
|
||||
targets=(
|
||||
null_resource.kyverno_helm_recovery
|
||||
helm_release.kyverno
|
||||
helm_release.kyverno_policies
|
||||
)
|
||||
;;
|
||||
logging)
|
||||
targets=(helm_release.loki helm_release.promtail)
|
||||
;;
|
||||
monitoring)
|
||||
targets=(
|
||||
kubernetes_namespace_v1.monitoring
|
||||
helm_release.mimir
|
||||
null_resource.prometheus_stack_helm_recovery
|
||||
helm_release.prometheus_stack
|
||||
null_resource.prometheus_stack_readiness
|
||||
kubernetes_config_map.grafana_dashboards
|
||||
)
|
||||
;;
|
||||
tools)
|
||||
targets=(helm_release.extra_tools)
|
||||
;;
|
||||
*)
|
||||
echo "Unknown platform component '${component}'. Use all, calico, metrics, dns, metallb, ingress, storage, argocd, security, logging, monitoring, or tools." >&2
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
|
||||
run_tofu_stack "bootstrap/platform" "${targets[@]}"
|
||||
}
|
||||
|
||||
edge_apply() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ set -euo pipefail
|
|||
REMOTE_URL="${JEANNIE_REMOTE_URL:-http://127.0.0.1:8787}"
|
||||
REMOTE_TOKEN="${JEANNIE_REMOTE_TOKEN:-${JEANNIE_SERVER_TOKEN:-}}"
|
||||
if [[ $# -lt 1 ]]; then
|
||||
echo "Usage: ./jeannie remote <read-only-command> [args...]" >&2
|
||||
echo "Usage: ./jeannie remote <jeannie-command> [args...]" >&2
|
||||
exit 2
|
||||
fi
|
||||
export JEANNIE_REMOTE_URL="${REMOTE_URL}" REMOTE_TOKEN
|
||||
|
|
|
|||
Loading…
Reference in New Issue