mirror of
https://github.com/andreicscs/HoneyWire
synced 2026-06-26 12:39:53 +00:00
refactor(api): streamline manifest fetching for wizard and update command paths
This commit is contained in:
@@ -108,7 +108,7 @@ type LoggingConfig struct {
|
||||
// MANIFEST FETCHING
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
func fetchCatalogManifests() ([]map[string]interface{}, error) {
|
||||
func fetchManifestBytes() ([]byte, error) {
|
||||
manifestURL := os.Getenv("HW_MANIFEST_URL")
|
||||
|
||||
if manifestURL == "" {
|
||||
@@ -125,7 +125,11 @@ func fetchCatalogManifests() ([]map[string]interface{}, error) {
|
||||
return nil, fmt.Errorf("manifest registry returned status %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
func fetchCatalogManifests() ([]map[string]interface{}, error) {
|
||||
body, err := fetchManifestBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -170,24 +168,13 @@ func (h *Handler) GetManifests(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
manifestURL := os.Getenv("HW_MANIFEST_URL")
|
||||
if manifestURL == "" {
|
||||
manifestURL = "https://raw.githubusercontent.com/andreicscs/HoneyWire/main/Sensors/official/manifests.json"
|
||||
}
|
||||
|
||||
resp, err := http.Get(manifestURL)
|
||||
body, err := fetchManifestBytes()
|
||||
if err != nil {
|
||||
RespondError(w, "Failed to reach manifest registry", http.StatusBadGateway)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
RespondError(w, "Manifest registry returned an error", http.StatusBadGateway)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = io.Copy(w, resp.Body)
|
||||
}
|
||||
w.Write(body)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ services:
|
||||
# 1. THE DECOY PROVISIONER: Safely creates missing files explicitly avoiding symlinks and directories.
|
||||
decoy-provisioner:
|
||||
image: ghcr.io/andreicscs/honeywire-filecanary:latest
|
||||
command: /app/sensor init
|
||||
command: /app/file-canary init
|
||||
user: "0:0"
|
||||
environment:
|
||||
- HW_DECOY_FILES=${HW_DECOY_FILES}
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
{
|
||||
"name": "decoy-provisioner",
|
||||
"image": "192.168.1.11:5000/honeywire-filecanary:dev",
|
||||
"command": "/app/filecanary init",
|
||||
"command": "/app/file-canary init",
|
||||
"user": "0:0",
|
||||
"cap_drop": ["ALL"],
|
||||
"security_opt": ["no-new-privileges:true"],
|
||||
|
||||
@@ -211,7 +211,7 @@
|
||||
{
|
||||
"name": "decoy-provisioner",
|
||||
"image": "ghcr.io/andreicscs/honeywire-filecanary:latest",
|
||||
"command": "/app/filecanary init",
|
||||
"command": "/app/file-canary init",
|
||||
"user": "0:0",
|
||||
"cap_drop": [
|
||||
"ALL"
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ define deploy_target
|
||||
chmod +x /root/wizard && \
|
||||
rm -f /etc/honeywire/config.json && \
|
||||
HW_DASHBOARD_PASSWORD="$(HUB_PASSWORD)" \
|
||||
/root/wizard --link $(HUB_URL) --registry /root/manifests.json \
|
||||
/root/wizard --link $(HUB_URL) \
|
||||
'
|
||||
endef
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/honeywire/wizard/core/api"
|
||||
"github.com/honeywire/wizard/internal/cli"
|
||||
"github.com/honeywire/wizard/internal/commands"
|
||||
"github.com/honeywire/wizard/internal/system"
|
||||
@@ -23,7 +22,6 @@ func run() error {
|
||||
|
||||
uninstallPtr := flag.Bool("uninstall", false, "Tear down and remove all managed sensors from this node")
|
||||
forcePtr := flag.Bool("force", false, "Bypass confirmation prompts (useful for automation)")
|
||||
registryPtr := flag.String("registry", api.DefaultRegistryURL, "URL or local path to manifests.json")
|
||||
linkURL := flag.String("link", "", "Hub URL to link to (e.g., https://hub.honeywire.local)")
|
||||
apiKeyPtr := flag.String("api-key", "", "Node API key (for linking to an existing node)")
|
||||
aliasPtr := flag.String("alias", "", "Custom alias for this node (defaults to OS hostname)")
|
||||
@@ -40,19 +38,19 @@ func run() error {
|
||||
}
|
||||
|
||||
if *linkURL != "" {
|
||||
return commands.HandleLink(*linkURL, *apiKeyPtr, *aliasPtr, *tagsPtr, *registryPtr, *forcePtr)
|
||||
return commands.HandleLink(*linkURL, *apiKeyPtr, *aliasPtr, *tagsPtr, *forcePtr)
|
||||
}
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) == 0 {
|
||||
return commands.HandleInteractiveMenu(*registryPtr, *forcePtr)
|
||||
return commands.HandleInteractiveMenu(*forcePtr)
|
||||
}
|
||||
|
||||
switch args[0] {
|
||||
case "apply":
|
||||
return commands.HandleApply()
|
||||
case "discover":
|
||||
return commands.HandleDiscover(*registryPtr, *forcePtr)
|
||||
return commands.HandleDiscover(*forcePtr)
|
||||
case "status":
|
||||
return commands.HandleStatus()
|
||||
case "relink":
|
||||
|
||||
@@ -31,7 +31,7 @@ var hubInjectedVars = map[string]bool{
|
||||
"HW_TEST_MODE": true,
|
||||
}
|
||||
|
||||
func HandleDiscover(registry string, force bool) error {
|
||||
func HandleDiscover(force bool) error {
|
||||
app, err := loadApp()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -58,7 +58,7 @@ func HandleDiscover(registry string, force bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
recommendations, err := buildStrategy(hostState, systemState, dockerMap, registry, app.Config, app.Random())
|
||||
recommendations, err := buildStrategy(hostState, systemState, dockerMap, app.Config, app.Random())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -253,11 +253,11 @@ func auditEnvironment() (*scanner.HostState, map[int]string, *system.SystemState
|
||||
return hostState, dockerMap, systemState, nil
|
||||
}
|
||||
|
||||
func buildStrategy(hostState *scanner.HostState, systemState *system.SystemState, dockerMap map[int]string, registry string, nodeConfig *app.NodeConfig, rng *rand.Rand) ([]*discovery.Recommendation, error) {
|
||||
func buildStrategy(hostState *scanner.HostState, systemState *system.SystemState, dockerMap map[int]string, nodeConfig *app.NodeConfig, rng *rand.Rand) ([]*discovery.Recommendation, error) {
|
||||
fmt.Printf("\n%s[*] Step 3/3: Formulating Deception Strategy...%s\n", cli.Bold, cli.Reset)
|
||||
|
||||
// Force the Wizard to pull the manifest directly from the Hub.
|
||||
registry = fmt.Sprintf("%s/api/v1/manifests?key=%s", strings.TrimRight(nodeConfig.HubURL, "/"), nodeConfig.APIKey)
|
||||
registry := fmt.Sprintf("%s/api/v1/manifests?key=%s", strings.TrimRight(nodeConfig.HubURL, "/"), nodeConfig.APIKey)
|
||||
|
||||
manifests, apiErr := api.FetchManifests(registry)
|
||||
if apiErr != nil {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/honeywire/wizard/internal/cli"
|
||||
)
|
||||
|
||||
func HandleLink(hubURL, apiKey, alias, tags, registry string, force bool) error {
|
||||
func HandleLink(hubURL, apiKey, alias, tags string, force bool) error {
|
||||
if apiKey != "" {
|
||||
if err := linkExistingNode(hubURL, apiKey); err != nil {
|
||||
return err
|
||||
@@ -24,14 +24,14 @@ func HandleLink(hubURL, apiKey, alias, tags, registry string, force bool) error
|
||||
}
|
||||
|
||||
if cli.ConfirmAction("Run host discovery now") {
|
||||
return HandleDiscover(registry, force)
|
||||
return HandleDiscover(force)
|
||||
}
|
||||
|
||||
fmt.Printf("\n %sRun 'wizard discover' when ready.%s\n\n", cli.Dim, cli.Reset)
|
||||
return nil
|
||||
}
|
||||
|
||||
func HandleInteractiveMenu(registry string, force bool) error {
|
||||
func HandleInteractiveMenu(force bool) error {
|
||||
app, err := loadApp()
|
||||
if err != nil {
|
||||
return cli.ShowOnboarding()
|
||||
@@ -74,7 +74,7 @@ func HandleInteractiveMenu(registry string, force bool) error {
|
||||
case "1":
|
||||
return HandleApply()
|
||||
case "2":
|
||||
return HandleDiscover(registry, force)
|
||||
return HandleDiscover(force)
|
||||
case "3":
|
||||
return HandleStatus()
|
||||
case "4":
|
||||
|
||||
Reference in New Issue
Block a user