feat: expose Jeannie commands through remote API
This commit is contained in:
parent
e1b499f362
commit
e7f4ff8fa9
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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