fix(controlplane): stored container policies replace file profiles; add profile image and workflow examples

A stored container-runtime-policies document that carries Profiles now
replaces the file's profiles instead of merging into them, so a profile
deleted in the dashboard stays deleted; one stored before profiles existed
still inherits the file's. Profiles drop their json tags so the stored
document keys them like its other fields.

Adds examples/profiles/Dockerfile.agent-net (agent image plus network
lookup tools) with a build-only agent-net compose service,
examples/workflows/firewall-investigate.yaml with a test that parses every
example against the registered step vocabulary, and names the postgres
service in the compose header.
This commit is contained in:
sam committed 2026-09-24 20:58:08 +10:00
1 parent 7b7aa62c28
commit 4046766abe
8 files changed
+128 -7

No files matched your search

+4 -2
View File
@@ -461,9 +461,11 @@ target = "127.0.0.1:9090" # REQUIRED. The State Store gRPC address arch
#
# Agent profiles a workflow selects with `profile: <name>`. A workflow that
# names none runs under [containers].image with every tool.
# Once the State Store holds container policies, edit profiles in the
# dashboard (Settings, Advanced); a stored set replaces the file's.
# [containers.profiles.network-investigator]
# image = "ghcr.io/samcharles93/archie-agent-net:latest" # empty uses [containers].image
# tools = ["whois", "dns_lookup"] # allowlist over MCP, script and plugin tools; empty allows all
# image = "archie-agent-net:local" # docker compose build agent-net; empty uses [containers].image
# tools = [] # allowlist over MCP, script and plugin tools; empty allows all
# At least one [[repos]] entry is required before archied will poll
# anything -- it is deliberately left commented rather than shipped active:
+16 -1
View File
@@ -1,12 +1,15 @@
# Optional external NATS, plus the agent image the daemon spawns per task.
# PostgreSQL for the State Store, optional external NATS, and the agent images
# the daemon spawns per task.
#
# archied itself runs on the host under systemd, not here -- its chat tools
# operate on host files, which a container cannot reach. See
# deployments/systemd-user-service.md.
#
# Embedded NATS is the normal deployment and needs no Compose service.
# State Store DB: docker compose up -d postgres
# External broker: docker compose up -d nats
# Build worker: docker compose build agent
# Profile image: docker compose build agent-net
# Stop external: docker compose down
# Logs: journalctl --user -u archied -f (the daemon)
# docker compose logs -f nats (the bus)
@@ -80,6 +83,18 @@ services:
# deployments/systemd-user-service.md#pinning-the-archie-agent-image.
image: ghcr.io/samcharles93/archie-agent@sha256:870f1b1357979cfea23fccacb24166ebeb9ab321708ef2c2b218a763ed99b090
# ── example agent profile image ─────────────────────────────────────
# The agent image plus network lookup tools, for a workflow that names
# `profile: network-investigator` (examples/workflows/firewall-investigate.yaml).
# Build-only for the same reason as agent. It is local, so leave
# containers.pull_policy at "missing": "always" would try to pull it.
agent-net:
profiles: ["build"]
build:
context: examples/profiles
dockerfile: Dockerfile.agent-net
image: archie-agent-net:local
volumes:
nats_data:
pg_data:
+11
View File
@@ -0,0 +1,11 @@
# An agent profile image: the archie-agent image plus network lookup tools,
# for a workflow that investigates addresses rather than code. Select it with
# [containers.profiles.network-investigator] image = "archie-agent-net:local".
#
# Build: docker compose build agent-net
ARG AGENT_IMAGE=ghcr.io/samcharles93/archie-agent:latest
FROM ${AGENT_IMAGE}
RUN apt-get update && apt-get install -y --no-install-recommends \
whois dnsutils iputils-ping traceroute && \
rm -rf /var/lib/apt/lists/*
@@ -0,0 +1,18 @@
# A workflow with no repository: a binding on a firewall event type assigns
# src_ip from a mapped parameter and runs one agent mission in a scratch
# workspace under the network-investigator profile. Paste it into the
# dashboard's workflow definitions.
id: firewall-investigate
repository: none
profile: network-investigator
inputs:
src_ip: { type: string, required: true }
severity: { type: string }
steps:
- type: agent.run
settings:
mission: >-
Investigate the source address in the inputs: who owns it, what it
resolves to, and whether it is reachable. Report what you found and
how serious it looks given the severity.
read_only: true
+14 -1
View File
@@ -187,7 +187,20 @@ func runtimeToolConfigFrom(ctx context.Context, reader controlplanerpc.ResourceR
}); err != nil {
return config.Config{}, nil, err
}
if err := layerResourceJSON(ctx, reader, versions, ContainerRuntimePoliciesKind, &out.Containers); err != nil {
if err := layerResource(ctx, reader, versions, ContainerRuntimePoliciesKind, func(value []byte) error {
// A document that omits Profiles (one stored before they existed)
// inherits the file's. One that carries them replaces the file's:
// json.Unmarshal merges into an existing map, so without clearing it a
// profile deleted from the store would come back from the file.
var keys map[string]json.RawMessage
if err := json.Unmarshal(value, &keys); err != nil {
return err
}
if _, stored := keys["Profiles"]; stored {
out.Containers.Profiles = nil
}
return json.Unmarshal(value, &out.Containers)
}); err != nil {
return config.Config{}, nil, err
}
return out, versions, nil
@@ -333,3 +333,40 @@ func TestSchedulingPolicySeedCarriesTheLabel(t *testing.T) {
t.Fatalf("seed label = %q, want the file document's label", label)
}
}
// Stored container policies that carry profiles replace the file's outright;
// ones stored before profiles existed inherit the file's.
func TestRuntimeConfigLayersStoredProfiles(t *testing.T) {
base := config.Config{Containers: config.ContainerConfig{Image: "agent:1", Profiles: map[string]config.AgentProfile{
"file-only": {Image: "file:1"},
}}}
for _, tt := range []struct {
name string
stored map[string]any
want []string
}{
{name: "stored profiles replace the file's", stored: map[string]any{"Image": "agent:2", "Profiles": map[string]any{"net": map[string]any{"Tools": []string{"whois"}}}}, want: []string{"net"}},
{name: "a document without profiles inherits the file's", stored: map[string]any{"Image": "agent:2"}, want: []string{"file-only"}},
} {
t.Run(tt.name, func(t *testing.T) {
client := NewRPCClient(&runtimeConfigClient{values: map[string]any{
SchedulingPolicyKind: map[string]any{"poll_interval": "2m", "dispatch": map[string]any{"trigger": "assignee"}},
ContainerRuntimePoliciesKind: tt.stored,
}})
got, _, err := client.RuntimeConfig(t.Context(), base)
if err != nil {
t.Fatalf("RuntimeConfig: %v", err)
}
var names []string
for name := range got.Containers.Profiles {
names = append(names, name)
}
if !reflect.DeepEqual(names, tt.want) {
t.Fatalf("profiles = %v, want %v", names, tt.want)
}
})
}
if got := base.Containers.Profiles; len(got) != 1 {
t.Fatalf("layering mutated the file document's profiles: %v", got)
}
}
+3 -3
View File
@@ -909,7 +909,7 @@ type ContainerConfig struct {
// Profiles are the named agent profiles a workflow selects with
// `profile:`. A workflow that names none runs under the default profile:
// Image and every tool.
Profiles map[string]AgentProfile `toml:"profiles" yaml:"profiles" json:"profiles,omitempty"`
Profiles map[string]AgentProfile `toml:"profiles" yaml:"profiles"`
}
// AgentProfile is a named execution environment for an agent. Secrets and
@@ -919,12 +919,12 @@ type ContainerConfig struct {
// an operator when it is dispatched (daemon pinTaskProfile).
type AgentProfile struct {
// Image is the container image; empty means [containers].image.
Image string `toml:"image" yaml:"image" json:"image,omitempty"`
Image string `toml:"image" yaml:"image"`
// Tools allowlists the tools archie adds to the agent (MCP servers,
// repository scripts and skill plugins) by name. Empty allows them all.
// The agent loop's own file tools are always present, read-only when a
// step asks for that.
Tools []string `toml:"tools" yaml:"tools" json:"tools,omitempty"`
Tools []string `toml:"tools" yaml:"tools"`
}
// Profile resolves the profile a workflow names: "" is the default profile,
@@ -1,6 +1,8 @@
package workflowsteps
import (
"os"
"path/filepath"
"slices"
"strings"
"testing"
@@ -189,3 +191,26 @@ func TestRepoHookStepsCompileThroughTheManager(t *testing.T) {
t.Fatalf("ParseAndCompile(%q) error = %v, want the unusable rule refused by name", broken, err)
}
}
// The shipped example workflows parse against the vocabulary the roots
// register, so an example cannot drift from the steps that exist.
func TestExampleWorkflowsParse(t *testing.T) {
paths, err := filepath.Glob("../../../examples/workflows/*.yaml")
if err != nil || len(paths) == 0 {
t.Fatalf("no example workflows found: %v", err)
}
manager, err := NewManager()
if err != nil {
t.Fatal(err)
}
registry := manager.Registry()
for _, path := range paths {
src, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if _, err := workflow.ParseDefinition(string(src), registry); err != nil {
t.Errorf("%s: %v", path, err)
}
}
}