aws-samples / aws-samples/sample-autonomous-cloud-coding-agents
agent: add deterministic secret and scope regex guards alongside Cedar
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 146
- フォーク
- 46
- 平均マージ
- 3日 10時間
- マージ済み PR(30日)
- 24
説明
Component
Agent (Python runtime)
Describe the feature
Add a fast, deterministic PreToolUse guard layer in agent/src/hooks.py (or a dedicated regex_guards.py) that runs before Cedar evaluation for selected tool classes. Guards should be pure regex / JSON field checks with no LLM involvement.
Minimum guard set:
| Guard | Triggers on | Blocks |
|---|---|---|
| Secret | Write, Edit, bash heredocs, Gateway push_files payloads |
AWS access keys (AKIA…), PEM blocks, ghp_/gho_/github_pat_, sk-…, Slack tokens |
| Scope | Gateway GitHub tools, git push MCP | owner/repo/issue/branch mismatch vs task context; fail-closed if task scope metadata missing |
| Bash | Bash tool |
rm -rf /, git push --force to protected refs, curl/wget with --data exfil patterns, dumping env/printenv |
Emit tool_decision / progress events when a guard blocks (for observability parity with Cedar denies).
Use case
Cedar policies express intent well but are not ideal for high-velocity pattern matching on raw file content or shell one-liners. A compromised or jailbroken model might still reach bash or write paths before policy catches edge cases.
Operators need defense-in-depth: Cedar for governance and HITL, regex guards for known credential and exfiltration shapes that must never reach the repo.
Proposed solution
- Implement guards as pure functions returning
ALLOW/DENY+ reason string. - Wire into existing
PreToolUsehook path inhooks.pybeforePolicyEngine.evaluate(). - Load scope from
agent/src/config.pytask context (repo,branch,issue_number, etc.) — same fields hydration already sets. - Add
agent/tests/test_regex_guards.pywith table-driven cases (≥10 per guard): allowed benign cases + blocked malicious cases. - Document in
docs/design/SECURITY.mdunder §Tool access control as "Layer 0: deterministic guards". - Optional: mirror critical patterns in
output_scanner.pyPostToolUse for defense in depth.
Other information
- Complements existing Cedar hard/soft deny (
docs/design/CEDAR_HITL_GATES.md) — does not replace it. - Related: #225 (egress DLP on progress events / PR content), #390 (execution-layer hardening below tool policy). This issue is PreToolUse input blocking; #225 is egress;
output_scanner.pytoday is PostToolUse only. - Scope guard should align with per-task SessionRole tags (
repo,task_id) semantics indocs/design/SECURITY.md. - Consider
nosemgreponly if semgrep flags intentional test fixtures.
Acknowledgements
- I may be able to implement this feature
- This might be a breaking change
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
agent/src/hooks.py と既存の PreToolUse パスから始め、次に agent/src/config.py を調べて task-scope の hydration と Cedar の評価呼び出しを確認してください。agent/tests/test_regex_guards.py を使って、テーブル駆動の benign ケースと malicious ケースを用意し、既存のセキュリティおよび observability の慣例について docs/design/SECURITY.md と output_scanner.py を確認してください。完了条件は、guards が Cedar より前に実行され、blocking events を発行し、要求された coverage があり、文書化されていることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- github, python
- 領域
- security
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100