Skip to content

Commit 2df3362

Browse files
PurpleCHOImsmschoi
andauthored
feat(launcher): enforced optional RoE controls in the scope wizard (#1191)
* feat(launcher): expose enforced optional RoE controls in the scope wizard The create + draft-edit wizard now collects the optional controls the runtime actually enforces, beyond in/out scope: - Authorized window length (days) — was hardcoded to 7; now operator-set and enforced by TimeWindowMiddleware. - Forbidden destinations — extra always-denied hosts (coverage guard). - Allow cloud-metadata endpoints? (default: blocked). - Allow sensitive TLDs .gov/.mil/.edu/.int? (default: blocked). scopeOptions threads through collectScope → buildRoeDocument/createDirectEngagement /writeDraftScope and into machine_enforcement (omitempty so defaults stay absent, matching the runtime). The preview shows window + forbidden + toggles. Draft edit seeds the current values via readScopeOptions. Non-enforced keys (rate limit, command patterns) are deliberately not offered — the runtime warns them unenforced. Verified on sec-dev: go build / vet / test (engagement + cmd) green; new test covers options written + omitempty + readScopeOptions round-trip. * docs(changelog): link RoE field-depth PR #1191 --------- Co-authored-by: mschoi <mschoi@elicer.com>
1 parent 013295c commit 2df3362

6 files changed

Lines changed: 234 additions & 54 deletions

File tree

‎CHAGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Keep proposed and unmerged changes out of released sections.
1515

1616
## [Unreleased]
1717

18+
- Added [enforced optional RoE controls in the scope wizard #1191](https://github.com/BitterSecurity/Decepticon/pull/1191), not released. The launcher's engagement scope wizard (create + draft-edit) now collects the optional RoE controls the runtime actually enforces: authorized **window length (days)** (was hardcoded to 7; enforced by `TimeWindowMiddleware`), **forbidden destinations** (coverage guard), and the **allow cloud-metadata** / **allow sensitive-TLD** toggles (default blocked). A `scopeOptions` value threads into `machine_enforcement` with `omitempty` so defaults stay absent; the preview shows them and the draft-edit form seeds current values. Non-enforced keys (rate limits, command patterns) are intentionally not offered. Verified on sec-dev (`go build`/`vet`/`test` green). Follow-ups: compiled-policy preview; passive-discovery depth + postgres asset inventory.
19+
1820
- Added [engagement draft→started scope lifecycle #1190](https://github.com/BitterSecurity/Decepticon/pull/1190), not released. The launcher now treats a not-yet-started engagement as a **draft** whose scope stays editable, and **locks the scope when the engagement starts** (the launcher→session handoff: TUI/desktop/background). `MarkStarted`/`IsStarted` manage a `plan/.started` marker; `writeDraftScope` is the only `roe.json` overwrite path and refuses once started; the picker labels engagements `draft — scope editable` vs `locked` and offers an Edit step on drafts (re-runs the scope wizard seeded with current targets + passive suggestions). Official stance: a different scope needs a new engagement. Verified on sec-dev (full launcher `go build`/`vet`/`test` green). Follow-ups: RoE field depth, compiled-policy preview, passive-discovery depth + postgres asset inventory.
1921

2022
- Added [launcher brings up the OpenShell gateway on start #1189](https://github.com/BitterSecurity/Decepticon/pull/1189), not released. `decepticon start` now stands up the standing OpenShell gateway (profile `openshell`, #1187) alongside the stack, so the default `openshell` sandbox provider admits the engagement out of the box — previously `start` only activated `cli` and the resolver stayed unbound. New `internal/openshell.PrepareGateway` picks the compute engine from the detected container runtime (podman → rootless, else docker), renders the engine's embedded gateway TOML into `DECEPTICON_HOME` (the launcher owns it — `SyncConfigFiles` ships only compose+litellm, not `containers/`), creates the podman data dir, and exports the `OPENSHELL_*` env the compose service reads; `start` prints a boundary banner and activates the `openshell` profile. Engine is auto-selected (no new prompt). Verified on ra-trial: a guarded live test (`OPENSHELL_LIVE=1`) runs the real `PrepareGateway` path → `compose --profile openshell up` → gateway healthy via `host.containers.internal` with the podman driver connected; `go build`/`vet`/`test` green on sec-dev. Follow-ups (separate): engagement draft/lock + asset inventory (postgres); full stack E2E.

‎clients/launcher/internal/engagement/direct_scope.go‎

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,53 @@ type directScopeWindow struct {
1919
// authorization, and the middleware enforces this block unconditionally
2020
// (post-unification there is no mode field: presence is enforcement).
2121
type machineScope struct {
22-
InScope []string `json:"in_scope"`
23-
OutOfScope []string `json:"out_of_scope"`
24-
AuthorizedWindows []directScopeWindow `json:"authorized_windows"`
22+
InScope []string `json:"in_scope"`
23+
OutOfScope []string `json:"out_of_scope"`
24+
AuthorizedWindows []directScopeWindow `json:"authorized_windows"`
25+
ForbiddenDestinations []string `json:"forbidden_destinations,omitempty"`
26+
AllowCloudMetadata bool `json:"allow_cloud_metadata,omitempty"`
27+
AllowSensitiveTLDs bool `json:"allow_sensitive_tlds,omitempty"`
2528
}
2629

2730
type machineRoeDocument struct {
2831
EngagementName string `json:"engagement_name"`
2932
MachineEnforcement machineScope `json:"machine_enforcement"`
3033
}
3134

35+
// scopeOptions carries the optional, ENFORCED RoE controls the wizard collects
36+
// beyond the in/out lists. The zero value is the safe default: a 7-day window,
37+
// no extra forbidden destinations, and cloud-metadata + sensitive TLDs blocked.
38+
// Only enforced fields are exposed — the runtime treats things like
39+
// rate-limit/command-pattern keys as "set but not enforced", so the launcher
40+
// does not offer them.
41+
type scopeOptions struct {
42+
WindowDays int // authorized window length in days (<=0 → 7)
43+
ForbiddenDestinations []string // extra always-denied destinations
44+
AllowCloudMetadata bool // allow 169.254.169.254 & friends (default: blocked)
45+
AllowSensitiveTLDs bool // allow .gov/.mil/.edu/.int (default: blocked)
46+
}
47+
48+
func (o scopeOptions) windowDays() int {
49+
if o.WindowDays <= 0 {
50+
return 7
51+
}
52+
return o.WindowDays
53+
}
54+
3255
// buildRoeDocument encodes the machine-enforced RoE JSON from the normalized
33-
// scope lists, stamping a now→now+7d authorized window.
34-
func buildRoeDocument(slug string, lists scopeLists, now time.Time) ([]byte, error) {
56+
// scope lists and options, stamping a now→now+N-day authorized window.
57+
func buildRoeDocument(slug string, lists scopeLists, opts scopeOptions, now time.Time) ([]byte, error) {
3558
now = now.UTC()
36-
end := now.AddDate(0, 0, 7)
59+
end := now.AddDate(0, 0, opts.windowDays())
3760
document := machineRoeDocument{
3861
EngagementName: slug,
3962
MachineEnforcement: machineScope{
40-
InScope: lists.InScope,
41-
OutOfScope: lists.OutOfScope,
42-
AuthorizedWindows: []directScopeWindow{{Start: now.Format(time.RFC3339), End: end.Format(time.RFC3339)}},
63+
InScope: lists.InScope,
64+
OutOfScope: lists.OutOfScope,
65+
AuthorizedWindows: []directScopeWindow{{Start: now.Format(time.RFC3339), End: end.Format(time.RFC3339)}},
66+
ForbiddenDestinations: opts.ForbiddenDestinations,
67+
AllowCloudMetadata: opts.AllowCloudMetadata,
68+
AllowSensitiveTLDs: opts.AllowSensitiveTLDs,
4369
},
4470
}
4571
raw, err := json.MarshalIndent(document, "", " ")
@@ -54,14 +80,14 @@ func buildRoeDocument(slug string, lists scopeLists, now time.Time) ([]byte, err
5480
// scope through the shared normalization contract (see scope_targets.go and
5581
// the golden vectors) and shows it for review; dropped entries are surfaced
5682
// in that preview, not re-reported here.
57-
func createDirectEngagement(home, slug string, lists scopeLists, now time.Time) (Choice, error) {
83+
func createDirectEngagement(home, slug string, lists scopeLists, opts scopeOptions, now time.Time) (Choice, error) {
5884
if err := validateSlug(home, slug); err != nil {
5985
return Choice{}, err
6086
}
6187
if len(lists.InScope) == 0 {
6288
return Choice{}, fmt.Errorf("engagement scope requires at least one in-scope target")
6389
}
64-
raw, err := buildRoeDocument(slug, lists, now)
90+
raw, err := buildRoeDocument(slug, lists, opts, now)
6591
if err != nil {
6692
return Choice{}, err
6793
}
@@ -86,7 +112,7 @@ func createDirectEngagement(home, slug string, lists scopeLists, now time.Time)
86112
// while the engagement is a draft (not yet started): once started the scope is
87113
// locked and a different scope requires a new engagement. This is the only
88114
// overwrite path for roe.json — creation never overwrites.
89-
func writeDraftScope(home, slug string, lists scopeLists, now time.Time) error {
115+
func writeDraftScope(home, slug string, lists scopeLists, opts scopeOptions, now time.Time) error {
90116
if !slugRe.MatchString(slug) {
91117
return fmt.Errorf("invalid engagement name %q", slug)
92118
}
@@ -97,7 +123,7 @@ func writeDraftScope(home, slug string, lists scopeLists, now time.Time) error {
97123
if IsStarted(root) {
98124
return fmt.Errorf("engagement %q has started; its scope is locked — create a new engagement for a different scope", slug)
99125
}
100-
raw, err := buildRoeDocument(slug, lists, now)
126+
raw, err := buildRoeDocument(slug, lists, opts, now)
101127
if err != nil {
102128
return err
103129
}

‎clients/launcher/internal/engagement/direct_scope_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestCreateDirectEngagement_MachineScopeFromCreationData(t *testing.T) {
2020
if err != nil {
2121
t.Fatal(err)
2222
}
23-
choice, err := createDirectEngagement(home, "direct-test", lists, time.Date(2026, 10, 18, 1, 0, 0, 0, time.UTC))
23+
choice, err := createDirectEngagement(home, "direct-test", lists, scopeOptions{}, time.Date(2026, 10, 18, 1, 0, 0, 0, time.UTC))
2424
if err != nil {
2525
t.Fatal(err)
2626
}
@@ -70,7 +70,7 @@ func TestCreateDirectEngagement_RejectsEmptyScopeWithoutWorkspace(t *testing.T)
7070
if listsErr != nil {
7171
err = listsErr
7272
} else {
73-
_, err = createDirectEngagement(home, "invalid-target", lists, time.Now())
73+
_, err = createDirectEngagement(home, "invalid-target", lists, scopeOptions{}, time.Now())
7474
}
7575
// Then no workspace is created.
7676
if err == nil {
@@ -105,7 +105,7 @@ func TestCreateDirectEngagement_PreservesExistingScope(t *testing.T) {
105105
t.Fatal(err)
106106
}
107107
// When another creation uses the same name.
108-
_, err = createDirectEngagement(home, "existing-test", mustLists(t, []string{"https://different.example.com"}, nil), time.Now())
108+
_, err = createDirectEngagement(home, "existing-test", mustLists(t, []string{"https://different.example.com"}, nil), scopeOptions{}, time.Now())
109109
// Then the existing scope remains intact.
110110
if err == nil {
111111
t.Fatal("reused existing engagement")
@@ -146,7 +146,7 @@ func TestCreateDirectEngagement_GoldenVectors(t *testing.T) {
146146
t.Run(tc.Name, func(t *testing.T) {
147147
home := t.TempDir()
148148
slug := fmt.Sprintf("vector-%02d", i)
149-
if _, err := createDirectEngagement(home, slug, mustLists(t, tc.Targets, tc.OutOfScope), time.Now()); err != nil {
149+
if _, err := createDirectEngagement(home, slug, mustLists(t, tc.Targets, tc.OutOfScope), scopeOptions{}, time.Now()); err != nil {
150150
t.Fatalf("create: %v", err)
151151
}
152152
raw, err := os.ReadFile(filepath.Join(home, "workspace", slug, "plan", "roe.json"))
@@ -186,7 +186,7 @@ func TestRenderScopePreview_ShowsGeneratedScope(t *testing.T) {
186186
if err != nil {
187187
t.Fatal(err)
188188
}
189-
preview := renderScopePreview("acme-2026", lists)
189+
preview := renderScopePreview("acme-2026", lists, scopeOptions{})
190190
rendered := huh.NewNote().Description(preview).WithWidth(120).View()
191191
for _, target := range lists.InScope {
192192
if !strings.Contains(rendered, target) {
@@ -213,7 +213,7 @@ func TestRenderScopePreview_ReportsDroppedEntries(t *testing.T) {
213213
if err != nil {
214214
t.Fatal(err)
215215
}
216-
preview := renderScopePreview("acme-2026", lists)
216+
preview := renderScopePreview("acme-2026", lists, scopeOptions{})
217217
rendered := huh.NewNote().Description(preview).WithWidth(120).View()
218218
for _, target := range lists.InScope {
219219
if !strings.Contains(rendered, target) {

‎clients/launcher/internal/engagement/draft_scope_test.go‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ func TestWriteDraftScopeOverwritesDraftButLocksAfterStart(t *testing.T) {
1515
roe := filepath.Join(root, "plan", "roe.json")
1616

1717
// Create the engagement (draft).
18-
if _, err := createDirectEngagement(home, slug, scopeLists{InScope: []string{"a.example.com"}}, time.Now()); err != nil {
18+
if _, err := createDirectEngagement(home, slug, scopeLists{InScope: []string{"a.example.com"}}, scopeOptions{}, time.Now()); err != nil {
1919
t.Fatalf("createDirectEngagement: %v", err)
2020
}
2121

2222
// Draft: edit allowed and takes effect.
23-
if err := writeDraftScope(home, slug, scopeLists{InScope: []string{"b.example.com"}, OutOfScope: []string{"admin.example.com"}}, time.Now()); err != nil {
23+
if err := writeDraftScope(home, slug, scopeLists{InScope: []string{"b.example.com"}, OutOfScope: []string{"admin.example.com"}}, scopeOptions{}, time.Now()); err != nil {
2424
t.Fatalf("writeDraftScope (draft): %v", err)
2525
}
2626
data, err := os.ReadFile(roe)
@@ -39,7 +39,7 @@ func TestWriteDraftScopeOverwritesDraftButLocksAfterStart(t *testing.T) {
3939
if err := MarkStarted(root); err != nil {
4040
t.Fatalf("MarkStarted: %v", err)
4141
}
42-
err = writeDraftScope(home, slug, scopeLists{InScope: []string{"c.example.com"}}, time.Now())
42+
err = writeDraftScope(home, slug, scopeLists{InScope: []string{"c.example.com"}}, scopeOptions{}, time.Now())
4343
if err == nil {
4444
t.Fatal("writeDraftScope succeeded after start; expected lock error")
4545
}
@@ -56,10 +56,43 @@ func TestWriteDraftScopeOverwritesDraftButLocksAfterStart(t *testing.T) {
5656
func TestWriteDraftScopeRejectsEmptyInScope(t *testing.T) {
5757
home := t.TempDir()
5858
slug := "empty-scope"
59-
if _, err := createDirectEngagement(home, slug, scopeLists{InScope: []string{"x.example.com"}}, time.Now()); err != nil {
59+
if _, err := createDirectEngagement(home, slug, scopeLists{InScope: []string{"x.example.com"}}, scopeOptions{}, time.Now()); err != nil {
6060
t.Fatalf("create: %v", err)
6161
}
62-
if err := writeDraftScope(home, slug, scopeLists{}, time.Now()); err == nil {
62+
if err := writeDraftScope(home, slug, scopeLists{}, scopeOptions{}, time.Now()); err == nil {
6363
t.Fatal("expected error for empty in-scope")
6464
}
6565
}
66+
67+
func TestCreateWithScopeOptionsWritesEnforcedFields(t *testing.T) {
68+
home := t.TempDir()
69+
opts := scopeOptions{
70+
WindowDays: 14,
71+
ForbiddenDestinations: []string{"metadata.internal"},
72+
AllowCloudMetadata: true,
73+
AllowSensitiveTLDs: false,
74+
}
75+
if _, err := createDirectEngagement(home, "opt-eng", scopeLists{InScope: []string{"a.example.com"}}, opts, time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)); err != nil {
76+
t.Fatalf("create: %v", err)
77+
}
78+
root := filepath.Join(home, "workspace", "opt-eng")
79+
data, err := os.ReadFile(filepath.Join(root, "plan", "roe.json"))
80+
if err != nil {
81+
t.Fatalf("read roe: %v", err)
82+
}
83+
s := string(data)
84+
for _, want := range []string{"metadata.internal", `"allow_cloud_metadata": true`, "2026-01-15T00:00:00Z"} {
85+
if !strings.Contains(s, want) {
86+
t.Errorf("roe missing %q:\n%s", want, s)
87+
}
88+
}
89+
// false toggle is omitted (omitempty) so the runtime default (blocked) holds.
90+
if strings.Contains(s, "allow_sensitive_tlds") {
91+
t.Errorf("false sensitive-TLD toggle should be omitted:\n%s", s)
92+
}
93+
// readScopeOptions round-trips the seed for the edit form.
94+
got := readScopeOptions(root)
95+
if got.WindowDays != 14 || !got.AllowCloudMetadata || got.AllowSensitiveTLDs || len(got.ForbiddenDestinations) != 1 {
96+
t.Errorf("readScopeOptions round-trip wrong: %+v", got)
97+
}
98+
}

0 commit comments

Comments
 (0)