feat(security): Phase 4 — Staged Workflows / Lethal Trifecta privilege separation (#85)#403
Draft
aviadshiber wants to merge 2 commits into
Draft
feat(security): Phase 4 — Staged Workflows / Lethal Trifecta privilege separation (#85)#403aviadshiber wants to merge 2 commits into
aviadshiber wants to merge 2 commits into
Conversation
…separation (#85) Implement multi-stage agent workflows so no single container run has all three risk factors simultaneously (Sensitive Data + Untrusted Content + External Communication), eliminating the "Lethal Trifecta" attack surface. New files: - scripts/lib/staged-workflows.sh: core library — config loading, stage application (network/security/credential overrides), approval gate evaluation (small_changes / docs_only / tests_only / always policies), handoff file I/O, BiDi/zero-width sanitization at the untrusted→trusted boundary - scripts/workflow-orchestrator.sh: multi-stage runner — sequential stage execution, per-stage env isolation via `env -i`, gate checking, workflow state tracking in ~/.kapsis/workflows/ - scripts/kapsis-approve.sh: CLI approval tool — approve/reject pending gates from another terminal, Slack bot, or CI script - tests/test-staged-workflows.sh: 25 tests covering config loading, stage application, approval policies, handoff I/O, sanitization, status field, and launch-agent --stage dry-run integration Modified files: - scripts/launch-agent.sh: add --stage <name> flag; after parse_config(), source staged-workflows.sh and call stage_apply_config() to override NETWORK_MODE, KAPSIS_SECURITY_PROFILE, and ENV_KEYCHAIN per stage - scripts/lib/status.sh: add stage field to status JSON (reads KAPSIS_STATUS_STAGE env var set by launch-agent.sh) - scripts/lib/constants.sh: add KAPSIS_HANDOFFS_DIR, KAPSIS_WORKFLOWS_DIR, per-stage defaults, and approval threshold constants - agent-sandbox.yaml.template: document workflow.stages and approval config - tests/run-all-tests.sh: register test-staged-workflows.sh in security category and QUICK_TESTS list - dashboard/shared/src/index.ts: add stage: string | null to AgentStatus (Dashboard Sync Rule — keeps TypeScript mirror in lockstep with status.sh) - dashboard/ui/src/views/AgentDetail.tsx: render "Workflow Stage" card when stage field is set - dashboard/ui/src/views/AgentList.tsx: add Stage column to agents table Security properties of the default 3-stage layout: research network=filtered security=minimal credentials=none implementation network=none security=strict credentials=filtered publish network=filtered security=standard credentials=GITHUB_TOKEN only Brainstormed with ensemble (3 parallel agents): architecture exploration, security design (env -i isolation, sanitizer-must-run-on-host invariant, path traversal validation, approval-timeout-defaults-to-deny), test patterns. Closes #85 https://claude.ai/code/session_01SKBncn264jjnABaUUqTMSW
| : "${KAPSIS_HANDOFF_DIR:=${HOME}/.kapsis/handoffs}" | ||
|
|
||
| # Valid stage names built into Kapsis (users can define custom ones in YAML) | ||
| readonly KAPSIS_BUILTIN_STAGES="research implementation publish" |
| readonly KAPSIS_BUILTIN_STAGES="research implementation publish" | ||
|
|
||
| # Approval policy names supported natively | ||
| readonly KAPSIS_APPROVAL_POLICIES_LIST="small_changes docs_only tests_only always" |
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| KAPSIS_ROOT="$(dirname "$SCRIPT_DIR")" |
…us override The /kapsis-status mount point exists in this environment, so _status_get_dir() returns that path instead of $KAPSIS_STATUS_DIR. The test now uses status_get_file() to resolve the actual path rather than constructing it from the overridden dir. https://claude.ai/code/session_01SKBncn264jjnABaUUqTMSW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #85.
Implements Phase 4: Staged Workflows — Privilege Separation so no single container run ever has all three "Lethal Trifecta" risk factors at once:
Each stage runs in its own container with a tailored isolation posture:
network_modesecurity_profileresearchfilteredminimalimplementationnonestrictpublishfilteredstandardGITHUB_TOKENonlyNew files
scripts/lib/staged-workflows.sh— core library: YAML config loading, stage application (mutatesNETWORK_MODE,KAPSIS_SECURITY_PROFILE,ENV_KEYCHAIN), approval gate evaluation (policies:small_changes/docs_only/tests_only/always), handoff file I/O, BiDi + zero-width sanitization at the untrusted→trusted boundaryscripts/workflow-orchestrator.sh— sequential multi-stage runner with per-stageenv -icredential isolation, gate checking, and workflow state in~/.kapsis/workflows/scripts/kapsis-approve.sh— CLI tool to approve/reject pending gates from another terminal, Slack bot, or CI script; filesystem IPC via~/.kapsis/workflows/*/approvals/*.pending.jsontests/test-staged-workflows.sh— 25 tests: config loading, stage application, all three approval policies, handoff I/O, JSON injection escaping, BiDi sanitization, statusstagefield,--stagedry-run integrationModified files
scripts/launch-agent.sh— new--stage <name>flag; callsstage_apply_config()afterparse_config()to override isolation per stagescripts/lib/status.sh— addsstagefield to status JSON (readsKAPSIS_STATUS_STAGEset bylaunch-agent.sh)scripts/lib/constants.sh—KAPSIS_HANDOFFS_DIR,KAPSIS_WORKFLOWS_DIR, per-stage network/security defaults, approval thresholdsagent-sandbox.yaml.template— documentedworkflow.stagesandworkflow.approvalconfig sectionstests/run-all-tests.sh— registered insecuritycategory +QUICK_TESTSdashboard/shared/src/index.ts—stage: string | nullonAgentStatus(Dashboard Sync Rule)dashboard/ui/src/views/AgentDetail.tsx— "Workflow Stage" card whenstageis setdashboard/ui/src/views/AgentList.tsx— Stage column in agents tableKey security design decisions (brainstormed with ensemble)
stage_sanitize_handoff()is called fromworkflow-orchestrator.shon the host between stage exits, never inside a container. A container cannot forge its own sanitization.env -iisolation —workflow-orchestrator.shusesenv -iwhen callinglaunch-agent.shso credentials in the orchestrator's environment cannot leak into the Research stage's container, bypassing the YAML credential filter._sw_interactive_approval()defaults toreturn 1(deny) on timeout and in non-TTY contexts. An unattended terminal never silently advances.network_mode: noneon Implementation means even a successful prompt-injection attack during Research cannot exfiltrate data, since the compromised Implementation container has no outbound path.stage_name+agent_id(both validated to[a-zA-Z0-9_-]+), never from user-supplied paths.Test plan
bash tests/test-staged-workflows.sh— 25/25 PASSbash -nsyntax check on all new scriptsdashboard/shared/src/index.tsupdated in lockstep withstatus.shper Dashboard Sync Rulehttps://claude.ai/code/session_01SKBncn264jjnABaUUqTMSW
Generated by Claude Code